EntryTest.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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_App
  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/Entry.php';
  23. require_once 'Zend/Gdata/App.php';
  24. require_once 'Zend/Gdata/TestUtility/MockHttpClient.php';
  25. require_once 'Zend/Gdata/HttpClient.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Gdata_App
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Gdata
  33. * @group Zend_Gdata_App
  34. */
  35. class Zend_Gdata_App_EntryTest extends PHPUnit_Framework_TestCase
  36. {
  37. public function setUp()
  38. {
  39. $this->enryText = $this->loadResponse(
  40. dirname(__FILE__) . '/../App/_files/EntrySample1.xml'
  41. );
  42. $this->httpEntrySample = $this->loadResponse(
  43. dirname(__FILE__) . '/../App/_files/EntrySampleHttp1.txt'
  44. );
  45. $this->enry = new Zend_Gdata_App_Entry();
  46. $this->adapter = new Test_Zend_Gdata_MockHttpClient();
  47. $this->client = new Zend_Gdata_HttpClient();
  48. $this->client->setAdapter($this->adapter);
  49. $this->service = new Zend_Gdata_App($this->client);
  50. }
  51. public function loadResponse($filename)
  52. {
  53. $response = file_get_contents($filename);
  54. // Line endings are sometimes an issue inside the canned responses; the
  55. // following is a negative lookbehind assertion, and replaces any \n
  56. // not preceded by \r with the sequence \r\n, ensuring that the message
  57. // is well-formed.
  58. return preg_replace("#(?<!\r)\n#", "\r\n", $response);
  59. }
  60. public function testEmptyEntryShouldHaveEmptyExtensionsList()
  61. {
  62. $this->assertTrue(is_array($this->enry->extensionElements));
  63. $this->assertTrue(count($this->enry->extensionElements) == 0);
  64. }
  65. public function testEmptyEntryToAndFromStringShouldMatch()
  66. {
  67. $enryXml = $this->enry->saveXML();
  68. $newEntry = new Zend_Gdata_App_Entry();
  69. $newEntry->transferFromXML($enryXml);
  70. $newEntryXml = $newEntry->saveXML();
  71. $this->assertTrue($enryXml == $newEntryXml);
  72. }
  73. public function testConvertEntryToAndFromString()
  74. {
  75. $this->enry->transferFromXML($this->enryText);
  76. $enryXml = $this->enry->saveXML();
  77. $newEntry = new Zend_Gdata_App_Entry();
  78. $newEntry->transferFromXML($enryXml);
  79. /*
  80. $this->assertEquals(1, count($newEntry->entry));
  81. $this->assertEquals('dive into mark', $newEntry->title->text);
  82. $this->assertEquals('text', $newEntry->title->type);
  83. $this->assertEquals('2005-07-31T12:29:29Z', $newEntry->updated->text);
  84. $this->assertEquals('tag:example.org,2003:3', $newEntry->id->text);
  85. $this->assertEquals(2, count($newEntry->link));
  86. $this->assertEquals('http://example.org/',
  87. $newEntry->getAlternateLink()->href);
  88. $this->assertEquals('en',
  89. $newEntry->getAlternateLink()->hrefLang);
  90. $this->assertEquals('text/html',
  91. $newEntry->getAlternateLink()->type);
  92. $this->assertEquals('http://example.org/enry.atom',
  93. $newEntry->getSelfLink()->href);
  94. $this->assertEquals('application/atom+xml',
  95. $newEntry->getSelfLink()->type);
  96. $this->assertEquals('Copyright (c) 2003, Mark Pilgrim',
  97. $newEntry->rights->text);
  98. $entry = $newEntry->entry[0];
  99. $this->assertEquals('Atom draft-07 snapshot', $entry->title->text);
  100. $this->assertEquals('tag:example.org,2003:3.2397',
  101. $entry->id->text);
  102. $this->assertEquals('2005-07-31T12:29:29Z', $entry->updated->text);
  103. $this->assertEquals('2003-12-13T08:29:29-04:00',
  104. $entry->published->text);
  105. $this->assertEquals('Mark Pilgrim',
  106. $entry->author[0]->name->text);
  107. $this->assertEquals('http://example.org/',
  108. $entry->author[0]->uri->text);
  109. $this->assertEquals(2, count($entry->contributor));
  110. $this->assertEquals('Sam Ruby',
  111. $entry->contributor[0]->name->text);
  112. $this->assertEquals('Joe Gregorio',
  113. $entry->contributor[1]->name->text);
  114. $this->assertEquals('xhtml', $entry->content->type);
  115. */
  116. }
  117. public function testCanSetAndGetEtag()
  118. {
  119. $data = "W/&amp;FooBarBaz&amp;";
  120. $this->enry->setEtag($data);
  121. $this->assertEquals($this->enry->getEtag(), $data);
  122. }
  123. public function testCanSetAndgetService()
  124. {
  125. $data = new Zend_Gdata_App();
  126. $this->enry->setService($data);
  127. $this->assertEquals($this->enry->getService(), $data);
  128. $data = null;
  129. $this->enry->setService($data);
  130. $this->assertEquals($this->enry->getService(), $data);
  131. }
  132. public function testsetServiceProvidesFluentInterface()
  133. {
  134. $result = $this->enry->setService(null);
  135. $this->assertEquals($this->enry, $result);
  136. }
  137. public function testGetHttpClientPullsFromServiceInstance()
  138. {
  139. $s = new Zend_Gdata_App();
  140. $this->enry->setService($s);
  141. $c = new Zend_Gdata_HttpClient();
  142. $s->setHttpClient($c);
  143. $this->assertEquals($this->enry->getHttpClient(),
  144. $s->getHttpClient());
  145. $c = new Zend_Http_Client();
  146. $s->setHttpClient($c);
  147. $this->assertEquals($this->enry->getHttpClient(),
  148. $s->getHttpClient($c));
  149. }
  150. public function testSetHttpClientPushesIntoServiceInstance()
  151. {
  152. $s = new Zend_Gdata_App();
  153. $this->enry->setService($s);
  154. $c = new Zend_Gdata_HttpClient();
  155. $this->enry->setHttpClient($c);
  156. $this->assertEquals(get_class($s->getHttpClient()),
  157. 'Zend_Gdata_HttpClient');
  158. $c = new Zend_Http_Client();
  159. $this->enry->setHttpClient($c);
  160. $this->assertEquals(get_class($s->getHttpClient()),
  161. 'Zend_Http_Client');
  162. }
  163. public function testSaveSupportsGdataV2()
  164. {
  165. // Prepare mock response
  166. $this->adapter->setResponse("HTTP/1.1 201 Created");
  167. // Make sure that we're using protocol v2
  168. $this->service->setMajorProtocolVersion(2);
  169. $this->enry->setService($this->service);
  170. // Set a URL for posting, so that save() will work
  171. $editLink = new Zend_Gdata_App_extension_Link('http://example.com',
  172. 'edit');
  173. $this->enry->setLink(array($editLink));
  174. // Perform a (mock) save
  175. $this->enry->save();
  176. // Check to make sure that a v2 header was sent
  177. $headers = $this->adapter->popRequest()->headers;
  178. $found = false;
  179. foreach ($headers as $header) {
  180. if ($header == 'GData-Version: 2')
  181. $found = true;
  182. }
  183. $this->assertTrue($found,
  184. 'GData-Version header missing or incorrect.');
  185. }
  186. public function testDeleteSupportsGdataV2()
  187. {
  188. // Prepare mock response
  189. $this->adapter->setResponse("HTTP/1.1 200 OK");
  190. // Make sure that we're using protocol v2
  191. $this->service->setMajorProtocolVersion(2);
  192. $this->enry->setService($this->service);
  193. // Set a URL for posting, so that save() will work
  194. $editLink = new Zend_Gdata_App_extension_Link('http://example.com',
  195. 'edit');
  196. $this->enry->setLink(array($editLink));
  197. // Perform a (mock) save
  198. $this->enry->delete();
  199. // Check to make sure that a v2 header was sent
  200. $headers = $this->adapter->popRequest()->headers;
  201. $found = false;
  202. foreach ($headers as $header) {
  203. if ($header == 'GData-Version: 2')
  204. $found = true;
  205. }
  206. $this->assertTrue($found,
  207. 'GData-Version header missing or incorrect.');
  208. }
  209. public function testIfMatchHeaderCanBeSetOnSave()
  210. {
  211. $etagOverride = 'foo';
  212. $etag = 'ABCD1234';
  213. $this->service->setMajorProtocolVersion(2);
  214. $this->adapter->setResponse($this->httpEntrySample);
  215. $entry = $this->service->newEntry();
  216. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  217. 'http://www.example.com',
  218. 'edit',
  219. 'application/atom+xml'));
  220. $entry->setEtag($etag);
  221. $newEntry = $entry->save(null, null,
  222. array('If-Match' => $etagOverride));
  223. $headers = $this->adapter->popRequest()->headers;
  224. $found = false;
  225. foreach ($headers as $header) {
  226. if ($header == 'If-Match: ' . $etagOverride)
  227. $found = true;
  228. }
  229. $this->assertTrue($found,
  230. 'If-Match header not found or incorrect');
  231. }
  232. public function testIfNoneMatchHeaderCanBeSetOnSave()
  233. {
  234. $etagOverride = 'foo';
  235. $etag = 'ABCD1234';
  236. $this->service->setMajorProtocolVersion(2);
  237. $this->adapter->setResponse($this->httpEntrySample);
  238. $entry = $this->service->newEntry();
  239. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  240. 'http://www.example.com',
  241. 'edit',
  242. 'application/atom+xml'));
  243. $entry->setEtag($etag);
  244. $newEntry = $entry->save(null, null,
  245. array('If-None-Match' => $etagOverride));
  246. $headers = $this->adapter->popRequest()->headers;
  247. $found = false;
  248. foreach ($headers as $header) {
  249. if ($header == 'If-None-Match: ' . $etagOverride)
  250. $found = true;
  251. }
  252. $this->assertTrue($found,
  253. 'If-None-Match header not found or incorrect');
  254. }
  255. public function testCanSetUriOnSave()
  256. {
  257. $uri = 'http://example.net/foo/bar';
  258. $this->adapter->setResponse($this->httpEntrySample);
  259. $entry = $this->service->newEntry();
  260. $newEntry = $entry->save($uri);
  261. $request = $this->adapter->popRequest();
  262. $uriObject = Zend_Uri_Http::fromString($uri);
  263. $uriObject->setPort('80');
  264. $this->assertEquals($uriObject, $request->uri);
  265. }
  266. public function testCanSetClassnameOnSave()
  267. {
  268. $className = 'Zend_Gdata_Entry';
  269. $this->adapter->setResponse($this->httpEntrySample);
  270. $entry = $this->service->newEntry();
  271. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  272. 'http://www.example.com',
  273. 'edit',
  274. 'application/atom+xml'));
  275. $newEntry = $entry->save(null, $className);
  276. $this->assertEquals($className, get_class($newEntry));
  277. }
  278. public function testIfNoneMatchSetOnReload()
  279. {
  280. $etag = 'ABCD1234';
  281. $this->adapter->setResponse($this->httpEntrySample);
  282. $entry = $this->service->newEntry();
  283. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  284. 'http://www.example.com',
  285. 'edit',
  286. 'application/atom+xml'));
  287. $entry->setEtag($etag);
  288. $newEntry = $entry->reload();
  289. $headers = $this->adapter->popRequest()->headers;
  290. $found = false;
  291. foreach ($headers as $header) {
  292. if ($header == 'If-None-Match: ' . $etag)
  293. $found = true;
  294. }
  295. $this->assertTrue($found,
  296. 'If-None-Match header not found or incorrect');
  297. }
  298. public function testIfNoneMatchCanBeSetOnReload()
  299. {
  300. $etagOverride = 'foo';
  301. $etag = 'ABCD1234';
  302. $this->adapter->setResponse($this->httpEntrySample);
  303. $entry = $this->service->newEntry();
  304. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  305. 'http://www.example.com',
  306. 'edit',
  307. 'application/atom+xml'));
  308. $entry->setEtag($etag);
  309. $newEntry = $entry->reload(null, null,
  310. array('If-None-Match' => $etagOverride));
  311. $headers = $this->adapter->popRequest()->headers;
  312. $found = false;
  313. foreach ($headers as $header) {
  314. if ($header == 'If-None-Match: ' . $etagOverride)
  315. $found = true;
  316. }
  317. $this->assertTrue($found,
  318. 'If-None-Match header not found or incorrect');
  319. }
  320. public function testReloadReturnsEntryObject()
  321. {
  322. $etag = 'ABCD1234';
  323. $this->adapter->setResponse($this->httpEntrySample);
  324. $entry = $this->service->newEntry();
  325. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  326. 'http://www.example.com',
  327. 'edit',
  328. 'application/atom+xml'));
  329. $entry->setEtag($etag);
  330. $newEntry = $entry->reload();
  331. $this->assertEquals('Zend_Gdata_App_Entry', get_class($newEntry));
  332. }
  333. public function testReloadPopulatesEntryObject()
  334. {
  335. $etag = 'ABCD1234';
  336. $this->adapter->setResponse($this->httpEntrySample);
  337. $entry = $this->service->newEntry();
  338. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  339. 'http://www.example.com',
  340. 'edit',
  341. 'application/atom+xml'));
  342. $entry->setEtag($etag);
  343. $newEntry = $entry->reload();
  344. $this->assertEquals('Hello world', $newEntry->title->text);
  345. }
  346. public function testReloadDoesntThrowExceptionIfNoEtag()
  347. {
  348. $this->adapter->setResponse($this->httpEntrySample);
  349. $entry = $this->service->newEntry();
  350. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  351. 'http://www.example.com',
  352. 'edit',
  353. 'application/atom+xml'));
  354. $newEntry = $entry->reload();
  355. $this->assertEquals('Zend_Gdata_App_Entry', get_class($newEntry));
  356. }
  357. public function testReloadExtractsURIFromEditLink()
  358. {
  359. $expectedUri = 'http://www.example.com';
  360. $etag = 'ABCD1234';
  361. $this->service->setMajorProtocolVersion(2);
  362. $this->adapter->setResponse($this->httpEntrySample);
  363. $entry = $this->service->newEntry();
  364. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  365. $expectedUri,
  366. 'edit',
  367. 'application/atom+xml'));
  368. $entry->setEtag($etag);
  369. $newEntry = $entry->reload();
  370. $requestUri = $this->adapter->popRequest()->uri;
  371. $expectedUriObject = Zend_Uri_Http::fromString($expectedUri);
  372. $expectedUriObject->setPort('80');
  373. $this->assertEquals($expectedUriObject, $requestUri);
  374. }
  375. public function testReloadAllowsCustomURI()
  376. {
  377. $uriOverride = 'http://www.example.org';
  378. $etag = 'ABCD1234';
  379. $this->service->setMajorProtocolVersion(2);
  380. $this->adapter->setResponse($this->httpEntrySample);
  381. $entry = $this->service->newEntry();
  382. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  383. 'http://www.example.com',
  384. 'edit',
  385. 'application/atom+xml'));
  386. $entry->setEtag($etag);
  387. $newEntry = $entry->reload($uriOverride);
  388. $requestUri = $this->adapter->popRequest()->uri;
  389. $uriOverrideObject = Zend_Uri_Http::fromString($uriOverride);
  390. $uriOverrideObject->setPort('80');
  391. $this->assertEquals($uriOverrideObject, $requestUri);
  392. }
  393. public function testReloadReturnsNullIfEntryNotModified()
  394. {
  395. $etag = 'ABCD1234';
  396. $this->service->setMajorProtocolVersion(2);
  397. $this->adapter->setResponse('HTTP/1.1 304 Not Modified');
  398. $entry = $this->service->newEntry();
  399. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  400. 'http://www.example.com',
  401. 'edit',
  402. 'application/atom+xml'));
  403. $entry->setEtag($etag);
  404. $newEntry = $entry->reload();
  405. $this->assertEquals(null, $newEntry);
  406. }
  407. public function testCanSetReloadReturnClassname()
  408. {
  409. $className = 'Zend_Gdata_Entry';
  410. $etag = 'ABCD1234';
  411. $this->service->setMajorProtocolVersion(2);
  412. $this->adapter->setResponse($this->httpEntrySample);
  413. $entry = $this->service->newEntry();
  414. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  415. 'http://www.example.com',
  416. 'edit',
  417. 'application/atom+xml'));
  418. $entry->setEtag($etag);
  419. $newEntry = $entry->reload(null, $className);
  420. $this->assertEquals($className, get_class($newEntry));
  421. }
  422. public function testReloadInheritsClassname()
  423. {
  424. $className = 'Zend_Gdata_Entry';
  425. $etag = 'ABCD1234';
  426. $this->service->setMajorProtocolVersion(2);
  427. $this->adapter->setResponse($this->httpEntrySample);
  428. $entry = new $className;
  429. $entry->setService($this->service);
  430. $entry->link = array(new Zend_Gdata_App_Extension_Link(
  431. 'http://www.example.com',
  432. 'edit',
  433. 'application/atom+xml'));
  434. $entry->setEtag($etag);
  435. $newEntry = $entry->reload();
  436. $this->assertEquals($className, get_class($newEntry));
  437. }
  438. public function testCanSetMajorProtocolVersion()
  439. {
  440. $expectedVersion = 42;
  441. $entry = $this->service->newEntry();
  442. $entry->setMajorProtocolVersion($expectedVersion);
  443. $receivedVersion = $entry->getMajorProtocolVersion();
  444. $this->assertEquals($expectedVersion, $receivedVersion);
  445. }
  446. public function testCanSetMinorProtocolVersion()
  447. {
  448. $expectedVersion = 42;
  449. $entry = $this->service->newEntry();
  450. $entry->setMinorProtocolVersion($expectedVersion);
  451. $receivedVersion = $entry->getMinorProtocolVersion();
  452. $this->assertEquals($expectedVersion, $receivedVersion);
  453. }
  454. public function testMajorProtocolVersionCannotBeZero()
  455. {
  456. $expectedVersion = 0;
  457. $entry = $this->service->newEntry();
  458. $this->setExpectedException('Zend_Gdata_App_InvalidArgumentException');
  459. $entry->setMajorProtocolVersion($expectedVersion);
  460. }
  461. public function testMajorProtocolVersionCannotBeNegative()
  462. {
  463. $expectedVersion = -1;
  464. $entry = $this->service->newEntry();
  465. $this->setExpectedException('Zend_Gdata_App_InvalidArgumentException');
  466. $entry->setMajorProtocolVersion($expectedVersion);
  467. }
  468. public function testMajorProtocolVersionMayBeNull()
  469. {
  470. $expectedVersion = null;
  471. $entry = $this->service->newEntry();
  472. $entry->setMajorProtocolVersion($expectedVersion);
  473. $receivedVersion = $entry->getMajorProtocolVersion();
  474. $this->assertNull($receivedVersion);
  475. }
  476. public function testMinorProtocolVersionMayBeZero()
  477. {
  478. $expectedVersion = 0;
  479. $entry = $this->service->newEntry();
  480. $entry->setMinorProtocolVersion($expectedVersion);
  481. $receivedVersion = $entry->getMinorProtocolVersion();
  482. $this->assertEquals($expectedVersion, $receivedVersion);
  483. }
  484. public function testMinorProtocolVersionCannotBeNegative()
  485. {
  486. $expectedVersion = -1;
  487. $entry = $this->service->newEntry();
  488. $this->setExpectedException('Zend_Gdata_App_InvalidArgumentException');
  489. $entry->setMinorProtocolVersion($expectedVersion);
  490. }
  491. public function testMinorProtocolVersionMayBeNull()
  492. {
  493. $expectedVersion = null;
  494. $entry = $this->service->newEntry();
  495. $entry->setMinorProtocolVersion($expectedVersion);
  496. $receivedVersion = $entry->getMinorProtocolVersion();
  497. $this->assertNull($receivedVersion);
  498. }
  499. public function testDefaultMajorProtocolVersionIs1()
  500. {
  501. $entry = $this->service->newEntry();
  502. $this->assertEquals(1, $entry->getMajorProtocolVersion());
  503. }
  504. public function testDefaultMinorProtocolVersionIsNull()
  505. {
  506. $entry = $this->service->newEntry();
  507. $this->assertNull($entry->getMinorProtocolVersion());
  508. }
  509. public function testLookupNamespaceUsesCurrentVersion()
  510. {
  511. $prefix = 'test';
  512. $v1TestString = 'TEST-v1';
  513. $v2TestString = 'TEST-v2';
  514. Zend_Gdata_App_Base::flushNamespaceLookupCache();
  515. $entry = $this->service->newEntry();
  516. $entry->registerNamespace($prefix, $v1TestString, 1, 0);
  517. $entry->registerNamespace($prefix, $v2TestString, 2, 0);
  518. $entry->setMajorProtocolVersion(1);
  519. $result = $entry->lookupNamespace($prefix);
  520. $this->assertEquals($v1TestString, $result);
  521. $entry->setMajorProtocolVersion(2);
  522. $result = $entry->lookupNamespace($prefix);
  523. $this->assertEquals($v2TestString, $result);
  524. $entry->setMajorProtocolVersion(null); // Should default to latest
  525. $result = $entry->lookupNamespace($prefix);
  526. $this->assertEquals($v2TestString, $result);
  527. }
  528. public function testLookupNamespaceObeysParentBehavior()
  529. {
  530. $prefix = 'test';
  531. $testString10 = 'TEST-v1-0';
  532. $testString20 = 'TEST-v2-0';
  533. $testString11 = 'TEST-v1-1';
  534. $testString21 = 'TEST-v2-1';
  535. $testString12 = 'TEST-v1-2';
  536. $testString22 = 'TEST-v2-2';
  537. Zend_Gdata_App_Base::flushNamespaceLookupCache();
  538. $entry = $this->service->newEntry();
  539. $entry->registerNamespace($prefix, $testString10, 1, 0);
  540. $entry->registerNamespace($prefix, $testString20, 2, 0);
  541. $entry->registerNamespace($prefix, $testString11, 1, 1);
  542. $entry->registerNamespace($prefix, $testString21, 2, 1);
  543. $entry->registerNamespace($prefix, $testString12, 1, 2);
  544. $entry->registerNamespace($prefix, $testString22, 2, 2);
  545. // Assumes default version (1)
  546. $result = $entry->lookupNamespace($prefix, 1, null);
  547. $this->assertEquals($testString12, $result);
  548. $result = $entry->lookupNamespace($prefix, 2, null);
  549. $this->assertEquals($testString22, $result);
  550. $result = $entry->lookupNamespace($prefix, 1, 1);
  551. $this->assertEquals($testString11, $result);
  552. $result = $entry->lookupNamespace($prefix, 2, 1);
  553. $this->assertEquals($testString21, $result);
  554. $result = $entry->lookupNamespace($prefix, null, null);
  555. $this->assertEquals($testString12, $result);
  556. $result = $entry->lookupNamespace($prefix, null, 1);
  557. $this->assertEquals($testString11, $result);
  558. // Override to retrieve latest version
  559. $entry->setMajorProtocolVersion(null);
  560. $result = $entry->lookupNamespace($prefix, null, null);
  561. $this->assertEquals($testString22, $result);
  562. $result = $entry->lookupNamespace($prefix, null, 1);
  563. $this->assertEquals($testString21, $result);
  564. }
  565. }