mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-08 18:51:12 +02:00
API CHANGE Changed Translatable datamodel to use locales ("en_US") instead of lang values ("en). API CHANGE Changed Translatable::$default_lang to $default_locale, Translatable::$reading_lang to $reading_locale API CHANGE Using "locale" instead of "lang" in Translatable::choose_site_lang() to auto-detect language from cookies or GET parameters API CHANGE Deprecated Translatable::is_default_lang(), set_default_lang(), get_default_lang(), current_lang(), set_reading_lang(), get_reading_lang(), get_by_lang(), get_one_by_lang() API CHANGE Removed Translatable::get_original() - with the new "translation groups" concept there no longer is an original for a translation BUGFIX Updated MigrateTranslatableTask to new Locale based datamodel git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@73468 467b73ca-7a2a-4603-9d3b-597d59a354a9
88 lines
2.9 KiB
PHP
88 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* @package sapphire
|
|
* @subpackage testing
|
|
*/
|
|
class TranslatableSearchFormTest extends FunctionalTest {
|
|
|
|
static $fixture_file = 'sapphire/tests/search/TranslatableSearchFormTest.yml';
|
|
|
|
protected $mockController;
|
|
|
|
protected $recreateTempDb = true;
|
|
|
|
function setUp() {
|
|
$this->origTranslatableSettings['enabled'] = Translatable::is_enabled();default_locale
|
|
$this->origTranslatableSettings['default_locale'] = Translatable::default_locale();
|
|
Translatable::enable();
|
|
Translatable::set_default_locale("en");
|
|
|
|
// needs to recreate the database schema with language properties
|
|
self::kill_temp_db();
|
|
// refresh the decorated statics - different fields in $db with Translatable enabled
|
|
singleton('SiteTree')->loadExtraStatics();
|
|
singleton('TranslatableTest_DataObject')->loadExtraStatics();
|
|
$dbname = self::create_temp_db();
|
|
DB::set_alternative_database_name($dbname);
|
|
|
|
parent::setUp();
|
|
|
|
$holderPage = $this->objFromFixture('SiteTree', 'searchformholder');
|
|
$this->mockController = new ContentController($holderPage);
|
|
}
|
|
|
|
function tearDown() {
|
|
if(!$this->origTranslatableSettings['enabled']) Translatable::disable();
|
|
|
|
Translatable::set_default_locale($this->origTranslatableSettings['default_locale']);
|
|
|
|
self::kill_temp_db();
|
|
self::create_temp_db();
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
function testPublishedPagesMatchedByTitleInDefaultLanguage() {
|
|
$sf = new SearchForm($this->mockController, 'SearchForm');
|
|
|
|
$publishedPage = $this->objFromFixture('SiteTree', 'publishedPage');
|
|
$publishedPage->publish('Stage', 'Live');
|
|
$translatedPublishedPage = $publishedPage->createTranslation('de');
|
|
$translatedPublishedPage->Title = 'translatedPublishedPage';
|
|
$translatedPublishedPage->Content = 'German content';
|
|
$translatedPublishedPage->write();
|
|
$translatedPublishedPage->publish('Stage', 'Live');
|
|
|
|
// Translatable::set_reading_locale() can't be used because the context
|
|
// from the holder is not present here - we set the language explicitly
|
|
// through a pseudo GET variable in getResults()
|
|
|
|
$lang = 'en';
|
|
$results = $sf->getResults(null, array('Search'=>'content', 'lang'=>$lang));
|
|
$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'
|
|
);
|
|
|
|
$lang = 'de';
|
|
$results = $sf->getResults(null, array('Search'=>'content', 'lang'=>$lang));
|
|
$this->assertNotContains(
|
|
$publishedPage->ID,
|
|
$results->column('ID'),
|
|
'Published pages in default language are not found when searching in another language'
|
|
);
|
|
$this->assertContains(
|
|
(string)$translatedPublishedPage->ID,
|
|
$results->column('ID'),
|
|
'Published pages in another language are found when searching in this language'
|
|
);
|
|
}
|
|
|
|
}
|
|
?>
|