]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
first unit tests for Bookmark2Tag::getPopularTags
authorChristian Weiske <cweiske@cweiske.de>
Wed, 23 Mar 2011 07:23:36 +0000 (08:23 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 23 Mar 2011 07:23:36 +0000 (08:23 +0100)
tests/Bookmark2TagTest.php
tests/TestBase.php

index 1823c603fa7f19edecb1f2331c07770ffa302315..6932a10ee64c36a7c29167f894fe340af05f5cdf 100644 (file)
@@ -204,6 +204,88 @@ class Bookmark2TagTest extends TestBase
             }
         }
     }
+
+
+    /**
+     * Create a bookmark
+     *
+     * @param integer $user    User ID the bookmark shall belong
+     * @param array   $tags    Array of tags to attach. If "null" is given,
+     *                         it will automatically be "unittest"
+     * @param string  $date    strtotime-compatible string
+     * @param string  $title   Bookmark title
+     *
+     * @return integer ID of bookmark
+     */
+    protected function addTagBookmark($user, $tags, $date = null, $title = null)
+    {
+        return $this->addBookmark(
+            $user, null, 0, $tags, $title, $date
+        );
+    }
+
+
+
+    /**
+     * Fetch the most popular tags in descending order
+     */
+    public function testGetPopularTagsOrder()
+    {
+        $user = $this->addUser();
+        $this->addTagBookmark($user, array('one', 'two'));
+        $this->addTagBookmark($user, array('one', 'three'));
+        $this->addTagBookmark($user, array('one', 'two'));
+
+        $arTags = $this->b2ts->getPopularTags();
+        $this->assertInternalType('array', $arTags);
+        $this->assertEquals(3, count($arTags));
+
+        $this->assertInternalType('array', $arTags[0]);
+
+        $this->assertEquals(
+            array(
+                array('tag' => 'one', 'bCount' => '3'),
+                array('tag' => 'two', 'bCount' => '2'),
+                array('tag' => 'three', 'bCount' => '1')
+            ),
+            $arTags
+        );
+    }
+
+
+
+    public function testGetPopularTagsLimit()
+    {
+        $user = $this->addUser();
+        $this->addTagBookmark($user, array('one', 'two'));
+        $this->addTagBookmark($user, array('one', 'three'));
+        $this->addTagBookmark($user, array('one', 'two'));
+
+        $arTags = $this->b2ts->getPopularTags();
+        $this->assertInternalType('array', $arTags);
+        $this->assertEquals(3, count($arTags));
+
+        $arTags = $this->b2ts->getPopularTags(null, 2);
+        $this->assertInternalType('array', $arTags);
+        $this->assertEquals(2, count($arTags));
+        $this->assertEquals(
+            array(
+                array('tag' => 'one', 'bCount' => '3'),
+                array('tag' => 'two', 'bCount' => '2'),
+            ),
+            $arTags
+        );
+
+        $arTags = $this->b2ts->getPopularTags(null, 1);
+        $this->assertInternalType('array', $arTags);
+        $this->assertEquals(1, count($arTags));
+        $this->assertEquals(
+            array(
+                array('tag' => 'one', 'bCount' => '3'),
+            ),
+            $arTags
+        );
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') {
index 6006f4ed86dc01a14d2b2eb093dfe0933e311061..3e2e213bc127e098bb1b7294484f7229daee139c 100644 (file)
@@ -31,6 +31,7 @@ class TestBase extends PHPUnit_Framework_TestCase
      * @param array   $tags    Array of tags to attach. If "null" is given,
      *                         it will automatically be "unittest"
      * @param string  $title   Bookmark title
+     * @param string  $date    strtotime-compatible string
      *
      * @return integer ID of bookmark
      *
@@ -38,7 +39,7 @@ class TestBase extends PHPUnit_Framework_TestCase
      */
     protected function addBookmark(
         $user = null, $address = null, $status = 0,
-        $tags = null, $title = null
+        $tags = null, $title = null, $date = null
     ) {
         if ($user === null) {
             $user = $this->addUser();
@@ -64,7 +65,7 @@ class TestBase extends PHPUnit_Framework_TestCase
             null,
             $status,
             $tags,
-            null, null, false, false,
+            null, $date, false, false,
             $user
         );
         return $bid;