summaryrefslogtreecommitdiff
path: root/zend/tests/Zend/Gdata/Books/VolumeFeedTest.php
blob: 423602c59e98ce181d288b45224648f5fcf8def9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Gdata_Books
 * @subpackage UnitTests
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id $
 */

require_once 'Zend/Gdata/Books/VolumeFeed.php';
require_once 'Zend/Gdata/Books.php';

/**
 * @category   Zend
 * @package    Zend_Gdata_Books
 * @subpackage UnitTests
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @group      Zend_Gdata
 * @group      Zend_Gdata_Books
 */
class Zend_Gdata_Books_VolumeFeedTest extends PHPUnit_Framework_TestCase
{

    public function setUp() {
        $this->feedText = file_get_contents(
                'Zend/Gdata/Books/_files/VolumeFeedDataSample1.xml',
                true);
        $this->feed = new Zend_Gdata_Books_VolumeFeed();
    }

    private function verifyAllSamplePropertiesAreCorrect ($volumeFeed) {
        $this->assertEquals('http://www.google.com/books/feeds/volumes',
            $volumeFeed->id->text);
        $this->assertEquals('2008-10-07T16:41:52.000Z', $volumeFeed->updated->text);
        $this->assertEquals('http://schemas.google.com/g/2005#kind', $volumeFeed->category[0]->scheme);
        $this->assertEquals('http://schemas.google.com/books/2008#volume', $volumeFeed->category[0]->term);
        $this->assertEquals('text', $volumeFeed->title->type);
        $this->assertEquals('Search results for Hamlet', $volumeFeed->title->text);;
        $this->assertEquals('self', $volumeFeed->getLink('self')->rel);
        $this->assertEquals('application/atom+xml', $volumeFeed->getLink('self')->type);
        $this->assertEquals('http://www.google.com/books/feeds/volumes?q=Hamlet&start-index=3&max-results=5', $volumeFeed->getLink('self')->href);
        $this->assertEquals('Google Books Search', $volumeFeed->author[0]->name->text);
        $this->assertEquals('http://www.google.com', $volumeFeed->author[0]->uri->text);
        $this->assertEquals(512, $volumeFeed->totalResults->text);
        $this->assertEquals(3, $volumeFeed->startIndex->text);
        $this->assertEquals(5, $volumeFeed->itemsPerPage->text);
    }

    public function testEmptyEntryShouldHaveNoExtensionElements() {
        $this->assertTrue(is_array($this->feed->extensionElements));
        $this->assertEquals(0, count($this->feed->extensionElements));
    }

    public function testEmptyEntryShouldHaveNoExtensionAttributes() {
        $this->assertTrue(is_array($this->feed->extensionAttributes));
        $this->assertEquals(0, count($this->feed->extensionAttributes));
    }

    public function testSampleEntryShouldHaveNoExtensionElements() {
        $this->feed->transferFromXML($this->feedText);
        $this->assertTrue(is_array($this->feed->extensionElements));
        $this->assertEquals(0, count($this->feed->extensionElements));
    }

    public function testSampleEntryShouldHaveNoExtensionAttributes() {
        $this->feed->transferFromXML($this->feedText);
        $this->assertTrue(is_array($this->feed->extensionAttributes));
        $this->assertEquals(0, count($this->feed->extensionAttributes));
    }

    public function testEmptyVolumeFeedToAndFromStringShouldMatch() {
        $entryXml = $this->feed->saveXML();
        $newVolumeFeed = new Zend_Gdata_Books_VolumeFeed();
        $newVolumeFeed->transferFromXML($entryXml);
        $newVolumeFeedXml = $newVolumeFeed->saveXML();
        $this->assertEquals($entryXml, $newVolumeFeedXml);
    }

    public function testSamplePropertiesAreCorrect () {
        $this->feed->transferFromXML($this->feedText);
        $this->verifyAllSamplePropertiesAreCorrect($this->feed);
    }

    public function testConvertVolumeFeedToAndFromString() {
        $this->feed->transferFromXML($this->feedText);
        $entryXml = $this->feed->saveXML();
        $newVolumeFeed = new Zend_Gdata_Books_VolumeFeed();
        $newVolumeFeed->transferFromXML($entryXml);
        $this->verifyAllSamplePropertiesAreCorrect($newVolumeFeed);
        $newVolumeFeedXml = $newVolumeFeed->saveXML();
        $this->assertEquals($entryXml, $newVolumeFeedXml);
    }

}