diff --git a/tests/ObjectStaticTest.php b/tests/ObjectStaticTest.php new file mode 100644 index 000000000..820bc2ca5 --- /dev/null +++ b/tests/ObjectStaticTest.php @@ -0,0 +1,79 @@ +assertEquals(Object::get_static('ObjectStaticTest_First', 'first'), array('test_1')); + $this->assertEquals(Object::get_static('ObjectStaticTest_Second', 'first'), array('test_2')); + $this->assertEquals(Object::get_static('ObjectStaticTest_Third', 'first'), array('test_3')); + + Object::addStaticVars('ObjectStaticTest_First', array('first' => array('test_1_2'))); + Object::addStaticVars('ObjectStaticTest_Third', array('first' => array('test_3_2'))); + Object::addStaticVars('ObjectStaticTest_Fourth', array('first' => array('test_4'))); + + $this->assertEquals(Object::get_static('ObjectStaticTest_First', 'first', true), array('test_1_2', 'test_1')); + $this->assertEquals(Object::get_static('ObjectStaticTest_Second', 'first', true), array('test_1_2', 'test_2')); + $this->assertEquals(Object::get_static('ObjectStaticTest_Third', 'first', true), array('test_1_2', 'test_3_2', 'test_3')); + } + + /** + * Test {@link Object::addStaticVar()} correctly replaces static vars + */ + public function testAddStaticReplace() { + Object::addStaticVars('ObjectStaticTest_Fourth', array('second' => array('test_4')), true); + Object::addStaticVars('ObjectStaticTest_Third', array('second' => array('test_3_2'))); + + $this->assertEquals(Object::get_static('ObjectStaticTest_Fourth', 'second', true), array('test_4')); + $this->assertEquals(Object::get_static('ObjectStaticTest_Third', 'second', true), array('test_3_2', 'test_3')); + + Object::addStaticVars('ObjectStaticTest_Third', array('second' => array('test_3_2')), true); + $this->assertEquals(Object::get_static('ObjectStaticTest_Third', 'second', true), array('test_3_2')); + + Object::add_static_var('ObjectStaticTest_Third', 'fourth', array('test_3_2')); + $this->assertEquals(Object::get_static('ObjectStaticTest_Fourth', 'fourth', true), array('test_3_2', 'test_4')); + + Object::add_static_var('ObjectStaticTest_Third', 'fourth', array('test_3_2'), true); + $this->assertEquals(Object::get_static('ObjectStaticTest_Fourth', 'fourth', true), array('test_4', 'test_3_2')); + } + + /** + * Tests {@link Object::uninherited_static()} + */ + public function testUninherited() { + $this->assertEquals(Object::uninherited_static('ObjectStaticTest_First', 'third', true), 'test_1'); + $this->assertEquals(Object::uninherited_static('ObjectStaticTest_Fourth', 'third', true), null); + } + +} + +/**#@+ + * @ignore + */ +class ObjectStaticTest_First extends Object { + public static $first = array('test_1'); + public static $second = array('test_1'); + public static $third = 'test_1'; +} + +class ObjectStaticTest_Second extends ObjectStaticTest_First { + public static $first = array('test_2'); +} + +class ObjectStaticTest_Third extends ObjectStaticTest_Second { + public static $first = array('test_3'); + public static $second = array('test_3'); + public static $fourth = array('test_3'); +} + +class ObjectStaticTest_Fourth extends ObjectStaticTest_Third { + public static $fourth = array('test_4'); +} +/**#@-*/ diff --git a/tests/search/TranslatableSearchFormTest.php b/tests/search/TranslatableSearchFormTest.php new file mode 100644 index 000000000..3aec62908 --- /dev/null +++ b/tests/search/TranslatableSearchFormTest.php @@ -0,0 +1,115 @@ +hasExtension('Translatable'); + self::$origTranslatableSettings['default_locale'] = Translatable::default_locale(); + + // overwrite locale + Translatable::set_default_locale("en_US"); + + // refresh the decorated statics - different fields in $db with Translatable enabled + if(!self::$origTranslatableSettings['has_extension']) Object::add_extension('SiteTree', 'Translatable'); + 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 + $dbname = self::create_temp_db(); + DB::set_alternative_database_name($dbname); + + parent::set_up_once(); + } + + function setUp() { + parent::setUp(); + + $holderPage = $this->objFromFixture('SiteTree', 'searchformholder'); + $this->mockController = new ContentController($holderPage); + } + + static function tear_down_once() { + if(!self::$origTranslatableSettings['has_extension']) Object::remove_extension('SiteTree', 'Translatable'); + + Translatable::set_default_locale(self::$origTranslatableSettings['default_locale']); + + self::kill_temp_db(); + self::create_temp_db(); + + parent::tear_down_once(); + } + + function testPublishedPagesMatchedByTitleInDefaultLanguage() { + $sf = new SearchForm($this->mockController, 'SearchForm'); + + $publishedPage = $this->objFromFixture('SiteTree', 'publishedPage'); + $publishedPage->publish('Stage', 'Live'); + $translatedPublishedPage = $publishedPage->createTranslation('de_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_US'; + $results = $sf->getResults(null, array('Search'=>'content', 'locale'=>$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_DE'; + $results = $sf->getResults(null, array('Search'=>'content', 'locale'=>$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' + ); + } + +} +?> \ No newline at end of file diff --git a/tests/search/TranslatableSearchFormTest.yml b/tests/search/TranslatableSearchFormTest.yml new file mode 100644 index 000000000..22a7c56f9 --- /dev/null +++ b/tests/search/TranslatableSearchFormTest.yml @@ -0,0 +1,7 @@ +SiteTree: + searchformholder: + URLSegment: searchformholder + Title: searchformholder + publishedPage: + Title: publishedPage + Content: English content \ No newline at end of file