VolumeEntryTest.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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) 2006-2008 Zend Technologies USA Inc. (http://www.zend.com);
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * Test helper
  23. */
  24. require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  25. require_once 'Zend/Gdata/Books/VolumeEntry.php';
  26. require_once 'Zend/Gdata/Books.php';
  27. /**
  28. * @package Zend_Gdata_App
  29. * @subpackage UnitTests
  30. */
  31. class Zend_Gdata_Books_VolumeEntryTest extends PHPUnit_Framework_TestCase
  32. {
  33. public function setUp() {
  34. $this->entryText = file_get_contents(
  35. 'Zend/Gdata/Books/_files/VolumeEntryDataSample1.xml',
  36. true);
  37. $this->entry = new Zend_Gdata_Books_VolumeEntry();
  38. }
  39. private function verifySamplePropertiesAreCorrect ($volumeEntry) {
  40. $this->assertEquals('http://www.google.com/books/feeds/volumes/Mfer_MFwQrkC',
  41. $volumeEntry->id->text);
  42. $this->assertEquals('2008-10-07T15:28:15.000Z', $volumeEntry->updated->text);
  43. $this->assertEquals('http://schemas.google.com/g/2005#kind', $volumeEntry->category[0]->scheme);
  44. $this->assertEquals('http://schemas.google.com/books/2008#volume', $volumeEntry->category[0]->term);
  45. $this->assertEquals('http://bks1.books.google.com/books?id=Mfer_MFwQrkC&printsec=frontcover&img=1&zoom=5&sig=ACfU3U1o90VpMryPI7WKSyIhmAWdC1uDtw&source=gbs_gdata', $volumeEntry->getThumbnailLink()->href);
  46. $this->assertEquals('http://books.google.com/books?id=Mfer_MFwQrkC&ie=ISO-8859-1&source=gbs_gdata', $volumeEntry->getInfoLink()->href);
  47. $this->assertEquals(null, $volumeEntry->getPreviewLink());
  48. $creators = $volumeEntry->getCreators();
  49. $this->assertEquals('William Shakespeare', $creators[0]->text);
  50. $titles = $volumeEntry->getTitles();
  51. $this->assertEquals('Hamlet', $titles[0]->text);
  52. $dates = $volumeEntry->getDates();
  53. $this->assertEquals('2002-02', $dates[0]->text);
  54. $identifiers = $volumeEntry->getIdentifiers();
  55. $this->assertEquals('Mfer_MFwQrkC', $identifiers[0]->text);
  56. $this->assertEquals('ISBN:0198320493', $identifiers[1]->text);
  57. $languages = $volumeEntry->getLanguages();
  58. $this->assertEquals('en', $languages[0]->text);
  59. $formats = $volumeEntry->getFormats();
  60. $this->assertEquals('178 pages', $formats[0]->text);
  61. $publishers = $volumeEntry->getPublishers();
  62. $this->assertEquals('Oxford University Press', $publishers[0]->text);
  63. $subjects = $volumeEntry->getSubjects();
  64. $this->assertEquals('Denmark', $subjects[0]->text);
  65. $this->assertEquals(null, $volumeEntry->getPreviewLink());
  66. $this->assertEquals('http://www.google.com/books/feeds/users/me/volumes', $volumeEntry->getAnnotationLink()->href);
  67. $this->assertEquals('http://books.google.com/books?id=Mfer_MFwQrkC&ie=ISO-8859-1&source=gbs_gdata', $volumeEntry->getInfoLink()->href);
  68. $this->assertEquals('http://bks1.books.google.com/books?id=Mfer_MFwQrkC&printsec=frontcover&img=1&zoom=5&sig=ACfU3U1o90VpMryPI7WKSyIhmAWdC1uDtw&source=gbs_gdata', $volumeEntry->getThumbnailLink()->href);
  69. $this->assertEquals('Denmark', $subjects[0]->text);
  70. $this->assertEquals('http://schemas.google.com/books/2008#view_partial', $volumeEntry->getViewability()->value);
  71. $this->assertEquals('Mfer_MFwQrkC', $volumeEntry->getVolumeId());
  72. }
  73. public function testEmptyEntryShouldHaveNoExtensionElements() {
  74. $this->assertTrue(is_array($this->entry->extensionElements));
  75. $this->assertEquals(0, count($this->entry->extensionElements));
  76. }
  77. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  78. $this->assertTrue(is_array($this->entry->extensionAttributes));
  79. $this->assertEquals(0, count($this->entry->extensionAttributes));
  80. }
  81. public function testSampleEntryShouldHaveNoExtensionElements() {
  82. $this->entry->transferFromXML($this->entryText);
  83. $this->assertTrue(is_array($this->entry->extensionElements));
  84. $this->assertEquals(0, count($this->entry->extensionElements));
  85. }
  86. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  87. $this->entry->transferFromXML($this->entryText);
  88. $this->assertTrue(is_array($this->entry->extensionAttributes));
  89. $this->assertEquals(0, count($this->entry->extensionAttributes));
  90. }
  91. public function testEmptyVolumeEntryToAndFromStringShouldMatch() {
  92. $entryXml = $this->entry->saveXML();
  93. $newVolumeEntry = new Zend_Gdata_Books_VolumeEntry();
  94. $newVolumeEntry->transferFromXML($entryXml);
  95. $newVolumeEntryXml = $newVolumeEntry->saveXML();
  96. $this->assertEquals($entryXml, $newVolumeEntryXml);
  97. }
  98. public function testSamplePropertiesAreCorrect () {
  99. $this->entry->transferFromXML($this->entryText);
  100. $this->verifySamplePropertiesAreCorrect($this->entry);
  101. }
  102. public function testConvertVolumeEntryToAndFromString() {
  103. $this->entry->transferFromXML($this->entryText);
  104. $entryXml = $this->entry->saveXML();
  105. $newVolumeEntry = new Zend_Gdata_Books_VolumeEntry();
  106. $newVolumeEntry->transferFromXML($entryXml);
  107. $this->verifySamplePropertiesAreCorrect($newVolumeEntry);
  108. $newVolumeEntryXml = $newVolumeEntry->saveXML();
  109. $this->assertEquals($entryXml, $newVolumeEntryXml);
  110. }
  111. }