|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package translatable |
|
4
|
|
|
*/ |
|
5
|
|
|
class TranslatableSearchFormTest extends FunctionalTest |
|
6
|
|
|
{ |
|
7
|
|
|
protected static $fixture_file = 'translatable/tests/unit/TranslatableSearchFormTest.yml'; |
|
8
|
|
|
|
|
9
|
|
|
protected $mockController; |
|
10
|
|
|
|
|
11
|
|
|
protected $requiredExtensions = array( |
|
12
|
|
|
'SiteTree' => array( |
|
13
|
|
|
'Translatable', |
|
14
|
|
|
"FulltextSearchable('Title,MenuTitle,Content,MetaDescription')", |
|
15
|
|
|
), |
|
16
|
|
|
"File" => array( |
|
17
|
|
|
"FulltextSearchable('Filename,Title,Content')", |
|
18
|
|
|
), |
|
19
|
|
|
"ContentController" => array( |
|
20
|
|
|
"ContentControllerSearchExtension", |
|
21
|
|
|
), |
|
22
|
|
|
); |
|
23
|
|
|
|
|
24
|
|
|
public function waitUntilIndexingFinished() |
|
25
|
|
|
{ |
|
26
|
|
|
$db = DB::getConn(); |
|
27
|
|
|
if (method_exists($db, 'waitUntilIndexingFinished')) { |
|
28
|
|
|
DB::getConn()->waitUntilIndexingFinished(); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function setUpOnce() |
|
33
|
|
|
{ |
|
34
|
|
|
// HACK Postgres doesn't refresh TSearch indexes when the schema changes after CREATE TABLE |
|
35
|
|
|
// MySQL will need a different table type |
|
36
|
|
|
self::kill_temp_db(); |
|
37
|
|
|
FulltextSearchable::enable(); |
|
38
|
|
|
self::create_temp_db(); |
|
39
|
|
|
$this->resetDBSchema(true); |
|
40
|
|
|
parent::setUpOnce(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function setUp() |
|
44
|
|
|
{ |
|
45
|
|
|
parent::setUp(); |
|
46
|
|
|
|
|
47
|
|
|
$holderPage = $this->objFromFixture('SiteTree', 'searchformholder'); |
|
48
|
|
|
$this->mockController = new ContentController($holderPage); |
|
49
|
|
|
|
|
50
|
|
|
// whenever a translation is created, canTranslate() is checked |
|
51
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
|
52
|
|
|
$admin->logIn(); |
|
53
|
|
|
|
|
54
|
|
|
$this->waitUntilIndexingFinished(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
public function testPublishedPagesMatchedByTitleInDefaultLanguage() |
|
60
|
|
|
{ |
|
61
|
|
|
$sf = new SearchForm($this->mockController, 'SearchForm'); |
|
62
|
|
|
|
|
63
|
|
|
$publishedPage = $this->objFromFixture('SiteTree', 'publishedPage'); |
|
64
|
|
|
$publishedPage->publish('Stage', 'Live'); |
|
65
|
|
|
$translatedPublishedPage = $publishedPage->createTranslation('de_DE'); |
|
66
|
|
|
$translatedPublishedPage->Title = 'translatedPublishedPage'; |
|
67
|
|
|
$translatedPublishedPage->Content = 'German content'; |
|
68
|
|
|
$translatedPublishedPage->write(); |
|
69
|
|
|
$translatedPublishedPage->publish('Stage', 'Live'); |
|
70
|
|
|
|
|
71
|
|
|
$this->waitUntilIndexingFinished(); |
|
72
|
|
|
|
|
73
|
|
|
// Translatable::set_current_locale() can't be used because the context |
|
74
|
|
|
// from the holder is not present here - we set the language explicitly |
|
75
|
|
|
// through a pseudo GET variable in getResults() |
|
76
|
|
|
|
|
77
|
|
|
$lang = 'en_US'; |
|
78
|
|
|
$results = $sf->getResults(null, array('Search'=>'content', 'searchlocale'=>$lang)); |
|
79
|
|
|
$this->assertContains( |
|
80
|
|
|
$publishedPage->ID, |
|
81
|
|
|
$results->column('ID'), |
|
82
|
|
|
'Published pages are found by searchform in default language' |
|
83
|
|
|
); |
|
84
|
|
|
$this->assertNotContains( |
|
85
|
|
|
$translatedPublishedPage->ID, |
|
86
|
|
|
$results->column('ID'), |
|
87
|
|
|
'Published pages in another language are not found when searching in default language' |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
$lang = 'de_DE'; |
|
91
|
|
|
$results = $sf->getResults(null, array('Search'=>'content', 'searchlocale'=>$lang)); |
|
92
|
|
|
$this->assertNotContains( |
|
93
|
|
|
$publishedPage->ID, |
|
94
|
|
|
$results->column('ID'), |
|
95
|
|
|
'Published pages in default language are not found when searching in another language' |
|
96
|
|
|
); |
|
97
|
|
|
$actual = $results->column('ID'); |
|
98
|
|
|
array_walk($actual, 'intval'); |
|
99
|
|
|
$this->assertContains( |
|
100
|
|
|
(int)$translatedPublishedPage->ID, |
|
101
|
|
|
$actual, |
|
102
|
|
|
'Published pages in another language are found when searching in this language' |
|
103
|
|
|
); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|