diff options
author | Christian Weiske <cweiske@cweiske.de> | 2011-05-13 06:57:54 +0200 |
---|---|---|
committer | Christian Weiske <cweiske@cweiske.de> | 2011-05-13 06:57:54 +0200 |
commit | 803b83fb7d051593066b5224a59fbf3ec6efc824 (patch) | |
tree | 173c97393f9e211b05f8c73793c180a1b88799b0 /tests | |
parent | fbfbd8d5cae579058b5d31b97c062cefd9bb36b6 (diff) | |
parent | 88d7b9631b444cef28115fb8e0bae736b45e557e (diff) | |
download | semanticscuttle-803b83fb7d051593066b5224a59fbf3ec6efc824.tar.gz semanticscuttle-803b83fb7d051593066b5224a59fbf3ec6efc824.tar.bz2 |
Merge branch 'master' into ssl-client-certs
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Api/PostsAddTest.php | 48 | ||||
-rw-r--r-- | tests/TestBaseApi.php | 24 | ||||
-rwxr-xr-x | tests/data/BookmarkTest_deliciousbookmarks.xml | 7 | ||||
-rwxr-xr-x | tests/data/BookmarkTest_netscapebookmarks.html | 27 | ||||
-rw-r--r-- | tests/prepare.php | 2 | ||||
-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 |
9 files changed, 286 insertions, 16 deletions
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index 53aa8e7..02e2b38 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -406,5 +406,51 @@ TXT; $this->assertEquals(1, $data['total']); $this->assertEquals($title2, $data['bookmarks'][0]['bTitle']); } + + + /** + * Test that a default privacy setting of 2 (Private) is used in adding + * a bookmark. + */ + public function testDefaultPrivacyPrivate() + { + $this->setUnittestConfig( + array('defaults' => array('privacy' => 2)) + ); + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_addprivate'); + $req->addPostParameter('description', 'Test bookmark 1 for default privacy.'); + $req->send(); + $this->us->setCurrentUserId($uId); + $bms = $this->bs->getBookmarks(0, null, $uId); + $this->assertEquals(1, count($bms['bookmarks'])); + $bm = reset($bms['bookmarks']); + $this->assertEquals('2', $bm['bStatus']); + }//end testDefaultPrivacyPrivate + + + /** + * Test that a default privacy setting of 0 (Public) is used in adding + * a bookmark. + */ + public function testDefaultPrivacyPublic() + { + $this->setUnittestConfig( + array('defaults' => array('privacy' => 0)) + ); + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_addpublic'); + $req->addPostParameter('description', 'Test bookmark 1 for default privacy.'); + $req->send(); + $this->us->setCurrentUserId($uId); + $bms = $this->bs->getBookmarks(0, null, $uId); + $this->assertEquals(1, count($bms['bookmarks'])); + $bm = reset($bms['bookmarks']); + $this->assertEquals('0', $bm['bStatus']); + }//end testDefaultPrivacyPublic + + } -?>
\ No newline at end of file +?> diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 036ab6b..2caa701 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -49,6 +49,11 @@ class TestBaseApi extends TestBase } $this->url = $GLOBALS['unittestUrl'] . $this->urlPart; + //clean up before test + if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) { + unlink($GLOBALS['datadir'] . '/config.unittest.php'); + } + $this->us = SemanticScuttle_Service_Factory::get('User'); $this->us->deleteAll(); $this->bs = SemanticScuttle_Service_Factory::get('Bookmark'); @@ -60,19 +65,7 @@ class TestBaseApi extends TestBase /** - * Clean up after test - */ - public function tearDown() - { - if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) { - unlink($GLOBALS['datadir'] . '/config.unittest.php'); - } - } - - - - /** - * Gets a HTTP request object. + * Creates and returns a HTTP GET request object. * Uses $this->url plus $urlSuffix as request URL. * * @param string $urlSuffix Suffix for the URL @@ -111,7 +104,7 @@ class TestBaseApi extends TestBase /** - * Creates a user and a HTTP request object and prepares + * Creates a user and a HTTP GET request object and prepares * the request object with authentication details, so that * the user is logged in. * @@ -125,6 +118,7 @@ class TestBaseApi extends TestBase * @return array(HTTP_Request2, integer) HTTP request object and user id * * @uses getRequest() + * @see getLoggedInRequest() */ protected function getAuthRequest($urlSuffix = null, $auth = true) { @@ -147,7 +141,7 @@ class TestBaseApi extends TestBase /** * Creates a user and a HTTP_Request2 object, does a normal login - * and prepares the cookies for the HTTP request object so that + * and prepares the cookies for the HTTP GET request object so that * the user is seen as logged in when requesting any HTML page. * * Useful for testing HTML pages or ajax URLs. diff --git a/tests/data/BookmarkTest_deliciousbookmarks.xml b/tests/data/BookmarkTest_deliciousbookmarks.xml new file mode 100755 index 0000000..87c67dc --- /dev/null +++ b/tests/data/BookmarkTest_deliciousbookmarks.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<posts user="dpuser" update="2011-03-24T21:09:22Z" tag="" total="3"> + <post href="http://www.example.org/testdefaultprivacyposts_import1/" hash="4f8533885bb5740b98b6415140a0c8c6" description="Test bookmark 1 for default privacy." tag="tag1, tag2" time="2011-03-24T21:09:11Z" extended="" meta="5c80704730a1bf1b9eb615d4ba7a59bd" /> + <post href="http://www.example.org/testdefaultprivacyposts_import2/" hash="21eee08d7945ac23c4cc2b6d08d02212" description="Test bookmark 2 for default privacy." tag="tag2, tag3" time="2011-03-24T21:08:33Z" extended="" meta="7514ab84f61ba1dd0413572f7c12348d" /> + <post href="http://www.example.org/testdefaultprivacyposts_import3/" hash="cd64042205a083f1cf1e009344daef84" description="Test bookmark 3 for default privacy." tag="tag1, tag2, tag3" time="2011-03-24T21:07:44Z" extended="" meta="9cb24fddbc011e9634595d2f5e1a6537" /> +</posts> +<!-- fe09.api.del.ac4.yahoo.net uncompressed/chunked Thur Mar 24 21:09:33 UTC 2011 --> diff --git a/tests/data/BookmarkTest_netscapebookmarks.html b/tests/data/BookmarkTest_netscapebookmarks.html new file mode 100755 index 0000000..305662c --- /dev/null +++ b/tests/data/BookmarkTest_netscapebookmarks.html @@ -0,0 +1,27 @@ +<!DOCTYPE NETSCAPE-Bookmark-file-1> + +<!-- This is an automatically generated file. + +It will be read and overwritten. + +Do Not Edit! --> + +<TITLE>Bookmarks for testuser</TITLE> + +<H1>Bookmarks for testuser</H1> + + +<DL><p> + + <DT><A HREF="http://www.example.org/testdefaultprivacyposts_importNetscape1" ADD_DATE="1301178264" LAST_VISIT="1301178075" LAST_MODIFIED="1301178075">Test bookmark 1 for default privacy.</A> + <DT><A HREF="http://www.example.org/testdefaultprivacyposts_importNetscape2" ADD_DATE="1301178264" LAST_VISIT="1301178075" LAST_MODIFIED="1301178075">Test bookmark 2 for default privacy.</A> + <DT><A HREF="http://www.example.org/testdefaultprivacyposts_importNetscape3" ADD_DATE="1301178264" LAST_VISIT="1301178075" LAST_MODIFIED="1301178075">Test bookmark 3 for default privacy.</A> + <DT><A HREF="http://www.thisbookmarkwillnotbeadded.com" ADD_DATE="1301178264" LAST_VISIT="1301178075" LAST_MODIFIED="1301178075">This bookmark will be ignored by importNetscape.php.</A> + +</DL><p> + +<DL><p> + + + +</DL><p> diff --git a/tests/prepare.php b/tests/prepare.php index 6afc284..c80306e 100644 --- a/tests/prepare.php +++ b/tests/prepare.php @@ -16,7 +16,9 @@ /** * Prepare the application for unit testing */ +//that's needed in constants.php $_SERVER['HTTP_HOST'] = 'http://localhost/'; + define('UNIT_TEST_MODE', true); if ('@data_dir@' == '@' . 'data_dir@') { 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 +?> |