diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Api/PostsAddTest.php | 158 | ||||
| -rwxr-xr-x | tests/www/bookmarksTest.php | 80 | ||||
| -rwxr-xr-x | tests/www/editTest.php | 48 | ||||
| -rwxr-xr-x | tests/www/importNetscapeTest.php | 33 | ||||
| -rwxr-xr-x | tests/www/importTest.php | 33 | 
5 files changed, 194 insertions, 158 deletions
| diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index 24cc600..02e2b38 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -452,163 +452,5 @@ TXT;      }//end testDefaultPrivacyPublic -    /** -     * Test that the default privacy setting is used when an existing -     * bookmark is updated with edit.php. -     */ -    public function testDefaultPrivacyEdit() -    { -        $this->setUnittestConfig( -            array('defaults' => array('privacy' => 2)) -        ); - -        list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1'); -        $cookies = $req->getCookieJar(); -        $req->setMethod(HTTP_Request2::METHOD_POST); -        $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_edit'); -        $req->addPostParameter('description', 'Test bookmark 2 for default privacy.'); -        $req->addPostParameter('status', '0'); -        $res = $req->send(); -        $this->assertEquals( -            200, $res->getStatus(), -            'Adding bookmark failed: ' . $res->getBody()); -        $bms = $this->bs->getBookmarks(0, null, $uId); -        $bm  = reset($bms['bookmarks']); -        $bmId = $bm['bId']; - -        $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1'; -        $req2 = new HTTP_Request2($reqUrl, HTTP_Request2::METHOD_POST); -        $req2->setCookieJar($cookies); -        $req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit'); -        $req2->addPostParameter('title', 'Test bookmark 2 for default privacy.'); -        $req2->addPostParameter('submitted', '1'); -        $res = $req2->send(); - -        $this->assertEquals(302, $res->getStatus(), 'Editing bookmark failed'); - -        $bm = $this->bs->getBookmark($bmId); -        $this->assertEquals('2', $bm['bStatus']); -    }//end testDefaultPrivacyEdit - - -    /** -     * Test that the default privacy setting is used when bookmarks -     * are imported from an HTML bookmarks file using importNetscape.php. -     */ -    public function testDefaultPrivacyImportNetscape() -    { -        $this->setUnittestConfig( -            array('defaults' => array('privacy' => 1)) -        ); -        list($req, $uId) = $this->getLoggedInRequest(); -        $req->setMethod(HTTP_Request2::METHOD_POST); -        $req->setUrl($GLOBALS['unittestUrl'] . 'importNetscape.php' . '?unittestMode=1'); -        $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_netscapebookmarks.html'); -        $res = $req->send(); -        $this->assertEquals(200, $res->getStatus(), 'Bookmark import failed'); - -        $this->us->setCurrentUserId($uId); -        $bms = $this->bs->getBookmarks(0, null, $uId); -        $this->assertEquals(3, count($bms['bookmarks'])); -        $bm = reset($bms['bookmarks']); -        $this->assertEquals('1', $bm['bStatus']); -    }//end testDefaultPrivacyImportNetscape - - -    /** -     * Test that the default privacy setting is used when bookmarks -     * are imported from an XML bookmarks file using import.php. -     */ -    public function testDefaultPrivacyImport() -    { -        $this->setUnittestConfig( -            array('defaults' => array('privacy' => 2)) -        ); -        list($req, $uId) = $this->getLoggedInRequest(); -        $req->setMethod(HTTP_Request2::METHOD_POST); -        $req->setUrl($GLOBALS['unittestUrl'] . 'import.php' . '?unittestMode=1'); -        $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_deliciousbookmarks.xml'); -        $res = $req->send(); -        $this->assertEquals(302, $res->getStatus(), 'Bookmark import failed'); - -        $this->us->setCurrentUserId($uId); -        $bms = $this->bs->getBookmarks(0, null, $uId); -        $this->assertEquals(3, count($bms['bookmarks'])); -        $bm = reset($bms['bookmarks']); -        $this->assertEquals('2', $bm['bStatus']); -    }//end testDefaultPrivacyImport - - -    /** -     * 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 testDefaultPrivacyBookmarksGet - - -    /** -     * 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 - -  }  ?> diff --git a/tests/www/bookmarksTest.php b/tests/www/bookmarksTest.php new file mode 100755 index 0000000..df360cc --- /dev/null +++ b/tests/www/bookmarksTest.php @@ -0,0 +1,80 @@ +<?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 + +}//end class www_bookmarksTest +?> diff --git a/tests/www/editTest.php b/tests/www/editTest.php new file mode 100755 index 0000000..1e0fbd5 --- /dev/null +++ b/tests/www/editTest.php @@ -0,0 +1,48 @@ +<?php +require_once dirname(__FILE__) . '/../prepare.php'; +require_once 'HTTP/Request2.php'; + +class www_editTest extends TestBaseApi +{ +    protected $urlPart = 'api/posts/add'; + +    /** +     * Test that the default privacy setting is used when an existing +     * bookmark is updated with edit.php. +     */ +    public function testDefaultPrivacyEdit() +    { +        $this->setUnittestConfig( +            array('defaults' => array('privacy' => 2)) +        ); + +        list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1'); +        $cookies = $req->getCookieJar(); +        $req->setMethod(HTTP_Request2::METHOD_POST); +        $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_edit'); +        $req->addPostParameter('description', 'Test bookmark 2 for default privacy.'); +        $req->addPostParameter('status', '0'); +        $res = $req->send(); +        $this->assertEquals( +            200, $res->getStatus(), +            'Adding bookmark failed: ' . $res->getBody()); +        $bms = $this->bs->getBookmarks(0, null, $uId); +        $bm  = reset($bms['bookmarks']); +        $bmId = $bm['bId']; + +        $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1'; +        $req2 = new HTTP_Request2($reqUrl, HTTP_Request2::METHOD_POST); +        $req2->setCookieJar($cookies); +        $req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit'); +        $req2->addPostParameter('title', 'Test bookmark 2 for default privacy.'); +        $req2->addPostParameter('submitted', '1'); +        $res = $req2->send(); + +        $this->assertEquals(302, $res->getStatus(), 'Editing bookmark failed'); + +        $bm = $this->bs->getBookmark($bmId); +        $this->assertEquals('2', $bm['bStatus']); +    }//end testDefaultPrivacyEdit + +}//end class www_editTest +?> diff --git a/tests/www/importNetscapeTest.php b/tests/www/importNetscapeTest.php new file mode 100755 index 0000000..9d4cacd --- /dev/null +++ b/tests/www/importNetscapeTest.php @@ -0,0 +1,33 @@ +<?php +require_once dirname(__FILE__) . '/../prepare.php'; +require_once 'HTTP/Request2.php'; + +class www_importNetscapeTest extends TestBaseApi +{ +    protected $urlPart = 'importNetscape.php'; + +    /** +     * Test that the default privacy setting is used when bookmarks +     * are imported from an HTML bookmarks file using importNetscape.php. +     */ +    public function testDefaultPrivacyImportNetscape() +    { +        $this->setUnittestConfig( +            array('defaults' => array('privacy' => 1)) +        ); +        list($req, $uId) = $this->getLoggedInRequest(); +        $req->setMethod(HTTP_Request2::METHOD_POST); +        $req->setUrl($GLOBALS['unittestUrl'] . 'importNetscape.php' . '?unittestMode=1'); +        $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_netscapebookmarks.html'); +        $res = $req->send(); +        $this->assertEquals(200, $res->getStatus(), 'Bookmark import failed'); + +        $this->us->setCurrentUserId($uId); +        $bms = $this->bs->getBookmarks(0, null, $uId); +        $this->assertEquals(3, count($bms['bookmarks'])); +        $bm = reset($bms['bookmarks']); +        $this->assertEquals('1', $bm['bStatus']); +    }//end testDefaultPrivacyImportNetscape + +}//end class www_importNetscapeTest +?> diff --git a/tests/www/importTest.php b/tests/www/importTest.php new file mode 100755 index 0000000..895a320 --- /dev/null +++ b/tests/www/importTest.php @@ -0,0 +1,33 @@ +<?php +require_once dirname(__FILE__) . '/../prepare.php'; +require_once 'HTTP/Request2.php'; + +class www_importTest extends TestBaseApi +{ +    protected $urlPart = 'import.php'; + +    /** +     * Test that the default privacy setting is used when bookmarks +     * are imported from an XML bookmarks file using import.php. +     */ +    public function testDefaultPrivacyImport() +    { +        $this->setUnittestConfig( +            array('defaults' => array('privacy' => 2)) +        ); +        list($req, $uId) = $this->getLoggedInRequest(); +        $req->setMethod(HTTP_Request2::METHOD_POST); +        $req->setUrl($GLOBALS['unittestUrl'] . 'import.php' . '?unittestMode=1'); +        $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_deliciousbookmarks.xml'); +        $res = $req->send(); +        $this->assertEquals(302, $res->getStatus(), 'Bookmark import failed'); + +        $this->us->setCurrentUserId($uId); +        $bms = $this->bs->getBookmarks(0, null, $uId); +        $this->assertEquals(3, count($bms['bookmarks'])); +        $bm = reset($bms['bookmarks']); +        $this->assertEquals('2', $bm['bStatus']); +    }//end testDefaultPrivacyImport + +}//end class www_importTest +?> | 
