AppTest.php 24 KB

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