From 39d5b8d40ba16c580d7436ad034d46e27e2468c0 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Thu, 25 Sep 2014 23:11:29 -0400 Subject: [PATCH] Cleaned up unit tests Wanted to get back to the point that the tests were running and not erroring. --- src/classes/Resource.php | 2 +- tests/classes/ControllerTest.php | 358 ------------------ tests/classes/DisplayTest.php | 132 ------- tests/classes/DynamicTest.php | 120 ------ .../{ModuleTest.php => ResourceTest.php} | 20 +- tests/classes/RouterTest.php | 230 +++++++++++ 6 files changed, 241 insertions(+), 621 deletions(-) delete mode 100644 tests/classes/ControllerTest.php delete mode 100644 tests/classes/DisplayTest.php delete mode 100644 tests/classes/DynamicTest.php rename tests/classes/{ModuleTest.php => ResourceTest.php} (72%) create mode 100644 tests/classes/RouterTest.php diff --git a/src/classes/Resource.php b/src/classes/Resource.php index 4723468..2dd893c 100644 --- a/src/classes/Resource.php +++ b/src/classes/Resource.php @@ -25,7 +25,7 @@ * be JSON encoded. In the future this may need to be changed out for logic * that allows the requested module to specify what display type(s) it can use. */ -abstract class Resource extends Object +class Resource extends Object { /** * Secure diff --git a/tests/classes/ControllerTest.php b/tests/classes/ControllerTest.php deleted file mode 100644 index cdb99e2..0000000 --- a/tests/classes/ControllerTest.php +++ /dev/null @@ -1,358 +0,0 @@ -config = Config::getInstance(); - $this->config->data['pickles']['disabled'] = false; - $this->config->data['pickles']['profiler'] = false; - $this->config->data['security']['levels'][10] = 'USER'; - $this->config->data['security']['levels'][20] = 'ADMIN'; - - setUpRequest('home'); - - $module = 'config->data['pickles']['disabled'] = true; - - $this->expectOutputRegex('/Test Server is currently down for maintenance/'); - - new Controller(); - } - - public function testCustomSiteDown() - { - $this->config->data['pickles']['disabled'] = true; - - file_put_contents(SITE_TEMPLATE_PATH . '__shared/maintenance.phtml', '

Custom Down for Maintenance

'); - - new Controller(); - - $this->expectOutputRegex('/

Custom Down for Maintenance<\/h1>/'); - } - - public function testAttributesInURI() - { - setUpRequest('home/id:123'); - - new Controller(); - - $this->assertEquals(123, Browser::get('id')); - - setUpRequest('home/id:456/foo:bar'); - - new Controller(); - - // Compensates for 2 empty template executions of the Controller - $this->expectOutputString('[][]'); - $this->assertEquals(456, Browser::get('id')); - $this->assertEquals('bar', Browser::get('foo')); - } - - public function testUpperCaseURI() - { - setUpRequest('TESTING'); - - new Controller(); - - $this->assertTrue(in_array('Location: /testing', xdebug_get_headers())); - } - - public function testForceSecure() - { - setUpRequest('secure'); - - $module = 'assertTrue(in_array('Location: https://testsite.com/secure', xdebug_get_headers())); - } - - public function testForceInsecure() - { - setUpRequest('insecure'); - $_SERVER['HTTPS'] = 'on'; - - $module = 'assertTrue(in_array('Location: http://testsite.com/insecure', xdebug_get_headers())); - } - - public function testNotAuthenticated() - { - setUpRequest('notauth'); - - $module = 'expectOutputString('[]'); - - $this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers())); - } - - public function testSecurityArray() - { - setUpRequest('securityarray'); - - $module = 'expectOutputString('[]'); - - $this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers())); - } - - public function testSecurityArrayTypeString() - { - setUpRequest('securityarraytypestring'); - - $module = ' "IS", "level" => SECURITY_LEVEL_USER]; }'; - - file_put_contents(SITE_MODULE_PATH . 'securityarraytypestring.php', $module); - - new Controller(); - - // Compensates for an empty template due to exit() being skipped - $this->expectOutputString('[]'); - - $this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers())); - } - - public function testSecurityArrayTypeArray() - { - setUpRequest('securityarraytypearray'); - - $module = ' "IS", "level" => [SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]]; }'; - - file_put_contents(SITE_MODULE_PATH . 'securityarraytypearray.php', $module); - - new Controller(); - - // Compensates for an empty template due to exit() being skipped - $this->expectOutputString('[]'); - - $this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers())); - } - - public function testSecurityArrayTypeBetween() - { - setUpRequest('securityarraytypebetween'); - - $module = ' "BETWEEN", "levels" => [SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]]; }'; - - file_put_contents(SITE_MODULE_PATH . 'securityarraytypebetween.php', $module); - - new Controller(); - - // Compensates for an empty template due to exit() being skipped - $this->expectOutputString('[]'); - - $this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers())); - } - - public function testSecurityArrayTypeHas() - { - setUpRequest('securityarraytypehas'); - - $module = ' "HAS", "level" => SECURITY_LEVEL_USER]; }'; - - file_put_contents(SITE_MODULE_PATH . 'securityarraytypehas.php', $module); - - new Controller(); - - // Compensates for an empty template due to exit() being skipped - $this->expectOutputString('[]'); - - $this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers())); - } - - public function testNotAuthenticatedPOST() - { - setUpRequest('notauthpost', 'POST'); - - $module = 'expectOutputRegex('/You are not properly authenticated/'); - } - - public function testAuthenticated() - { - setUpRequest('auth'); - - $module = ' "bar"]; }' - . '}'; - - file_put_contents(SITE_MODULE_PATH . 'auth.php', $module); - - Security::login(1, 10, 'USER'); - new Controller(); - - $this->expectOutputString('{"foo":"bar"}'); - } - - public function testRoleDefaultMethod() - { - setUpRequest('rolemethod'); - - $module = ' "bar"]; }' - . 'public function __default_USER() { return ["user" => "me"]; }' - . '}'; - - file_put_contents(SITE_MODULE_PATH . 'rolemethod.php', $module); - - Security::login(1, 10, 'USER'); - new Controller(); - - $this->expectOutputString('{"user":"me"}'); - } - - public function testValidRequestMethod() - { - setUpRequest('validrequestmethod'); - - $module = ' "bar"]; }' - . '}'; - - file_put_contents(SITE_MODULE_PATH . 'validrequestmethod.php', $module); - - new Controller(); - - $this->expectOutputString('{"foo":"bar"}'); - } - - public function testInvalidRequestMethod() - { - setUpRequest('invalidrequestmethod'); - - $module = ' "bar"]; }' - . '}'; - - file_put_contents(SITE_MODULE_PATH . 'invalidrequestmethod.php', $module); - - new Controller(); - - $this->expectOutputString('{"status":"error","message":"There was a problem with your request method."}'); - } - - public function testValidationErrors() - { - setUpRequest('validationerrors'); - - $module = ' "bar"]; }' - . '}'; - - file_put_contents(SITE_MODULE_PATH . 'validationerrors.php', $module); - - new Controller(); - - $this->expectOutputString('{"status":"error","message":"The test field is required."}'); - } - - public function testError404() - { - setUpRequest('fourohfour'); - - new Controller(); - - $this->assertTrue(in_array('Status: 404 Not Found', xdebug_get_headers())); - $this->expectOutputRegex('/

Not Found<\/h1>/'); - } - - public function testCustomError404() - { - setUpRequest('customfourohfour'); - - file_put_contents(SITE_TEMPLATE_PATH . '__shared/404.phtml', '

Custom Not Found

'); - - new Controller(); - - $this->assertTrue(in_array('Status: 404 Not Found', xdebug_get_headers())); - $this->expectOutputRegex('/

Custom Not Found<\/h1>/'); - } - - public function testProfilerOutput() - { - $this->config->data['pickles']['profiler'] = true; - - $this->expectOutputRegex('/id="pickles-profiler"/'); - - new Controller(); - } - - public function testTwoValidTemplates() - { - $this->config->data['pickles']['profiler'] = true; - - setUpRequest('validtemplates'); - - $module = 'child template'); - - // Vim syntax highlighting borks unless ----v - $child = 'template; ?' . '>' . "\n"; - - $html = << - - -

parent template

- {$child} - - -HTML; - - file_put_contents(SITE_TEMPLATE_PATH . '__shared/index.phtml', $html); - - new Controller(); - - $this->expectOutputRegex('/^ - - -

parent template<\/h1> -
child template<\/div> -<\/body> -<\/html>.+