1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use SilverStripe\Elastica\Searchable; |
4
|
|
|
use SilverStripe\Elastica\ReindexTask; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Test that inheritance works correctly with configuration properties |
9
|
|
|
* @package elastica |
10
|
|
|
*/ |
11
|
|
|
class InheritanceTest extends ElasticsearchBaseTest { |
12
|
|
|
public static $fixture_file = 'elastica/tests/ElasticaTest.yml'; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/* |
16
|
|
|
Check that searchable and autocomplete are inherited mapping wise |
17
|
|
|
*/ |
18
|
|
|
public function testSearchableAndAutocompleteInherited() { |
19
|
|
|
$page = $this->objFromFixture('SearchableTestPage', 'first'); |
20
|
|
|
$this->assertTrue($page->hasExtension('SilverStripe\Elastica\Searchable'), |
21
|
|
|
'Page extending SiteTree has Searchable extension'); |
22
|
|
|
|
23
|
|
|
$fields = $page->getElasticaFields(); |
24
|
|
|
$terms = $page->getTermVectors(); |
25
|
|
|
|
26
|
|
|
$expected = array('first'); |
27
|
|
|
$this->assertEquals($expected, array_keys($terms['Title.standard']['terms'])); |
28
|
|
|
|
29
|
|
|
$expected = array('fi','fir','firs','first','ir','irs','irst','rs','rst','st'); |
30
|
|
|
$this->assertEquals($expected, array_keys($terms['Title.autocomplete']['terms'])); |
31
|
|
|
|
32
|
|
|
// ---- now a parental class page ---- |
33
|
|
|
$this->assertTrue(isset($fields['Title']['fields']['autocomplete'])); |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
$page = $this->objFromFixture('SearchableTestFatherPage', 'father0001'); |
37
|
|
|
$this->assertTrue($page->hasExtension('SilverStripe\Elastica\Searchable'), |
38
|
|
|
'Page extending SiteTree has Searchable extension'); |
39
|
|
|
|
40
|
|
|
$fields = $page->getElasticaFields(); |
41
|
|
|
$this->assertTrue(isset($fields['Title']['fields']['autocomplete'])); |
42
|
|
|
|
43
|
|
|
$page = $this->objFromFixture('SearchableTestGrandFatherPage', 'grandfather0001'); |
44
|
|
|
$this->assertTrue($page->hasExtension('SilverStripe\Elastica\Searchable'), |
45
|
|
|
'Page extending SiteTree has Searchable extension'); |
46
|
|
|
|
47
|
|
|
$fields = $page->getElasticaFields(); |
48
|
|
|
$this->assertTrue(isset($fields['Title']['fields']['autocomplete'])); |
49
|
|
|
|
50
|
|
|
$terms = $page->getTermVectors(); |
51
|
|
|
|
52
|
|
|
//Check the expected fields are indexed |
53
|
|
|
$expected = array('Content','Content.shingles','Content.standard','FatherText','FatherText.shingles','FatherText.standard', |
54
|
|
|
'GrandFatherText','GrandFatherText.shingles','GrandFatherText.standard','Link','Title','Title.autocomplete', |
55
|
|
|
'Title.shingles','Title.standard'); |
56
|
|
|
$indexedFields = array_keys($terms); |
57
|
|
|
sort($indexedFields); |
58
|
|
|
|
59
|
|
|
$this->assertEquals($expected, $indexedFields); |
60
|
|
|
|
61
|
|
|
$fatherTerms = $terms['FatherText.standard']['terms']; |
62
|
|
|
$grandFatherTerms = $terms['GrandFatherText.standard']['terms']; |
63
|
|
|
|
64
|
|
|
$expected = array('father', 'field', 'grandfather', 'page', 'trace3');; |
65
|
|
|
$this->assertEquals($expected, array_keys($fatherTerms)); |
66
|
|
|
|
67
|
|
|
$expected = array('grandfather', 'page', 'trace4'); |
68
|
|
|
$this->assertEquals($expected, array_keys($grandFatherTerms)); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
} |
72
|
|
|
|