Change Elastic Field structure to cope with Collection base_ids

This commit is contained in:
Benoît Burnichon
2015-06-05 20:14:33 +02:00
parent acb8ed86c8
commit fea47ef5ee
4 changed files with 26 additions and 19 deletions

View File

@@ -14,8 +14,8 @@ class FieldTest extends \PHPUnit_Framework_TestCase
{
public function testBasicMerge()
{
$field = new Field('foo', Mapping::TYPE_STRING);
$other = new Field('foo', Mapping::TYPE_STRING);
$field = new Field('foo', Mapping::TYPE_STRING, ['used_by_collections' => ['1', '2']]);
$other = new Field('foo', Mapping::TYPE_STRING, ['used_by_collections' => ['3', '4']]);
$merged = $field->mergeWith($other);
$this->assertInstanceOf(Field::class, $merged);
$this->assertNotSame($field, $merged);
@@ -26,6 +26,7 @@ class FieldTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($merged->isPrivate());
$this->assertFalse($merged->isFacet());
$this->assertNull($merged->getThesaurusRoots());
$this->assertEquals(['1', '2', '3', '4'], $merged->getCollections());
}
/**

View File

@@ -34,22 +34,21 @@ class StructureTest extends \PHPUnit_Framework_TestCase
$field->isPrivate()->willReturn(false);
$field->isFacet()->willReturn(false);
$field->hasConceptInference()->willReturn(false);
$field->getCollections()->willReturn(['1']);
$structure->add($field->reveal());
$this->assertCount(1, $structure->getAllFields());
$conflicting_field = $this->prophesize(Field::class);
$conflicting_field->getName()->willReturn('foo');
$conflicting_field->getType()->willReturn(Mapping::TYPE_STRING);
$conflicting_field->isPrivate()->willReturn(false);
$conflicting_field->isFacet()->willReturn(false);
$conflicting_field->hasConceptInference()->willReturn(false);
$dummy = $conflicting_field->reveal();
$conflicting_field = new Field('foo', Mapping::TYPE_STRING, ['2']);
$field->mergeWith($dummy)->willReturn($dummy);
$merged = new Field('foo', Mapping::TYPE_STRING, ['1', '2']);
$field->mergeWith($conflicting_field)->willReturn($merged);
// Should still have only one (both have the same name)
$structure->add($dummy);
$this->assertCount(1, $structure->getAllFields());
$structure->add($conflicting_field);
$this->assertCount(1, $fields = $structure->getAllFields());
$this->assertInternalType('array', $fields);
$this->assertSame($merged, reset($fields));
}
public function testFieldMerge()
@@ -166,7 +165,7 @@ class StructureTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException DomainException
* @expectedException \DomainException
* @expectedExceptionMessageRegExp #field#u
*/
public function testPrivateCheckWithInvalidField()