]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
fix unfreed sql result and add deleteAll() for users
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Wed, 28 Oct 2009 22:25:27 +0000 (22:25 +0000)
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>
Wed, 28 Oct 2009 22:25:27 +0000 (22:25 +0000)
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@457 b3834d28-1941-0410-a4f8-b48e95affb8f

src/SemanticScuttle/Service/User.php
tests/UserTest.php

index 8b7227430bd277a6a0b97f18dd8778bdf367f3c4..73b71d67e03b5520c49d60ee19457cd32ac3c8b3 100644 (file)
@@ -368,13 +368,15 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
             return false;
         }
 
-        if ($row =& $this->db->sql_fetchrow($dbresult)) {
+        $row = $this->db->sql_fetchrow($dbresult);
+        $this->db->sql_freeresult($dbresult);
+
+        if ($row) {
             $id = $_SESSION[$this->getSessionKey()] = $row[$this->getFieldName('primary')];
             if ($remember) {
                 $cookie = $id .':'. md5($username.$password);
                 setcookie($this->cookiekey, $cookie, time() + $this->cookietime, '/');
             }
-            $this->db->sql_freeresult($dbresult);
             return true;
         } else {
             return false;
@@ -593,6 +595,21 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
     }
 
 
+
+    /**
+     * Delete all bookmarks.
+     * Mainly used in unit tests.
+     *
+     * @return void
+     */
+    public function deleteAll()
+    {
+        $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';
+        $this->db->sql_query($query);
+    }
+
+
+
     function sanitisePassword($password) {
         return sha1(trim($password));
     }
index 5c905a006d619daa5580901d38e3aa7ad4374bf8..513011badd7d1b36a8d5d693c91634306f9c5a27 100644 (file)
@@ -103,6 +103,21 @@ class UserTest extends TestBase
         $this->assertEquals($uid2, $user['uId']);
     }
 
+
+
+    /**
+     * Test login() function with invalid creditentials
+     *
+     * @return void
+     */
+    public function testLoginInvalid()
+    {
+        $this->us->deleteAll();
+        $this->assertFalse(
+            $this->us->login('doesnot', 'exist', false)
+        );
+    }
+
 }