1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use SilverStripe\Elastica\ElasticSearcher; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Test the functionality of the Searchable extension |
8
|
|
|
* @package elastica |
9
|
|
|
*/ |
10
|
|
|
class TranslatableSearchableTest extends ElasticsearchBaseTest { |
11
|
|
|
public static $fixture_file = 'elastica/tests/ElasticaTest.yml'; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
|
15
|
|
|
public function setUpOnce() { |
16
|
|
|
//Add translatable if it exists |
17
|
|
|
if (class_exists('Translatable')) { |
18
|
|
|
SiteTree::add_extension('Translatable'); |
19
|
|
|
} |
20
|
|
|
parent::setUpOnce(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
public function setUp() { |
25
|
|
|
// this needs to be called in order to create the list of searchable |
26
|
|
|
// classes and fields that are available. Simulates part of a build |
27
|
|
|
$classes = array('SearchableTestPage', 'SiteTree', 'Page', 'FlickrPhotoTO', 'FlickrSetTO', |
28
|
|
|
'FlickrTagTO', 'FlickrAuthorTO', 'FlickrSetTO'); |
29
|
|
|
$this->requireDefaultRecordsFrom = $classes; |
30
|
|
|
// load fixtures |
31
|
|
|
parent::setUp(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function testgetFieldValuesAsArrayWithLocale() { |
37
|
|
|
if(!class_exists('Translatable')) { |
38
|
|
|
$this->markTestSkipped('Translatable not installed'); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$manyTypes = $this->objFromFixture('ManyTypesPage', 'manytypes0001'); |
42
|
|
|
$result = $manyTypes->getFieldValuesAsArray(); |
43
|
|
|
$this->generateAssertionsFromArray($result); |
44
|
|
|
|
45
|
|
|
$expected = array( |
46
|
|
|
'BooleanField' => '1', |
47
|
|
|
'CurrencyField' => '100.25', |
48
|
|
|
'DateField' => '2014-04-15', |
49
|
|
|
'DecimalField' => '0', |
50
|
|
|
'EnumField' => '', |
51
|
|
|
'HTMLTextField' => '', |
52
|
|
|
'HTMLVarcharField' => 'This is some *HTML*varchar field', |
53
|
|
|
'IntField' => '677', |
54
|
|
|
'PercentageField' => '27', |
55
|
|
|
'SS_DatetimeField' => '2014-10-18 08:24:00', |
56
|
|
|
'TextField' => 'This is a text field', |
57
|
|
|
'TimeField' => '17:48:18', |
58
|
|
|
'Title' => 'Many Types Page', |
59
|
|
|
'Content' => 'Many types of fields', |
60
|
|
|
); |
61
|
|
|
$this->assertEquals($expected, $result); |
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Test a valid identifier |
68
|
|
|
*/ |
69
|
|
|
public function testMappingWithLocale() { |
70
|
|
|
if(!class_exists('Translatable')) { |
71
|
|
|
$this->markTestSkipped('Translatable not installed'); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$manyTypes = $this->objFromFixture('ManyTypesPage', 'manytypes0001'); |
75
|
|
|
$mapping = $manyTypes->getElasticaMapping(); |
76
|
|
|
|
77
|
|
|
// Only check mapping of locale as that is what has changed |
78
|
|
|
$properties = $mapping->getProperties(); |
79
|
|
|
$localeProperties = $properties['Locale']; |
80
|
|
|
$this->assertEquals(array('type' => 'string', 'index' => 'not_analyzed'), $localeProperties); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/* |
86
|
|
|
Get a record as an Elastic document and check values |
87
|
|
|
*/ |
88
|
|
|
public function testGetElasticaDocumentWithLocale() { |
89
|
|
|
if(!class_exists('Translatable')) { |
90
|
|
|
$this->markTestSkipped('Translatable not installed'); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$this->markTestSkipped('Translatable not installed'); |
|
|
|
|
94
|
|
|
|
95
|
|
|
// Need to get something from the SiteTree |
96
|
|
|
$manyTypes = $this->objFromFixture('ManyTypesPage', 'manytypes0001'); |
97
|
|
|
$result = $manyTypes->getFieldValuesAsArray(); |
|
|
|
|
98
|
|
|
$doc = $manyTypes->getElasticaDocument()->getData(); |
99
|
|
|
|
100
|
|
|
$expected = array( |
101
|
|
|
'BooleanField' => '1', |
102
|
|
|
'CurrencyField' => '100.25', |
103
|
|
|
'DateField' => '2014-04-15', |
104
|
|
|
'DecimalField' => '0', |
105
|
|
|
'EnumField' => '', |
106
|
|
|
'HTMLTextField' => '', |
107
|
|
|
'HTMLVarcharField' => 'This is some *HTML*varchar field', |
108
|
|
|
'IntField' => '677', |
109
|
|
|
'PercentageField' => '27', |
110
|
|
|
'SS_DatetimeField' => '2014-10-18 08:24:00', |
111
|
|
|
'TextField' => 'This is a text field', |
112
|
|
|
'TimeField' => '17:48:18', |
113
|
|
|
'Title' => 'Many Types Page', |
114
|
|
|
'Content' => 'Many types of fields', |
115
|
|
|
'IsInSiteTree' => '1', |
116
|
|
|
'Link' => 'http://moduletest.silverstripe/many-types-page/', |
117
|
|
|
'Locale' => 'en_US', |
118
|
|
|
); |
119
|
|
|
$this->assertEquals($expected, $doc); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.