]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
make the private tests really test something
authorChristian Weiske <cweiske@cweiske.de>
Mon, 27 Jun 2011 17:39:38 +0000 (19:39 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Mon, 27 Jun 2011 17:39:38 +0000 (19:39 +0200)
src/SemanticScuttle/Model/Bookmark.php
tests/TestBase.php
tests/TestBaseApi.php
tests/www/rssTest.php

index 8bda0b3050c6afc0d673459419d9958beb2e76df..133064270274bf3ec9cfcf3d88e21019bce98455 100644 (file)
  */
 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.
index 5ea656c52f8239b0843e056817917316e43376b6..2180d2d24129621bbbbcd0857fc2e38e38f2bc07 100644 (file)
@@ -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
index f860d106413538f4c5b06ca574ab0dccfe1d4332..1052ae7c4aa703eac101713ec96770ed274d5430 100644 (file)
@@ -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);
     }
index 9d4e41b749655645ae27a68ae8ce60510c00a8de..fc49264630c54d91b6978a20bb382fc1fa00b0b6 100644 (file)
@@ -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