Finished up Controller tests for existing functionality

This commit is contained in:
Joshua Sherman 2013-12-31 10:39:21 -05:00
parent efa8f77eba
commit 5a15c791c5
3 changed files with 59 additions and 25 deletions

View file

@ -263,6 +263,7 @@ class Controller extends Object
if (!$valid_request) 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.'; $error_message = 'There was a problem with your request method.';
} }
} }
@ -398,7 +399,7 @@ class Controller extends Object
} }
elseif ($child_exists) elseif ($child_exists)
{ {
$module->template = $templates[1]; $module->template = [$templates[1]];
return true; return true;
} }

View file

@ -1,6 +1,7 @@
<?php <?php
ob_start(); ob_start();
session_start();
require_once '.composer/autoload.php'; require_once '.composer/autoload.php';
@ -26,6 +27,11 @@ if (!file_exists(SITE_TEMPLATE_PATH))
mkdir(SITE_TEMPLATE_PATH, 0644); mkdir(SITE_TEMPLATE_PATH, 0644);
} }
if (!file_exists(SITE_TEMPLATE_PATH . '__shared/'))
{
mkdir(SITE_TEMPLATE_PATH . '__shared/', 0644);
}
$_SERVER['HTTP_HOST'] = 'testsite.com'; $_SERVER['HTTP_HOST'] = 'testsite.com';
$_SERVER['SERVER_NAME'] = 'Test Server'; $_SERVER['SERVER_NAME'] = 'Test Server';

View file

@ -125,56 +125,83 @@ class ControllerTest extends PHPUnit_Framework_TestCase
file_put_contents(SITE_MODULE_PATH . 'auth.php', $module); file_put_contents(SITE_MODULE_PATH . 'auth.php', $module);
session_start();
Security::login(1, 10, 'USER'); Security::login(1, 10, 'USER');
new Controller(); new Controller();
$this->expectOutputString('{"foo":"bar"}'); $this->expectOutputString('{"foo":"bar"}');
} }
/*
public function testHasLevelAccess()
{
$this->fail();
}
public function testIsLevelAccess()
{
$this->fail();
}
public function testRoleDefaultMethod() public function testRoleDefaultMethod()
{ {
$this->fail(); setUpRequest('rolemethod');
$module = '<?php class rolemethod extends Module { '
. 'public $security = SECURITY_LEVEL_USER;'
. 'public function __default() { return ["foo" => "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() public function testBadRequestMethod()
{ {
$this->fail(); setUpRequest('requestmethod');
$module = '<?php class requestmethod extends Module { '
. 'public $method = "POST";'
. 'public function __default() { return ["foo" => "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() public function testValidationErrors()
{ {
$this->fail(); setUpRequest('validationerrors');
$module = '<?php class validationerrors extends Module { '
. 'protected $validate = ["test"];'
. 'public function __default() { return ["foo" => "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() public function testError404()
{ {
$this->fail(); setUpRequest('fourohfour');
new Controller();
$this->assertTrue(in_array('Status: 404 Not Found', xdebug_get_headers()));
$this->expectOutputRegex('/<h1>Not Found<\/h1>/');
} }
public function testCustomError404() public function testCustomError404()
{ {
$this->fail(); setUpRequest('customfourohfour');
}
// @todo Reuse one of the Display tests? file_put_contents(SITE_TEMPLATE_PATH . '__shared/404.phtml', '<h1>Custom Not Found</h1>');
public function testOutput()
{ new Controller();
$this->fail();
$this->assertTrue(in_array('Status: 404 Not Found', xdebug_get_headers()));
$this->expectOutputRegex('/<h1>Custom Not Found<\/h1>/');
} }
*/
public function testProfilerOutput() public function testProfilerOutput()
{ {