]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
first working unittest for ajax/getcontacttags with login!
authorChristian Weiske <cweiske@cweiske.de>
Sat, 26 Mar 2011 09:00:18 +0000 (10:00 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Sat, 26 Mar 2011 09:00:18 +0000 (10:00 +0100)
tests/TestBaseApi.php
tests/ajax/GetContactTagsTest.php

index b7c19217b372555c3e7142523bd889a059bcfc13..2af228a66caae5b4cbff72eb01de51d1c4eb76a8 100644 (file)
@@ -131,7 +131,6 @@ class TestBaseApi extends TestBase
      */
     protected function getLoggedInRequest($urlSuffix = null, $auth = true)
     {
-        $req = $this->getRequest($urlSuffix);
         if (is_array($auth)) {
             list($username, $password) = $auth;
         } else {
@@ -140,8 +139,22 @@ class TestBaseApi extends TestBase
         }
         $uid = $this->addUser($username, $password);
 
-        //FIXME: login via the login form, check if it worked
-        //FIXME: prepare new request with cookie
+        $req = new HTTP_Request2(
+            $GLOBALS['unittestUrl'] . '/login.php',
+            HTTP_Request2::METHOD_POST
+        );
+        $cookies = $req->setCookieJar()->getCookieJar();
+        $req->addPostParameter('username', $username);
+        $req->addPostParameter('password', $password);
+        $req->addPostParameter('submitted', 'Log In');
+        $res = $req->send();
+
+        //after login, we normally get redirected
+        $this->assertEquals(302, $res->getStatus(), 'Login failure');
+
+        $req = $this->getRequest($urlSuffix);
+        $req->setCookieJar($cookies);
+
         return array($req, $uid);
     }
 
index 7f46888c794811bc5de4b77bab717812a5c8c699..757dce90f4c2810a1bfd07125c1aa3157efd853a 100644 (file)
@@ -47,13 +47,17 @@ class ajax_GetContactTagsTest extends TestBaseApi
     }
 
 
-    public function testUserLoggedIn()
+    public function testUserLoggedInWatchlist()
     {
-        list($req, $uId) = $this->getAuthRequest();
-        $this->addBookmark($uId, null, 0, array('public'));
-        $this->addBookmark($uId, null, 1, array('shared'));
-        $this->addBookmark($uId, null, 2, array('private'));
-        
+        list($req, $uId) = $this->getLoggedInRequest();
+        $this->addBookmark($uId, null, 0, array('public', 'public2'));
+
+        $user2 = $this->addUser();
+        $this->us->setCurrentUserId($uId);
+        $this->us->setWatchStatus($user2);
+        //uId watches user2 now
+        $this->addBookmark($user2, null, 0, array('user2tag'));
+
         $res = $req->send();
         $this->assertEquals(200, $res->getStatus());
         $this->assertEquals(
@@ -64,8 +68,8 @@ class ajax_GetContactTagsTest extends TestBaseApi
         $this->assertInternalType('array', $data);
         $this->assertEquals(3, count($data));
         $this->assertContains('public', $data);
-        $this->assertContains('shared', $data);
-        $this->assertContains('private', $data);
+        $this->assertContains('public2', $data);
+        $this->assertContains('user2tag', $data);
     }
 }