2009-01-19 03:18:41 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage testing
|
|
|
|
*/
|
|
|
|
class TranslatableSearchFormTest extends FunctionalTest {
|
|
|
|
|
|
|
|
static $fixture_file = 'sapphire/tests/search/TranslatableSearchFormTest.yml';
|
|
|
|
|
|
|
|
protected $mockController;
|
2009-04-01 18:35:32 +02:00
|
|
|
|
2010-01-13 00:03:27 +01:00
|
|
|
protected $requiredExtensions = array(
|
2010-03-15 06:14:31 +01:00
|
|
|
'SiteTree' => array(
|
|
|
|
'Translatable',
|
2010-04-01 02:56:13 +02:00
|
|
|
"FulltextSearchable('Title,MenuTitle,Content,MetaTitle,MetaDescription,MetaKeywords')",
|
2010-03-15 06:14:31 +01:00
|
|
|
),
|
|
|
|
"File" => array(
|
2010-04-01 02:56:13 +02:00
|
|
|
"FulltextSearchable('Filename,Title,Content')",
|
2010-03-15 06:14:31 +01:00
|
|
|
),
|
|
|
|
"ContentController" => array(
|
|
|
|
"ContentControllerSearchExtension",
|
|
|
|
),
|
2010-01-13 00:03:27 +01:00
|
|
|
);
|
2010-08-31 07:52:48 +02:00
|
|
|
|
|
|
|
function waitUntilIndexingFinished() {
|
|
|
|
$db = DB::getConn();
|
|
|
|
if (method_exists($db, 'waitUntilIndexingFinished')) DB::getConn()->waitUntilIndexingFinished();
|
|
|
|
}
|
2009-04-22 05:24:50 +02:00
|
|
|
|
2010-04-30 04:00:01 +02:00
|
|
|
function setUpOnce() {
|
|
|
|
// HACK Postgres doesn't refresh TSearch indexes when the schema changes after CREATE TABLE
|
|
|
|
if(is_a(DB::getConn(), 'PostgreSQLDatabase')) {
|
|
|
|
self::kill_temp_db();
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::setUpOnce();
|
|
|
|
}
|
|
|
|
|
2009-04-22 05:24:50 +02:00
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
2009-01-19 03:18:41 +01:00
|
|
|
|
|
|
|
$holderPage = $this->objFromFixture('SiteTree', 'searchformholder');
|
|
|
|
$this->mockController = new ContentController($holderPage);
|
2009-10-05 21:47:00 +02:00
|
|
|
|
|
|
|
// whenever a translation is created, canTranslate() is checked
|
|
|
|
$admin = $this->objFromFixture('Member', 'admin');
|
|
|
|
$admin->logIn();
|
2010-08-31 07:52:48 +02:00
|
|
|
|
|
|
|
$this->waitUntilIndexingFinished();
|
2009-01-19 03:18:41 +01:00
|
|
|
}
|
|
|
|
|
2010-01-13 00:03:27 +01:00
|
|
|
|
2009-01-19 03:18:41 +01:00
|
|
|
|
|
|
|
function testPublishedPagesMatchedByTitleInDefaultLanguage() {
|
|
|
|
$sf = new SearchForm($this->mockController, 'SearchForm');
|
|
|
|
|
|
|
|
$publishedPage = $this->objFromFixture('SiteTree', 'publishedPage');
|
|
|
|
$publishedPage->publish('Stage', 'Live');
|
2009-04-01 18:35:32 +02:00
|
|
|
$translatedPublishedPage = $publishedPage->createTranslation('de_DE');
|
2009-01-19 03:18:41 +01:00
|
|
|
$translatedPublishedPage->Title = 'translatedPublishedPage';
|
|
|
|
$translatedPublishedPage->Content = 'German content';
|
|
|
|
$translatedPublishedPage->write();
|
|
|
|
$translatedPublishedPage->publish('Stage', 'Live');
|
|
|
|
|
2010-08-31 07:52:48 +02:00
|
|
|
$this->waitUntilIndexingFinished();
|
|
|
|
|
2009-05-17 07:36:01 +02:00
|
|
|
// Translatable::set_current_locale() can't be used because the context
|
2009-01-19 03:18:41 +01:00
|
|
|
// from the holder is not present here - we set the language explicitly
|
|
|
|
// through a pseudo GET variable in getResults()
|
|
|
|
|
2009-04-01 18:35:32 +02:00
|
|
|
$lang = 'en_US';
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'content', 'locale'=>$lang));
|
2009-01-19 03:18:41 +01:00
|
|
|
$this->assertContains(
|
|
|
|
$publishedPage->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Published pages are found by searchform in default language'
|
|
|
|
);
|
|
|
|
$this->assertNotContains(
|
|
|
|
$translatedPublishedPage->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Published pages in another language are not found when searching in default language'
|
|
|
|
);
|
|
|
|
|
2009-04-01 18:35:32 +02:00
|
|
|
$lang = 'de_DE';
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'content', 'locale'=>$lang));
|
2009-01-19 03:18:41 +01:00
|
|
|
$this->assertNotContains(
|
|
|
|
$publishedPage->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Published pages in default language are not found when searching in another language'
|
|
|
|
);
|
2010-04-30 06:11:55 +02:00
|
|
|
$actual = $results->column('ID');
|
|
|
|
array_walk($actual, 'intval');
|
2009-01-19 03:18:41 +01:00
|
|
|
$this->assertContains(
|
2010-04-30 06:11:55 +02:00
|
|
|
(int)$translatedPublishedPage->ID,
|
|
|
|
$actual,
|
2009-01-19 03:18:41 +01:00
|
|
|
'Published pages in another language are found when searching in this language'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-08-31 07:52:48 +02:00
|
|
|
?>
|