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