EntryTest.php 22 KB

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