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
|
|
|
/**
|
|
|
|
* @todo Necessary because of monolithic Translatable design
|
|
|
|
*/
|
2009-04-22 05:22:09 +02:00
|
|
|
static protected $origTranslatableSettings = array();
|
2009-04-01 18:35:32 +02:00
|
|
|
|
2009-04-22 05:22:09 +02:00
|
|
|
static function set_up_once() {
|
2009-01-19 03:18:41 +01:00
|
|
|
// needs to recreate the database schema with language properties
|
|
|
|
self::kill_temp_db();
|
2009-04-01 18:35:32 +02:00
|
|
|
|
|
|
|
// store old defaults
|
2009-04-22 05:22:09 +02:00
|
|
|
self::$origTranslatableSettings['has_extension'] = singleton('SiteTree')->hasExtension('Translatable');
|
|
|
|
self::$origTranslatableSettings['default_locale'] = Translatable::default_locale();
|
2009-04-01 18:35:32 +02:00
|
|
|
|
|
|
|
// overwrite locale
|
|
|
|
Translatable::set_default_locale("en_US");
|
|
|
|
|
2009-01-19 03:18:41 +01:00
|
|
|
// refresh the decorated statics - different fields in $db with Translatable enabled
|
2009-04-22 05:22:09 +02:00
|
|
|
if(!self::$origTranslatableSettings['has_extension']) Object::add_extension('SiteTree', 'Translatable');
|
2009-04-01 18:35:32 +02:00
|
|
|
Object::add_extension('TranslatableTest_DataObject', 'Translatable');
|
|
|
|
|
|
|
|
// clear singletons, they're caching old extension info which is used in DatabaseAdmin->doBuild()
|
|
|
|
global $_SINGLETONS;
|
|
|
|
$_SINGLETONS = array();
|
|
|
|
|
|
|
|
// @todo Hack to refresh statics on the newly decorated classes
|
|
|
|
$newSiteTree = new SiteTree();
|
|
|
|
foreach($newSiteTree->getExtensionInstances() as $extInstance) {
|
|
|
|
$extInstance->loadExtraStatics();
|
|
|
|
}
|
|
|
|
// @todo Hack to refresh statics on the newly decorated classes
|
|
|
|
$TranslatableTest_DataObject = new TranslatableTest_DataObject();
|
|
|
|
foreach($TranslatableTest_DataObject->getExtensionInstances() as $extInstance) {
|
|
|
|
$extInstance->loadExtraStatics();
|
|
|
|
}
|
|
|
|
|
|
|
|
// recreate database with new settings
|
2009-01-19 03:18:41 +01:00
|
|
|
$dbname = self::create_temp_db();
|
|
|
|
DB::set_alternative_database_name($dbname);
|
2009-04-01 18:35:32 +02:00
|
|
|
|
2009-04-22 05:22:09 +02:00
|
|
|
parent::set_up_once();
|
2009-01-19 03:18:41 +01:00
|
|
|
|
|
|
|
$holderPage = $this->objFromFixture('SiteTree', 'searchformholder');
|
|
|
|
$this->mockController = new ContentController($holderPage);
|
|
|
|
}
|
|
|
|
|
2009-04-22 05:22:09 +02:00
|
|
|
static function tear_down_once() {
|
|
|
|
if(!self::$origTranslatableSettings['has_extension']) Object::remove_extension('SiteTree', 'Translatable');
|
2009-01-19 03:18:41 +01:00
|
|
|
|
2009-04-22 05:22:09 +02:00
|
|
|
Translatable::set_default_locale(self::$origTranslatableSettings['default_locale']);
|
2009-01-19 03:18:41 +01:00
|
|
|
|
|
|
|
self::kill_temp_db();
|
|
|
|
self::create_temp_db();
|
|
|
|
|
2009-04-22 05:22:09 +02:00
|
|
|
parent::tear_down_once();
|
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');
|
|
|
|
|
ENHANCEMENT Adjusted SearchForm, Debug, ErrorPage, SiteTree to using locales instead of lang codes
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
2009-03-20 09:47:06 +01:00
|
|
|
// Translatable::set_reading_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'
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
(string)$translatedPublishedPage->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Published pages in another language are found when searching in this language'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
?>
|