| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Controller
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- // Call Zend_Controller_Request_HttpTestCaseTest::main() if this source file is executed directly.
- if (!defined("PHPUnit_MAIN_METHOD")) {
- define("PHPUnit_MAIN_METHOD", "Zend_Controller_Request_HttpTestCaseTest::main");
- }
- /** Zend_Controller_Request_HttpTestCase */
- require_once 'Zend/Controller/Request/HttpTestCase.php';
- /**
- * Test class for Zend_Controller_Request_HttpTestCase.
- *
- * @category Zend
- * @package Zend_Controller
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Controller
- * @group Zend_Controller_Request
- */
- class Zend_Controller_Request_HttpTestCaseTest extends PHPUnit_Framework_TestCase
- {
- /**
- * Runs the test methods of this class.
- *
- * @return void
- */
- public static function main()
- {
- $suite = new PHPUnit_Framework_TestSuite("Zend_Controller_Request_HttpTestCaseTest");
- $result = PHPUnit_TextUI_TestRunner::run($suite);
- }
- /**
- * Sets up the fixture, for example, open a network connection.
- * This method is called before a test is executed.
- *
- * @return void
- */
- public function setUp()
- {
- $this->request = new Zend_Controller_Request_HttpTestCase();
- $_GET = array();
- $_POST = array();
- $_COOKIE = array();
- }
- /**
- * Tears down the fixture, for example, close a network connection.
- * This method is called after a test is executed.
- *
- * @return void
- */
- public function tearDown()
- {
- }
- public function testGetRequestUriShouldNotAttemptToAutoDiscoverFromEnvironment()
- {
- $this->assertNull($this->request->getRequestUri());
- }
- public function testGetPathInfoShouldNotAttemptToAutoDiscoverFromEnvironment()
- {
- $pathInfo = $this->request->getPathInfo();
- $this->assertTrue(empty($pathInfo));
- }
- public function testGetShouldBeEmptyByDefault()
- {
- $post = $this->request->getQuery();
- $this->assertTrue(is_array($post));
- $this->assertTrue(empty($post));
- }
- public function testShouldAllowSpecifyingGetParameters()
- {
- $this->testGetShouldBeEmptyByDefault();
- $expected = array(
- 'foo' => 'bar',
- 'bar' => 'baz',
- 'baz' => 'bat',
- );
- $this->request->setQuery($expected);
- $test = $this->request->getQuery();
- $this->assertSame($expected, $test);
- $this->request->setQuery('bat', 'bogus');
- $this->assertEquals('bogus', $this->request->getQuery('bat'));
- $test = $this->request->getQuery();
- $this->assertEquals(4, count($test));
- foreach ($expected as $key => $value) {
- $this->assertEquals($value, $test[$key]);
- }
- }
- public function testShouldPopulateGetSuperglobal()
- {
- $this->testShouldAllowSpecifyingGetParameters();
- $expected = array(
- 'foo' => 'bar',
- 'bar' => 'baz',
- 'baz' => 'bat',
- 'bat' => 'bogus',
- );
- $this->assertEquals($expected, $_GET);
- }
- public function testShouldAllowClearingQuery()
- {
- $this->testShouldPopulateGetSuperglobal();
- $this->request->clearQuery();
- $test = $this->request->getQuery();
- $this->assertTrue(is_array($test));
- $this->assertTrue(empty($test));
- }
- public function testPostShouldBeEmptyByDefault()
- {
- $post = $this->request->getPost();
- $this->assertTrue(is_array($post));
- $this->assertTrue(empty($post));
- }
- public function testShouldAllowSpecifyingPostParameters()
- {
- $this->testPostShouldBeEmptyByDefault();
- $expected = array(
- 'foo' => 'bar',
- 'bar' => 'baz',
- 'baz' => 'bat',
- );
- $this->request->setPost($expected);
- $test = $this->request->getPost();
- $this->assertSame($expected, $test);
- $this->request->setPost('bat', 'bogus');
- $this->assertEquals('bogus', $this->request->getPost('bat'));
- $test = $this->request->getPost();
- $this->assertEquals(4, count($test));
- foreach ($expected as $key => $value) {
- $this->assertEquals($value, $test[$key]);
- }
- }
- public function testShouldPopulatePostSuperglobal()
- {
- $this->testShouldAllowSpecifyingPostParameters();
- $expected = array(
- 'foo' => 'bar',
- 'bar' => 'baz',
- 'baz' => 'bat',
- 'bat' => 'bogus',
- );
- $this->assertEquals($expected, $_POST);
- }
- public function testShouldAllowClearingPost()
- {
- $this->testShouldPopulatePostSuperglobal();
- $this->request->clearPost();
- $test = $this->request->getPost();
- $this->assertTrue(is_array($test));
- $this->assertTrue(empty($test));
- }
- public function testRawPostBodyShouldBeNullByDefault()
- {
- $this->assertNull($this->request->getRawBody());
- }
- public function testShouldAllowSpecifyingRawPostBody()
- {
- $this->request->setRawBody('Some content for the body');
- $this->assertEquals('Some content for the body', $this->request->getRawBody());
- }
- public function testShouldAllowClearingRawPostBody()
- {
- $this->testShouldAllowSpecifyingRawPostBody();
- $this->request->clearRawBody();
- $this->assertNull($this->request->getRawBody());
- }
- public function testHeadersShouldBeEmptyByDefault()
- {
- $headers = $this->request->getHeaders();
- $this->assertTrue(is_array($headers));
- $this->assertTrue(empty($headers));
- }
- public function testShouldAllowSpecifyingRequestHeaders()
- {
- $headers = array(
- 'Content-Type' => 'text/html',
- 'Content-Encoding' => 'utf-8',
- );
- $this->request->setHeaders($headers);
- $test = $this->request->getHeaders();
- $this->assertTrue(is_array($test));
- $this->assertEquals(2, count($test));
- foreach ($headers as $key => $value) {
- $this->assertEquals($value, $this->request->getHeader($key));
- }
- $this->request->setHeader('X-Requested-With', 'XMLHttpRequest');
- $test = $this->request->getHeaders();
- $this->assertTrue(is_array($test));
- $this->assertEquals(3, count($test));
- $this->assertEquals('XMLHttpRequest', $this->request->getHeader('X-Requested-With'));
- }
- public function testShouldAllowClearingRequestHeaders()
- {
- $this->testShouldAllowSpecifyingRequestHeaders();
- $this->request->clearHeaders();
- $headers = $this->request->getHeaders();
- $this->assertTrue(is_array($headers));
- $this->assertTrue(empty($headers));
- }
- public function testCookiesShouldBeEmptyByDefault()
- {
- $cookies = $this->request->getCookie();
- $this->assertTrue(is_array($cookies));
- $this->assertTrue(empty($cookies));
- }
- public function testShouldAllowSpecifyingCookies()
- {
- $cookies = array(
- 'foo' => 'bar',
- 'bar' => 'baz',
- 'baz' => 'bat'
- );
- $this->request->setCookies($cookies);
- $test = $this->request->getCookie();
- $this->assertEquals($cookies, $test);
- $this->request->setCookie('bat', 'bogus');
- $this->assertEquals('bogus', $this->request->getCookie('bat'));
- }
- public function testShouldPopulateCookieSuperGlobal()
- {
- $cookies = array(
- 'foo' => 'bar',
- 'bar' => 'baz',
- 'baz' => 'bat',
- 'bat' => 'bogus',
- );
- $this->testShouldAllowSpecifyingCookies();
- $this->assertEquals($cookies, $_COOKIE);
- }
- public function testShouldAllowClearingAllCookies()
- {
- $this->testShouldAllowSpecifyingCookies();
- $this->request->clearCookies();
- $test = $this->request->getCookie();
- $this->assertTrue(is_array($test));
- $this->assertTrue(empty($test));
- }
- /**
- * @group ZF-6162
- */
- public function testRequestMethodShouldBeGetByDefault()
- {
- $this->assertEquals('GET', $this->request->getMethod());
- }
- public function testShouldAllowSpecifyingRequestMethod()
- {
- $this->testRequestMethodShouldBeGetByDefault();
- $this->request->setMethod('POST');
- $this->assertTrue($this->request->isPost());
- $this->request->setMethod('GET');
- $this->assertTrue($this->request->isGet());
- $this->request->setMethod('PUT');
- $this->assertTrue($this->request->isPut());
- $this->request->setMethod('OPTIONS');
- $this->assertTrue($this->request->isOptions());
- $this->request->setMethod('HEAD');
- $this->assertTrue($this->request->isHead());
- $this->request->setMethod('DELETE');
- $this->assertTrue($this->request->isDelete());
- $this->request->setMethod('PATCH');
- $this->assertTrue($this->request->isPatch());
- }
- }
- // Call Zend_Controller_Request_HttpTestCaseTest::main() if this source file is executed directly.
- if (PHPUnit_MAIN_METHOD == "Zend_Controller_Request_HttpTestCaseTest::main") {
- Zend_Controller_Request_HttpTestCaseTest::main();
- }
|