浏览代码

Fix shim extension and add tests.

Mark Scherer 11 年之前
父节点
当前提交
f1a3fdb482

+ 85 - 0
Test/Case/TestSuite/IntegrationTestCaseTest.php

@@ -0,0 +1,85 @@
+<?php
+App::uses('IntegrationTestCase', 'Tools.TestSuite');
+
+class IntegrationTestCaseTest extends IntegrationTestCase {
+
+	public function setUp() {
+		parent::setUp();
+
+		App::build(array(
+			'Controller' => array(CakePlugin::path('Shim') . 'Test' . DS . 'test_app' . DS . 'Controller' . DS),
+			'Model' => array(CakePlugin::path('Shim') . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
+			'View' => array(CakePlugin::path('Shim') . 'Test' . DS . 'test_app' . DS . 'View' . DS)
+		), App::RESET);
+	}
+
+	/**
+	 * A basic GET.
+	 *
+	 * @return void
+	 */
+	public function testBasic() {
+		$this->get(array('controller' => 'items', 'action' => 'index'));
+		$this->assertResponseCode(200);
+		$this->assertNoRedirect();
+		$this->assertResponseNotEmpty();
+		$this->assertResponseContains('My Index Test ctp');
+	}
+
+	/**
+	 * Test that POST also works.
+	 *
+	 * @return void
+	 */
+	public function testPosting() {
+		$data = array(
+			'key' => 'sth'
+		);
+		$this->post(array('controller' => 'items', 'action' => 'posting'), $data);
+		$this->assertResponseCode(200);
+		$this->assertNoRedirect();
+	}
+
+	/**
+	 * Let us change a value in session
+	 *
+	 * @return void
+	 */
+	public function testSession() {
+		$this->session(array('Auth.User.id' => 1));
+
+		$this->get(array('controller' => 'items', 'action' => 'session'));
+		$this->assertResponseCode(200);
+		$this->assertNoRedirect();
+
+		$this->assertSession('2', 'Auth.User.id');
+	}
+
+	/**
+	 * Redirecting is recognized as 302 status code.
+	 *
+	 * @return void
+	 */
+	public function testRedirecting() {
+		$this->get(array('controller' => 'items', 'action' => 'redirecting'));
+		$this->assertResponseCode(302);
+		$this->assertRedirect('/foobar');
+
+		$this->assertSession('yeah', 'Message.flash.message');
+
+		// Make sure we dont have cross contamination from the previous test
+		$this->assertSession(null, 'Auth.User.id');
+		$this->assertResponseEmpty();
+	}
+
+	/**
+	 * We still have to set assertion headers, though, for exceptions.
+	 *
+	 * @expectedException NotFoundException
+	 * @return void
+	 */
+	public function testExceptional() {
+		$this->get(array('controller' => 'items', 'action' => 'exceptional'));
+	}
+
+}

+ 31 - 0
Test/Case/TestSuite/MyCakeTestCaseTest.php

@@ -0,0 +1,31 @@
+<?php
+
+App::uses('MyCakeTestCase', 'Tools.TestSuite');
+
+class MyCakeTestCaseTest extends MyCakeTestCase {
+
+	public function setUp() {
+		parent::setUp();
+	}
+
+	/**
+	 * test testAssertWithinRange()
+	 *
+	 * @return void
+	 */
+	public function testAssertWithinRange() {
+		$this->assertWithinRange(21, 22, 1, 'Not within range');
+		$this->assertWithinRange(21.3, 22.2, 1.0, 'Not within range');
+	}
+
+	/**
+	 * test testAssertNotWithinRange()
+	 *
+	 * @return void
+	 */
+	public function testAssertNotWithinRange() {
+		$this->assertNotWithinRange(21, 23, 1, 'Within range');
+		$this->assertNotWithinRange(21.3, 22.2, 0.7, 'Within range');
+	}
+
+}

+ 2 - 2
TestSuite/IntegrationTestCase.php

@@ -1,5 +1,5 @@
 <?php
 <?php
-App::uses('ShimControllerTestCase', 'Shim.TestSuite');
+App::uses('ShimIntegrationTestCase', 'Shim.TestSuite');
 App::uses('Router', 'Routing');
 App::uses('Router', 'Routing');
 App::uses('Dispatcher', 'Routing');
 App::uses('Dispatcher', 'Routing');
 App::uses('EventManager', 'Event');
 App::uses('EventManager', 'Event');
@@ -18,5 +18,5 @@ App::uses('CakeSession', 'Model/Datasource');
  * more of your code easily and avoid some of the maintenance pitfalls
  * more of your code easily and avoid some of the maintenance pitfalls
  * that mock objects create.
  * that mock objects create.
  */
  */
-abstract class IntegrationTestCase extends ShimControllerTestCase {
+abstract class IntegrationTestCase extends ShimIntegrationTestCase {
 }
 }