2
0

EntryTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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-2008 Zend Technologies USA Inc. (http://www.zend.com);
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. require_once 'Zend/Gdata/Entry.php';
  22. /**
  23. * @package Zend_Gdata
  24. * @subpackage UnitTests
  25. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  26. * @license http://framework.zend.com/license/new-bsd New BSD License
  27. */
  28. class Zend_Gdata_EntryTest extends PHPUnit_Framework_TestCase
  29. {
  30. public function setUp() {
  31. $this->entry = new Zend_Gdata_Entry();
  32. $this->entryText = file_get_contents(
  33. 'Zend/Gdata/_files/EntrySample1.xml',
  34. true);
  35. $this->etagLocalName = 'etag';
  36. $this->expectedEtag = 'W/"CkcHQH8_fCp7ImA9WxRTGEw."';
  37. $this->expectedMismatchExceptionMessage = "ETag mismatch";
  38. $this->gdNamespace = 'http://schemas.google.com/g/2005';
  39. $this->openSearchNamespacev1 = 'http://a9.com/-/spec/opensearchrss/1.0/';
  40. $this->openSearchNamespacev2 = 'http://a9.com/-/spec/opensearch/1.1/';
  41. }
  42. public function testXMLHasNoEtagsWhenUsingV1() {
  43. $etagData = 'Quux';
  44. $this->entry->setEtag($etagData);
  45. $domNode = $this->entry->getDOM(null, 1, null);
  46. $this->assertNull($domNode->attributes->getNamedItemNS($this->gdNamespace, $this->etagLocalName));
  47. }
  48. public function testXMLHasNoEtagsWhenUsingV1X() {
  49. $etagData = 'Quux';
  50. $this->entry->setEtag($etagData);
  51. $domNode = $this->entry->getDOM(null, 1, 1);
  52. $this->assertNull($domNode->attributes->getNamedItemNS($this->gdNamespace, $this->etagLocalName));
  53. }
  54. public function testXMLHasEtagsWhenUsingV2() {
  55. $etagData = 'Quux';
  56. $this->entry->setEtag($etagData);
  57. $domNode = $this->entry->getDOM(null, 2, null);
  58. $this->assertEquals($etagData, $domNode->attributes->getNamedItemNS($this->gdNamespace, $this->etagLocalName)->nodeValue);
  59. }
  60. public function testXMLHasEtagsWhenUsingV2X() {
  61. $etagData = 'Quux';
  62. $this->entry->setEtag($etagData);
  63. $domNode = $this->entry->getDOM(null, 2, 1);
  64. $this->assertEquals($etagData, $domNode->attributes->getNamedItemNS($this->gdNamespace, $this->etagLocalName)->nodeValue);
  65. }
  66. public function testXMLETagsPropagateToEntry() {
  67. $this->entry->transferFromXML($this->entryText);
  68. $this->assertEquals($this->expectedEtag, $this->entry->getEtag());
  69. }
  70. public function testXMLandHTMLEtagsDifferingThrowsException() {
  71. $exceptionCaught = false;
  72. $this->entry->setEtag("Foo");
  73. try {
  74. $this->entry->transferFromXML($this->entryText);
  75. } catch (Zend_Gdata_App_IOException $e) {
  76. $exceptionCaught = true;
  77. }
  78. $this->assertTrue($exceptionCaught, "Exception Zend_Gdata_IO_Exception expected");
  79. }
  80. public function testHttpAndXmlEtagsDifferingThrowsExceptionWithMessage() {
  81. $messageCorrect = false;
  82. $this->entry->setEtag("Foo");
  83. try {
  84. $this->entry->transferFromXML($this->entryText);
  85. } catch (Zend_Gdata_App_IOException $e) {
  86. if ($e->getMessage() == $this->expectedMismatchExceptionMessage)
  87. $messageCorrect = true;
  88. }
  89. $this->assertTrue($messageCorrect, "Exception Zend_Gdata_IO_Exception message incorrect");
  90. }
  91. public function testNothingBadHappensWhenHttpAndXmlEtagsMatch() {
  92. $this->entry->setEtag($this->expectedEtag);
  93. $this->entry->transferFromXML($this->entryText);
  94. $this->assertEquals($this->expectedEtag, $this->entry->getEtag());
  95. }
  96. public function testLookUpOpenSearchv1Namespace() {
  97. $this->assertEquals($this->openSearchNamespacev1,
  98. $this->entry->lookupNamespace('openSearch', 1, 0));
  99. $this->assertEquals($this->openSearchNamespacev1,
  100. $this->entry->lookupNamespace('openSearch', 1, null));
  101. }
  102. public function testLookupOpenSearchv2Namespace() {
  103. $this->assertEquals($this->openSearchNamespacev2,
  104. $this->entry->lookupNamespace('openSearch', 2, 0));
  105. $this->assertEquals($this->openSearchNamespacev2,
  106. $this->entry->lookupNamespace('openSearch', 2, null));
  107. }
  108. }