]> source.dussan.org Git - nextcloud-server.git/commitdiff
Updated method names and added a few more tests.
authorThomas Tanghus <thomas@tanghus.net>
Thu, 19 Sep 2013 09:27:13 +0000 (11:27 +0200)
committerThomas Tanghus <thomas@tanghus.net>
Mon, 23 Sep 2013 21:39:36 +0000 (23:39 +0200)
lib/public/itags.php
lib/tags.php
tests/lib/tags.php

index 047d4f5f40bf21bbf95e1664fb023f880b6413df..126434005486e1be7b1620ebd9dd724bb73da5b3 100644 (file)
@@ -65,7 +65,7 @@ interface ITags {
        *
        * @returns array
        */
-       public function tags();
+       public function getTags();
 
        /**
        * Get the a list if items tagged with $tag.
@@ -75,7 +75,7 @@ interface ITags {
        * @param string|integer $tag Tag id or name.
        * @return array An array of object ids or false on error.
        */
-       public function idsForTag($tag);
+       public function getIdsForTag($tag);
 
        /**
        * Checks whether a tag is already saved.
@@ -111,7 +111,7 @@ interface ITags {
        * @param int|null $id int Optional object id to add to this|these tag(s)
        * @return bool Returns false on error.
        */
-       public function addMulti($names, $sync=false, $id = null);
+       public function addMultiple($names, $sync=false, $id = null);
 
        /**
        * Delete tag/object relations from the db
index 3320d9ea1a84dadfb5d83079234963c324f7f611..2eaa603c1a3783520de4aa02964533743b10d180 100644 (file)
@@ -96,7 +96,7 @@ class Tags implements \OCP\ITags {
                }
 
                if(count($defaultTags) > 0 && count($this->tags) === 0) {
-                       $this->addMulti($defaultTags, true);
+                       $this->addMultiple($defaultTags, true);
                }
                \OCP\Util::writeLog('core', __METHOD__.', tags: ' . print_r($this->tags, true),
                        \OCP\Util::DEBUG);
@@ -119,7 +119,7 @@ class Tags implements \OCP\ITags {
                                \OCP\Util::writeLog('core', __METHOD__. ', DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
                                return false;
                        }
-                       return ($result->numRows() === 0);
+                       return ((int)$result->numRows() === 0);
                } catch(\Exception $e) {
                        \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
                                \OCP\Util::ERROR);
@@ -138,7 +138,7 @@ class Tags implements \OCP\ITags {
        *
        * @return array
        */
-       public function tags() {
+       public function getTags() {
                if(!count($this->tags)) {
                        return array();
                }
@@ -167,7 +167,7 @@ class Tags implements \OCP\ITags {
        * @param string|integer $tag Tag id or name.
        * @return array An array of object ids or false on error.
        */
-       public function idsForTag($tag) {
+       public function getIdsForTag($tag) {
                $result = null;
                if(is_numeric($tag)) {
                        $tagId = $tag;
@@ -293,7 +293,7 @@ class Tags implements \OCP\ITags {
        * @param int|null $id int Optional object id to add to this|these tag(s)
        * @return bool Returns false on error.
        */
-       public function addMulti($names, $sync=false, $id = null) {
+       public function addMultiple($names, $sync=false, $id = null) {
                if(!is_array($names)) {
                        $names = array($names);
                }
@@ -456,7 +456,7 @@ class Tags implements \OCP\ITags {
        */
        public function getFavorites() {
                try {
-                       return $this->idsForTag(self::TAG_FAVORITE);
+                       return $this->getIdsForTag(self::TAG_FAVORITE);
                } catch(\Exception $e) {
                        \OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(),
                                \OCP\Util::ERROR);
index 06baebc0af799f70b53dcc7e9b7b6131d4d95e55..16a03f5645ad43f8209b0cfe155a782f5c7ffb4f 100644 (file)
@@ -48,7 +48,7 @@ class Test_Tags extends PHPUnit_Framework_TestCase {
                $tagMgr = new OC\Tags($this->user);
                $tagMgr->loadTagsFor($this->objectType, $defaultTags);
 
-               $this->assertEquals(4, count($tagMgr->tags()));
+               $this->assertEquals(4, count($tagMgr->getTags()));
        }
 
        public function testAddTags() {
@@ -65,7 +65,37 @@ class Test_Tags extends PHPUnit_Framework_TestCase {
                $this->assertFalse($tagMgr->add('Family'));
                $this->assertFalse($tagMgr->add('fAMILY'));
 
-               $this->assertEquals(4, count($tagMgr->tags()));
+               $this->assertEquals(4, count($tagMgr->getTags()));
+       }
+
+       public function testAddMultiple() {
+               $tags = array('Friends', 'Family', 'Work', 'Other');
+
+               $tagMgr = new OC\Tags($this->user);
+               $tagMgr->loadTagsFor($this->objectType);
+
+               foreach($tags as $tag) {
+                       $this->assertFalse($tagMgr->hasTag($tag));
+               }
+
+               $result = $tagMgr->addMultiple($tags);
+               $this->assertTrue((bool)$result);
+
+               foreach($tags as $tag) {
+                       $this->assertTrue($tagMgr->hasTag($tag));
+               }
+
+               $this->assertEquals(4, count($tagMgr->getTags()));
+       }
+
+       public function testIsEmpty() {
+               $tagMgr = new OC\Tags($this->user);
+               $tagMgr->loadTagsFor($this->objectType);
+
+               $this->assertEquals(0, count($tagMgr->getTags()));
+               $this->assertTrue($tagMgr->isEmpty());
+               $tagMgr->add('Tag');
+               $this->assertFalse($tagMgr->isEmpty());
        }
 
        public function testdeleteTags() {
@@ -73,13 +103,13 @@ class Test_Tags extends PHPUnit_Framework_TestCase {
                $tagMgr = new OC\Tags($this->user);
                $tagMgr->loadTagsFor($this->objectType, $defaultTags);
 
-               $this->assertEquals(4, count($tagMgr->tags()));
+               $this->assertEquals(4, count($tagMgr->getTags()));
 
                $tagMgr->delete('family');
-               $this->assertEquals(3, count($tagMgr->tags()));
+               $this->assertEquals(3, count($tagMgr->getTags()));
 
                $tagMgr->delete(array('Friends', 'Work', 'Other'));
-               $this->assertEquals(0, count($tagMgr->tags()));
+               $this->assertEquals(0, count($tagMgr->getTags()));
 
        }
 
@@ -105,8 +135,8 @@ class Test_Tags extends PHPUnit_Framework_TestCase {
                        $tagMgr->tagAs($id, 'Family');
                }
 
-               $this->assertEquals(1, count($tagMgr->tags()));
-               $this->assertEquals(9, count($tagMgr->idsForTag('Family')));
+               $this->assertEquals(1, count($tagMgr->getTags()));
+               $this->assertEquals(9, count($tagMgr->getIdsForTag('Family')));
        }
 
        /**
@@ -121,13 +151,20 @@ class Test_Tags extends PHPUnit_Framework_TestCase {
                $tagMgr->loadTagsFor($this->objectType);
 
                foreach($objIds as $id) {
-                       $this->assertTrue(in_array($id, $tagMgr->idsForTag('Family')));
+                       $this->assertTrue(in_array($id, $tagMgr->getIdsForTag('Family')));
                        $tagMgr->unTag($id, 'Family');
-                       $this->assertFalse(in_array($id, $tagMgr->idsForTag('Family')));
+                       $this->assertFalse(in_array($id, $tagMgr->getIdsForTag('Family')));
                }
 
-               $this->assertEquals(1, count($tagMgr->tags()));
-               $this->assertEquals(0, count($tagMgr->idsForTag('Family')));
+               $this->assertEquals(1, count($tagMgr->getTags()));
+               $this->assertEquals(0, count($tagMgr->getIdsForTag('Family')));
+       }
+
+       public function testFavorite() {
+               $tagMgr = new OC\Tags($this->user);
+               $tagMgr->loadTagsFor($this->objectType);
+               $this->assertTrue($tagMgr->addToFavorites(1));
+               $this->assertTrue($tagMgr->removeFromFavorites(1));
        }
 
 }