|
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
|
1 |
|
public function testSearchableAndAutocompleteInherited() { |
|
19
|
1 |
|
$page = $this->objFromFixture('SearchableTestPage', 'first'); |
|
20
|
1 |
|
$this->assertTrue($page->hasExtension('SilverStripe\Elastica\Searchable'), |
|
21
|
1 |
|
'Page extending SiteTree has Searchable extension'); |
|
22
|
|
|
|
|
23
|
1 |
|
$fields = $page->getElasticaFields(); |
|
24
|
1 |
|
$terms = $page->getTermVectors(); |
|
25
|
|
|
|
|
26
|
1 |
|
$expected = array('first'); |
|
27
|
1 |
|
$this->assertEquals($expected, array_keys($terms['Title.standard']['terms'])); |
|
28
|
|
|
|
|
29
|
1 |
|
$expected = array('fi','fir','firs','first','ir','irs','irst','rs','rst','st'); |
|
30
|
1 |
|
$this->assertEquals($expected, array_keys($terms['Title.autocomplete']['terms'])); |
|
31
|
|
|
|
|
32
|
|
|
// ---- now a parental class page ---- |
|
33
|
1 |
|
$this->assertTrue(isset($fields['Title']['fields']['autocomplete'])); |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
1 |
|
$page = $this->objFromFixture('SearchableTestFatherPage', 'father0001'); |
|
37
|
1 |
|
$this->assertTrue($page->hasExtension('SilverStripe\Elastica\Searchable'), |
|
38
|
1 |
|
'Page extending SiteTree has Searchable extension'); |
|
39
|
|
|
|
|
40
|
1 |
|
$fields = $page->getElasticaFields(); |
|
41
|
1 |
|
$this->assertTrue(isset($fields['Title']['fields']['autocomplete'])); |
|
42
|
|
|
|
|
43
|
1 |
|
$page = $this->objFromFixture('SearchableTestGrandFatherPage', 'grandfather0001'); |
|
44
|
1 |
|
$this->assertTrue($page->hasExtension('SilverStripe\Elastica\Searchable'), |
|
45
|
1 |
|
'Page extending SiteTree has Searchable extension'); |
|
46
|
|
|
|
|
47
|
1 |
|
$fields = $page->getElasticaFields(); |
|
48
|
1 |
|
$this->assertTrue(isset($fields['Title']['fields']['autocomplete'])); |
|
49
|
|
|
|
|
50
|
1 |
|
$terms = $page->getTermVectors(); |
|
51
|
|
|
|
|
52
|
|
|
//Check the expected fields are indexed |
|
53
|
1 |
|
$expected = array('Content','Content.shingles','Content.standard','FatherText','FatherText.shingles','FatherText.standard', |
|
54
|
1 |
|
'GrandFatherText','GrandFatherText.shingles','GrandFatherText.standard','Link','Title','Title.autocomplete', |
|
55
|
1 |
|
'Title.shingles','Title.standard'); |
|
56
|
1 |
|
$indexedFields = array_keys($terms); |
|
57
|
1 |
|
sort($indexedFields); |
|
58
|
|
|
|
|
59
|
1 |
|
$this->assertEquals($expected, $indexedFields); |
|
60
|
|
|
|
|
61
|
1 |
|
$fatherTerms = $terms['FatherText.standard']['terms']; |
|
62
|
1 |
|
$grandFatherTerms = $terms['GrandFatherText.standard']['terms']; |
|
63
|
|
|
|
|
64
|
1 |
|
$expected = array('father', 'field', 'grandfather', 'page', 'trace3');; |
|
65
|
1 |
|
$this->assertEquals($expected, array_keys($fatherTerms)); |
|
66
|
|
|
|
|
67
|
1 |
|
$expected = array('grandfather', 'page', 'trace4'); |
|
68
|
1 |
|
$this->assertEquals($expected, array_keys($grandFatherTerms)); |
|
69
|
1 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|