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

class www_bookmarksTest extends TestBaseApi
{
    protected $urlPart = 'api/posts/add';

    /**
     * Test that the default privacy setting is selected in the Privacy
     * drop-down list when adding a new bookmark, sending the form and
     * missing the title and the privacy setting.
     */
    public function testDefaultPrivacyBookmarksAddMissingTitleMissingPrivacy()
    {
        $this->setUnittestConfig(
            array('defaults' => array('privacy' => 2))
        );
        list($req, $uId) = $this->getLoggedInRequest();
        $cookies = $req->getCookieJar();
        $req->setMethod(HTTP_Request2::METHOD_POST);
        $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksget');
        $req->addPostParameter('description', 'Test bookmark 1 for default privacy.');
        $req->addPostParameter('status', '0');
        $req->send();

        $bms = $this->bs->getBookmarks(0, null, $uId);
        $this->assertEquals(1, count($bms['bookmarks']));
        $user = $this->us->getUser($uId);
        $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $user['username'] . '?action=get' . '&unittestMode=1';

        list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
        $req->setMethod(HTTP_Request2::METHOD_POST);
        $req->setUrl($reqUrl);
        $req->setCookieJar($cookies);
        $req->addPostParameter('submitted', '1');
        $response = $req->send();
        $response_body = $response->getBody();

        $x = simplexml_load_string($response_body);
        $ns = $x->getDocNamespaces();
        $x->registerXPathNamespace('ns', reset($ns));

        $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]');
        $this->assertEquals(1, count($elements), 'No selected status option found');
        $this->assertEquals(2, (string)$elements[0]['value']);
    }//end testDefaultPrivacyBookmarksAddMissingTitleMissingPrivacy


    /**
     * Test that the default privacy setting is selected in the Privacy
     * drop-down list when a new bookmark is being created.
     */
    public function testDefaultPrivacyBookmarksAdd()
    {
        $this->setUnittestConfig(
            array('defaults' => array('privacy' => 1))
        );
        list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1');

        $user = $this->us->getUser($uId);
        $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/'
            . $user['username'] . '?action=add' . '&unittestMode=1';
        $req->setUrl($reqUrl);
        $req->setMethod(HTTP_Request2::METHOD_GET);
        $response = $req->send();
        $response_body = $response->getBody();
        $this->assertNotEquals('', $response_body, 'Response is empty');

        $x = simplexml_load_string($response_body);
        $ns = $x->getDocNamespaces();
        $x->registerXPathNamespace('ns', reset($ns));

        $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]');
        $this->assertEquals(1, count($elements), 'No selected status option found');
        $this->assertEquals(1, (string)$elements[0]['value']);
    }//end testDefaultPrivacyBookmarksAdd


    /**
     * Test that the private RSS link exists when a user
     * has a private key and is enabled
     */
    public function testVerifyPrivateRSSLinkExists()
    {
        list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1', true, true);

        $user = $this->us->getUser($uId);
        $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/'
            . $user['username'];
        $req->setUrl($reqUrl);
        $req->setMethod(HTTP_Request2::METHOD_GET);
        $response = $req->send();
        $response_body = $response->getBody();
        $this->assertNotEquals('', $response_body, 'Response is empty');

        $x = simplexml_load_string($response_body);
        $ns = $x->getDocNamespaces();
        $x->registerXPathNamespace('ns', reset($ns));

        $elements = $x->xpath('//ns:link');
        $this->assertEquals(5, count($elements), 'Number of Links in Head not correct');
        $this->assertContains('privatekey=', (string)$elements[4]['href']);
    }//end testVerifyPrivateRSSLinkExists

}//end class www_bookmarksTest
?>