Skip to content

Commit f1a3fdb

Browse files
author
Mark Scherer
committed
Fix shim extension and add tests.
1 parent 653c427 commit f1a3fdb

File tree

3 files changed

+118
-2
lines changed

3 files changed

+118
-2
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
App::uses('IntegrationTestCase', 'Tools.TestSuite');
3+
4+
class IntegrationTestCaseTest extends IntegrationTestCase {
5+
6+
public function setUp() {
7+
parent::setUp();
8+
9+
App::build(array(
10+
'Controller' => array(CakePlugin::path('Shim') . 'Test' . DS . 'test_app' . DS . 'Controller' . DS),
11+
'Model' => array(CakePlugin::path('Shim') . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
12+
'View' => array(CakePlugin::path('Shim') . 'Test' . DS . 'test_app' . DS . 'View' . DS)
13+
), App::RESET);
14+
}
15+
16+
/**
17+
* A basic GET.
18+
*
19+
* @return void
20+
*/
21+
public function testBasic() {
22+
$this->get(array('controller' => 'items', 'action' => 'index'));
23+
$this->assertResponseCode(200);
24+
$this->assertNoRedirect();
25+
$this->assertResponseNotEmpty();
26+
$this->assertResponseContains('My Index Test ctp');
27+
}
28+
29+
/**
30+
* Test that POST also works.
31+
*
32+
* @return void
33+
*/
34+
public function testPosting() {
35+
$data = array(
36+
'key' => 'sth'
37+
);
38+
$this->post(array('controller' => 'items', 'action' => 'posting'), $data);
39+
$this->assertResponseCode(200);
40+
$this->assertNoRedirect();
41+
}
42+
43+
/**
44+
* Let us change a value in session
45+
*
46+
* @return void
47+
*/
48+
public function testSession() {
49+
$this->session(array('Auth.User.id' => 1));
50+
51+
$this->get(array('controller' => 'items', 'action' => 'session'));
52+
$this->assertResponseCode(200);
53+
$this->assertNoRedirect();
54+
55+
$this->assertSession('2', 'Auth.User.id');
56+
}
57+
58+
/**
59+
* Redirecting is recognized as 302 status code.
60+
*
61+
* @return void
62+
*/
63+
public function testRedirecting() {
64+
$this->get(array('controller' => 'items', 'action' => 'redirecting'));
65+
$this->assertResponseCode(302);
66+
$this->assertRedirect('/foobar');
67+
68+
$this->assertSession('yeah', 'Message.flash.message');
69+
70+
// Make sure we dont have cross contamination from the previous test
71+
$this->assertSession(null, 'Auth.User.id');
72+
$this->assertResponseEmpty();
73+
}
74+
75+
/**
76+
* We still have to set assertion headers, though, for exceptions.
77+
*
78+
* @expectedException NotFoundException
79+
* @return void
80+
*/
81+
public function testExceptional() {
82+
$this->get(array('controller' => 'items', 'action' => 'exceptional'));
83+
}
84+
85+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
App::uses('MyCakeTestCase', 'Tools.TestSuite');
4+
5+
class MyCakeTestCaseTest extends MyCakeTestCase {
6+
7+
public function setUp() {
8+
parent::setUp();
9+
}
10+
11+
/**
12+
* test testAssertWithinRange()
13+
*
14+
* @return void
15+
*/
16+
public function testAssertWithinRange() {
17+
$this->assertWithinRange(21, 22, 1, 'Not within range');
18+
$this->assertWithinRange(21.3, 22.2, 1.0, 'Not within range');
19+
}
20+
21+
/**
22+
* test testAssertNotWithinRange()
23+
*
24+
* @return void
25+
*/
26+
public function testAssertNotWithinRange() {
27+
$this->assertNotWithinRange(21, 23, 1, 'Within range');
28+
$this->assertNotWithinRange(21.3, 22.2, 0.7, 'Within range');
29+
}
30+
31+
}

TestSuite/IntegrationTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
App::uses('ShimControllerTestCase', 'Shim.TestSuite');
2+
App::uses('ShimIntegrationTestCase', 'Shim.TestSuite');
33
App::uses('Router', 'Routing');
44
App::uses('Dispatcher', 'Routing');
55
App::uses('EventManager', 'Event');
@@ -18,5 +18,5 @@
1818
* more of your code easily and avoid some of the maintenance pitfalls
1919
* that mock objects create.
2020
*/
21-
abstract class IntegrationTestCase extends ShimControllerTestCase {
21+
abstract class IntegrationTestCase extends ShimIntegrationTestCase {
2222
}

0 commit comments

Comments
 (0)