PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/include/tests/Zend/Gdata/Books/VolumeFeedTest.php

http://becontent.googlecode.com/
PHP | 108 lines | 68 code | 14 blank | 26 comment | 0 complexity | c7d66601431a35701f8870a22f367aac MD5 | raw file
Possible License(s): LGPL-2.1
  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/VolumeFeed.php';
  26. require_once 'Zend/Gdata/Books.php';
  27. /**
  28. * @package Zend_Gdata_App
  29. * @subpackage UnitTests
  30. */
  31. class Zend_Gdata_Books_VolumeFeedTest extends PHPUnit_Framework_TestCase
  32. {
  33. public function setUp() {
  34. $this->feedText = file_get_contents(
  35. 'Zend/Gdata/Books/_files/VolumeFeedDataSample1.xml',
  36. true);
  37. $this->feed = new Zend_Gdata_Books_VolumeFeed();
  38. }
  39. private function verifyAllSamplePropertiesAreCorrect ($volumeFeed) {
  40. $this->assertEquals('http://www.google.com/books/feeds/volumes',
  41. $volumeFeed->id->text);
  42. $this->assertEquals('2008-10-07T16:41:52.000Z', $volumeFeed->updated->text);
  43. $this->assertEquals('http://schemas.google.com/g/2005#kind', $volumeFeed->category[0]->scheme);
  44. $this->assertEquals('http://schemas.google.com/books/2008#volume', $volumeFeed->category[0]->term);
  45. $this->assertEquals('text', $volumeFeed->title->type);
  46. $this->assertEquals('Search results for Hamlet', $volumeFeed->title->text);;
  47. $this->assertEquals('self', $volumeFeed->getLink('self')->rel);
  48. $this->assertEquals('application/atom+xml', $volumeFeed->getLink('self')->type);
  49. $this->assertEquals('http://www.google.com/books/feeds/volumes?q=Hamlet&start-index=3&max-results=5', $volumeFeed->getLink('self')->href);
  50. $this->assertEquals('Google Books Search', $volumeFeed->author[0]->name->text);
  51. $this->assertEquals('http://www.google.com', $volumeFeed->author[0]->uri->text);
  52. $this->assertEquals(512, $volumeFeed->totalResults->text);
  53. $this->assertEquals(3, $volumeFeed->startIndex->text);
  54. $this->assertEquals(5, $volumeFeed->itemsPerPage->text);
  55. }
  56. public function testEmptyEntryShouldHaveNoExtensionElements() {
  57. $this->assertTrue(is_array($this->feed->extensionElements));
  58. $this->assertEquals(0, count($this->feed->extensionElements));
  59. }
  60. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  61. $this->assertTrue(is_array($this->feed->extensionAttributes));
  62. $this->assertEquals(0, count($this->feed->extensionAttributes));
  63. }
  64. public function testSampleEntryShouldHaveNoExtensionElements() {
  65. $this->feed->transferFromXML($this->feedText);
  66. $this->assertTrue(is_array($this->feed->extensionElements));
  67. $this->assertEquals(0, count($this->feed->extensionElements));
  68. }
  69. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  70. $this->feed->transferFromXML($this->feedText);
  71. $this->assertTrue(is_array($this->feed->extensionAttributes));
  72. $this->assertEquals(0, count($this->feed->extensionAttributes));
  73. }
  74. public function testEmptyVolumeFeedToAndFromStringShouldMatch() {
  75. $entryXml = $this->feed->saveXML();
  76. $newVolumeFeed = new Zend_Gdata_Books_VolumeFeed();
  77. $newVolumeFeed->transferFromXML($entryXml);
  78. $newVolumeFeedXml = $newVolumeFeed->saveXML();
  79. $this->assertEquals($entryXml, $newVolumeFeedXml);
  80. }
  81. public function testSamplePropertiesAreCorrect () {
  82. $this->feed->transferFromXML($this->feedText);
  83. $this->verifyAllSamplePropertiesAreCorrect($this->feed);
  84. }
  85. public function testConvertVolumeFeedToAndFromString() {
  86. $this->feed->transferFromXML($this->feedText);
  87. $entryXml = $this->feed->saveXML();
  88. $newVolumeFeed = new Zend_Gdata_Books_VolumeFeed();
  89. $newVolumeFeed->transferFromXML($entryXml);
  90. $this->verifyAllSamplePropertiesAreCorrect($newVolumeFeed);
  91. $newVolumeFeedXml = $newVolumeFeed->saveXML();
  92. $this->assertEquals($entryXml, $newVolumeFeedXml);
  93. }
  94. }