diff --git a/classes/Controller.php b/classes/Controller.php index 5dfb869..b9817f3 100644 --- a/classes/Controller.php +++ b/classes/Controller.php @@ -263,6 +263,7 @@ class Controller extends Object if (!$valid_request) { + // @todo Should probably utilize that AJAX flag to determine the type of return $error_message = 'There was a problem with your request method.'; } } @@ -398,7 +399,7 @@ class Controller extends Object } elseif ($child_exists) { - $module->template = $templates[1]; + $module->template = [$templates[1]]; return true; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a3b0c5b..b029286 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,6 +1,7 @@ expectOutputString('{"foo":"bar"}'); } - /* - public function testHasLevelAccess() - { - $this->fail(); - } - - public function testIsLevelAccess() - { - $this->fail(); - } - public function testRoleDefaultMethod() { - $this->fail(); + 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 testBadRequestMethod() { - $this->fail(); + setUpRequest('requestmethod'); + + $module = ' "bar"]; }' + . '} ?>'; + + file_put_contents(SITE_MODULE_PATH . 'requestmethod.php', $module); + + new Controller(); + + $this->expectOutputString('{"status":"error","message":"There was a problem with your request method."}'); } - // @todo Reuse one of the Module tests? public function testValidationErrors() { - $this->fail(); + 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() { - $this->fail(); + setUpRequest('fourohfour'); + + new Controller(); + + $this->assertTrue(in_array('Status: 404 Not Found', xdebug_get_headers())); + $this->expectOutputRegex('/

Not Found<\/h1>/'); } public function testCustomError404() { - $this->fail(); - } + setUpRequest('customfourohfour'); - // @todo Reuse one of the Display tests? - public function testOutput() - { - $this->fail(); + 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() {