Files
Phraseanet/tests/Alchemy/Tests/Phrasea/SearchEngine/Structure/LimitedStructureTest.php
jygaulier a70bf2fc70 PHRAS-1304_AUTO-COMPLETION_MASTER (#2061)
* PHRAS-1304_AUTO-COMPLETION_MASTER
ported from 4.0

* PHRAS-1304_AUTO-COMPLETION_MASTER
fix

* PHRAS-1304_AUTO-COMPLETION_MASTER
fix

* PHRAS-1304_AUTO-COMPLETION_MASTER
bump php version to 5.5.31 (5.5.21 is obsolete in cicleci)

* PHRAS-1304_AUTO-COMPLETION_MASTER
bump php version to 5.5.31 : php.ini moved in circelci

* PHRAS-1304_AUTO-COMPLETION_MASTER
add zmq & date to php for circleci

* PHRAS-1304_AUTO-COMPLETION_MASTER
add zmq

* PHRAS-1304_AUTO-COMPLETION_MASTER
bump amqp

* PHRAS-1304_AUTO-COMPLETION_MASTER
downgrade amqp to 1.2 to test compilation against old librabbit 0.4 (ubuntu)

* PHRAS-1304_AUTO-COMPLETION_MASTER
add amqp.so to php.ini, (re)bump amqp to 1.6

* PHRAS-1304_AUTO-COMPLETION_MASTER
build rabittmq from git

* PHRAS-1304_AUTO-COMPLETION_MASTER
build rabittmq from git again

* PHRAS-1304_AUTO-COMPLETION_MASTER
build rabittmq from git again and again

* PHRAS-1304_AUTO-COMPLETION_MASTER
fix test on media rotation 600*400 -> 400*599 !!!

* PHRAS-1304_AUTO-COMPLETION_MASTER
restore facebook sdk to 4.0.1 due to mistake

* PHRAS-1304_AUTO-COMPLETION_MASTER
deleted unwanted file
2017-02-06 18:26:56 +01:00

94 lines
3.2 KiB
PHP

<?php
namespace Alchemy\Tests\Phrasea\SearchEngine\Structure;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\LimitedStructure;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Structure;
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
/**
* @group unit
* @group structure
*/
class LimitedStructureTest extends \PHPUnit_Framework_TestCase
{
public function testGetUnrestrictedFields()
{
$field = new Field('foo', FieldMapping::TYPE_STRING);
$wrapped = $this->prophesize(Structure::class);
$wrapped
->getUnrestrictedFields()
->shouldBeCalled()
->willReturn(['foo' => $field]);
$options = $this->prophesize(SearchEngineOptions::class);
$structure = new LimitedStructure($wrapped->reveal(), $options->reveal());
$this->assertEquals(['foo' => $field], $structure->getUnrestrictedFields());
}
public function testGet()
{
$wrapped = $this->prophesize(Structure::class);
$options = $this->prophesize(SearchEngineOptions::class);
$options->getBusinessFieldsOn()->willReturn([2]);
$structure = new LimitedStructure($wrapped->reveal(), $options->reveal());
$wrapped->get('foo')
->shouldBeCalled()
->willReturn(
new Field('foo', FieldMapping::TYPE_STRING, [
'used_by_collections' => [1, 2, 3]
])
)
;
$this->assertEquals(
new Field('foo', FieldMapping::TYPE_STRING, [
'used_by_collections' => [2]
]),
$structure->get('foo')
);
$wrapped->get('bar')->shouldBeCalled();
$this->assertNull($structure->get('bar'));
}
public function testGetAllFields()
{
$options = $this->prophesize(SearchEngineOptions::class);
$options->getBusinessFieldsOn()->willReturn([1, 3]);
$wrapped = $this->prophesize(Structure::class);
$structure = new LimitedStructure($wrapped->reveal(), $options->reveal());
$wrapped->getAllFields()->willReturn([
'foo' => new Field('foo', FieldMapping::TYPE_STRING, [
'private' => false,
'used_by_collections' => [1, 2, 3]
]),
'bar' => new Field('bar', FieldMapping::TYPE_STRING, [
'private' => true,
'used_by_collections' => [1, 2, 3]
])
]);
$this->assertEquals([
'foo' => new Field('foo', FieldMapping::TYPE_STRING, [
'private' => false,
'used_by_collections' => [1, 2, 3]
]),
'bar' => new Field('bar', FieldMapping::TYPE_STRING, [
'private' => true,
'used_by_collections' => [1, 3]
])
], $structure->getAllFields());
}
private function getCollectionStub($base_id)
{
$prophecy = $this->prophesize(\collection::class);
$prophecy->get_base_id()->willReturn($base_id);
return $prophecy->reveal();
}
}