AppTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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_Gdata
  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. require_once 'Zend/Gdata/App.php';
  23. require_once 'Zend/Gdata/HttpClient.php';
  24. require_once 'Zend/Gdata/TestUtility/MockHttpClient.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Gdata_App
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @group Zend_Gdata
  32. * @group Zend_Gdata_App
  33. */
  34. class Zend_Gdata_AppTest extends PHPUnit_Framework_TestCase
  35. {
  36. public function setUp()
  37. {
  38. $this->fileName = 'Zend/Gdata/App/_files/FeedSample1.xml';
  39. $this->expectedEtag = 'W/"CkcHQH8_fCp7ImA9WxRTGEw."';
  40. $this->expectedMajorProtocolVersion = 1;
  41. $this->expectedMinorProtocolVersion = 2;
  42. $this->httpEntrySample = $this->loadResponse(
  43. dirname(__FILE__) . '/_files/AppSample1.txt'
  44. );
  45. $this->httpEntrySampleWithoutVersion = $this->loadResponse(
  46. dirname(__FILE__) . '/_files/AppSample2.txt'
  47. );
  48. $this->httpFeedSample = $this->loadResponse(
  49. dirname(__FILE__) . '/_files/AppSample3.txt'
  50. );
  51. $this->httpFeedSampleWithoutVersion = $this->loadResponse(
  52. dirname(__FILE__) . '/_files/AppSample4.txt'
  53. );
  54. $this->adapter = new Test_Zend_Gdata_MockHttpClient();
  55. $this->client = new Zend_Gdata_HttpClient();
  56. $this->client->setAdapter($this->adapter);
  57. $this->service = new Zend_Gdata_App($this->client);
  58. }
  59. public function loadResponse($filename)
  60. {
  61. $response = file_get_contents($filename);
  62. // Line endings are sometimes an issue inside the canned responses; the
  63. // following is a negative lookbehind assertion, and replaces any \n
  64. // not preceded by \r with the sequence \r\n, ensuring that the message
  65. // is well-formed.
  66. return preg_replace("#(?<!\r)\n#", "\r\n", $response);
  67. }
  68. public function testImportFile()
  69. {
  70. $feed = Zend_Gdata_App::importFile($this->fileName,
  71. 'Zend_Gdata_App_Feed', true);
  72. $this->assertEquals('dive into mark', $feed->title->text);
  73. }
  74. public function testSetAndGetHttpMethodOverride()
  75. {
  76. Zend_Gdata_App::setHttpMethodOverride(true);
  77. $this->assertEquals(true, Zend_Gdata_App::getHttpMethodOverride());
  78. }
  79. public function testSetAndGetProtocolVersion()
  80. {
  81. $this->service->setMajorProtocolVersion(2);
  82. $this->service->setMinorProtocolVersion(1);
  83. $this->assertEquals(2, $this->service->getMajorProtocolVersion());
  84. $this->assertEquals(1, $this->service->getMinorProtocolVersion());
  85. }
  86. public function testDefaultProtocolVersionIs1X()
  87. {
  88. $this->assertEquals(1, $this->service->getMajorProtocolVersion());
  89. $this->assertEquals(null, $this->service->getMinorProtocolVersion());
  90. }
  91. public function testMajorProtocolVersionCannotBeLessThanOne()
  92. {
  93. $exceptionCaught = false;
  94. try {
  95. $this->service->setMajorProtocolVersion(0);
  96. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  97. $exceptionCaught = true;
  98. }
  99. $this->assertTrue($exceptionCaught, 'Expected exception not caught: '
  100. + 'Zend_Gdata_App_InvalidArgumentException');
  101. }
  102. public function testMajorProtocolVersionCannotBeNull()
  103. {
  104. $exceptionCaught = false;
  105. try {
  106. $this->service->setMajorProtocolVersion(null);
  107. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  108. $exceptionCaught = true;
  109. }
  110. $this->assertTrue($exceptionCaught, 'Expected exception not caught: '
  111. + 'Zend_Gdata_App_InvalidArgumentException');
  112. }
  113. public function testMinorProtocolVersionCannotBeLessThanZero()
  114. {
  115. $exceptionCaught = false;
  116. try {
  117. $this->service->setMinorProtocolVersion(-1);
  118. } catch (Zend_Gdata_App_InvalidArgumentException $e) {
  119. $exceptionCaught = true;
  120. }
  121. $this->assertTrue($exceptionCaught, 'Expected exception not caught: '
  122. + 'Zend_Gdata_App_InvalidArgumentException');
  123. }
  124. public function testNoGdataVersionHeaderSentWhenUsingV1()
  125. {
  126. $this->adapter->setResponse(array('HTTP/1.1 200 OK\r\n\r\n'));
  127. $this->service->setMajorProtocolVersion(1);
  128. $this->service->setMinorProtocolVersion(null);
  129. $this->service->get('http://www.example.com');
  130. $headers = $this->adapter->popRequest()->headers;
  131. $found = false;
  132. foreach ($headers as $header) {
  133. if (strstr($header, 'GData-Version:'))
  134. $found = true;
  135. }
  136. $this->assertFalse($found, 'Version header found in V1 feed');
  137. }
  138. public function testNoGdataVersionHeaderSentWhenUsingV1X()
  139. {
  140. $this->adapter->setResponse(array('HTTP/1.1 200 OK\r\n\r\n'));
  141. $this->service->setMajorProtocolVersion(1);
  142. $this->service->setMinorProtocolVersion(1);
  143. $this->service->get('http://www.example.com');
  144. $headers = $this->adapter->popRequest()->headers;
  145. $found = false;
  146. foreach ($headers as $header) {
  147. if (strstr($header, 'GData-Version:'))
  148. $found = true;
  149. }
  150. $this->assertTrue(!$found, 'Version header found in V1 feed');
  151. }
  152. public function testGdataVersionHeaderSentWhenUsingV2()
  153. {
  154. $this->adapter->setResponse(array('HTTP/1.1 200 OK\r\n\r\n'));
  155. $this->service->setMajorProtocolVersion(2);
  156. $this->service->setMinorProtocolVersion(null);
  157. $this->service->get('http://www.example.com');
  158. $headers = $this->adapter->popRequest()->headers;
  159. $found = false;
  160. foreach ($headers as $header) {
  161. if ($header == 'GData-Version: 2')
  162. $found = true;
  163. }
  164. $this->assertTrue($found, 'Version header not found or incorrect');
  165. }
  166. public function testGdataVersionHeaderSentWhenUsingV2X()
  167. {
  168. $this->adapter->setResponse(array('HTTP/1.1 200 OK\r\n\r\n'));
  169. $this->service->setMajorProtocolVersion(2);
  170. $this->service->setMinorProtocolVersion(1);
  171. $this->service->get('http://www.example.com');
  172. $headers = $this->adapter->popRequest()->headers;
  173. $found = false;
  174. foreach ($headers as $header) {
  175. if ($header == 'GData-Version: 2')
  176. $found = true;
  177. }
  178. $this->assertTrue($found, 'Version header not found or incorrect');
  179. }
  180. public function testHTTPETagsPropagateToEntriesOnGet()
  181. {
  182. $this->adapter->setResponse($this->httpEntrySample);
  183. $entry = $this->service->getEntry('http://www.example.com');
  184. $this->assertEquals($this->expectedEtag, $entry->getEtag());
  185. }
  186. public function testHTTPETagsPropagateToEntriesOnUpdate()
  187. {
  188. $this->adapter->setResponse($this->httpEntrySample);
  189. $entry = new Zend_Gdata_App_Entry();
  190. $newEntry = $this->service->updateEntry($entry, 'http://www.example.com');
  191. $this->assertEquals($this->expectedEtag, $newEntry->getEtag());
  192. }
  193. public function testHTTPEtagsPropagateToEntriesOnInsert()
  194. {
  195. $this->adapter->setResponse($this->httpEntrySample);
  196. $entry = new Zend_Gdata_App_Entry();
  197. $newEntry = $this->service->insertEntry($entry, 'http://www.example.com');
  198. $this->assertEquals($this->expectedEtag, $newEntry->getEtag());
  199. }
  200. public function testIfMatchHTTPHeaderSetOnUpdate()
  201. {
  202. $etag = 'ABCD1234';
  203. $this->adapter->setResponse("HTTP/1.1 201 Created");
  204. $this->service->setMajorProtocolVersion(2);
  205. $entry = new Zend_Gdata_App_Entry();
  206. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  207. 'http://www.example.com',
  208. 'edit',
  209. 'application/atom+xml'));
  210. $entry->setEtag($etag);
  211. $this->service->updateEntry($entry);
  212. $headers = $this->adapter->popRequest()->headers;
  213. $found = false;
  214. foreach ($headers as $header) {
  215. if ($header == 'If-Match: ' . $etag)
  216. $found = true;
  217. }
  218. $this->assertTrue($found, 'If-Match header not found or incorrect');
  219. }
  220. public function testIfMatchHTTPHeaderSetOnUpdateIfWeak()
  221. {
  222. $etag = 'W/ABCD1234';
  223. $this->adapter->setResponse("HTTP/1.1 201 Created");
  224. $this->service->setMajorProtocolVersion(2);
  225. $entry = new Zend_Gdata_App_Entry();
  226. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  227. 'http://www.example.com',
  228. 'edit',
  229. 'application/atom+xml'));
  230. $entry->setEtag($etag);
  231. $this->service->updateEntry($entry);
  232. $headers = $this->adapter->popRequest()->headers;
  233. $found = false;
  234. foreach ($headers as $header) {
  235. if ($header == 'If-Match: ' . $etag)
  236. $found = true;
  237. }
  238. $this->assertFalse($found, 'If-Match header found');
  239. }
  240. public function testIfMatchHTTPHeaderSetOnSave()
  241. {
  242. $etag = 'ABCD1234';
  243. $this->adapter->setResponse("HTTP/1.1 201 Created");
  244. $this->service->setMajorProtocolVersion(2);
  245. $entry = $this->service->newEntry();
  246. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  247. 'http://www.example.com',
  248. 'edit',
  249. 'application/atom+xml'));
  250. $entry->setEtag($etag);
  251. $entry->setService($this->service);
  252. $entry->save();
  253. $headers = $this->adapter->popRequest()->headers;
  254. $found = false;
  255. foreach ($headers as $header) {
  256. if ($header == 'If-Match: ' . $etag)
  257. $found = true;
  258. }
  259. $this->assertTrue($found, 'If-Match header not found or incorrect');
  260. }
  261. public function testIfMatchHTTPHeaderNotSetOnDelete()
  262. {
  263. $etag = 'ABCD1234';
  264. $this->adapter->setResponse("HTTP/1.1 201 Created");
  265. $this->service->setMajorProtocolVersion(2);
  266. $entry = $this->service->newEntry();
  267. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  268. 'http://www.example.com',
  269. 'edit',
  270. 'application/atom+xml'));
  271. $entry->setEtag($etag);
  272. $entry->setService($this->service);
  273. $entry->delete();
  274. $headers = $this->adapter->popRequest()->headers;
  275. $found = false;
  276. foreach ($headers as $header) {
  277. if ($header == 'If-Match: ' . $etag)
  278. $found = true;
  279. }
  280. $this->assertFalse($found, 'If-Match header found on delete');
  281. }
  282. public function testIfMatchHTTPHeaderSetOnManualPost()
  283. {
  284. $etag = 'ABCD1234';
  285. $this->adapter->setResponse("HTTP/1.1 201 Created");
  286. $this->service->setMajorProtocolVersion(2);
  287. $entry = $this->service->newEntry();
  288. $entry->setEtag($etag);
  289. $entry->setService($this->service);
  290. $this->service->post($entry, 'http://www.example.com');
  291. $headers = $this->adapter->popRequest()->headers;
  292. $found = false;
  293. foreach ($headers as $header) {
  294. if ($header == 'If-Match: ' . $etag)
  295. $found = true;
  296. }
  297. $this->assertTrue($found, 'If-Match header not found or incorrect');
  298. }
  299. public function testIfMatchHTTPHeaderSetOnManualPut()
  300. {
  301. $etag = 'ABCD1234';
  302. $this->adapter->setResponse("HTTP/1.1 201 Created");
  303. $this->service->setMajorProtocolVersion(2);
  304. $entry = $this->service->newEntry();
  305. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  306. 'http://www.example.com',
  307. 'edit',
  308. 'application/atom+xml'));
  309. $entry->setEtag($etag);
  310. $entry->setService($this->service);
  311. $this->service->put($entry);
  312. $headers = $this->adapter->popRequest()->headers;
  313. $found = false;
  314. foreach ($headers as $header) {
  315. if ($header == 'If-Match: ' . $etag)
  316. $found = true;
  317. }
  318. $this->assertTrue($found, 'If-Match header not found or incorrect');
  319. }
  320. public function testIfMatchHTTPHeaderSetOnManualDelete()
  321. {
  322. $etag = 'ABCD1234';
  323. $this->adapter->setResponse("HTTP/1.1 201 Created");
  324. $this->service->setMajorProtocolVersion(2);
  325. $entry = $this->service->newEntry();
  326. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  327. 'http://www.example.com',
  328. 'edit',
  329. 'application/atom+xml'));
  330. $entry->setEtag($etag);
  331. $entry->setService($this->service);
  332. $this->service->delete($entry);
  333. $headers = $this->adapter->popRequest()->headers;
  334. $found = false;
  335. foreach ($headers as $header) {
  336. if ($header == 'If-Match: ' . $etag)
  337. $found = true;
  338. }
  339. $this->assertFalse($found, 'If-Match header found on delete');
  340. }
  341. public function testIfMatchHeaderCanBeSetOnInsert() {
  342. $etagOverride = 'foo';
  343. $etag = 'ABCD1234';
  344. $this->service->setMajorProtocolVersion(2);
  345. $this->adapter->setResponse($this->httpEntrySample);
  346. $entry = new Zend_Gdata_App_Entry();
  347. $entry->setEtag($etag);
  348. $newEntry = $this->service->insertEntry($entry,
  349. 'http://www.example.com',
  350. 'Zend_Gdata_App_Entry',
  351. array('If-Match' => $etagOverride));
  352. $headers = $this->adapter->popRequest()->headers;
  353. $found = false;
  354. foreach ($headers as $header) {
  355. if ($header == 'If-Match: ' . $etagOverride)
  356. $found = true;
  357. }
  358. $this->assertTrue($found, 'If-Match header not found or incorrect');
  359. }
  360. public function testIfNoneMatchHeaderCanBeSetOnInsert() {
  361. $etagOverride = 'foo';
  362. $etag = 'ABCD1234';
  363. $this->service->setMajorProtocolVersion(2);
  364. $this->adapter->setResponse($this->httpEntrySample);
  365. $entry = new Zend_Gdata_App_Entry();
  366. $entry->setEtag($etag);
  367. $newEntry = $this->service->insertEntry($entry,
  368. 'http://www.example.com',
  369. 'Zend_Gdata_App_Entry',
  370. array('If-None-Match' => $etagOverride));
  371. $headers = $this->adapter->popRequest()->headers;
  372. $found = false;
  373. foreach ($headers as $header) {
  374. if ($header == 'If-None-Match: ' . $etagOverride)
  375. $found = true;
  376. }
  377. $this->assertTrue($found, 'If-None-Match header not found or incorrect ');
  378. }
  379. public function testIfMatchHeaderCanBeSetOnUpdate() {
  380. $etagOverride = 'foo';
  381. $etag = 'ABCD1234';
  382. $this->service->setMajorProtocolVersion(2);
  383. $this->adapter->setResponse($this->httpEntrySample);
  384. $entry = new Zend_Gdata_App_Entry();
  385. $entry->setEtag($etag);
  386. $newEntry = $this->service->updateEntry($entry,
  387. 'http://www.example.com',
  388. 'Zend_Gdata_App_Entry',
  389. array('If-Match' => $etagOverride));
  390. $headers = $this->adapter->popRequest()->headers;
  391. $found = false;
  392. foreach ($headers as $header) {
  393. if ($header == 'If-Match: ' . $etagOverride)
  394. $found = true;
  395. }
  396. $this->assertTrue($found, 'If-Match header not found or incorrect or incorrect');
  397. }
  398. public function testIfNoneMatchHeaderCanBeSetOnUpdate() {
  399. $etagOverride = 'foo';
  400. $etag = 'ABCD1234';
  401. $this->service->setMajorProtocolVersion(2);
  402. $this->adapter->setResponse($this->httpEntrySample);
  403. $entry = new Zend_Gdata_App_Entry();
  404. $entry->setEtag($etag);
  405. $newEntry = $this->service->updateEntry($entry,
  406. 'http://www.example.com',
  407. 'Zend_Gdata_App_Entry',
  408. array('If-None-Match' => $etagOverride));
  409. $headers = $this->adapter->popRequest()->headers;
  410. $found = false;
  411. foreach ($headers as $header) {
  412. if ($header == 'If-None-Match: ' . $etagOverride)
  413. $found = true;
  414. }
  415. $this->assertTrue($found, 'If-None-Match header not found or incorrect');
  416. }
  417. /**
  418. * @group ZF-8397
  419. */
  420. public function testIfMatchHTTPHeaderIsResetEachRequest()
  421. {
  422. // Update an entry
  423. $etag = 'ABCD1234';
  424. $this->adapter->setResponse("HTTP/1.1 201 Created");
  425. $this->service->setMajorProtocolVersion(2);
  426. $entry = new Zend_Gdata_App_Entry();
  427. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  428. 'http://www.example.com',
  429. 'edit',
  430. 'application/atom+xml'));
  431. $entry->setEtag($etag);
  432. $this->service->updateEntry($entry);
  433. // Get another entry without ETag set,
  434. // Previous value of If-Match HTTP header should not be sent
  435. $this->adapter->setResponse($this->httpEntrySample);
  436. $entry = $this->service->getEntry('http://www.example.com');
  437. $headers = $this->adapter->popRequest()->headers;
  438. $found = false;
  439. foreach ($headers as $header) {
  440. if ($header == 'If-Match: ' . $etag)
  441. $found = true;
  442. }
  443. $this->assertFalse($found, 'If-Match header found');
  444. }
  445. public function testGenerateIfMatchHeaderDataReturnsEtagIfV2() {
  446. $etag = 'ABCD1234';
  447. $this->service->setMajorProtocolVersion(2);
  448. $entry = new Zend_Gdata_App_Entry();
  449. $entry->setEtag($etag);
  450. $result = $this->service->generateIfMatchHeaderData($entry, false);
  451. $this->assertEquals($etag, $result);
  452. }
  453. public function testGenerateIfMatchHeaderDataReturnsNullIfV1() {
  454. $etag = 'ABCD1234';
  455. $this->service->setMajorProtocolVersion(1);
  456. $entry = new Zend_Gdata_App_Entry();
  457. $entry->setEtag($etag);
  458. $result = $this->service->generateIfMatchHeaderData($entry, false);
  459. $this->assertEquals(null, $result);
  460. }
  461. public function testGenerateIfMatchHeaderDataReturnsNullIfNotEntry() {
  462. $this->service->setMajorProtocolVersion(2);
  463. $result = $this->service->generateIfMatchHeaderData("Hello world", false);
  464. $this->assertEquals(null, $result);
  465. }
  466. public function testGenerateIfMatchHeaderDataReturnsNullIfWeak() {
  467. $etag = 'W/ABCD1234';
  468. $this->service->setMajorProtocolVersion(2);
  469. $entry = new Zend_Gdata_App_Entry();
  470. $entry->setEtag($etag);
  471. $result = $this->service->generateIfMatchHeaderData($entry, false);
  472. $this->assertEquals(null, $result);
  473. }
  474. public function testGenerateIfMatchHeaderDataReturnsEtagIfWeakAndFlagSet() {
  475. $etag = 'W/ABCD1234';
  476. $this->service->setMajorProtocolVersion(2);
  477. $entry = new Zend_Gdata_App_Entry();
  478. $entry->setEtag($etag);
  479. $result = $this->service->generateIfMatchHeaderData($entry, true);
  480. $this->assertEquals($etag, $result);
  481. }
  482. public function testGenerateIfMatchHeaderDataReturnsEtagIfNotWeakAndFlagSet() {
  483. $etag = 'ABCD1234';
  484. $this->service->setMajorProtocolVersion(2);
  485. $entry = new Zend_Gdata_App_Entry();
  486. $entry->setEtag($etag);
  487. $result = $this->service->generateIfMatchHeaderData($entry, true);
  488. $this->assertEquals($etag, $result);
  489. }
  490. public function testImportUrlSetsMajorProtocolVersionOnEntry() {
  491. $this->adapter->setResponse($this->httpEntrySample);
  492. $entry = $this->service->getEntry('http://www.example.com');
  493. $this->assertEquals($this->expectedMajorProtocolVersion, $entry->getMajorProtocolVersion());
  494. }
  495. public function testImportUrlSetsMinorProtocolVersionOnEntry() {
  496. $this->adapter->setResponse($this->httpEntrySample);
  497. $entry = $this->service->getEntry('http://www.example.com');
  498. $this->assertEquals($this->expectedMinorProtocolVersion, $entry->getMinorProtocolVersion());
  499. }
  500. public function testImportUrlSetsNullVersionIfNoVersionHeaderOnEntry() {
  501. $this->adapter->setResponse($this->httpEntrySampleWithoutVersion);
  502. $entry = $this->service->getEntry('http://www.example.com');
  503. $this->assertEquals(null, $entry->getMinorProtocolVersion());
  504. $this->assertEquals(null, $entry->getMinorProtocolVersion());
  505. }
  506. public function testImportUrlSetsMajorProtocolVersionOnFeed() {
  507. $this->adapter->setResponse($this->httpFeedSample);
  508. $feed = $this->service->getFeed('http://www.example.com');
  509. $this->assertEquals($this->expectedMajorProtocolVersion, $feed->getMajorProtocolVersion());
  510. foreach ($feed as $entry) {
  511. $this->assertEquals($this->expectedMajorProtocolVersion, $entry->getMajorProtocolVersion());
  512. }
  513. }
  514. public function testImportUrlSetsMinorProtocolVersionOnFeed() {
  515. $this->adapter->setResponse($this->httpFeedSample);
  516. $feed = $this->service->getFeed('http://www.example.com');
  517. $this->assertEquals($this->expectedMinorProtocolVersion, $feed->getMinorProtocolVersion());
  518. foreach ($feed as $entry) {
  519. $this->assertEquals($this->expectedMinorProtocolVersion, $entry->getMinorProtocolVersion());
  520. }
  521. }
  522. public function testImportUrlSetsNullVersionIfNoVersionHeaderOnFeed() {
  523. $this->adapter->setResponse($this->httpFeedSampleWithoutVersion);
  524. $feed = $this->service->getFeed('http://www.example.com');
  525. $this->assertEquals(null, $feed->getMajorProtocolVersion());
  526. $this->assertEquals(null, $feed->getMinorProtocolVersion());
  527. foreach ($feed as $entry) {
  528. $this->assertEquals(null, $entry->getMajorProtocolVersion());
  529. $this->assertEquals(null, $entry->getMinorProtocolVersion());
  530. }
  531. }
  532. public function testMagicConstructorsPropogateMajorVersion() {
  533. $v = 42;
  534. $this->service->setMajorProtocolVersion($v);
  535. $feed = $this->service->newFeed();
  536. $this->assertEquals($v, $feed->getMajorProtocolVersion());
  537. }
  538. public function testMagicConstructorsPropogateMinorVersion() {
  539. $v = 84;
  540. $this->service->setMinorProtocolVersion($v);
  541. $feed = $this->service->newFeed();
  542. $this->assertEquals($v, $feed->getMinorProtocolVersion());
  543. }
  544. /**
  545. * When error handler is overridden to throw an ErrorException, the extension loader
  546. * in Zend_Gdata will throw an ErrorException when the class doesn't exist in the
  547. * first extension directory even if it exists in subsequent ones. This test
  548. * enforces a fix that keeps this from happening
  549. *
  550. * @group ZF-12268
  551. * @group ZF-7013
  552. */
  553. public function testLoadExtensionCausesFatalErrorWhenErrorHandlerIsOverridden()
  554. {
  555. // Override the error handler to throw an ErrorException
  556. set_error_handler(function($a, $b, $c, $d) { throw new ErrorException($b, 0, $a, $c, $d); }, E_ALL);
  557. try {
  558. $eq = $this->service->newEventQuery();
  559. restore_error_handler();
  560. $this->assertTrue($eq instanceof Zend_Gdata_Calendar_EventQuery);
  561. } catch ( Zend_Gdata_App_Exception $ex ) {
  562. // If we catch this exception, it means the ErrorException resulting
  563. // from the include_once E_NOTICE was caught in the right place,
  564. // but the extension was not found in any directory
  565. // (Expected since we didn't load the Calendar extension dir)
  566. restore_error_handler();
  567. $this->assertContains('EventQuery', $ex->getMessage());
  568. } catch ( ErrorException $ex ) {
  569. restore_error_handler();
  570. $this->fail('Did not expect ErrorException');
  571. }
  572. }
  573. /**
  574. * @group ZF-10243
  575. */
  576. public function testStaticImportWithoutUsingObjectMapping()
  577. {
  578. $this->adapter->setResponse($this->httpEntrySample);
  579. $feed = Zend_Gdata_App::import(
  580. 'http://www.example.com',
  581. $this->client,
  582. 'Zend_Gdata_App_Feed',
  583. false
  584. );
  585. $this->assertContains('<id>12345678901234567890</id>', $feed);
  586. }
  587. }