Skip to content
Permalink
Browse files

making assertions run against the test case, not the subject test case.

  • Loading branch information...
markstory committed Dec 16, 2010
1 parent 5ff376e commit 9dcea304c1475aba76ae7e2a22a6483e7dc771d8
Showing with 41 additions and 39 deletions.
  1. +41 −39 cake/tests/cases/libs/controller_test_case.test.php
@@ -137,41 +137,42 @@ function tearDown() {
*/
function testGenerate() {
$Posts = $this->Case->generate('Posts');
$this->Case->assertEquals($Posts->name, 'Posts');
$this->Case->assertEquals($Posts->modelClass, 'Post');
$this->Case->assertNull($Posts->response->send());
$this->assertEquals($Posts->name, 'Posts');
$this->assertEquals($Posts->modelClass, 'Post');
$this->assertNull($Posts->response->send());
$Posts = $this->Case->generate('Posts', array(
'methods' => array(
'render'
)
));
$this->Case->assertNull($Posts->render('index'));
$this->assertNull($Posts->render('index'));
$Posts = $this->Case->generate('Posts', array(
'models' => array('Post'),
'components' => array('RequestHandler')
));
$this->Case->assertNull($Posts->Post->save(array()));
$this->Case->assertNull($Posts->Post->find('all'));
$this->Case->assertEquals($Posts->Post->useTable, 'posts');
$this->Case->assertNull($Posts->RequestHandler->isAjax());
$this->assertNull($Posts->Post->save(array()));
$this->assertNull($Posts->Post->find('all'));
$this->assertEquals($Posts->Post->useTable, 'posts');
$this->assertNull($Posts->RequestHandler->isAjax());
$Posts = $this->Case->generate('Posts', array(
'models' => array(
'Post' => true
)
));
$this->Case->assertNull($Posts->Post->save(array()));
$this->Case->assertNull($Posts->Post->find('all'));
$this->assertNull($Posts->Post->save(array()));
$this->assertNull($Posts->Post->find('all'));
$Posts = $this->Case->generate('Posts', array(
'models' => array(
'Post' => array('save'),
)
));
$this->Case->assertNull($Posts->Post->save(array()));
$this->Case->assertIsA($Posts->Post->find('all'), 'array');
$this->assertNull($Posts->Post->save(array()));
$this->assertIsA($Posts->Post->find('all'), 'array');
$Posts = $this->Case->generate('Posts', array(
'models' => array('Post'),
@@ -198,24 +199,24 @@ function testGenerate() {
function testTestAction() {
$Controller = $this->Case->generate('TestsApps');
$this->Case->testAction('/tests_apps/index');
$this->Case->assertIsA($this->Case->controller->viewVars, 'array');
$this->assertIsA($this->Case->controller->viewVars, 'array');
$this->Case->testAction('/tests_apps/set_action');
$results = $this->Case->controller->viewVars;
$expected = array(
'var' => 'string'
);
$this->Case->assertEquals($expected, $results);
$this->assertEquals($expected, $results);
$result = $this->Case->controller->response->body();
$this->Case->assertPattern('/This is the TestsAppsController index view/', $result);
$this->assertPattern('/This is the TestsAppsController index view/', $result);
$this->Case->testAction('/tests_apps/redirect_to');
$results = $this->Case->headers;
$expected = array(
'Location' => 'http://cakephp.org'
);
$this->Case->assertEquals($expected, $results);
$this->assertEquals($expected, $results);
}
/**
@@ -228,32 +229,33 @@ function testUseRoutes() {
$result = $this->Case->testAction('/tests_apps/index.json', array('return' => 'view'));
$result = json_decode($result, true);
$expected = array('cakephp' => 'cool');
$this->Case->assertEquals($result, $expected);
$this->assertEquals($result, $expected);
include TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config' . DS . 'routes.php';
$result = $this->Case->testAction('/some_alias');
$this->Case->assertEquals($result, 5);
$this->assertEquals($result, 5);
include TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config' . DS . 'routes.php';
$this->Case->testAction('/redirect_me_now');
$result = $this->Case->headers['Location'];
$this->Case->assertEquals($result, 'http://cakephp.org');
$this->assertEquals($result, 'http://cakephp.org');
include TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config' . DS . 'routes.php';
$this->Case->testAction('/redirect_me');
$result = $this->Case->headers['Location'];
$this->Case->assertEquals($result, Router::url(array('controller' => 'tests_apps', 'action' => 'some_method'), true));
$this->assertEquals($result, Router::url(array('controller' => 'tests_apps', 'action' => 'some_method'), true));
}
/**
* Tests not using loaded routes during tests
*
* @expectedException MissingActionException
*/
function testSkipRoutes() {
include TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config' . DS . 'routes.php';
$this->Case->loadRoutes = false;
$this->expectException('MissingActionException');
$result = $this->Case->testAction('/tests_apps/index.json', array('return' => 'view'));
}
@@ -264,26 +266,26 @@ function testBCSetReturn() {
$this->Case->autoMock = true;
$result = $this->Case->testAction('/tests_apps/some_method');
$this->Case->assertEquals($result, 5);
$this->assertEquals($result, 5);
$data = array('var' => 'set');
$result = $this->Case->testAction('/tests_apps_posts/post_var', array(
'data' => $data,
'return' => 'vars'
));
$this->Case->assertEquals($result['data'], $data);
$this->assertEquals($result['data'], $data);
$result = $this->Case->testAction('/tests_apps/set_action', array(
'return' => 'view'
));
$this->Case->assertEquals($result, 'This is the TestsAppsController index view');
$this->assertEquals($result, 'This is the TestsAppsController index view');
$result = $this->Case->testAction('/tests_apps/set_action', array(
'return' => 'contents'
));
$this->Case->assertPattern('/<html/', $result);
$this->Case->assertPattern('/This is the TestsAppsController index view/', $result);
$this->Case->assertPattern('/<\/html>/', $result);
$this->assertPattern('/<html/', $result);
$this->assertPattern('/This is the TestsAppsController index view/', $result);
$this->assertPattern('/<\/html>/', $result);
}
/**
@@ -300,17 +302,17 @@ function testTestActionPostData() {
$this->Case->testAction('/tests_apps_posts/post_var', array(
'data' => $data
));
$this->Case->assertEquals($this->Case->controller->viewVars['data'], $data);
$this->Case->assertEquals($this->Case->controller->data, $data);
$this->assertEquals($this->Case->controller->viewVars['data'], $data);
$this->assertEquals($this->Case->controller->data, $data);
$this->Case->testAction('/tests_apps_posts/post_var/named:param', array(
'data' => $data
));
$expected = array(
'named' => 'param'
);
$this->Case->assertEqual($this->Case->controller->request->named, $expected);
$this->Case->assertEquals($this->Case->controller->data, $data);
$this->assertEqual($this->Case->controller->request->named, $expected);
$this->assertEquals($this->Case->controller->data, $data);
$result = $this->Case->testAction('/tests_apps_posts/post_var', array(
'return' => 'vars',
@@ -340,8 +342,8 @@ function testTestActionGetData() {
'lackof' => 'creativity'
)
));
$this->Case->assertEquals($this->Case->controller->request->query['some'], 'var');
$this->Case->assertEquals($this->Case->controller->request->query['lackof'], 'creativity');
$this->assertEquals($this->Case->controller->request->query['some'], 'var');
$this->assertEquals($this->Case->controller->request->query['lackof'], 'creativity');
$result = $this->Case->testAction('/tests_apps_posts/url_var/var1:value1/var2:val2', array(
'return' => 'vars',
@@ -379,7 +381,7 @@ function testAutoMock() {
$expected = array(
'var' => 'string'
);
$this->Case->assertEquals($expected, $results);
$this->assertEquals($expected, $results);
}
/**
@@ -394,19 +396,19 @@ function testNoMocking() {
'data' => $data,
'return' => 'vars'
));
$this->Case->assertEquals($result['data'], $data);
$this->assertEquals($result['data'], $data);
$result = $this->Case->testAction('/tests_apps/set_action', array(
'return' => 'view'
));
$this->Case->assertEquals($result, 'This is the TestsAppsController index view');
$this->assertEquals($result, 'This is the TestsAppsController index view');
$result = $this->Case->testAction('/tests_apps/set_action', array(
'return' => 'contents'
));
$this->Case->assertPattern('/<html/', $result);
$this->Case->assertPattern('/This is the TestsAppsController index view/', $result);
$this->Case->assertPattern('/<\/html>/', $result);
$this->assertPattern('/<html/', $result);
$this->assertPattern('/This is the TestsAppsController index view/', $result);
$this->assertPattern('/<\/html>/', $result);
}
}

0 comments on commit 9dcea30

Please sign in to comment.
You can’t perform that action at this time.