|
| 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 | +} |
0 commit comments