|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\Translatable\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\CMS\Controllers\ContentController; |
|
6
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
7
|
|
|
use SilverStripe\CMS\Search\ContentControllerSearchExtension; |
|
8
|
|
|
use SilverStripe\CMS\Search\SearchForm; |
|
9
|
|
|
use SilverStripe\Dev\FunctionalTest; |
|
10
|
|
|
use SilverStripe\ORM\DB; |
|
11
|
|
|
use SilverStripe\ORM\Search\FulltextSearchable; |
|
12
|
|
|
use SilverStripe\Security\Member; |
|
13
|
|
|
use SilverStripe\Translatable\Model\Translatable; |
|
14
|
|
|
use SilverStripe\Versioned\Versioned; |
|
15
|
|
|
use SilverStripe\Control\HTTPRequest; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @package translatable |
|
19
|
|
|
*/ |
|
20
|
|
|
class TranslatableSearchFormTest extends FunctionalTest |
|
21
|
|
|
{ |
|
22
|
|
|
protected static $fixture_file = 'TranslatableSearchFormTest.yml'; |
|
23
|
|
|
|
|
24
|
|
|
protected $mockController; |
|
25
|
|
|
|
|
26
|
|
|
protected static $required_extensions = [ |
|
27
|
|
|
SiteTree::class => [ |
|
28
|
|
|
Translatable::class, |
|
29
|
|
|
FulltextSearchable::class . "('Title,MenuTitle,Content,MetaDescription')", |
|
30
|
|
|
], |
|
31
|
|
|
ContentController::class => [ |
|
32
|
|
|
ContentControllerSearchExtension::class, |
|
33
|
|
|
], |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @see {@link ZZZSearchFormTest} |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function waitUntilIndexingFinished() |
|
40
|
|
|
{ |
|
41
|
|
|
$schema = DB::get_schema(); |
|
42
|
|
|
if (method_exists($schema, 'waitUntilIndexingFinished')) { |
|
43
|
|
|
$schema->waitUntilIndexingFinished(); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public static function setUpBeforeClass() |
|
48
|
|
|
{ |
|
49
|
|
|
static::start(); |
|
50
|
|
|
// HACK Postgres doesn't refresh TSearch indexes when the schema changes after CREATE TABLE |
|
51
|
|
|
// MySQL will need a different table type |
|
52
|
|
|
static::$tempDB->kill(); |
|
53
|
|
|
FulltextSearchable::enable(); |
|
54
|
|
|
static::$tempDB->build(); |
|
55
|
|
|
static::resetDBSchema(true, true); |
|
56
|
|
|
parent::setUpBeforeClass(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
protected function setUp() |
|
60
|
|
|
{ |
|
61
|
|
|
parent::setUp(); |
|
62
|
|
|
|
|
63
|
|
|
$holderPage = $this->objFromFixture(SiteTree::class, 'searchformholder'); |
|
64
|
|
|
$this->mockController = new ContentController($holderPage); |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
// whenever a translation is created, canTranslate() is checked |
|
67
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
|
68
|
|
|
$admin->logIn(); |
|
69
|
|
|
|
|
70
|
|
|
$this->waitUntilIndexingFinished(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testPublishedPagesMatchedByTitleInDefaultLanguage() |
|
74
|
|
|
{ |
|
75
|
|
|
$publishedPage = $this->objFromFixture(SiteTree::class, 'publishedPage'); |
|
76
|
|
|
$publishedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); |
|
77
|
|
|
|
|
78
|
|
|
$translatedPublishedPage = $publishedPage->createTranslation('de_DE'); |
|
79
|
|
|
$translatedPublishedPage->Title = 'translatedPublishedPage'; |
|
80
|
|
|
$translatedPublishedPage->Content = 'German content'; |
|
81
|
|
|
$translatedPublishedPage->write(); |
|
82
|
|
|
$publishedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); |
|
83
|
|
|
|
|
84
|
|
|
$this->waitUntilIndexingFinished(); |
|
85
|
|
|
|
|
86
|
|
|
$lang = 'en_US'; |
|
87
|
|
|
$request = new HTTPRequest('GET', 'search', ['Search'=>'content', 'searchlocale' => $lang]); |
|
88
|
|
|
$request->setSession($this->session()); |
|
89
|
|
|
$this->mockController->setRequest($request); |
|
90
|
|
|
$sf = new SearchForm($this->mockController); |
|
91
|
|
|
$results = $sf->getResults(); |
|
92
|
|
|
|
|
93
|
|
|
$this->assertContains( |
|
94
|
|
|
$publishedPage->ID, |
|
95
|
|
|
$results->column('ID'), |
|
96
|
|
|
'Published pages are found by searchform in default language' |
|
97
|
|
|
); |
|
98
|
|
|
$this->assertNotContains( |
|
99
|
|
|
$translatedPublishedPage->ID, |
|
100
|
|
|
$results->column('ID'), |
|
101
|
|
|
'Published pages in another language are not found when searching in default language' |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
|
|
$lang = 'de_DE'; |
|
105
|
|
|
$request = new HTTPRequest('GET', 'search', ['Search'=>'content', 'searchlocale' => $lang]); |
|
106
|
|
|
$request->setSession($this->session()); |
|
107
|
|
|
$this->mockController->setRequest($request); |
|
108
|
|
|
$sf2 = new SearchForm($this->mockController); |
|
109
|
|
|
$results = $sf2->getResults(); |
|
110
|
|
|
|
|
111
|
|
|
$this->assertNotContains( |
|
112
|
|
|
$publishedPage->ID, |
|
113
|
|
|
$results->column('ID'), |
|
114
|
|
|
'Published pages in default language are not found when searching in another language' |
|
115
|
|
|
); |
|
116
|
|
|
$actual = $results->column('ID'); |
|
117
|
|
|
array_walk($actual, 'intval'); |
|
118
|
|
|
$this->assertContains( |
|
119
|
|
|
(int)$translatedPublishedPage->ID, |
|
120
|
|
|
$actual, |
|
121
|
|
|
'Published pages in another language are found when searching in this language' |
|
122
|
|
|
); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
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.