Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MINOR Tidy up of code formatting in TestRunner

MINOR Fixing up old ObjectStaticTest and merging into ConfigTest
  • Loading branch information...
commit 16e950cb6aa9d80912724124ef0ad826f641c6dd 1 parent 4c6be29
@halkyon halkyon authored
View
2  admin/code/CMSBatchActionHandler.php
@@ -203,7 +203,7 @@ function batchActionList() {
* @return array See {@link register()} for the returned format.
*/
function batchActions() {
- $actions = Config::inst()->get($this->class, 'batch_actions', Config::FIRST_SET)
+ $actions = Config::inst()->get($this->class, 'batch_actions', Config::FIRST_SET);
if($actions) foreach($actions as $action) {
if($action['recordClass'] != $this->recordClass) unset($action);
}
View
25 dev/TestRunner.php
@@ -254,19 +254,20 @@ function module($request, $coverage = false) {
*/
function runTests($classList, $coverage = false) {
$startTime = microtime(true);
-
- // XDEBUG seem to cause problems with test execution :-(
+
+ // disable xdebug, as it messes up test execution
if(function_exists('xdebug_disable')) xdebug_disable();
-
- ini_set('max_execution_time', 0);
-
+
+ ini_set('max_execution_time', 0);
+
$this->setUp();
-
+
// Optionally skip certain tests
$skipTests = array();
if($this->request->getVar('SkipTests')) {
$skipTests = explode(',', $this->request->getVar('SkipTests'));
}
+
$classList = array_diff($classList, $skipTests);
// run tests before outputting anything to the client
@@ -281,16 +282,14 @@ class_exists($className);
// Remove the error handler so that PHPUnit can add its own
restore_error_handler();
-
self::$default_reporter->writeHeader("SilverStripe Test Runner");
- if (count($classList) > 1) {
+ if (count($classList) > 1) {
self::$default_reporter->writeInfo("All Tests", "Running test cases: ",implode(", ", $classList));
- } else
- if (count($classList) == 1) {
- self::$default_reporter->writeInfo($classList[0], "");
+ } elseif (count($classList) == 1) {
+ self::$default_reporter->writeInfo($classList[0], '');
} else {
- // border case: no tests are available.
- self::$default_reporter->writeInfo("", "");
+ // border case: no tests are available.
+ self::$default_reporter->writeInfo('', '');
}
// perform unit tests (use PhpUnitWrapper or derived versions)
View
86 tests/core/ConfigTest.php
@@ -17,8 +17,94 @@ class ConfigTest_DefinesFooDoesntExtendObject {
protected static $foo = 4;
}
+class ConfigStaticTest_First extends Config {
+ public static $first = array('test_1');
+ public static $second = array('test_1');
+ public static $third = 'test_1';
+}
+
+class ConfigStaticTest_Second extends ConfigStaticTest_First {
+ public static $first = array('test_2');
+}
+
+class ConfigStaticTest_Third extends ConfigStaticTest_Second {
+ public static $first = array('test_3');
+ public static $second = array('test_3');
+ public static $fourth = array('test_3');
+}
+
+class ConfigStaticTest_Fourth extends ConfigStaticTest_Third {
+ public static $fourth = array('test_4');
+}
+
+class ConfigStaticTest_Combined1 extends Config {
+ public static $first = array('test_1');
+ public static $second = array('test_1');
+}
+
+class ConfigStaticTest_Combined2 extends ConfigStaticTest_Combined1 {
+ public static $first = array('test_2');
+ public static $second = null;
+}
+
+class ConfigStaticTest_Combined3 extends ConfigStaticTest_Combined2 {
+ public static $first = array('test_3');
+ public static $second = array('test_3');
+}
+
class ConfigTest extends SapphireTest {
+ function testUpdateStatic() {
+ $this->assertEquals(Config::inst()->get('ConfigStaticTest_First', 'first', Config::FIRST_SET), array('test_1'));
+ $this->assertEquals(Config::inst()->get('ConfigStaticTest_Second', 'first', Config::FIRST_SET), array('test_2'));
+ $this->assertEquals(Config::inst()->get('ConfigStaticTest_Third', 'first', Config::FIRST_SET), array('test_3'));
+
+ Config::inst()->update('ConfigStaticTest_First', 'first', array('test_1_2'));
+ Config::inst()->update('ConfigStaticTest_Third', 'first', array('test_3_2'));
+ Config::inst()->update('ConfigStaticTest_Fourth', 'first', array('test_4'));
+
+ $this->assertEquals(Config::inst()->get('ConfigStaticTest_First', 'first', Config::FIRST_SET), array('test_1_2', 'test_1'));
+
+ Config::inst()->update('ConfigStaticTest_Fourth', 'second', array('test_4'));
+ Config::inst()->update('ConfigStaticTest_Third', 'second', array('test_3_2'));
+
+ $this->assertEquals(Config::inst()->get('ConfigStaticTest_Fourth', 'second', Config::FIRST_SET), array('test_4'));
+ $this->assertEquals(Config::inst()->get('ConfigStaticTest_Third', 'second', Config::FIRST_SET), array('test_3_2', 'test_3'));
+
+ Config::inst()->remove('ConfigStaticTest_Third', 'second');
+ Config::inst()->update('ConfigStaticTest_Third', 'second', array('test_3_2'));
+ $this->assertEquals(Config::inst()->get('ConfigStaticTest_Third', 'second', Config::FIRST_SET), array('test_3_2'));
+ }
+
+ function testUninheritedStatic() {
+ $this->assertEquals(Config::inst()->get('ConfigStaticTest_First', 'third', Config::UNINHERITED), 'test_1');
+ $this->assertEquals(Config::inst()->get('ConfigStaticTest_Fourth', 'third', Config::UNINHERITED), null);
+
+ Config::inst()->update('ConfigStaticTest_First', 'first', array('test_1b'));
+ Config::inst()->update('ConfigStaticTest_Second', 'first', array('test_2b'));
+
+ // Check that it can be applied to parent and subclasses, and queried directly
+ $this->assertContains('test_1b', Config::inst()->get('ConfigStaticTest_First', 'first', Config::UNINHERITED));
+ $this->assertContains('test_2b', Config::inst()->get('ConfigStaticTest_Second', 'first', Config::UNINHERITED));
+
+ // But it won't affect subclasses - this is *uninherited* static
+ $this->assertNotContains('test_2b', Config::inst()->get('ConfigStaticTest_Third', 'first', Config::UNINHERITED));
+ $this->assertNotContains('test_2b', Config::inst()->get('ConfigStaticTest_Fourth', 'first', Config::UNINHERITED));
+
+ // Subclasses that don't have the static explicitly defined should allow definition, also
+ // This also checks that set can be called after the first uninherited get()
+ // call (which can be buggy due to caching)
+ Config::inst()->update('ConfigStaticTest_Fourth', 'first', array('test_4b'));
+ $this->assertContains('test_4b', Config::inst()->get('ConfigStaticTest_Fourth', 'first', Config::UNINHERITED));
+ }
+
+ function testCombinedStatic() {
+ $this->assertEquals(Config::inst()->get('ConfigStaticTest_Combined3', 'first'), array('test_3', 'test_2', 'test_1'));
+
+ // test that null values are ignored, but values on either side are still merged
+ $this->assertEquals(Config::inst()->get('ConfigStaticTest_Combined3', 'second'), array('test_3', 'test_1'));
+ }
+
function testMerges() {
$result = array('A' => 1, 'B' => 2, 'C' => 3);
Config::merge_array_low_into_high($result, array('C' => 4, 'D' => 5));
View
136 tests/core/ObjectStaticTest.php
@@ -1,136 +0,0 @@
-<?php
-/**
- * Tests various static getter and setter methods on {@link Object}
- *
- * @package framework
- * @subpackage tests
- */
-class ObjectStaticTest extends SapphireTest {
-
- /**
- * Tests {@link Object::get_static()}
- */
- public function testGetStatic() {
- $this->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'));
- // @todo - This fails. Decide if we can ignore this particular behaviour (it seems weird and counter-intuitive anyway)
- // $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'));
- // @todo - This fails. Decide if we can ignore this particular behaviour (it seems weird and counter-intuitive anyway)
- // $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);
- // @todo - This fails. Decide if we can ignore this particular behaviour (it seems weird and counter-intuitive anyway)
- // $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);
- }
-
- public function testCombinedStatic() {
- // test basic operation
- $this->assertEquals (
- array('test_3', 'test_2', 'test_1'), Object::combined_static('ObjectStaticTest_Combined3', 'first')
- );
-
- // test that null values are ignored, but values on either side are still merged
- $this->assertEquals (
- array('test_3', 'test_1'), Object::combined_static('ObjectStaticTest_Combined3', 'second')
- );
-
- // test the $ceiling param
- // @todo - This fails, as it's been removed. Do we need it?
- // $this->assertEquals (
- // array('test_3', 'test_2'), Object::combined_static('ObjectStaticTest_Combined3', 'first', 'ObjectStaticTest_Combined2')
- // );
- }
-
- /**
- * Checks that Object::add_static_var() also works for uninherited stats
- */
- public function testAddStaticVarWorksForUninheritedStatics() {
- Object::add_static_var('ObjectStaticTest_First', 'first', array('test_1b'));
- Object::add_static_var('ObjectStaticTest_Second', 'first', array('test_2b'));
-
- // Check that it can be applied to parent and subclasses, and queried directly
- $this->assertContains('test_1b', Object::uninherited_static('ObjectStaticTest_First', 'first'));
- $this->assertContains('test_2b', Object::uninherited_static('ObjectStaticTest_Second', 'first'));
-
- // But it won't affect subclasses - this is *uninherited* static
- $this->assertNotContains('test_2b', Object::uninherited_static('ObjectStaticTest_Third', 'first'));
- $this->assertNotContains('test_2b', Object::uninherited_static('ObjectStaticTest_Fourth', 'first'));
-
- // Subclasses that don't have the static explicitly defined should allow definition, also
- // This also checks that add_static_var can be called after the first uninherited_static()
- // call (which can be buggy due to caching)
- Object::add_static_var('ObjectStaticTest_Fourth', 'first', array('test_4b'));
- $this->assertContains('test_4b', Object::uninherited_static('ObjectStaticTest_Fourth', 'first'));
- }
-
-}
-
-/**#@+
- * @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');
-}
-
-class ObjectStaticTest_Combined1 extends Object {
- public static $first = array('test_1');
- public static $second = array('test_1');
-}
-
-class ObjectStaticTest_Combined2 extends ObjectStaticTest_Combined1 {
- public static $first = array('test_2');
- public static $second = null;
-}
-
-class ObjectStaticTest_Combined3 extends ObjectStaticTest_Combined2 {
- public static $first = array('test_3');
- public static $second = array('test_3');
-}
View
2  tests/model/DataObjectTest.php
@@ -1021,9 +1021,11 @@ function testRelField() {
function testRelObject() {
$captain = $this->objFromFixture('DataObjectTest_Player', 'captain1');
+
// Test traversal of a single has_one
$this->assertInstanceOf("Varchar", $captain->relObject('FavouriteTeam.Title'));
$this->assertEquals("Team 1", $captain->relObject('FavouriteTeam.Title')->getValue());
+
// Test direct field access
$this->assertInstanceOf("Boolean", $captain->relObject('IsRetired'));
$this->assertEquals(1, $captain->relObject('IsRetired')->getValue());
Please sign in to comment.
Something went wrong with that request. Please try again.