CommonHttpTests.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  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
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. // Read local configuration
  23. if (! defined('TESTS_ZEND_HTTP_CLIENT_BASEURI') &&
  24. is_readable('TestConfiguration.php')) {
  25. require_once 'TestConfiguration.php';
  26. }
  27. require_once 'Zend/Http/Client.php';
  28. require_once 'Zend/Uri/Http.php';
  29. /**
  30. * This Testsuite includes all Zend_Http_Client that require a working web
  31. * server to perform. It was designed to be extendable, so that several
  32. * test suites could be run against several servers, with different client
  33. * adapters and configurations.
  34. *
  35. * Note that $this->baseuri must point to a directory on a web server
  36. * containing all the files under the _files directory. You should symlink
  37. * or copy these files and set 'baseuri' properly.
  38. *
  39. * You can also set the proper constant in your test configuration file to
  40. * point to the right place.
  41. *
  42. * @category Zend
  43. * @package Zend_Http_Client
  44. * @subpackage UnitTests
  45. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  46. * @license http://framework.zend.com/license/new-bsd New BSD License
  47. * @group Zend_Http
  48. * @group Zend_Http_Client
  49. */
  50. abstract class Zend_Http_Client_CommonHttpTests extends PHPUnit_Framework_TestCase
  51. {
  52. /**
  53. * The bast URI for this test, containing all files in the _files directory
  54. * Should be set in TestConfiguration.php or TestConfiguration.php.dist
  55. *
  56. * @var string
  57. */
  58. protected $baseuri;
  59. /**
  60. * Common HTTP client
  61. *
  62. * @var Zend_Http_Client
  63. */
  64. protected $client = null;
  65. /**
  66. * Common HTTP client adapter
  67. *
  68. * @var Zend_Http_Client_Adapter_Interface
  69. */
  70. protected $_adapter = null;
  71. /**
  72. * Configuration array
  73. *
  74. * @var array
  75. */
  76. protected $config = array(
  77. 'adapter' => 'Zend_Http_Client_Adapter_Socket'
  78. );
  79. /**
  80. * Set up the test case
  81. *
  82. */
  83. protected function setUp()
  84. {
  85. if (defined('TESTS_ZEND_HTTP_CLIENT_BASEURI') &&
  86. Zend_Uri_Http::check(TESTS_ZEND_HTTP_CLIENT_BASEURI)) {
  87. $this->baseuri = TESTS_ZEND_HTTP_CLIENT_BASEURI;
  88. if (substr($this->baseuri, -1) != '/') $this->baseuri .= '/';
  89. $name = $this->getName();
  90. if (($pos = strpos($name, ' ')) !== false) {
  91. $name = substr($name, 0, $pos);
  92. }
  93. $uri = $this->baseuri . $name . '.php';
  94. $this->_adapter = new $this->config['adapter'];
  95. $this->client = new Zend_Http_Client($uri, $this->config);
  96. $this->client->setAdapter($this->_adapter);
  97. } else {
  98. // Skip tests
  99. $this->markTestSkipped("Zend_Http_Client dynamic tests are not enabled in TestConfiguration.php");
  100. }
  101. }
  102. /**
  103. * Clean up the test environment
  104. *
  105. */
  106. protected function tearDown()
  107. {
  108. $this->client = null;
  109. $this->_adapter = null;
  110. }
  111. /**
  112. * Simple request tests
  113. */
  114. /**
  115. * Test simple requests
  116. *
  117. */
  118. public function testSimpleRequests()
  119. {
  120. $methods = array('GET', 'POST', 'OPTIONS', 'PUT', 'PATCH', 'DELETE');
  121. foreach ($methods as $method) {
  122. $res = $this->client->request($method);
  123. $this->assertEquals('Success', $res->getBody(), "HTTP {$method} request failed.");
  124. }
  125. }
  126. /**
  127. * Test we can get the last request as string
  128. *
  129. */
  130. public function testGetLastRequest()
  131. {
  132. $this->client->setUri($this->baseuri . 'testHeaders.php');
  133. $this->client->setParameterGet('someinput', 'somevalue');
  134. $this->client->setHeaders(array(
  135. 'X-Powered-By' => 'My Glorious Golden Ass',
  136. ));
  137. $res = $this->client->request(Zend_Http_Client::TRACE);
  138. if ($res->getStatus() == 405 || $res->getStatus() == 501) {
  139. $this->markTestSkipped("Server does not allow the TRACE method");
  140. }
  141. $this->assertEquals($this->client->getLastRequest(), $res->getBody(), 'Response body should be exactly like the last request');
  142. }
  143. /**
  144. * GET and POST parameters tests
  145. */
  146. /**
  147. * Test we can properly send GET parameters
  148. *
  149. * @dataProvider parameterArrayProvider
  150. */
  151. public function testGetData($params)
  152. {
  153. $this->client->setUri($this->client->getUri(true) . '?name=Arthur');
  154. $this->client->setParameterGet($params);
  155. $res = $this->client->request('GET');
  156. $this->assertEquals(serialize(array_merge(array('name' => 'Arthur'), $params)), $res->getBody());
  157. }
  158. /**
  159. * Test we can properly send POST parameters with
  160. * application/x-www-form-urlencoded content type
  161. *
  162. * @dataProvider parameterArrayProvider
  163. */
  164. public function testPostDataUrlEncoded($params)
  165. {
  166. $this->client->setUri($this->baseuri . 'testPostData.php');
  167. $this->client->setEncType(Zend_Http_Client::ENC_URLENCODED);
  168. $this->client->setParameterPost($params);
  169. $res = $this->client->request('POST');
  170. $this->assertEquals(serialize($params), $res->getBody(), "POST data integrity test failed");
  171. }
  172. /**
  173. * Test we can properly send PUT parameters with
  174. * application/x-www-form-urlencoded content type
  175. *
  176. * @dataProvider parameterArrayProvider
  177. */
  178. public function testPutDataUrlEncoded($params)
  179. {
  180. $this->client->setUri($this->baseuri . 'testPutData.php');
  181. $this->client->setEncType(Zend_Http_Client::ENC_URLENCODED);
  182. $this->client->setParameterPost($params);
  183. $res = $this->client->request('PUT');
  184. $this->assertEquals(serialize($params), $res->getBody(), "PUT data integrity test failed");
  185. }
  186. /**
  187. * Test we can properly send PUT parameters without
  188. * content type, relying on default content type (urlencoded)
  189. *
  190. * @dataProvider parameterArrayProvider
  191. */
  192. public function testPutDataDefault($params)
  193. {
  194. $this->client->setUri($this->baseuri . 'testPutData.php');
  195. // note that no content type is set
  196. $this->client->setParameterPost($params);
  197. $res = $this->client->request('PUT');
  198. $this->assertEquals(serialize($params), $res->getBody(), "PUT data integrity test failed for default content-type");
  199. }
  200. /**
  201. * Test we can properly send PATCH parameters with
  202. * application/x-www-form-urlencoded content type
  203. *
  204. * @dataProvider parameterArrayProvider
  205. */
  206. public function testPatchDataUrlEncoded($params)
  207. {
  208. $this->client->setUri($this->baseuri . 'testPatchData.php');
  209. $this->client->setEncType(Zend_Http_Client::ENC_URLENCODED);
  210. $this->client->setParameterPost($params);
  211. $res = $this->client->request('PATCH');
  212. $this->assertEquals(serialize($params), $res->getBody(), "PATCH data integrity test failed");
  213. }
  214. /**
  215. * Test we can properly send PATCH parameters without
  216. * content type, relying on default content type (urlencoded)
  217. *
  218. * @dataProvider parameterArrayProvider
  219. */
  220. public function testPatchDataDefault($params)
  221. {
  222. $this->client->setUri($this->baseuri . 'testPatchData.php');
  223. // note that no content type is set
  224. $this->client->setParameterPost($params);
  225. $res = $this->client->request('PATCH');
  226. $this->assertEquals(serialize($params), $res->getBody(), "PATCH data integrity test failed for default content-type");
  227. }
  228. /**
  229. * Test we can properly send OPTIONS parameters with
  230. * application/x-www-form-urlencoded content type
  231. *
  232. * @dataProvider parameterArrayProvider
  233. */
  234. public function testOptionsDataUrlEncoded($params)
  235. {
  236. $this->client->setUri($this->baseuri . 'testOptionsData.php');
  237. $this->client->setEncType(Zend_Http_Client::ENC_URLENCODED);
  238. $this->client->setParameterPost($params);
  239. $res = $this->client->request('OPTIONS');
  240. $this->assertEquals(serialize($params), $res->getBody(), "OPTIONS data integrity test failed");
  241. }
  242. /**
  243. * Test we can properly send OPTIONS parameters without
  244. * content type, relying on default content type (urlencoded)
  245. *
  246. * @dataProvider parameterArrayProvider
  247. */
  248. public function testOptionsDataDefault($params)
  249. {
  250. $this->client->setUri($this->baseuri . 'testOptionsData.php');
  251. // note that no content type is set
  252. $this->client->setParameterPost($params);
  253. $res = $this->client->request('OPTIONS');
  254. $this->assertEquals(serialize($params), $res->getBody(), "OPTIONS data integrity test failed for default content-type");
  255. }
  256. /**
  257. * Test we can properly send parameters with
  258. * application/x-www-form-urlencoded content type
  259. *
  260. * @dataProvider parameterArrayProvider
  261. */
  262. public function testDeleteDataUrlEncoded($params)
  263. {
  264. $this->client->setUri($this->baseuri . 'testDeleteData.php');
  265. $this->client->setEncType(Zend_Http_Client::ENC_URLENCODED);
  266. $this->client->setParameterPost($params);
  267. $res = $this->client->request('DELETE');
  268. $this->assertEquals(serialize($params), $res->getBody(), "DELETE data integrity test failed");
  269. }
  270. /**
  271. * Test we can properly send POST parameters with
  272. * multipart/form-data content type
  273. *
  274. * @dataProvider parameterArrayProvider
  275. */
  276. public function testPostDataMultipart($params)
  277. {
  278. $this->client->setUri($this->baseuri . 'testPostData.php');
  279. $this->client->setEncType(Zend_Http_Client::ENC_FORMDATA);
  280. $this->client->setParameterPost($params);
  281. $res = $this->client->request('POST');
  282. $this->assertEquals(serialize($params), $res->getBody(), "POST data integrity test failed");
  283. }
  284. /**
  285. * Test we can properly send PUT parameters with
  286. * multipart/form-data content type
  287. *
  288. * @dataProvider parameterArrayProvider
  289. */
  290. public function testPutDataMultipart($params)
  291. {
  292. $this->client->setUri($this->baseuri . 'testRawPutData.php');
  293. $this->client->setParameterPost($params);
  294. $this->client->setMethod(Zend_Http_Client::PUT);
  295. $this->client->setEncType(Zend_Http_Client::ENC_FORMDATA);
  296. $response = $this->client->request();
  297. $responseText = $response->getBody();
  298. $this->_checkPresence($responseText, $params);
  299. }
  300. /**
  301. * Test we can properly send PATCH parameters with
  302. * multipart/form-data content type
  303. *
  304. * @dataProvider parameterArrayProvider
  305. */
  306. public function testPatchDataMultipart($params)
  307. {
  308. $this->client->setUri($this->baseuri . 'testRawPatchData.php');
  309. $this->client->setParameterPost($params);
  310. $this->client->setMethod(Zend_Http_Client::PATCH);
  311. $this->client->setEncType(Zend_Http_Client::ENC_FORMDATA);
  312. $response = $this->client->request();
  313. $responseText = $response->getBody();
  314. $this->_checkPresence($responseText, $params);
  315. }
  316. /**
  317. * Test we can properly send OPTIONS parameters with
  318. * multipart/form-data content type
  319. *
  320. * @dataProvider parameterArrayProvider
  321. */
  322. public function testOptionsDataMultipart($params)
  323. {
  324. $this->client->setUri($this->baseuri . 'testRawOptionsData.php');
  325. $this->client->setParameterPost($params);
  326. $this->client->setMethod(Zend_Http_Client::OPTIONS);
  327. $this->client->setEncType(Zend_Http_Client::ENC_FORMDATA);
  328. $response = $this->client->request();
  329. $responseText = $response->getBody();
  330. $this->_checkPresence($responseText, $params);
  331. }
  332. /**
  333. * Checks the presence of keys (non-numeric only) and values
  334. * in the raw form data reponse for a PUT or DELETE request recursively
  335. *
  336. * An example response (I do not know of a better way to check it):
  337. * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828
  338. * Content-Disposition: form-data; name="quest"
  339. *
  340. * To seek the holy grail
  341. * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828
  342. * Content-Disposition: form-data; name="YourMother"
  343. *
  344. * Was a hamster
  345. * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828
  346. * Content-Disposition: form-data; name="specialChars"
  347. *
  348. * <>$+ &?=[]^%
  349. * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828
  350. * Content-Disposition: form-data; name="array[]"
  351. *
  352. * firstItem
  353. * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828
  354. * Content-Disposition: form-data; name="array[]"
  355. *
  356. * secondItem
  357. * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828
  358. * Content-Disposition: form-data; name="array[]"
  359. *
  360. * 3rdItem
  361. * -----ZENDHTTPCLIENT-c63973519a6bb3ec45495876f5e15828--
  362. * @param string $responseText
  363. * @param string|integer|array $needle
  364. */
  365. protected function _checkPresence($responseText, $needle)
  366. {
  367. if (is_array($needle)) {
  368. foreach ($needle as $key => $value) {
  369. // treat array values recursively, let them re-enter this function
  370. if (is_array($value)) {
  371. $this->_checkPresence($responseText, $value);
  372. continue;
  373. }
  374. // continue with non array keys and values
  375. // numeric keys will not be present in the response
  376. if (!is_int($key)) {
  377. $this->assertGreaterThan(
  378. 0,
  379. strpos($responseText, $key),
  380. "key '$key' is missing from the reponse for raw multipart PUT or DELETE request"
  381. );
  382. }
  383. $this->assertGreaterThan(
  384. 0,
  385. strpos($responseText, $value),
  386. "value '$value' is missing from the reponse for raw multipart PUT or DELETE request"
  387. );
  388. }
  389. }
  390. }
  391. /**
  392. * Test we can properly send DELETE parameters with
  393. * multipart/form-data content type
  394. *
  395. * @dataProvider parameterArrayProvider
  396. */
  397. public function testDeleteDataMultipart($params)
  398. {
  399. $this->client->setUri($this->baseuri . 'testRawDeleteData.php');
  400. $this->client->setParameterPost($params);
  401. $this->client->setMethod(Zend_Http_Client::DELETE);
  402. $this->client->setEncType(Zend_Http_Client::ENC_FORMDATA);
  403. $response = $this->client->request();
  404. $responseText = $response->getBody();
  405. $this->_checkPresence($responseText, $params);
  406. }
  407. /**
  408. * Test using raw HTTP POST data
  409. *
  410. */
  411. public function testRawPostData()
  412. {
  413. $data = "Chuck Norris never wet his bed as a child. The bed wet itself out of fear.";
  414. $res = $this->client->setRawData($data, 'text/html')->request('POST');
  415. $this->assertEquals($data, $res->getBody(), 'Response body does not contain the expected data');
  416. }
  417. /**
  418. * Test using raw HTTP PUT data
  419. *
  420. * @group ZF-11030
  421. *
  422. */
  423. public function testRawPutData()
  424. {
  425. $data = "Chuck Norris never wet his bed as a child. The bed wet itself out of fear.";
  426. $this->client->setUri($this->baseuri . 'testRawPutData.php');
  427. $this->client->setRawData($data, 'text/plain');
  428. $this->client->setMethod(Zend_Http_Client::PUT);
  429. $response = $this->client->request();
  430. $this->assertEquals($data, $response->getBody(), 'Response body does not contain the expected data');
  431. }
  432. /**
  433. * Test using raw HTTP DELETE data
  434. *
  435. * @group ZF-11030
  436. *
  437. */
  438. public function testRawDeleteData()
  439. {
  440. $data = "Chuck Norris never wet his bed as a child. The bed wet itself out of fear.";
  441. $this->client->setUri($this->baseuri . 'testRawDeleteData.php');
  442. $this->client->setRawData($data, 'text/plain');
  443. $this->client->setMethod(Zend_Http_Client::DELETE);
  444. $response = $this->client->request();
  445. $this->assertEquals($data, $response->getBody(), 'Response body does not contain the expected data');
  446. }
  447. /**
  448. * Make sure we can reset the parameters between consecutive requests
  449. *
  450. */
  451. public function testResetParameters()
  452. {
  453. $params = array(
  454. 'quest' => 'To seek the holy grail',
  455. 'YourMother' => 'Was a hamster',
  456. 'specialChars' => '<>$+ &?=[]^%',
  457. 'array' => array('firstItem', 'secondItem', '3rdItem')
  458. );
  459. $headers = array("X-Foo" => "bar");
  460. $this->client->setParameterPost($params);
  461. $this->client->setParameterGet($params);
  462. $this->client->setHeaders($headers);
  463. $res = $this->client->request('POST');
  464. $this->assertContains(serialize($params) . "\n" . serialize($params),
  465. $res->getBody(), "returned body does not contain all GET and POST parameters (it should!)");
  466. $this->client->resetParameters();
  467. $res = $this->client->request('POST');
  468. $this->assertNotContains(serialize($params), $res->getBody(),
  469. "returned body contains GET or POST parameters (it shouldn't!)");
  470. $this->assertContains($headers["X-Foo"], $this->client->getHeader("X-Foo"), "Header not preserved by reset");
  471. $this->client->resetParameters(true);
  472. $this->assertNull($this->client->getHeader("X-Foo"), "Header preserved by reset(true)");
  473. }
  474. /**
  475. * Test parameters get reset when we unset them
  476. *
  477. */
  478. public function testParameterUnset()
  479. {
  480. $this->client->setUri($this->baseuri . 'testResetParameters.php');
  481. $gparams = array (
  482. 'cheese' => 'camambert',
  483. 'beer' => 'jever pilnsen',
  484. );
  485. $pparams = array (
  486. 'from' => 'bob',
  487. 'to' => 'alice'
  488. );
  489. $this->client->setParameterGet($gparams)->setParameterPost($pparams);
  490. // Remove some parameters
  491. $this->client->setParameterGet('cheese', null)->setParameterPost('to', null);
  492. $res = $this->client->request('POST');
  493. $this->assertNotContains('cheese', $res->getBody(), 'The "cheese" GET parameter was expected to be unset');
  494. $this->assertNotContains('alice', $res->getBody(), 'The "to" POST parameter was expected to be unset');
  495. }
  496. /**
  497. * Header Tests
  498. */
  499. /**
  500. * Make sure we can set a single header
  501. *
  502. */
  503. public function testHeadersSingle()
  504. {
  505. $this->client->setUri($this->baseuri . 'testHeaders.php');
  506. $headers = array(
  507. 'Accept-encoding' => 'gzip,deflate',
  508. 'X-baz' => 'Foo',
  509. 'X-powered-by' => 'A large wooden badger'
  510. );
  511. foreach ($headers as $key => $val) {
  512. $this->client->setHeaders($key, $val);
  513. }
  514. $acceptHeader = "Accept: text/xml,text/html,*/*";
  515. $this->client->setHeaders($acceptHeader);
  516. $res = $this->client->request('TRACE');
  517. if ($res->getStatus() == 405 || $res->getStatus() == 501) {
  518. $this->markTestSkipped("Server does not allow the TRACE method");
  519. }
  520. $body = strtolower($res->getBody());
  521. foreach ($headers as $key => $val)
  522. $this->assertContains(strtolower("$key: $val"), $body);
  523. $this->assertContains(strtolower($acceptHeader), $body);
  524. }
  525. /**
  526. * Test we can set an array of headers
  527. *
  528. */
  529. public function testHeadersArray()
  530. {
  531. $this->client->setUri($this->baseuri . 'testHeaders.php');
  532. $headers = array(
  533. 'Accept-encoding' => 'gzip,deflate',
  534. 'X-baz' => 'Foo',
  535. 'X-powered-by' => 'A large wooden badger',
  536. 'Accept: text/xml,text/html,*/*'
  537. );
  538. $this->client->setHeaders($headers);
  539. $res = $this->client->request('TRACE');
  540. if ($res->getStatus() == 405 || $res->getStatus() == 501) {
  541. $this->markTestSkipped("Server does not allow the TRACE method");
  542. }
  543. $body = strtolower($res->getBody());
  544. foreach ($headers as $key => $val) {
  545. if (is_string($key)) {
  546. $this->assertContains(strtolower("$key: $val"), $body);
  547. } else {
  548. $this->assertContains(strtolower($val), $body);
  549. }
  550. }
  551. }
  552. /**
  553. * Test we can set a set of values for one header
  554. *
  555. */
  556. public function testMultipleHeader()
  557. {
  558. $this->client->setUri($this->baseuri . 'testHeaders.php');
  559. $headers = array(
  560. 'Accept-encoding' => 'gzip,deflate',
  561. 'X-baz' => 'Foo',
  562. 'X-powered-by' => array(
  563. 'A large wooden badger',
  564. 'My Shiny Metal Ass',
  565. 'Dark Matter'
  566. ),
  567. 'Cookie' => array(
  568. 'foo=bar',
  569. 'baz=waka'
  570. )
  571. );
  572. $this->client->setHeaders($headers);
  573. $res = $this->client->request('TRACE');
  574. if ($res->getStatus() == 405 || $res->getStatus() == 501) {
  575. $this->markTestSkipped("Server does not allow the TRACE method");
  576. }
  577. $body = strtolower($res->getBody());
  578. foreach ($headers as $key => $val) {
  579. if (is_array($val))
  580. $val = implode(', ', $val);
  581. $this->assertContains(strtolower("$key: $val"), $body);
  582. }
  583. }
  584. /**
  585. * Redirection tests
  586. */
  587. /**
  588. * Test the client properly redirects in default mode
  589. *
  590. */
  591. public function testRedirectDefault()
  592. {
  593. $this->client->setUri($this->baseuri . 'testRedirections.php');
  594. // Set some parameters
  595. $this->client->setParameterGet('swallow', 'african');
  596. $this->client->setParameterPost('Camelot', 'A silly place');
  597. // Request
  598. $res = $this->client->request('POST');
  599. $this->assertEquals(3, $this->client->getRedirectionsCount(), 'Redirection counter is not as expected');
  600. // Make sure the body does *not* contain the set parameters
  601. $this->assertNotContains('swallow', $res->getBody());
  602. $this->assertNotContains('Camelot', $res->getBody());
  603. }
  604. /**
  605. * Make sure the client properly redirects in strict mode
  606. *
  607. */
  608. public function testRedirectStrict()
  609. {
  610. $this->client->setUri($this->baseuri . 'testRedirections.php');
  611. // Set some parameters
  612. $this->client->setParameterGet('swallow', 'african');
  613. $this->client->setParameterPost('Camelot', 'A silly place');
  614. // Set strict redirections
  615. $this->client->setConfig(array('strictredirects' => true));
  616. // Request
  617. $res = $this->client->request('POST');
  618. $this->assertEquals(3, $this->client->getRedirectionsCount(), 'Redirection counter is not as expected');
  619. // Make sure the body *does* contain the set parameters
  620. $this->assertContains('swallow', $res->getBody());
  621. $this->assertContains('Camelot', $res->getBody());
  622. }
  623. /**
  624. * Make sure redirections stop when limit is exceeded
  625. *
  626. */
  627. public function testMaxRedirectsExceeded()
  628. {
  629. $this->client->setUri($this->baseuri . 'testRedirections.php');
  630. // Set some parameters
  631. $this->client->setParameterGet('swallow', 'african');
  632. $this->client->setParameterPost('Camelot', 'A silly place');
  633. // Set lower max redirections
  634. // Try with strict redirections first
  635. $this->client->setConfig(array('strictredirects' => true, 'maxredirects' => 2));
  636. $res = $this->client->request('POST');
  637. $this->assertTrue($res->isRedirect(),
  638. "Last response was not a redirection as expected. Response code: {$res->getStatus()}. Redirections counter: {$this->client->getRedirectionsCount()} (when strict redirects are on)");
  639. // Then try with normal redirections
  640. $this->client->setParameterGet('redirection', '0');
  641. $this->client->setConfig(array('strictredirects' => false));
  642. $res = $this->client->request('POST');
  643. $this->assertTrue($res->isRedirect(),
  644. "Last response was not a redirection as expected. Response code: {$res->getStatus()}. Redirections counter: {$this->client->getRedirectionsCount()} (when strict redirects are off)");
  645. }
  646. /**
  647. * Test we can properly redirect to an absolute path (not full URI)
  648. *
  649. */
  650. public function testAbsolutePathRedirect()
  651. {
  652. $this->client->setUri($this->baseuri . 'testRelativeRedirections.php');
  653. $this->client->setParameterGet('redirect', 'abpath');
  654. $this->client->setConfig(array('maxredirects' => 1));
  655. // Get the host and port part of our baseuri
  656. $uri = $this->client->getUri()->getScheme() . '://' . $this->client->getUri()->getHost() . ':' .
  657. $this->client->getUri()->getPort();
  658. $res = $this->client->request('GET');
  659. $this->assertEquals("{$uri}/path/to/fake/file.ext?redirect=abpath", $this->client->getUri(true),
  660. "The new location is not as expected: {$this->client->getUri(true)}");
  661. }
  662. /**
  663. * Test we can properly redirect to a relative path
  664. *
  665. */
  666. public function testRelativePathRedirect()
  667. {
  668. $this->client->setUri($this->baseuri . 'testRelativeRedirections.php');
  669. $this->client->setParameterGet('redirect', 'relpath');
  670. $this->client->setConfig(array('maxredirects' => 1));
  671. // Set the new expected URI
  672. $uri = clone $this->client->getUri();
  673. $uri->setPath(rtrim(dirname($uri->getPath()), '/') . '/path/to/fake/file.ext');
  674. $uri = $uri->__toString();
  675. $res = $this->client->request('GET');
  676. $this->assertEquals("{$uri}?redirect=relpath", $this->client->getUri(true),
  677. "The new location is not as expected: {$this->client->getUri(true)}");
  678. }
  679. /**
  680. * HTTP Authentication Tests
  681. *
  682. */
  683. /**
  684. * Test we can properly use Basic HTTP authentication
  685. *
  686. */
  687. public function testHttpAuthBasic()
  688. {
  689. $this->client->setUri($this->baseuri. 'testHttpAuth.php');
  690. $this->client->setParameterGet(array(
  691. 'user' => 'alice',
  692. 'pass' => 'secret',
  693. 'method' => 'Basic'
  694. ));
  695. // First - fail password
  696. $this->client->setAuth('alice', 'wrong');
  697. $res = $this->client->request();
  698. $this->assertEquals(401, $res->getStatus(), 'Expected HTTP 401 response was not recieved');
  699. // Now use good password
  700. $this->client->setAuth('alice', 'secret');
  701. $res = $this->client->request();
  702. $this->assertEquals(200, $res->getStatus(), 'Expected HTTP 200 response was not recieved');
  703. }
  704. /**
  705. * Test that we can properly use Basic HTTP authentication by specifying username and password
  706. * in the URI
  707. *
  708. */
  709. public function testHttpAuthBasicWithCredentialsInUri()
  710. {
  711. $uri = str_replace('http://', 'http://%s:%s@', $this->baseuri) . 'testHttpAuth.php';
  712. $this->client->setParameterGet(array(
  713. 'user' => 'alice',
  714. 'pass' => 'secret',
  715. 'method' => 'Basic'
  716. ));
  717. // First - fail password
  718. $this->client->setUri(sprintf($uri, 'alice', 'wrong'));
  719. $res = $this->client->request();
  720. $this->assertEquals(401, $res->getStatus(), 'Expected HTTP 401 response was not recieved');
  721. // Now use good password
  722. $this->client->setUri(sprintf($uri, 'alice', 'secret'));
  723. $res = $this->client->request();
  724. $this->assertEquals(200, $res->getStatus(), 'Expected HTTP 200 response was not recieved');
  725. }
  726. /**
  727. * Test we can unset HTTP authentication
  728. *
  729. */
  730. public function testCancelAuth()
  731. {
  732. $this->client->setUri($this->baseuri. 'testHttpAuth.php');
  733. // Set auth and cancel it
  734. $this->client->setAuth('alice', 'secret');
  735. $this->client->setAuth(false);
  736. $res = $this->client->request();
  737. $this->assertEquals(401, $res->getStatus(), 'Expected HTTP 401 response was not recieved');
  738. $this->assertNotContains('alice', $res->getBody(), "Body contains the user name, but it shouldn't");
  739. $this->assertNotContains('secret', $res->getBody(), "Body contains the password, but it shouldn't");
  740. }
  741. /**
  742. * Test that we can unset HTTP authentication when credentials is specified in the URI
  743. *
  744. */
  745. public function testCancelAuthWithCredentialsInUri()
  746. {
  747. $uri = str_replace('http://', 'http://%s:%s@', $this->baseuri) . 'testHttpAuth.php';
  748. // Set auth and cancel it
  749. $this->client->setUri(sprintf($uri, 'alice', 'secret'));
  750. $this->client->setAuth(false);
  751. $res = $this->client->request();
  752. $this->assertEquals(401, $res->getStatus(), 'Expected HTTP 401 response was not recieved');
  753. $this->assertNotContains('alice', $res->getBody(), "Body contains the user name, but it shouldn't");
  754. $this->assertNotContains('secret', $res->getBody(), "Body contains the password, but it shouldn't");
  755. }
  756. /**
  757. * Cookie and CookieJar Tests
  758. *
  759. */
  760. /**
  761. * Test we can set string cookies with no jar
  762. *
  763. */
  764. public function testCookiesStringNoJar()
  765. {
  766. $this->client->setUri($this->baseuri. 'testCookies.php');
  767. $cookies = array(
  768. 'name' => 'value',
  769. 'cookie' => 'crumble'
  770. );
  771. foreach ($cookies as $k => $v) {
  772. $this->client->setCookie($k, $v);
  773. }
  774. $res = $this->client->request();
  775. $this->assertEquals($res->getBody(), serialize($cookies), 'Response body does not contain the expected cookies');
  776. }
  777. /**
  778. * Make sure we can set object cookies with no jar
  779. *
  780. */
  781. public function testSetCookieObjectNoJar()
  782. {
  783. $this->client->setUri($this->baseuri. 'testCookies.php');
  784. $refuri = $this->client->getUri();
  785. $cookies = array(
  786. Zend_Http_Cookie::fromString('chocolate=chips', $refuri),
  787. Zend_Http_Cookie::fromString('crumble=apple', $refuri)
  788. );
  789. $strcookies = array();
  790. foreach ($cookies as $c) {
  791. $this->client->setCookie($c);
  792. $strcookies[$c->getName()] = $c->getValue();
  793. }
  794. $res = $this->client->request();
  795. $this->assertEquals($res->getBody(), serialize($strcookies), 'Response body does not contain the expected cookies');
  796. }
  797. /**
  798. * Make sure we can set an array of object cookies
  799. *
  800. */
  801. public function testSetCookieObjectArray()
  802. {
  803. $this->client->setUri($this->baseuri. 'testCookies.php');
  804. $refuri = $this->client->getUri();
  805. $cookies = array(
  806. Zend_Http_Cookie::fromString('chocolate=chips', $refuri),
  807. Zend_Http_Cookie::fromString('crumble=apple', $refuri),
  808. Zend_Http_Cookie::fromString('another=cookie', $refuri)
  809. );
  810. $this->client->setCookie($cookies);
  811. $strcookies = array();
  812. foreach ($cookies as $c) {
  813. $strcookies[$c->getName()] = $c->getValue();
  814. }
  815. $res = $this->client->request();
  816. $this->assertEquals($res->getBody(), serialize($strcookies), 'Response body does not contain the expected cookies');
  817. }
  818. /**
  819. * Make sure we can set an array of string cookies
  820. *
  821. */
  822. public function testSetCookieStringArray()
  823. {
  824. $this->client->setUri($this->baseuri. 'testCookies.php');
  825. $cookies = array(
  826. 'chocolate' => 'chips',
  827. 'crumble' => 'apple',
  828. 'another' => 'cookie'
  829. );
  830. $this->client->setCookie($cookies);
  831. $res = $this->client->request();
  832. $this->assertEquals($res->getBody(), serialize($cookies), 'Response body does not contain the expected cookies');
  833. }
  834. /**
  835. * Make sure we can set cookie objects with a jar
  836. *
  837. */
  838. public function testSetCookieObjectJar()
  839. {
  840. $this->client->setUri($this->baseuri. 'testCookies.php');
  841. $this->client->setCookieJar();
  842. $refuri = $this->client->getUri();
  843. $cookies = array(
  844. Zend_Http_Cookie::fromString('chocolate=chips', $refuri),
  845. Zend_Http_Cookie::fromString('crumble=apple', $refuri)
  846. );
  847. $strcookies = array();
  848. foreach ($cookies as $c) {
  849. $this->client->setCookie($c);
  850. $strcookies[$c->getName()] = $c->getValue();
  851. }
  852. $res = $this->client->request();
  853. $this->assertEquals($res->getBody(), serialize($strcookies), 'Response body does not contain the expected cookies');
  854. }
  855. /**
  856. * File Upload Tests
  857. *
  858. */
  859. /**
  860. * Test we can upload raw data as a file
  861. *
  862. */
  863. public function testUploadRawData()
  864. {
  865. if (!ini_get('file_uploads')) {
  866. $this->markTestSkipped('File uploads disabled.');
  867. }
  868. $this->client->setUri($this->baseuri. 'testUploads.php');
  869. $rawdata = file_get_contents(__FILE__);
  870. $this->client->setFileUpload('myfile.txt', 'uploadfile', $rawdata, 'text/plain');
  871. $res = $this->client->request('POST');
  872. $body = 'uploadfile myfile.txt text/plain ' . strlen($rawdata) . "\n";
  873. $this->assertEquals($body, $res->getBody(), 'Response body does not include expected upload parameters');
  874. }
  875. /**
  876. * Test we can upload an existing file
  877. *
  878. */
  879. public function testUploadLocalFile()
  880. {
  881. if (!ini_get('file_uploads')) {
  882. $this->markTestSkipped('File uploads disabled.');
  883. }
  884. $this->client->setUri($this->baseuri. 'testUploads.php');
  885. $this->client->setFileUpload(__FILE__, 'uploadfile', null, 'text/x-foo-bar');
  886. $res = $this->client->request('POST');
  887. $size = filesize(__FILE__);
  888. $body = "uploadfile " . basename(__FILE__) . " text/x-foo-bar $size\n";
  889. $this->assertEquals($body, $res->getBody(), 'Response body does not include expected upload parameters');
  890. }
  891. public function testUploadLocalDetectMime()
  892. {
  893. if (!ini_get('file_uploads')) {
  894. $this->markTestSkipped('File uploads disabled.');
  895. }
  896. $detect = null;
  897. if (function_exists('finfo_file')) {
  898. $f = @finfo_open(FILEINFO_MIME);
  899. if ($f) $detect = 'finfo';
  900. } elseif (function_exists('mime_content_type')) {
  901. if (mime_content_type(__FILE__)) {
  902. $detect = 'mime_magic';
  903. }
  904. }
  905. if (! $detect) {
  906. $this->markTestSkipped('No MIME type detection capability (fileinfo or mime_magic extensions) is available');
  907. }
  908. $file = dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'staticFile.jpg';
  909. $this->client->setUri($this->baseuri. 'testUploads.php');
  910. $this->client->setFileUpload($file, 'uploadfile');
  911. $res = $this->client->request('POST');
  912. $size = filesize($file);
  913. $body = "uploadfile " . basename($file) . " image/jpeg $size\n";
  914. $this->assertEquals($body, $res->getBody(), 'Response body does not include expected upload parameters (detect: ' . $detect . ')');
  915. }
  916. public function testUploadNameWithSpecialChars()
  917. {
  918. if (!ini_get('file_uploads')) {
  919. $this->markTestSkipped('File uploads disabled.');
  920. }
  921. $this->client->setUri($this->baseuri. 'testUploads.php');
  922. $rawdata = file_get_contents(__FILE__);
  923. $this->client->setFileUpload('/some strage/path%/with[!@#$&]/myfile.txt', 'uploadfile', $rawdata, 'text/plain');
  924. $res = $this->client->request('POST');
  925. $body = 'uploadfile myfile.txt text/plain ' . strlen($rawdata) . "\n";
  926. $this->assertEquals($body, $res->getBody(), 'Response body does not include expected upload parameters');
  927. }
  928. public function testStaticLargeFileDownload()
  929. {
  930. $this->client->setUri($this->baseuri . 'staticFile.jpg');
  931. $got = $this->client->request()->getBody();
  932. $expected = $this->_getTestFileContents('staticFile.jpg');
  933. $this->assertEquals($expected, $got, 'Downloaded file does not seem to match!');
  934. }
  935. /**
  936. * Test that one can upload multiple files with the same form name, as an
  937. * array
  938. *
  939. * @link http://framework.zend.com/issues/browse/ZF-5744
  940. */
  941. public function testMutipleFilesWithSameFormNameZF5744()
  942. {
  943. if (!ini_get('file_uploads')) {
  944. $this->markTestSkipped('File uploads disabled.');
  945. }
  946. $rawData = 'Some test raw data here...';
  947. $this->client->setUri($this->baseuri . 'testUploads.php');
  948. $files = array('file1.txt', 'file2.txt', 'someotherfile.foo');
  949. $expectedBody = '';
  950. foreach($files as $filename) {
  951. $this->client->setFileUpload($filename, 'uploadfile[]', $rawData, 'text/plain');
  952. $expectedBody .= "uploadfile $filename text/plain " . strlen($rawData) . "\n";
  953. }
  954. $res = $this->client->request('POST');
  955. $this->assertEquals($expectedBody, $res->getBody(), 'Response body does not include expected upload parameters');
  956. }
  957. /**
  958. * Test that lines that might be evaluated as boolean false do not break
  959. * the reading prematurely.
  960. *
  961. * @link http://framework.zend.com/issues/browse/ZF-4238
  962. */
  963. public function testZF4238FalseLinesInResponse()
  964. {
  965. $this->client->setUri($this->baseuri . 'ZF4238-zerolineresponse.txt');
  966. $got = $this->client->request()->getBody();
  967. $expected = $this->_getTestFileContents('ZF4238-zerolineresponse.txt');
  968. $this->assertEquals($expected, $got);
  969. }
  970. public function testStreamResponse()
  971. {
  972. if(!($this->client->getAdapter() instanceof Zend_Http_Client_Adapter_Stream)) {
  973. $this->markTestSkipped('Current adapter does not support streaming');
  974. return;
  975. }
  976. $this->client->setUri($this->baseuri . 'staticFile.jpg');
  977. $this->client->setStream();
  978. $response = $this->client->request();
  979. $this->assertTrue($response instanceof Zend_Http_Response_Stream, 'Request did not return stream response!');
  980. $this->assertTrue(is_resource($response->getStream()), 'Request does not contain stream!');
  981. $stream_name = $response->getStreamName();
  982. $stream_read = stream_get_contents($response->getStream());
  983. $file_read = file_get_contents($stream_name);
  984. $expected = $this->_getTestFileContents('staticFile.jpg');
  985. $this->assertEquals($expected, $stream_read, 'Downloaded stream does not seem to match!');
  986. $this->assertEquals($expected, $file_read, 'Downloaded file does not seem to match!');
  987. }
  988. public function testStreamResponseBody()
  989. {
  990. if(!($this->client->getAdapter() instanceof Zend_Http_Client_Adapter_Stream)) {
  991. $this->markTestSkipped('Current adapter does not support streaming');
  992. return;
  993. }
  994. $this->client->setUri($this->baseuri . 'staticFile.jpg');
  995. $this->client->setStream();
  996. $response = $this->client->request();
  997. $this->assertTrue($response instanceof Zend_Http_Response_Stream, 'Request did not return stream response!');
  998. $this->assertTrue(is_resource($response->getStream()), 'Request does not contain stream!');
  999. $body = $response->getBody();
  1000. $expected = $this->_getTestFileContents('staticFile.jpg');
  1001. $this->assertEquals($expected, $body, 'Downloaded stream does not seem to match!');
  1002. }
  1003. public function testStreamResponseNamed()
  1004. {
  1005. if(!($this->client->getAdapter() instanceof Zend_Http_Client_Adapter_Stream)) {
  1006. $this->markTestSkipped('Current adapter does not support streaming');
  1007. return;
  1008. }
  1009. $this->client->setUri($this->baseuri . 'staticFile.jpg');
  1010. $outfile = tempnam(sys_get_temp_dir(), "outstream");
  1011. $this->client->setStream($outfile);
  1012. $response = $this->client->request();
  1013. $this->assertTrue($response instanceof Zend_Http_Response_Stream, 'Request did not return stream response!');
  1014. $this->assertTrue(is_resource($response->getStream()), 'Request does not contain stream!');
  1015. $this->assertEquals($outfile, $response->getStreamName());
  1016. $stream_read = stream_get_contents($response->getStream());
  1017. $file_read = file_get_contents($outfile);
  1018. $expected = $this->_getTestFileContents('staticFile.jpg');
  1019. $this->assertEquals($expected, $stream_read, 'Downloaded stream does not seem to match!');
  1020. $this->assertEquals($expected, $file_read, 'Downloaded file does not seem to match!');
  1021. }
  1022. public function testStreamRequest()
  1023. {
  1024. if(!($this->client->getAdapter() instanceof Zend_Http_Client_Adapter_Stream)) {
  1025. $this->markTestSkipped('Current adapter does not support streaming');
  1026. return;
  1027. }
  1028. $data = fopen(dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'staticFile.jpg', "r");
  1029. $res = $this->client->setRawData($data, 'image/jpeg')->request('PUT');
  1030. $expected = $this->_getTestFileContents('staticFile.jpg');
  1031. $this->assertEquals($expected, $res->getBody(), 'Response body does not contain the expected data');
  1032. }
  1033. /**
  1034. * Test that we can deal with double Content-Length headers
  1035. *
  1036. * @link http://framework.zend.com/issues/browse/ZF-9404
  1037. */
  1038. public function testZF9404DoubleContentLengthHeader()
  1039. {
  1040. $this->client->setUri($this->baseuri . 'ZF9404-doubleContentLength.php');
  1041. $expect = filesize(dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'ZF9404-doubleContentLength.php');
  1042. $response = $this->client->request();
  1043. if (! $response->isSuccessful()) {
  1044. throw new ErrorException("Error requesting test URL");
  1045. }
  1046. $clen = $response->getHeader('content-length');
  1047. if (! (is_array($clen))) {
  1048. $this->markTestSkipped("Didn't get multiple Content-length headers");
  1049. }
  1050. $this->assertEquals($expect, strlen($response->getBody()));
  1051. }
  1052. /**
  1053. * @group ZF-10645
  1054. */
  1055. public function testPutRequestsHonorSpecifiedContentType()
  1056. {
  1057. $this->client->setUri($this->baseuri . 'ZF10645-PutContentType.php');
  1058. $this->client->setMethod(Zend_Http_Client::PUT);
  1059. $data = array('foo' => 'bar');
  1060. $this->client->setRawData(http_build_query($data), 'text/html; charset=ISO-8859-1');
  1061. $response = $this->client->request();
  1062. $request = $this->client->getLastRequest();
  1063. $this->assertContains('text/html; charset=ISO-8859-1', $request, $request);
  1064. $this->assertContains('REQUEST_METHOD: PUT', $response->getBody(), $response->getBody());
  1065. }
  1066. /**
  1067. * @group ZF-11418
  1068. */
  1069. public function testMultiplePuts()
  1070. {
  1071. $this->client->setUri($this->baseuri . 'ZF10645-PutContentType.php');
  1072. $data= 'test';
  1073. $this->client->setRawData($data, 'text/plain');
  1074. $this->client->setMethod(Zend_Http_Client::PUT);
  1075. $response = $this->client->request();
  1076. $this->assertContains('REQUEST_METHOD: PUT', $response->getBody(), $response->getBody());
  1077. $this->client->resetParameters(true);
  1078. $this->client->setUri($this->baseuri . 'ZF10645-PutContentType.php');
  1079. $this->client->setMethod(Zend_Http_Client::PUT);
  1080. $response = $this->client->request();
  1081. $request= $this->client->getLastRequest();
  1082. $this->assertNotContains('Content-Type: text/plain', $request);
  1083. }
  1084. /**
  1085. * @group ZF-11598
  1086. */
  1087. public function testGetAdapterWithoutSet()
  1088. {
  1089. $client = new Zend_Http_Client(null, $this->config);
  1090. $adapter = $client->getAdapter();
  1091. $this->assertTrue(!empty($adapter));
  1092. }
  1093. /**
  1094. * Internal helpder function to get the contents of test files
  1095. *
  1096. * @param string $file
  1097. * @return string
  1098. */
  1099. protected function _getTestFileContents($file)
  1100. {
  1101. return file_get_contents(dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR .
  1102. '_files' . DIRECTORY_SEPARATOR . $file);
  1103. }
  1104. /**
  1105. * Data provider for complex, nesting parameter arrays
  1106. *
  1107. * @return array
  1108. */
  1109. public static function parameterArrayProvider()
  1110. {
  1111. return array(
  1112. array(
  1113. array(
  1114. 'quest' => 'To seek the holy grail',
  1115. 'YourMother' => 'Was a hamster',
  1116. 'specialChars' => '<>$+ &?=[]^%',
  1117. 'array' => array('firstItem', 'secondItem', '3rdItem')
  1118. )
  1119. ),
  1120. array(
  1121. array(
  1122. 'someData' => array(
  1123. "1",
  1124. "2",
  1125. 'key' => 'value',
  1126. 'nesting' => array(
  1127. 'a' => 'AAA',
  1128. 'b' => 'BBB'
  1129. )
  1130. ),
  1131. 'someOtherData' => array('foo', 'bar')
  1132. )
  1133. ),
  1134. array(
  1135. array(
  1136. 'foo1' => 'bar',
  1137. 'foo2' => array('baz', 'w00t')
  1138. )
  1139. )
  1140. );
  1141. }
  1142. /**
  1143. * Data provider for invalid configuration containers
  1144. *
  1145. * @return array
  1146. */
  1147. public static function invalidConfigProvider()
  1148. {
  1149. return array(
  1150. array(false),
  1151. array('foo => bar'),
  1152. array(null),
  1153. array(new stdClass),
  1154. array(55)
  1155. );
  1156. }
  1157. }