summaryrefslogtreecommitdiff
path: root/tests/Bookmark2TagTest.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2011-03-23 08:23:36 +0100
committerChristian Weiske <cweiske@cweiske.de>2011-03-23 08:23:36 +0100
commitd4ccb1d3d3abf433200b39e8a5566a71bb1e6c2b (patch)
tree0f2929238c43a86ce261604d6848c598cbdc3fc5 /tests/Bookmark2TagTest.php
parentf67250a720c96031309f7c9ed129bb30e4972242 (diff)
downloadsemanticscuttle-d4ccb1d3d3abf433200b39e8a5566a71bb1e6c2b.tar.gz
semanticscuttle-d4ccb1d3d3abf433200b39e8a5566a71bb1e6c2b.tar.bz2
first unit tests for Bookmark2Tag::getPopularTags
Diffstat (limited to 'tests/Bookmark2TagTest.php')
-rw-r--r--tests/Bookmark2TagTest.php82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php
index 1823c60..6932a10 100644
--- a/tests/Bookmark2TagTest.php
+++ b/tests/Bookmark2TagTest.php
@@ -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') {