IntegrationTestCaseTest.php 2.0 KB

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