aboutsummaryrefslogtreecommitdiff
path: root/tests/www/rssTest.php
blob: 75e4363e0384419927f0a9c9d5967c034d542ac8 (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
<?php
require_once dirname(__FILE__) . '/../prepare.php';
require_once 'HTTP/Request2.php';

class www_rssTest extends TestBaseApi
{
    protected $urlPart = 'rss.php';


    /**
     * Verifies that the given number of feed items exist in the feed
     * XML tree.
     *
     * @var SimpleXMLElement $simpleXml RSS feed root element
     * @var integer          $nCount    Number of expected feed items
     * @var string           $msg       Error message
     */
    protected function assertItemCount(
        SimpleXMLElement $simpleXml, $nCount, $msg = null
    ) {
        $this->assertEquals($nCount, count($simpleXml->channel->item), $msg);
    }




    /**
     * A private bookmark should not show up in the global rss feed if the
     * user is not logged in nor passes the private key
     */
    public function testAllPrivateBookmarkNotLoggedIn()
    {
        list($uId, $username) = $this->addUserData();
        $this->addBookmark(
            $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE
        );

        $req = $this->getRequest();
        $response_body = $req->send()->getBody();

        $rss = simplexml_load_string($response_body);
        $this->assertItemCount($rss, 0, 'I see a private bookmark');
    }



    /**
     * A private bookmark should not show up in the user's rss feed if the
     * user is not logged in nor passes the private key
     */
    public function testUserPrivateBookmarkNotLoggedIn()
    {
        list($uId, $username) = $this->addUserData();
        $this->addBookmark(
            $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE
        );

        $req = $this->getRequest('/' . $username);
        $response_body = $req->send()->getBody();

        $rss = simplexml_load_string($response_body);
        $this->assertItemCount($rss, 0, 'I see a private bookmark');
    }




    /**
     * Test the global feed by passing the private key
     */
    public function testAllPrivateBookmarkWithPrivateKey()
    {
        list($uId, $username, $password, $privateKey) = $this->addUserData(
            null, null, true
        );
        $this->addBookmark(
            $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE,
            null, 'private bookmark'
        );

        $req = $this->getRequest('?privatekey=' . $privateKey);
        $response_body = $req->send()->getBody();

        $rss = simplexml_load_string($response_body);
        $this->assertItemCount($rss, 1, 'I miss the private bookmark');
        $this->assertEquals(
            'private bookmark', (string)$rss->channel->item[0]->title
        );
    }



    /**
     * Test the user feed by passing the private key
     */
    public function testUserPrivateBookmarkWithPrivateKey()
    {
        list($uId, $username, $password, $privateKey) = $this->addUserData(
            null, null, true
        );
        $this->addBookmark(
            $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE,
            null, 'private bookmark'
        );

        $req = $this->getRequest('/' . $username . '?privatekey=' . $privateKey);
        $response_body = $req->send()->getBody();

        $rss = simplexml_load_string($response_body);
        $this->assertItemCount($rss, 1, 'I miss the private bookmark');
        $this->assertEquals(
            'private bookmark', (string)$rss->channel->item[0]->title
        );
    }



    /**
     * Verify that fetching the feed with a private key
     * does not keep you logged in
     */
    public function testUserPrivateKeyDoesNotKeepLoggedYouIn()
    {
        list($uId, $username, $password, $privateKey) = $this->addUserData(
            null, null, true
        );
        $this->addBookmark(
            $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE,
            null, 'private bookmark'
        );

        $req = $this->getRequest('/' . $username . '?privatekey=' . $privateKey);
        $cookies = $req->setCookieJar()->getCookieJar();
        $response_body = $req->send()->getBody();

        $rss = simplexml_load_string($response_body);
        $items = $rss->channel->item;

        $this->assertEquals(1, count($items), 'I miss the private bookmark');
        $this->assertEquals('private bookmark', (string)$items[0]->title);

        //request the feed again, with the same cookies
        $req = $this->getRequest('/' . $username);
        $req->setCookieJar($cookies);
        $response_body = $req->send()->getBody();
        $rss = simplexml_load_string($response_body);
        $this->assertItemCount($rss, 0, 'I still see the private bookmark');
    }

}//end class www_rssTest
?>