PageRenderTime 64ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/tests/Zend/Http/Client/StaticTest.php

https://bitbucket.org/dbaltas/zend-framework-1.x-on-git
PHP | 803 lines | 423 code | 108 blank | 272 comment | 5 complexity | d88d639712b5f32e9e80d87e50300953 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Http_Client
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: StaticTest.php 24761 2012-05-05 03:10:28Z adamlundrigan $
  21. */
  22. require_once 'Zend/Http/Client.php';
  23. require_once 'Zend/Http/Client/Adapter/Test.php';
  24. /**
  25. * This Testsuite includes all Zend_Http_Client tests that do not rely
  26. * on performing actual requests to an HTTP server. These tests can be
  27. * executed once, and do not need to be tested with different servers /
  28. * client setups.
  29. *
  30. * @category Zend
  31. * @package Zend_Http_Client
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Http
  36. * @group Zend_Http_Client
  37. */
  38. class Zend_Http_Client_StaticTest extends PHPUnit_Framework_TestCase
  39. {
  40. /**
  41. * Common HTTP client
  42. *
  43. * @var Zend_Http_Client
  44. */
  45. protected $_client = null;
  46. /**
  47. * Set up the test suite before each test
  48. *
  49. */
  50. public function setUp()
  51. {
  52. $this->_client = new Zend_Http_Client_StaticTest_Mock('http://www.example.com');
  53. }
  54. /**
  55. * Clean up after running a test
  56. *
  57. */
  58. public function tearDown()
  59. {
  60. $this->_client = null;
  61. }
  62. /**
  63. * URI Tests
  64. */
  65. /**
  66. * Test we can SET and GET a URI as string
  67. *
  68. */
  69. public function testSetGetUriString()
  70. {
  71. $uristr = 'http://www.zend.com:80/';
  72. $this->_client->setUri($uristr);
  73. $uri = $this->_client->getUri();
  74. $this->assertTrue($uri instanceof Zend_Uri_Http, 'Returned value is not a Uri object as expected');
  75. $this->assertEquals($uri->__toString(), $uristr, 'Returned Uri object does not hold the expected URI');
  76. $uri = $this->_client->getUri(true);
  77. $this->assertTrue(is_string($uri), 'Returned value expected to be a string, ' . gettype($uri) . ' returned');
  78. $this->assertEquals($uri, $uristr, 'Returned string is not the expected URI');
  79. }
  80. /**
  81. * Test we can SET and GET a URI as object
  82. *
  83. */
  84. public function testSetGetUriObject()
  85. {
  86. $uriobj = Zend_Uri::factory('http://www.zend.com:80/');
  87. $this->_client->setUri($uriobj);
  88. $uri = $this->_client->getUri();
  89. $this->assertTrue($uri instanceof Zend_Uri_Http, 'Returned value is not a Uri object as expected');
  90. $this->assertEquals($uri, $uriobj, 'Returned object is not the excepted Uri object');
  91. }
  92. /**
  93. * Test that passing an invalid URI string throws an exception
  94. *
  95. * @expectedException Zend_Uri_Exception
  96. */
  97. public function testInvalidUriStringException()
  98. {
  99. $this->_client->setUri('httpp://__invalid__.com');
  100. }
  101. /**
  102. * Test that passing an invalid URI object throws an exception
  103. *
  104. */
  105. public function testInvalidUriObjectException()
  106. {
  107. try {
  108. $uri = Zend_Uri::factory('mailto:nobody@example.com');
  109. $this->_client->setUri($uri);
  110. $this->fail('Excepted invalid URI object exception was not thrown');
  111. } catch (Zend_Http_Client_Exception $e) {
  112. // We're good
  113. } catch (Zend_Uri_Exception $e) {
  114. // URI is currently unimplemented
  115. $this->markTestIncomplete('Zend_Uri_Mailto is not implemented yet');
  116. }
  117. }
  118. /**
  119. * Test that setting the same parameter twice in the query string does not
  120. * get reduced to a single value only.
  121. *
  122. */
  123. public function testDoubleGetParameter()
  124. {
  125. $qstr = 'foo=bar&foo=baz';
  126. $this->_client->setUri('http://example.com/test/?' . $qstr);
  127. $this->_client->setAdapter('Zend_Http_Client_Adapter_Test');
  128. $res = $this->_client->request('GET');
  129. $this->assertContains($qstr, $this->_client->getLastRequest(),
  130. 'Request is expected to contain the entire query string');
  131. }
  132. /**
  133. * Header Tests
  134. */
  135. /**
  136. * Make sure an exception is thrown if an invalid header name is used
  137. *
  138. * @expectedException Zend_Http_Client_Exception
  139. */
  140. public function testInvalidHeaderExcept()
  141. {
  142. $this->_client->setHeaders('Ina_lid* Hea%der', 'is not good');
  143. }
  144. /**
  145. * Make sure non-strict mode disables header name validation
  146. *
  147. */
  148. public function testInvalidHeaderNonStrictMode()
  149. {
  150. // Disable strict validation
  151. $this->_client->setConfig(array('strict' => false));
  152. try {
  153. $this->_client->setHeaders('Ina_lid* Hea%der', 'is not good');
  154. } catch (Zend_Http_Client_Exception $e) {
  155. $this->fail('Invalid header names should be allowed in non-strict mode');
  156. }
  157. }
  158. /**
  159. * Test we can get already set headers
  160. *
  161. */
  162. public function testGetHeader()
  163. {
  164. $this->_client->setHeaders(array(
  165. 'Accept-encoding' => 'gzip,deflate',
  166. 'Accept-language' => 'en,de,*',
  167. ));
  168. $this->assertEquals($this->_client->getHeader('Accept-encoding'), 'gzip,deflate', 'Returned value of header is not as expected');
  169. $this->assertEquals($this->_client->getHeader('X-Fake-Header'), null, 'Non-existing header should not return a value');
  170. }
  171. public function testUnsetHeader()
  172. {
  173. $this->_client->setHeaders('Accept-Encoding', 'gzip,deflate');
  174. $this->_client->setHeaders('Accept-Encoding', null);
  175. $this->assertNull($this->_client->getHeader('Accept-encoding'), 'Returned value of header is expected to be null');
  176. }
  177. /**
  178. * Authentication tests
  179. */
  180. /**
  181. * Test setAuth (dynamic method) fails when trying to use an unsupported
  182. * authentication scheme
  183. *
  184. * @expectedException Zend_Http_Client_Exception
  185. */
  186. public function testExceptUnsupportedAuthDynamic()
  187. {
  188. $this->_client->setAuth('shahar', '1234', 'SuperStrongAlgo');
  189. }
  190. /**
  191. * Test encodeAuthHeader (static method) fails when trying to use an
  192. * unsupported authentication scheme
  193. *
  194. * @expectedException Zend_Http_Client_Exception
  195. */
  196. public function testExceptUnsupportedAuthStatic()
  197. {
  198. Zend_Http_Client::encodeAuthHeader('shahar', '1234', 'SuperStrongAlgo');
  199. }
  200. /**
  201. * Cookie and Cookie Jar tests
  202. */
  203. /**
  204. * Test we can properly set a new cookie jar
  205. *
  206. */
  207. public function testSetNewCookieJar()
  208. {
  209. $this->_client->setCookieJar();
  210. $this->_client->setCookie('cookie', 'value');
  211. $this->_client->setCookie('chocolate', 'chips');
  212. $jar = $this->_client->getCookieJar();
  213. // Check we got the right cookiejar
  214. $this->assertTrue($jar instanceof Zend_Http_CookieJar, '$jar is not an instance of Zend_Http_CookieJar as expected');
  215. $this->assertEquals(count($jar->getAllCookies()), 2, '$jar does not contain 2 cookies as expected');
  216. }
  217. /**
  218. * Test we can properly set an existing cookie jar
  219. *
  220. */
  221. public function testSetReadyCookieJar()
  222. {
  223. $jar = new Zend_Http_CookieJar();
  224. $jar->addCookie('cookie=value', 'http://www.example.com');
  225. $jar->addCookie('chocolate=chips; path=/foo', 'http://www.example.com');
  226. $this->_client->setCookieJar($jar);
  227. // Check we got the right cookiejar
  228. $this->assertEquals($jar, $this->_client->getCookieJar(), '$jar is not the client\'s cookie jar as expected');
  229. }
  230. /**
  231. * Test we can unset a cookie jar
  232. *
  233. */
  234. public function testUnsetCookieJar()
  235. {
  236. // Set the cookie jar just like in testSetNewCookieJar
  237. $this->_client->setCookieJar();
  238. $this->_client->setCookie('cookie', 'value');
  239. $this->_client->setCookie('chocolate', 'chips');
  240. $jar = $this->_client->getCookieJar();
  241. // Try unsetting the cookiejar
  242. $this->_client->setCookieJar(null);
  243. $this->assertNull($this->_client->getCookieJar(), 'Cookie jar is expected to be null but it is not');
  244. }
  245. /**
  246. * Make sure using an invalid cookie jar object throws an exception
  247. *
  248. * @expectedException Zend_Http_Client_Exception
  249. */
  250. public function testSetInvalidCookieJar()
  251. {
  252. $this->_client->setCookieJar('cookiejar');
  253. }
  254. /**
  255. * Test that when the encodecookies flag is set to FALSE, cookies captured
  256. * from a response by Zend_Http_CookieJar are not encoded
  257. *
  258. * @group ZF-1850
  259. */
  260. public function testCaptureCookiesNoEncodeZF1850()
  261. {
  262. $cookieName = "cookieWithSpecialChars";
  263. $cookieValue = "HID=XXXXXX&UN=XXXXXXX&UID=XXXXX";
  264. $adapter = new Zend_Http_Client_Adapter_Test();
  265. $adapter->setResponse(
  266. "HTTP/1.0 200 OK\r\n" .
  267. "Content-type: text/plain\r\n" .
  268. "Content-length: 2\r\n" .
  269. "Connection: close\r\n" .
  270. "Set-Cookie: $cookieName=$cookieValue; path=/\r\n" .
  271. "\r\n" .
  272. "OK"
  273. );
  274. $this->_client->setUri('http://example.example/test');
  275. $this->_client->setConfig(array(
  276. 'adapter' => $adapter,
  277. 'encodecookies' => false
  278. ));
  279. $this->_client->setCookieJar();
  280. // First request is expected to set the cookie
  281. $this->_client->request();
  282. // Next request should contain the cookie
  283. $this->_client->request();
  284. $request = $this->_client->getLastRequest();
  285. if (! preg_match("/^Cookie: $cookieName=([^;]+)/m", $request, $match)) {
  286. $this->fail("Could not find cookie in request");
  287. }
  288. $this->assertEquals($cookieValue, $match[1]);
  289. }
  290. /**
  291. * Configuration Handling
  292. */
  293. /**
  294. * Test that we can set a valid configuration array with some options
  295. *
  296. */
  297. public function testConfigSetAsArray()
  298. {
  299. $config = array(
  300. 'timeout' => 500,
  301. 'someoption' => 'hasvalue'
  302. );
  303. $this->_client->setConfig($config);
  304. $hasConfig = $this->_client->config;
  305. foreach($config as $k => $v) {
  306. $this->assertEquals($v, $hasConfig[$k]);
  307. }
  308. }
  309. /**
  310. * Test that a Zend_Config object can be used to set configuration
  311. *
  312. * @link http://framework.zend.com/issues/browse/ZF-5577
  313. */
  314. public function testConfigSetAsZendConfig()
  315. {
  316. require_once 'Zend/Config.php';
  317. $config = new Zend_Config(array(
  318. 'timeout' => 400,
  319. 'nested' => array(
  320. 'item' => 'value',
  321. )
  322. ));
  323. $this->_client->setConfig($config);
  324. $hasConfig = $this->_client->config;
  325. $this->assertEquals($config->timeout, $hasConfig['timeout']);
  326. $this->assertEquals($config->nested->item, $hasConfig['nested']['item']);
  327. }
  328. /**
  329. * Test that passing invalid variables to setConfig() causes an exception
  330. *
  331. * @dataProvider invalidConfigProvider
  332. * @expectedException Zend_Http_Client_Exception
  333. */
  334. public function testConfigSetInvalid($config)
  335. {
  336. $this->_client->setConfig($config);
  337. }
  338. /**
  339. * Test that configuration options are passed to the adapter after the
  340. * adapter is instantiated
  341. *
  342. * @link http://framework.zend.com/issues/browse/ZF-4557
  343. */
  344. public function testConfigPassToAdapterZF4557()
  345. {
  346. $adapter = new Zend_Http_Client_StaticTest_TestAdapter_Mock();
  347. // test that config passes when we set the adapter
  348. $this->_client->setConfig(array('param' => 'value1'));
  349. $this->_client->setAdapter($adapter);
  350. $adapterCfg = $adapter->config;
  351. $this->assertEquals('value1', $adapterCfg['param']);
  352. // test that adapter config value changes when we set client config
  353. $this->_client->setConfig(array('param' => 'value2'));
  354. $adapterCfg = $adapter->config;
  355. $this->assertEquals('value2', $adapterCfg['param']);
  356. }
  357. /**
  358. * Other Tests
  359. */
  360. /**
  361. * Test the getLastResponse() method actually returns the last response
  362. *
  363. */
  364. public function testGetLastResponse()
  365. {
  366. // First, make sure we get null before the request
  367. $this->assertEquals(null, $this->_client->getLastResponse(),
  368. 'getLastResponse() is still expected to return null');
  369. // Now, test we get a proper response after the request
  370. $this->_client->setUri('http://example.com/foo/bar');
  371. $this->_client->setAdapter('Zend_Http_Client_Adapter_Test');
  372. $response = $this->_client->request();
  373. $this->assertTrue(($response === $this->_client->getLastResponse()),
  374. 'Response is expected to be identical to the result of getLastResponse()');
  375. }
  376. /**
  377. * Test that getLastResponse returns null when not storing
  378. *
  379. */
  380. public function testGetLastResponseWhenNotStoring()
  381. {
  382. // Now, test we get a proper response after the request
  383. $this->_client->setUri('http://example.com/foo/bar');
  384. $this->_client->setAdapter('Zend_Http_Client_Adapter_Test');
  385. $this->_client->setConfig(array('storeresponse' => false));
  386. $response = $this->_client->request();
  387. $this->assertNull($this->_client->getLastResponse(),
  388. 'getLastResponse is expected to be null when not storing');
  389. }
  390. /**
  391. * Check we get an exception when trying to send a POST request with an
  392. * invalid content-type header
  393. *
  394. * @expectedException Zend_Http_Client_Exception
  395. */
  396. public function testInvalidPostContentType()
  397. {
  398. $this->_client->setEncType('x-foo/something-fake');
  399. $this->_client->setParameterPost('parameter', 'value');
  400. // This should throw an exception
  401. $this->_client->request('POST');
  402. }
  403. /**
  404. * Check we get an exception if there's an error in the socket
  405. *
  406. * @expectedException Zend_Http_Client_Adapter_Exception
  407. */
  408. public function testSocketErrorException()
  409. {
  410. // Try to connect to an invalid host
  411. $this->_client->setUri('http://255.255.255.255');
  412. // Reduce timeout to 3 seconds to avoid waiting
  413. $this->_client->setConfig(array('timeout' => 3));
  414. // This call should cause an exception
  415. $this->_client->request();
  416. }
  417. /**
  418. * Check that we can set methods which are not documented in the RFC.
  419. *
  420. * @dataProvider validMethodProvider
  421. */
  422. public function testSettingExtendedMethod($method)
  423. {
  424. try {
  425. $this->_client->setMethod($method);
  426. } catch (Exception $e) {
  427. $this->fail("An unexpected exception was thrown when setting request method to '{$method}'");
  428. }
  429. }
  430. /**
  431. * Check that an exception is thrown if non-word characters are used in
  432. * the request method.
  433. *
  434. * @dataProvider invalidMethodProvider
  435. * @expectedException Zend_Http_Client_Exception
  436. */
  437. public function testSettingInvalidMethodThrowsException($method)
  438. {
  439. $this->_client->setMethod($method);
  440. }
  441. /**
  442. * Test that POST data with mutli-dimentional array is properly encoded as
  443. * multipart/form-data
  444. *
  445. */
  446. public function testFormDataEncodingWithMultiArrayZF7038()
  447. {
  448. $this->_client->setAdapter('Zend_Http_Client_Adapter_Test');
  449. $this->_client->setUri('http://example.com');
  450. $this->_client->setEncType(Zend_Http_Client::ENC_FORMDATA);
  451. $this->_client->setParameterPost('test', array(
  452. 'v0.1',
  453. 'v0.2',
  454. 'k1' => 'v1.0',
  455. 'k2' => array(
  456. 'v2.1',
  457. 'k2.1' => 'v2.1.0'
  458. )
  459. ));
  460. $this->_client->request('POST');
  461. $expectedLines = file(dirname(__FILE__) . '/_files/ZF7038-multipartarrayrequest.txt');
  462. $gotLines = explode("\n", $this->_client->getLastRequest());
  463. $this->assertEquals(count($expectedLines), count($gotLines));
  464. while (($expected = array_shift($expectedLines)) &&
  465. ($got = array_shift($gotLines))) {
  466. $expected = trim($expected);
  467. $got = trim($got);
  468. $this->assertRegExp("/^$expected$/", $got);
  469. }
  470. }
  471. /**
  472. * @group ZF-4236
  473. */
  474. public function testFormFileUpload()
  475. {
  476. $this->_client->setAdapter('Zend_Http_Client_Adapter_Test');
  477. $this->_client->setUri('http://example.com');
  478. $this->_client->setFileUpload('testFile.name', 'testFile', 'TESTDATA12345', 'text/plain');
  479. $this->_client->request('POST');
  480. $expectedLines = file(dirname(__FILE__) . '/_files/ZF4236-fileuploadrequest.txt');
  481. $gotLines = explode("\n", trim($this->_client->getLastRequest()));
  482. $this->assertEquals(count($expectedLines), count($gotLines));
  483. while (($expected = array_shift($expectedLines)) &&
  484. ($got = array_shift($gotLines))) {
  485. $expected = trim($expected);
  486. $got = trim($got);
  487. $this->assertRegExp("/^$expected$/", $got);
  488. }
  489. }
  490. /**
  491. * @group ZF-4236
  492. */
  493. public function testClientBodyRetainsFieldOrdering()
  494. {
  495. $this->_client->setAdapter('Zend_Http_Client_Adapter_Test');
  496. $this->_client->setUri('http://example.com');
  497. $this->_client->setParameterPost('testFirst', 'foo');
  498. $this->_client->setFileUpload('testFile.name', 'testFile', 'TESTDATA12345', 'text/plain');
  499. $this->_client->setParameterPost('testLast', 'bar');
  500. $this->_client->request('POST');
  501. $expectedLines = file(dirname(__FILE__) . '/_files/ZF4236-clientbodyretainsfieldordering.txt');
  502. $gotLines = explode("\n", trim($this->_client->getLastRequest()));
  503. $this->assertEquals(count($expectedLines), count($gotLines));
  504. while (($expected = array_shift($expectedLines)) &&
  505. ($got = array_shift($gotLines))) {
  506. $expected = trim($expected);
  507. $got = trim($got);
  508. $this->assertRegExp("/^$expected$/", $got);
  509. }
  510. }
  511. /**
  512. * Test that we properly calculate the content-length of multibyte-encoded
  513. * request body
  514. *
  515. * This may file in case that mbstring overloads the substr and strlen
  516. * functions, and the mbstring internal encoding is a multibyte encoding.
  517. *
  518. * @link http://framework.zend.com/issues/browse/ZF-2098
  519. */
  520. public function testMultibyteRawPostDataZF2098()
  521. {
  522. $this->_client->setAdapter('Zend_Http_Client_Adapter_Test');
  523. $this->_client->setUri('http://example.com');
  524. $bodyFile = dirname(__FILE__) . '/_files/ZF2098-multibytepostdata.txt';
  525. $this->_client->setRawData(file_get_contents($bodyFile), 'text/plain');
  526. $this->_client->request('POST');
  527. $request = $this->_client->getLastRequest();
  528. if (! preg_match('/^content-length:\s+(\d+)/mi', $request, $match)) {
  529. $this->fail("Unable to find content-length header in request");
  530. }
  531. $this->assertEquals(filesize($bodyFile), (int) $match[1]);
  532. }
  533. /**
  534. * @group ZF-8057
  535. */
  536. public function testSetDisabledAuthBeforSettingUriBug()
  537. {
  538. $client = new Zend_Http_Client_StaticTest_Mock();
  539. // if the bug exists this call should creates a fatal error
  540. $client->setAuth(false);
  541. }
  542. /**
  543. * Testing if the connection isn't closed
  544. *
  545. * @group ZF-9685
  546. */
  547. public function testOpenTempStreamWithValidFileDoesntThrowsException()
  548. {
  549. $url = 'http://www.example.com';
  550. $config = array (
  551. 'output_stream' => realpath(dirname(__FILE__) . '/_files/zend_http_client_stream.file'),
  552. );
  553. $client = new Zend_Http_Client($url, $config);
  554. try {
  555. $result = $client->request();
  556. } catch (Zend_Http_Client_Exception $e) {
  557. $this->fail('Unexpected exception was thrown');
  558. }
  559. // we can safely return until we can verify link is still active
  560. // @todo verify link is still active
  561. return;
  562. }
  563. /**
  564. * Testing if the connection can be closed
  565. *
  566. * @group ZF-9685
  567. */
  568. public function testOpenTempStreamWithBogusFileClosesTheConnection()
  569. {
  570. $url = 'http://www.example.com';
  571. $config = array (
  572. 'output_stream' => '/path/to/bogus/file.ext',
  573. );
  574. $client = new Zend_Http_Client($url, $config);
  575. try {
  576. $result = $client->request();
  577. $this->fail('Expected exception was not thrown');
  578. } catch (Zend_Http_Client_Exception $e) {
  579. // we return since we expect the exception
  580. return;
  581. }
  582. }
  583. /**
  584. * Test that we can handle trailing space in location header
  585. *
  586. * @group ZF-11283
  587. * @link http://framework.zend.com/issues/browse/ZF-11283
  588. */
  589. public function testRedirectWithTrailingSpaceInLocationHeaderZF11283()
  590. {
  591. $this->_client->setUri('http://example.com/');
  592. $this->_client->setAdapter('Zend_Http_Client_Adapter_Test');
  593. $adapter = $this->_client->getAdapter(); /* @var $adapter Zend_Http_Client_Adapter_Test */
  594. $adapter->setResponse(<<<RESPONSE
  595. HTTP/1.1 302 Redirect
  596. Content-Type: text/html; charset=UTF-8
  597. Location: /test
  598. Server: Microsoft-IIS/7.0
  599. Date: Tue, 19 Apr 2011 11:23:48 GMT
  600. RESPONSE
  601. );
  602. $res = $this->_client->request('GET');
  603. $lastUri = $this->_client->getUri();
  604. $this->assertEquals("/test", $lastUri->getPath());
  605. }
  606. /**
  607. * @group ZF-11162
  608. */
  609. function testClientDoesNotModifyPassedUri() {
  610. $uri = Zend_Uri_Http::fromString('http://example.org/');
  611. $orig = clone $uri;
  612. $client = new Zend_Http_Client($uri);
  613. $this->assertEquals((string)$orig, (string)$uri);
  614. }
  615. /*
  616. * @group ZF-9206
  617. */
  618. function testStreamWarningRewind()
  619. {
  620. $httpClient = new Zend_Http_Client();
  621. $httpClient->setUri('http://example.org');
  622. $httpClient->setMethod(Zend_Http_Client::GET);
  623. ob_start();
  624. $httpClient->setStream('php://output')->request();
  625. ob_clean();
  626. }
  627. /**
  628. * Data providers
  629. */
  630. /**
  631. * Data provider of valid non-standard HTTP methods
  632. *
  633. * @return array
  634. */
  635. static public function validMethodProvider()
  636. {
  637. return array(
  638. array('OPTIONS'),
  639. array('POST'),
  640. array('DOSOMETHING'),
  641. array('PROPFIND'),
  642. array('Some_Characters'),
  643. array('X-MS-ENUMATTS')
  644. );
  645. }
  646. /**
  647. * Data provider of invalid HTTP methods
  648. *
  649. * @return array
  650. */
  651. static public function invalidMethodProvider()
  652. {
  653. return array(
  654. array('N@5TYM3T#0D'),
  655. array('TWO WORDS'),
  656. array('GET http://foo.com/?'),
  657. array("Injected\nnewline")
  658. );
  659. }
  660. /**
  661. * Data provider for invalid configuration containers
  662. *
  663. * @return array
  664. */
  665. static public function invalidConfigProvider()
  666. {
  667. return array(
  668. array(false),
  669. array('foo => bar'),
  670. array(null),
  671. array(new stdClass),
  672. array(55)
  673. );
  674. }
  675. }
  676. class Zend_Http_Client_StaticTest_Mock extends Zend_Http_Client
  677. {
  678. public $config = array(
  679. 'maxredirects' => 5,
  680. 'strictredirects' => false,
  681. 'useragent' => 'Zend_Http_Client',
  682. 'timeout' => 10,
  683. 'adapter' => 'Zend_Http_Client_Adapter_Socket',
  684. 'httpversion' => self::HTTP_1,
  685. 'keepalive' => false,
  686. 'storeresponse' => true,
  687. 'strict' => true,
  688. 'output_stream' => false,
  689. 'encodecookies' => true,
  690. );
  691. }
  692. class Zend_Http_Client_StaticTest_TestAdapter_Mock extends Zend_Http_Client_Adapter_Test
  693. {
  694. public $config = array();
  695. }