EntryTest.php 4.8 KB

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