2
0

VolumeFeedTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_Books
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 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. /**
  23. * Test helper
  24. */
  25. require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  26. require_once 'Zend/Gdata/Books/VolumeFeed.php';
  27. require_once 'Zend/Gdata/Books.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_Gdata_Books
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. * @group Zend_Gdata
  35. * @group Zend_Gdata_Books
  36. */
  37. class Zend_Gdata_Books_VolumeFeedTest extends PHPUnit_Framework_TestCase
  38. {
  39. public function setUp() {
  40. $this->feedText = file_get_contents(
  41. 'Zend/Gdata/Books/_files/VolumeFeedDataSample1.xml',
  42. true);
  43. $this->feed = new Zend_Gdata_Books_VolumeFeed();
  44. }
  45. private function verifyAllSamplePropertiesAreCorrect ($volumeFeed) {
  46. $this->assertEquals('http://www.google.com/books/feeds/volumes',
  47. $volumeFeed->id->text);
  48. $this->assertEquals('2008-10-07T16:41:52.000Z', $volumeFeed->updated->text);
  49. $this->assertEquals('http://schemas.google.com/g/2005#kind', $volumeFeed->category[0]->scheme);
  50. $this->assertEquals('http://schemas.google.com/books/2008#volume', $volumeFeed->category[0]->term);
  51. $this->assertEquals('text', $volumeFeed->title->type);
  52. $this->assertEquals('Search results for Hamlet', $volumeFeed->title->text);;
  53. $this->assertEquals('self', $volumeFeed->getLink('self')->rel);
  54. $this->assertEquals('application/atom+xml', $volumeFeed->getLink('self')->type);
  55. $this->assertEquals('http://www.google.com/books/feeds/volumes?q=Hamlet&start-index=3&max-results=5', $volumeFeed->getLink('self')->href);
  56. $this->assertEquals('Google Books Search', $volumeFeed->author[0]->name->text);
  57. $this->assertEquals('http://www.google.com', $volumeFeed->author[0]->uri->text);
  58. $this->assertEquals(512, $volumeFeed->totalResults->text);
  59. $this->assertEquals(3, $volumeFeed->startIndex->text);
  60. $this->assertEquals(5, $volumeFeed->itemsPerPage->text);
  61. }
  62. public function testEmptyEntryShouldHaveNoExtensionElements() {
  63. $this->assertTrue(is_array($this->feed->extensionElements));
  64. $this->assertEquals(0, count($this->feed->extensionElements));
  65. }
  66. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  67. $this->assertTrue(is_array($this->feed->extensionAttributes));
  68. $this->assertEquals(0, count($this->feed->extensionAttributes));
  69. }
  70. public function testSampleEntryShouldHaveNoExtensionElements() {
  71. $this->feed->transferFromXML($this->feedText);
  72. $this->assertTrue(is_array($this->feed->extensionElements));
  73. $this->assertEquals(0, count($this->feed->extensionElements));
  74. }
  75. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  76. $this->feed->transferFromXML($this->feedText);
  77. $this->assertTrue(is_array($this->feed->extensionAttributes));
  78. $this->assertEquals(0, count($this->feed->extensionAttributes));
  79. }
  80. public function testEmptyVolumeFeedToAndFromStringShouldMatch() {
  81. $entryXml = $this->feed->saveXML();
  82. $newVolumeFeed = new Zend_Gdata_Books_VolumeFeed();
  83. $newVolumeFeed->transferFromXML($entryXml);
  84. $newVolumeFeedXml = $newVolumeFeed->saveXML();
  85. $this->assertEquals($entryXml, $newVolumeFeedXml);
  86. }
  87. public function testSamplePropertiesAreCorrect () {
  88. $this->feed->transferFromXML($this->feedText);
  89. $this->verifyAllSamplePropertiesAreCorrect($this->feed);
  90. }
  91. public function testConvertVolumeFeedToAndFromString() {
  92. $this->feed->transferFromXML($this->feedText);
  93. $entryXml = $this->feed->saveXML();
  94. $newVolumeFeed = new Zend_Gdata_Books_VolumeFeed();
  95. $newVolumeFeed->transferFromXML($entryXml);
  96. $this->verifyAllSamplePropertiesAreCorrect($newVolumeFeed);
  97. $newVolumeFeedXml = $newVolumeFeed->saveXML();
  98. $this->assertEquals($entryXml, $newVolumeFeedXml);
  99. }
  100. }