summaryrefslogtreecommitdiff
path: root/zend/tests/Zend/Gdata/YouTube/InboxFeedTest.php
blob: a7a63cda0846f3dfdfbaeb52f3686a6268bb40a5 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?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_YouTube
 * @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/YouTube/InboxFeed.php';
require_once 'Zend/Gdata/YouTube.php';

/**
 * @category   Zend
 * @package    Zend_Gdata_YouTube
 * @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_YouTube
 */
class Zend_Gdata_YouTube_InboxFeedTest extends PHPUnit_Framework_TestCase
{

    public function setUp() {
        $this->feedText = file_get_contents(
            'Zend/Gdata/YouTube/_files/InboxFeedDataSample1.xml',
            true);
        $this->V2feedText = file_get_contents(
            'Zend/Gdata/YouTube/_files/InboxFeedDataSampleV2.xml',
            true);
        $this->feed = new Zend_Gdata_YouTube_InboxFeed();
    }

    private function verifyAllSamplePropertiesAreCorrect ($inboxFeed) {
        $this->assertEquals('http://gdata.youtube.com/feeds/api/users/' .
            'default/inbox',
            $inboxFeed->id->text);
        $this->assertEquals('2008-06-10T20:55:40.271Z',
            $inboxFeed->updated->text);
        $this->assertEquals('http://schemas.google.com/g/2005#kind',
            $inboxFeed->category[0]->scheme);
        $this->assertEquals(
            'http://gdata.youtube.com/schemas/2007#videoMessage',
            $inboxFeed->category[0]->term);
        $this->assertEquals(
            'http://www.youtube.com/img/pic_youtubelogo_123x63.gif',
            $inboxFeed->logo->text);
        $this->assertEquals('text', $inboxFeed->title->type);
        $this->assertEquals('Inbox of andyland74',
            $inboxFeed->title->text);;
        $this->assertEquals('self', $inboxFeed->getLink('self')->rel);
        $this->assertEquals('application/atom+xml',
            $inboxFeed->getLink('self')->type);
        $this->assertEquals(
            'http://gdata.youtube.com/feeds/api/users/andyland74/inbox?...',
            $inboxFeed->getLink('self')->href);
        $this->assertEquals('andyland74', $inboxFeed->author[0]->name->text);
        $this->assertEquals(
            'http://gdata.youtube.com/feeds/api/users/andyland74',
            $inboxFeed->author[0]->uri->text);
        $this->assertEquals(1, $inboxFeed->totalResults->text);
    }

    private function verifyAllSamplePropertiesAreCorrectV2 ($inboxFeed) {
        $this->assertEquals('tag:youtube,2008:user:andyland74:inbox',
            $inboxFeed->id->text);
        $this->assertEquals('2008-07-21T17:54:30.236Z',
            $inboxFeed->updated->text);
        $this->assertEquals('http://schemas.google.com/g/2005#kind',
            $inboxFeed->category[0]->scheme);
        $this->assertEquals(
            'http://gdata.youtube.com/schemas/2007#videoMessage',
            $inboxFeed->category[0]->term);
        $this->assertEquals(
            'http://www.youtube.com/img/pic_youtubelogo_123x63.gif',
            $inboxFeed->logo->text);
        $this->assertEquals('Inbox of andyland74',
            $inboxFeed->title->text);;
        $this->assertEquals('andyland74',
            $inboxFeed->author[0]->name->text);
        $this->assertEquals(
            'http://gdata.youtube.com/feeds/api/users/andyland74',
            $inboxFeed->author[0]->uri->text);
        $this->assertEquals('self', $inboxFeed->getLink('self')->rel);
        $this->assertEquals('application/atom+xml',
            $inboxFeed->getLink('self')->type);
        $this->assertEquals(
            'http://gdata.youtube.com/feeds/api/users/andyland74/inbox?...',
            $inboxFeed->getLink('self')->href);
        $this->assertEquals('alternate', $inboxFeed->getLink('alternate')->rel);
        $this->assertEquals('text/html',
            $inboxFeed->getLink('alternate')->type);
        $this->assertEquals(
            'http://www.youtube.com/my_messages?folder=inbox&filter=videos',
            $inboxFeed->getLink('alternate')->href);
        $this->assertEquals('service', $inboxFeed->getLink('service')->rel);
        $this->assertEquals('application/atomsvc+xml',
            $inboxFeed->getLink('service')->type);
        $this->assertEquals(
            'http://gdata.youtube.com/feeds/api/users/andyland74/inbox?' .
            'alt=...',
            $inboxFeed->getLink('service')->href);

    }

    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 testEmptyInboxFeedToAndFromStringShouldMatch() {
        $feedXml = $this->feed->saveXML();
        $newInboxFeed = new Zend_Gdata_YouTube_InboxFeed();
        $newInboxFeed->transferFromXML($feedXml);
        $newInboxFeedXml = $newInboxFeed->saveXML();
        $this->assertTrue($feedXml == $newInboxFeedXml);
    }

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

    public function testSamplePropertiesAreCorrectV2 () {
        $this->feed->transferFromXML($this->V2feedText);
        $this->verifyAllSamplePropertiesAreCorrectV2($this->feed);
    }

    public function testConvertInboxFeedToAndFromString() {
        $this->feed->transferFromXML($this->feedText);
        $feedXml = $this->feed->saveXML();
        $newInboxFeed = new Zend_Gdata_YouTube_InboxFeed();
        $newInboxFeed->transferFromXML($feedXml);
        $this->verifyAllSamplePropertiesAreCorrect($newInboxFeed);
        $newInboxFeedXml = $newInboxFeed->saveXML();
        $this->assertEquals($feedXml, $newInboxFeedXml);
    }

    public function testConvertInboxFeedToAndFromStringV2() {
        $this->feed->setMajorProtocolVersion(2);
        $this->feed->transferFromXML($this->V2feedText);
        $feedXml = $this->feed->saveXML();
        $newInboxFeed = new Zend_Gdata_YouTube_InboxFeed();
        $newInboxFeed->transferFromXML($feedXml);
        $newInboxFeed->setMajorProtocolVersion(2);
        $this->verifyAllSamplePropertiesAreCorrectV2($newInboxFeed);
        $newInboxFeedXml = $newInboxFeed->saveXML();
        $this->assertEquals($feedXml, $newInboxFeedXml);
    }

}