public function setUp() { parent::setUp(); self::$originalVersionInfo = Deprecation::dump_settings(); Deprecation::$notice_level = E_USER_NOTICE; Deprecation::set_enabled(true); }
public function setUp() { parent::setUp(); // This test tests code that was deprecated after 2.4 $this->originalDeprecation = Deprecation::dump_settings(); Deprecation::notification_version('2.4'); }
public function testGetArray() { $originalDeprecation = Deprecation::dump_settings(); Deprecation::notification_version('2.4'); $array = array('Foo' => 'Foo', 'Bar' => 'Bar', 'Baz' => 'Baz'); $arrayData = new ArrayData($array); $this->assertEquals($arrayData->toMap(), $array); Deprecation::restore_settings($originalDeprecation); }
/** * Get version * * @return string */ public static function getFrameworkVersion() { $lm = new LeftAndMain(); $version = $lm->CMSVersion(); if ($version) { $parts = explode(', ', $version); foreach ($parts as $part) { $p = explode(': ', $part); if ($p[0] == 'Framework') { return $p[1]; } } } // As fallback, we can use deprecation but this can be changed by the user return Deprecation::dump_settings()['version']; }
/** * Test the Group::map() function */ public function testGroupMap() { // 2.4 only $originalDeprecation = Deprecation::dump_settings(); Deprecation::notification_version('2.4'); /* Group::map() returns an SQLMap object implementing iterator. You can use foreach to get ID-Title pairs. */ // We will iterate over the map and build mapOuput to more easily call assertions on the result. $map = Group::map(); $mapOutput = $map->toArray(); $group1 = $this->objFromFixture('Group', 'group1'); $group2 = $this->objFromFixture('Group', 'group2'); /* We have added 2 groups to our fixture. They should both appear in $mapOutput. */ $this->assertEquals($mapOutput[$group1->ID], $group1->Title); $this->assertEquals($mapOutput[$group2->ID], $group2->Title); Deprecation::restore_settings($originalDeprecation); }
public function setUp() { parent::setUp(); $this->depSettings = Deprecation::dump_settings(); }
/** * Test methods that get DataObjects * - DataObject::get() * - All records of a DataObject * - Filtering * - Sorting * - Joins * - Limit * - Container class * - DataObject::get_by_id() * - DataObject::get_one() * - With and without caching * - With and without ordering */ public function testGet() { // Test getting all records of a DataObject $comments = DataObject::get('DataObjectTest_TeamComment'); $this->assertEquals(3, $comments->Count()); // Test WHERE clause $comments = DataObject::get('DataObjectTest_TeamComment', "\"Name\"='Bob'"); $this->assertEquals(1, $comments->Count()); foreach ($comments as $comment) { $this->assertEquals('Bob', $comment->Name); } // Test sorting $comments = DataObject::get('DataObjectTest_TeamComment', '', "\"Name\" ASC"); $this->assertEquals(3, $comments->Count()); $this->assertEquals('Bob', $comments->First()->Name); $comments = DataObject::get('DataObjectTest_TeamComment', '', "\"Name\" DESC"); $this->assertEquals(3, $comments->Count()); $this->assertEquals('Phil', $comments->First()->Name); // Test join - 2.4 only $originalDeprecation = Deprecation::dump_settings(); Deprecation::notification_version('2.4'); $comments = DataObject::get('DataObjectTest_TeamComment', "\"DataObjectTest_Team\".\"Title\" = 'Team 1'", "\"Name\" ASC", "INNER JOIN \"DataObjectTest_Team\"" . " ON \"DataObjectTest_TeamComment\".\"TeamID\" = \"DataObjectTest_Team\".\"ID\""); $this->assertEquals(2, $comments->Count()); $this->assertEquals('Bob', $comments->First()->Name); $this->assertEquals('Joe', $comments->Last()->Name); Deprecation::restore_settings($originalDeprecation); // Test limit $comments = DataObject::get('DataObjectTest_TeamComment', '', "\"Name\" ASC", '', '1,2'); $this->assertEquals(2, $comments->Count()); $this->assertEquals('Joe', $comments->First()->Name); $this->assertEquals('Phil', $comments->Last()->Name); // Test get_by_id() $captain1ID = $this->idFromFixture('DataObjectTest_Player', 'captain1'); $captain1 = DataObject::get_by_id('DataObjectTest_Player', $captain1ID); $this->assertEquals('Captain', $captain1->FirstName); // Test get_one() without caching $comment1 = DataObject::get_one('DataObjectTest_TeamComment', "\"Name\" = 'Joe'", false); $comment1->Comment = "Something Else"; $comment2 = DataObject::get_one('DataObjectTest_TeamComment', "\"Name\" = 'Joe'", false); $this->assertNotEquals($comment1->Comment, $comment2->Comment); // Test get_one() with caching $comment1 = DataObject::get_one('DataObjectTest_TeamComment', "\"Name\" = 'Bob'", true); $comment1->Comment = "Something Else"; $comment2 = DataObject::get_one('DataObjectTest_TeamComment', "\"Name\" = 'Bob'", true); $this->assertEquals((string) $comment1->Comment, (string) $comment2->Comment); // Test get_one() with order by without caching $comment = DataObject::get_one('DataObjectTest_TeamComment', '', false, "\"Name\" ASC"); $this->assertEquals('Bob', $comment->Name); $comment = DataObject::get_one('DataObjectTest_TeamComment', '', false, "\"Name\" DESC"); $this->assertEquals('Phil', $comment->Name); // Test get_one() with order by with caching $comment = DataObject::get_one('DataObjectTest_TeamComment', '', true, '"Name" ASC'); $this->assertEquals('Bob', $comment->Name); $comment = DataObject::get_one('DataObjectTest_TeamComment', '', true, '"Name" DESC'); $this->assertEquals('Phil', $comment->Name); }
public function testURLParams() { // 2.4 only $originalDeprecation = Deprecation::dump_settings(); Deprecation::notification_version('2.4'); Director::test('DirectorTestRule/myaction/myid/myotherid'); // TODO Works on the assumption that urlParam() is not unset after a test run, which is dodgy $this->assertEquals(Director::urlParams(), array('Controller' => 'DirectorTestRequest_Controller', 'Action' => 'myaction', 'ID' => 'myid', 'OtherID' => 'myotherid')); Deprecation::restore_settings($originalDeprecation); }
public function testLRUCleaning() { $depSettings = Deprecation::dump_settings(); Deprecation::restore_settings(array('level' => false, 'version' => false, 'moduleVersions' => false)); $cache = new ConfigTest_Config_LRU(); for ($i = 0; $i < Config_LRU::SIZE; $i++) { $cache->set($i, $i); } $this->assertEquals(Config_LRU::SIZE, count($cache->indexing)); $cache->clean(); $this->assertEquals(0, count($cache->indexing), 'Clean clears all items'); $this->assertFalse($cache->get(1), 'Clean clears all items'); $cache->set(1, 1, array('Foo')); $this->assertEquals(1, count($cache->indexing)); $cache->clean('Foo'); $this->assertEquals(0, count($cache->indexing), 'Clean items with matching tag'); $this->assertFalse($cache->get(1), 'Clean items with matching tag'); $cache->set(1, 1, array('Foo', 'Bar')); $this->assertEquals(1, count($cache->indexing)); $cache->clean('Bar'); $this->assertEquals(0, count($cache->indexing), 'Clean items with any single matching tag'); $this->assertFalse($cache->get(1), 'Clean items with any single matching tag'); Deprecation::restore_settings($depSettings); }
public function testRewriteTabPathFindOrMakeTab() { $originalDeprecation = Deprecation::dump_settings(); Deprecation::notification_version('2.4'); $fields = new FieldList(new Tabset("Root", $tab1Level1 = new Tab("Tab1Level1Renamed", $tab1Level2 = new Tab("Tab1Level2"), $tab2Level2 = new Tab("Tab2Level2")), $tab2Level1 = new Tab("Tab2Level1"))); $fields->setTabPathRewrites(array('/Root\\.Tab1Level1\\.([^.]+)$/' => 'Root.Tab1Level1Renamed.\\1', '/Root\\.Tab1Level1$/' => 'Root.Tab1Level1Renamed')); $this->assertEquals($tab1Level1, $fields->findOrMakeTab('Root.Tab1Level1'), 'findOrMakeTab() with toplevel tab under old name'); $this->assertEquals($tab1Level1, $fields->findOrMakeTab('Root.Tab1Level1Renamed'), 'findOrMakeTab() with toplevel tab under new name'); $this->assertEquals($tab1Level2, $fields->findOrMakeTab('Root.Tab1Level1.Tab1Level2'), 'findOrMakeTab() with nested tab under old parent tab name'); $this->assertEquals($tab1Level2, $fields->findOrMakeTab('Root.Tab1Level1Renamed.Tab1Level2'), 'findOrMakeTab() with nested tab under new parent tab name'); Deprecation::restore_settings($originalDeprecation); }
function setUp() { self::$originalVersionInfo = Deprecation::dump_settings(); Deprecation::$notice_level = E_USER_NOTICE; }
public function setUp() { parent::setUp(); $this->depSettings = Deprecation::dump_settings(); Deprecation::set_enabled(false); }