Files
Phraseanet/tests/Alchemy/Tests/Phrasea/SearchEngine/Structure/LimitedStructureTest.php
2015-07-16 18:27:48 +02:00

96 lines
3.2 KiB
PHP

<?php
namespace Alchemy\Tests\Phrasea\SearchEngine\Structure;
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', Mapping::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([$this->getCollectionStub(2)]);
$structure = new LimitedStructure($wrapped->reveal(), $options->reveal());
$wrapped->get('foo')
->shouldBeCalled()
->willReturn(
new Field('foo', Mapping::TYPE_STRING, [
'used_by_collections' => [1, 2, 3]
])
)
;
$this->assertEquals(
new Field('foo', Mapping::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([
$this->getCollectionStub(1),
$this->getCollectionStub(3)
]);
$wrapped = $this->prophesize(Structure::class);
$structure = new LimitedStructure($wrapped->reveal(), $options->reveal());
$wrapped->getAllFields()->willReturn([
'foo' => new Field('foo', Mapping::TYPE_STRING, [
'private' => false,
'used_by_collections' => [1, 2, 3]
]),
'bar' => new Field('bar', Mapping::TYPE_STRING, [
'private' => true,
'used_by_collections' => [1, 2, 3]
])
]);
$this->assertEquals([
'foo' => new Field('foo', Mapping::TYPE_STRING, [
'private' => false,
'used_by_collections' => [1, 2, 3]
]),
'bar' => new Field('bar', Mapping::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();
}
}