mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 14:05:29 +02:00
Test for ambiguous relationships
See https://github.com/silverstripe/silverstripe-fulltextsearch/pull/145
This commit is contained in:
parent
2b3357565e
commit
b7f4c1e5f8
@ -21,6 +21,20 @@ class SearchUpdaterTest_Container extends DataObject
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to test ambiguous relationships.
|
||||||
|
*/
|
||||||
|
class SearchUpdaterTest_OtherContainer extends DataObject
|
||||||
|
{
|
||||||
|
private static $has_many = array(
|
||||||
|
'HasManyObjects' => 'SearchUpdaterTest_HasMany'
|
||||||
|
);
|
||||||
|
|
||||||
|
private static $many_many = array(
|
||||||
|
'ManyManyObjects' => 'SearchUpdaterTest_ManyMany'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
class SearchUpdaterTest_HasOne extends DataObject
|
class SearchUpdaterTest_HasOne extends DataObject
|
||||||
{
|
{
|
||||||
private static $db = array(
|
private static $db = array(
|
||||||
@ -41,7 +55,8 @@ class SearchUpdaterTest_HasMany extends DataObject
|
|||||||
);
|
);
|
||||||
|
|
||||||
private static $has_one = array(
|
private static $has_one = array(
|
||||||
'HasManyContainer' => 'SearchUpdaterTest_Container'
|
'HasManyContainer' => 'SearchUpdaterTest_Container',
|
||||||
|
'HasManyOtherContainer' => 'SearchUpdaterTest_OtherContainer'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +68,8 @@ class SearchUpdaterTest_ManyMany extends DataObject
|
|||||||
);
|
);
|
||||||
|
|
||||||
private static $belongs_many_many = array(
|
private static $belongs_many_many = array(
|
||||||
'ManyManyContainer' => 'SearchUpdaterTest_Container'
|
'ManyManyContainer' => 'SearchUpdaterTest_Container',
|
||||||
|
'ManyManyOtherContainer' => 'SearchUpdaterTest_OtherContainer'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +53,44 @@ class SolrIndexTest extends SapphireTest
|
|||||||
$this->assertEquals('SearchUpdaterTest_ManyMany', $data['class']);
|
$this->assertEquals('SearchUpdaterTest_ManyMany', $data['class']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFieldDataAmbiguousHasMany()
|
||||||
|
{
|
||||||
|
$index = new SolrIndexTest_AmbiguousRelationIndex();
|
||||||
|
$data = $index->fieldData('HasManyObjects.Field1');
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('SearchUpdaterTest_Container_HasManyObjects_Field1', $data);
|
||||||
|
$this->assertArrayHasKey('SearchUpdaterTest_OtherContainer_HasManyObjects_Field1', $data);
|
||||||
|
|
||||||
|
$dataContainer = $data['SearchUpdaterTest_Container_HasManyObjects_Field1'];
|
||||||
|
$this->assertEquals($dataContainer['origin'], 'SearchUpdaterTest_Container');
|
||||||
|
$this->assertEquals($dataContainer['base'], 'SearchUpdaterTest_Container');
|
||||||
|
$this->assertEquals($dataContainer['class'], 'SearchUpdaterTest_HasMany');
|
||||||
|
|
||||||
|
$dataOtherContainer = $data['SearchUpdaterTest_OtherContainer_HasManyObjects_Field1'];
|
||||||
|
$this->assertEquals($dataOtherContainer['origin'], 'SearchUpdaterTest_OtherContainer');
|
||||||
|
$this->assertEquals($dataOtherContainer['base'], 'SearchUpdaterTest_OtherContainer');
|
||||||
|
$this->assertEquals($dataOtherContainer['class'], 'SearchUpdaterTest_HasMany');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFieldDataAmbiguousManyMany()
|
||||||
|
{
|
||||||
|
$index = new SolrIndexTest_AmbiguousRelationIndex();
|
||||||
|
$data = $index->fieldData('ManyManyObjects.Field1');
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('SearchUpdaterTest_Container_ManyManyObjects_Field1', $data);
|
||||||
|
$this->assertArrayHasKey('SearchUpdaterTest_OtherContainer_ManyManyObjects_Field1', $data);
|
||||||
|
|
||||||
|
$dataContainer = $data['SearchUpdaterTest_Container_ManyManyObjects_Field1'];
|
||||||
|
$this->assertEquals($dataContainer['origin'], 'SearchUpdaterTest_Container');
|
||||||
|
$this->assertEquals($dataContainer['base'], 'SearchUpdaterTest_Container');
|
||||||
|
$this->assertEquals($dataContainer['class'], 'SearchUpdaterTest_ManyMany');
|
||||||
|
|
||||||
|
$dataOtherContainer = $data['SearchUpdaterTest_OtherContainer_ManyManyObjects_Field1'];
|
||||||
|
$this->assertEquals($dataOtherContainer['origin'], 'SearchUpdaterTest_OtherContainer');
|
||||||
|
$this->assertEquals($dataOtherContainer['base'], 'SearchUpdaterTest_OtherContainer');
|
||||||
|
$this->assertEquals($dataOtherContainer['class'], 'SearchUpdaterTest_ManyMany');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test boosting on SearchQuery
|
* Test boosting on SearchQuery
|
||||||
*/
|
*/
|
||||||
@ -359,3 +397,22 @@ class SolrIndexTest_BoostedIndex extends SolrIndex
|
|||||||
$this->addBoostedField('Field2', null, array(), 2.1);
|
$this->addBoostedField('Field2', null, array(), 2.1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SolrIndexTest_AmbiguousRelationIndex extends SolrIndex
|
||||||
|
{
|
||||||
|
protected function getStoredDefault()
|
||||||
|
{
|
||||||
|
// Override isDev defaulting to stored
|
||||||
|
return 'false';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->addClass('SearchUpdaterTest_Container');
|
||||||
|
$this->addClass('SearchUpdaterTest_OtherContainer');
|
||||||
|
|
||||||
|
// These relationships exist on both classes
|
||||||
|
$this->addFilterField('HasManyObjects.Field1');
|
||||||
|
$this->addFilterField('ManyManyObjects.Field1');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user