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

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

    /**
     * Test a user who does not have RSS private key enabled
     * and with a private bookmark.
     */
    public function testNoRSSPrivateKeyEnabled()
    {
        $this->setUnittestConfig(
            array('defaults' => array('privacy' => 2))
        );

        /* create user without RSS private Key */
        list($req, $uId) = $this->getLoggedInRequest(null, true, false, false);

        /* create private bookmark */
        $this->bs->addBookmark(
            'http://test', 'test', 'desc', 'note',
            2,//private
            array(), null, null, false, false, $uId
        );
        /* create public bookmark */
        $this->bs->addBookmark(
            'http://example.org', 'title', 'desc', 'priv',
            0,//public
            array(), null, null, false, false, $uId
        );

        /* get user details */
        $user = $this->us->getUser($uId);

        $req->setMethod(HTTP_Request2::METHOD_POST);
        $req->setUrl($this->getTestUrl('/' . $user['username'] . '?sort=date_desc'));
        $response = $req->send();
        $response_body = $response->getBody();

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

        $this->assertEquals(1, count($items), 'Incorrect Number of RSS Items');
        $this->assertEquals('title', (string)$items[0]->title);
    }//end testNoRSSPrivateKeyEnabled


    /**
     * Test a user who has RSS private key setup
     * with private bookmark.
     */
    public function testRSSPrivateKeyEnabled()
    {
        $this->setUnittestConfig(
            array('defaults' => array('privacy' => 2))
        );

        /* create user with RSS private Key */
        list($req, $uId) = $this->getLoggedInRequest(null, true, false, true);

        /* create private bookmark */
        $this->bs->addBookmark(
            'http://test', 'test', 'desc', 'note',
            2,//private
            array(), null, null, false, false, $uId
        );
        /* create public bookmark */
        $this->bs->addBookmark(
            'http://example.org', 'title', 'desc', 'priv',
            0,//public
            array(), null, null, false, false, $uId
        );

        /* get user details */
        $user = $this->us->getUser($uId);

        $req->setMethod(HTTP_Request2::METHOD_POST);
        $req->setUrl($this->getTestUrl('/' . $user['username'] . '?sort=date_desc&privatekey=' . $user['privateKey']));
        $response = $req->send();
        $response_body = $response->getBody();

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

        $this->assertEquals(2, count($items), 'Incorrect Number of RSS Items');
    }//end testRSSPrivateKeyEnabled



}//end class www_rssTest
?>