From 84e603aa91a303a1419962ff3ff6086710a7b1a9 Mon Sep 17 00:00:00 2001 From: Mark Pemberton Date: Sat, 4 Jun 2011 00:29:04 -0400 Subject: Reverted changes of date() to gdate(), added tests to confirm existence of private RSS feed, and finalized changes to the user session usage with rss.php --- tests/TestBaseApi.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'tests/TestBaseApi.php') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 20574f3..d8917aa 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -164,15 +164,16 @@ class TestBaseApi extends TestBase * * Useful for testing HTML pages or ajax URLs. * - * @param string $urlSuffix Suffix for the URL - * @param mixed $auth If user authentication is needed (true/false) - * or array with username and password + * @param string $urlSuffix Suffix for the URL + * @param mixed $auth If user authentication is needed (true/false) + * or array with username and password + * @param boolean $privateKey True if to add user with private key * * @return array(HTTP_Request2, integer) HTTP request object and user id * * @uses getRequest() */ - protected function getLoggedInRequest($urlSuffix = null, $auth = true) + protected function getLoggedInRequest($urlSuffix = null, $auth = true, $privateKey = false) { if (is_array($auth)) { list($username, $password) = $auth; @@ -180,7 +181,13 @@ class TestBaseApi extends TestBase $username = 'testuser'; $password = 'testpassword'; } - $uid = $this->addUser($username, $password); + //include privatekey if requested + if ($privateKey) { + $pKey = $this->us->getNewPrivateKey(); + } else { + $pKey = null; + } + $uid = $this->addUser($username, $password, $pKey); $req = new HTTP_Request2( $GLOBALS['unittestUrl'] . '/login.php?unittestMode=1', @@ -234,7 +241,7 @@ class TestBaseApi extends TestBase */ protected function setUnittestConfig($arConfig) { - $str = '<' . "?php\r\n"; + $str = '<' . "?php\n"; foreach ($arConfig as $name => $value) { $str .= '$' . $name . ' = ' . var_export($value, true) . ";\n"; @@ -253,4 +260,4 @@ class TestBaseApi extends TestBase ); } } -?> \ No newline at end of file +?> -- cgit v1.2.3-54-g00ecf From 39dfe3f1acf620eccb668d4f8d7451c1cef96ba5 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 8 Jun 2011 07:00:24 +0200 Subject: CS --- tests/TestBaseApi.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tests/TestBaseApi.php') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index d8917aa..7568147 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -164,17 +164,18 @@ class TestBaseApi extends TestBase * * Useful for testing HTML pages or ajax URLs. * - * @param string $urlSuffix Suffix for the URL - * @param mixed $auth If user authentication is needed (true/false) - * or array with username and password + * @param string $urlSuffix Suffix for the URL + * @param mixed $auth If user authentication is needed (true/false) + * or array with username and password * @param boolean $privateKey True if to add user with private key * * @return array(HTTP_Request2, integer) HTTP request object and user id * * @uses getRequest() */ - protected function getLoggedInRequest($urlSuffix = null, $auth = true, $privateKey = false) - { + protected function getLoggedInRequest( + $urlSuffix = null, $auth = true, $privateKey = false + ) { if (is_array($auth)) { list($username, $password) = $auth; } else { -- cgit v1.2.3-54-g00ecf From 5009535d3438ecc338dacc8120fa143fd28c5628 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 8 Jun 2011 07:21:33 +0200 Subject: docblocks for url and urlPart variables --- tests/TestBaseApi.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/TestBaseApi.php') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 7568147..50a2413 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -24,7 +24,20 @@ require_once 'HTTP/Request2.php'; */ class TestBaseApi extends TestBase { + /** + * Created from the configured host and the $urlPart. + * Should be used as base for all generated URLs + * + * @var string + */ protected $url; + + /** + * Part of the URL behind the configured host. + * Needs to be overwritten in each derived test case class. + * + * @var string + */ protected $urlPart = null; /** -- cgit v1.2.3-54-g00ecf From 045d139d64ada2c510ed05e177ba6f484ad68496 Mon Sep 17 00:00:00 2001 From: Mark Pemberton Date: Wed, 15 Jun 2011 00:58:29 -0400 Subject: Added RSS Feed tests --- tests/TestBaseApi.php | 7 ++-- tests/www/rssTest.php | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 tests/www/rssTest.php (limited to 'tests/TestBaseApi.php') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 50a2413..f860d10 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -187,7 +187,8 @@ class TestBaseApi extends TestBase * @uses getRequest() */ protected function getLoggedInRequest( - $urlSuffix = null, $auth = true, $privateKey = false + $urlSuffix = null, $auth = true, $privateKey = false, + $setCookie = true ) { if (is_array($auth)) { list($username, $password) = $auth; @@ -217,7 +218,9 @@ class TestBaseApi extends TestBase $this->assertEquals(302, $res->getStatus(), 'Login failure'); $req = $this->getRequest($urlSuffix); - $req->setCookieJar($cookies); + if ($setCookie) { + $req->setCookieJar($cookies); + } return array($req, $uid); } diff --git a/tests/www/rssTest.php b/tests/www/rssTest.php new file mode 100644 index 0000000..1822fc9 --- /dev/null +++ b/tests/www/rssTest.php @@ -0,0 +1,94 @@ +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 +?> -- cgit v1.2.3-54-g00ecf From 6ec3b102aa896df8ddcf6323e0635dc42ac25f98 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 27 Jun 2011 19:39:38 +0200 Subject: make the private tests really test something --- src/SemanticScuttle/Model/Bookmark.php | 17 ++++++++ tests/TestBase.php | 8 ++-- tests/TestBaseApi.php | 15 ++----- tests/www/rssTest.php | 73 +++++++++------------------------- 4 files changed, 42 insertions(+), 71 deletions(-) (limited to 'tests/TestBaseApi.php') diff --git a/src/SemanticScuttle/Model/Bookmark.php b/src/SemanticScuttle/Model/Bookmark.php index 8bda0b3..1330642 100644 --- a/src/SemanticScuttle/Model/Bookmark.php +++ b/src/SemanticScuttle/Model/Bookmark.php @@ -23,6 +23,23 @@ */ class SemanticScuttle_Model_Bookmark { + /** + * Status "public" / visible for all + */ + const SPUBLIC = 0; + + /** + * Status "shared" / visible for people on your watchlist + */ + const SWATCHLIST = 1; + + /** + * Status "private" / visible for yourself only + */ + const SPRIVATE = 2; + + + /** * Checks if the given URL is valid and may be used with this * SemanticScuttle installation. diff --git a/tests/TestBase.php b/tests/TestBase.php index 5ea656c..2180d2d 100644 --- a/tests/TestBase.php +++ b/tests/TestBase.php @@ -76,8 +76,8 @@ class TestBase extends PHPUnit_Framework_TestCase /** * Creates a new user in the database. * - * @param string $username Username - * @param string $password Password + * @param string $username Username, may be null + * @param string $password Password, may be null * @param mixed $privateKey String private key or boolean true to generate one * * @return integer ID of user @@ -95,8 +95,8 @@ class TestBase extends PHPUnit_Framework_TestCase /** * Creates a new user in the database and returns id, username and password. * - * @param string $username Username - * @param string $password Password + * @param string $username Username, may be null + * @param string $password Password, may be null * @param mixed $privateKey String private key or boolean true to generate one * * @return array ID of user, Name of user, password of user, privatekey diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index f860d10..1052ae7 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -187,8 +187,7 @@ class TestBaseApi extends TestBase * @uses getRequest() */ protected function getLoggedInRequest( - $urlSuffix = null, $auth = true, $privateKey = false, - $setCookie = true + $urlSuffix = null, $auth = true, $privateKey = null ) { if (is_array($auth)) { list($username, $password) = $auth; @@ -196,13 +195,7 @@ class TestBaseApi extends TestBase $username = 'testuser'; $password = 'testpassword'; } - //include privatekey if requested - if ($privateKey) { - $pKey = $this->us->getNewPrivateKey(); - } else { - $pKey = null; - } - $uid = $this->addUser($username, $password, $pKey); + $uid = $this->addUser($username, $password, $privateKey); $req = new HTTP_Request2( $GLOBALS['unittestUrl'] . '/login.php?unittestMode=1', @@ -218,9 +211,7 @@ class TestBaseApi extends TestBase $this->assertEquals(302, $res->getStatus(), 'Login failure'); $req = $this->getRequest($urlSuffix); - if ($setCookie) { - $req->setCookieJar($cookies); - } + $req->setCookieJar($cookies); return array($req, $uid); } diff --git a/tests/www/rssTest.php b/tests/www/rssTest.php index 9d4e41b..fc49264 100644 --- a/tests/www/rssTest.php +++ b/tests/www/rssTest.php @@ -7,44 +7,23 @@ 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. + * A private bookmark should not show up in an rss feed if the + * user is not logged in nor passes the private key */ - public function testNoRSSPrivateKeyEnabled() + public function testPrivateNotLoggedIn() { - $this->setUnittestConfig( - array('defaults' => array('privacy' => 2)) + list($uId, $username) = $this->addUserData(); + $this->addBookmark( + $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE ); - /* 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(); + $req = $this->getRequest('/' . $username); + $response_body = $req->send()->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); + $this->assertEquals(0, count($items), 'I see a private bookmark'); }//end testNoRSSPrivateKeyEnabled @@ -54,38 +33,22 @@ class www_rssTest extends TestBaseApi */ public function testRSSPrivateKeyEnabled() { - $this->setUnittestConfig( - array('defaults' => array('privacy' => 2)) + list($uId, $username, $password, $privateKey) = $this->addUserData( + null, null, true ); - - /* 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 + $this->addBookmark( + $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE, + null, 'private bookmark' ); - /* 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(); + $req = $this->getRequest('/' . $username . '?privatekey=' . $privateKey); + $response_body = $req->send()->getBody(); $rss = simplexml_load_string($response_body); $items = $rss->channel->item; - $this->assertEquals(2, count($items), 'Incorrect Number of RSS Items'); + $this->assertEquals(1, count($items), 'I miss the private bookmark'); + $this->assertEquals('private bookmark', (string)$items[0]->title); }//end testRSSPrivateKeyEnabled -- cgit v1.2.3-54-g00ecf