浏览代码

Merge pull request #10769 from Iandenh/patch-5

Add options and head methods to IntegrationTestCase
Mark Story 8 年之前
父节点
当前提交
70ea324caa
共有 2 个文件被更改,包括 70 次插入0 次删除
  1. 30 0
      src/TestSuite/IntegrationTestCase.php
  2. 40 0
      tests/TestCase/TestSuite/IntegrationTestCaseTest.php

+ 30 - 0
src/TestSuite/IntegrationTestCase.php

@@ -435,6 +435,36 @@ abstract class IntegrationTestCase extends TestCase
     }
 
     /**
+     * Performs a HEAD request using the current request data.
+     *
+     * The response of the dispatched request will be stored as
+     * a property. You can use various assert methods to check the
+     * response.
+     *
+     * @param string|array $url The URL to request.
+     * @return void
+     */
+    public function head($url)
+    {
+        $this->_sendRequest($url, 'HEAD');
+    }
+
+    /**
+     * Performs an OPTIONS request using the current request data.
+     *
+     * The response of the dispatched request will be stored as
+     * a property. You can use various assert methods to check the
+     * response.
+     *
+     * @param string|array $url The URL to request.
+     * @return void
+     */
+    public function options($url)
+    {
+        $this->_sendRequest($url, 'OPTIONS');
+    }
+
+    /**
      * Creates and send the request into a Dispatcher instance.
      *
      * Receives and stores the response for future inspection.

+ 40 - 0
tests/TestCase/TestSuite/IntegrationTestCaseTest.php

@@ -40,6 +40,8 @@ class IntegrationTestCaseTest extends IntegrationTestCase
         Configure::write('App.namespace', 'TestApp');
 
         Router::connect('/get/:controller/:action', ['_method' => 'GET'], ['routeClass' => 'InflectedRoute']);
+        Router::connect('/head/:controller/:action', ['_method' => 'HEAD'], ['routeClass' => 'InflectedRoute']);
+        Router::connect('/options/:controller/:action', ['_method' => 'OPTIONS'], ['routeClass' => 'InflectedRoute']);
         Router::connect('/:controller/:action/*', [], ['routeClass' => 'InflectedRoute']);
         DispatcherFactory::clear();
         DispatcherFactory::add('Routing');
@@ -188,6 +190,44 @@ class IntegrationTestCaseTest extends IntegrationTestCase
     }
 
     /**
+     * Test sending head requests.
+     *
+     * @return void
+     */
+    public function testHead()
+    {
+        $this->assertNull($this->_response);
+
+        $this->head('/request_action/test_request_action');
+        $this->assertNotEmpty($this->_response);
+        $this->assertInstanceOf('Cake\Http\Response', $this->_response);
+        $this->assertResponseSuccess();
+
+        $this->_response = null;
+        $this->head('/head/request_action/test_request_action');
+        $this->assertResponseSuccess();
+    }
+
+    /**
+     * Test sending options requests.
+     *
+     * @return void
+     */
+    public function testOptions()
+    {
+        $this->assertNull($this->_response);
+
+        $this->options('/request_action/test_request_action');
+        $this->assertNotEmpty($this->_response);
+        $this->assertInstanceOf('Cake\Http\Response', $this->_response);
+        $this->assertResponseSuccess();
+
+        $this->_response = null;
+        $this->options('/options/request_action/test_request_action');
+        $this->assertResponseSuccess();
+    }
+
+    /**
      * Test sending get requests sets the request method
      *
      * @return void