From d4ccb1d3d3abf433200b39e8a5566a71bb1e6c2b Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 23 Mar 2011 08:23:36 +0100 Subject: first unit tests for Bookmark2Tag::getPopularTags --- tests/Bookmark2TagTest.php | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'tests/Bookmark2TagTest.php') 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') { -- cgit v1.2.3 From 7d31d9d1654bf5bdb1765397bb7bfd1a85c770a7 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 23 Mar 2011 08:33:49 +0100 Subject: test for the days parameter --- tests/Bookmark2TagTest.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/Bookmark2TagTest.php') diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index 6932a10..0fae2ea 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -286,6 +286,43 @@ class Bookmark2TagTest extends TestBase $arTags ); } + + + + public function testGetPopularTagsDays() + { + $user = $this->addUser(); + $this->addTagBookmark($user, array('one', 'two'), 'today'); + $this->addTagBookmark($user, array('one', 'three'), 'today'); + $this->addTagBookmark($user, array('one', 'two'), '-1 day 1 hour'); + $this->addTagBookmark($user, array('one', 'three'), '-3 days 1 hour'); + + $arTags = $this->b2ts->getPopularTags(null, 10, null, 1); + $this->assertInternalType('array', $arTags); + $this->assertEquals(3, count($arTags)); + $this->assertContains(array('tag' => 'one', 'bCount' => '2'), $arTags); + $this->assertContains(array('tag' => 'two', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'three', 'bCount' => '1'), $arTags); + + $arTags = $this->b2ts->getPopularTags(null, 10, null, 2); + $this->assertInternalType('array', $arTags); + $this->assertEquals(3, count($arTags)); + $this->assertEquals( + array( + array('tag' => 'one', 'bCount' => '3'), + array('tag' => 'two', 'bCount' => '2'), + array('tag' => 'three', 'bCount' => '1'), + ), + $arTags + ); + + $arTags = $this->b2ts->getPopularTags(null, 10, null, 5); + $this->assertInternalType('array', $arTags); + $this->assertEquals(3, count($arTags)); + $this->assertContains(array('tag' => 'one', 'bCount' => '4'), $arTags); + $this->assertContains(array('tag' => 'two', 'bCount' => '2'), $arTags); + $this->assertContains(array('tag' => 'three', 'bCount' => '2'), $arTags); + } } if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') { -- cgit v1.2.3 From 9f46e9f3ff2454318f50ead7790e3bf46bb868f2 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 23 Mar 2011 08:58:20 +0100 Subject: getPopularTags is fully covered now --- tests/Bookmark2TagTest.php | 124 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) (limited to 'tests/Bookmark2TagTest.php') diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index 0fae2ea..8ee3fc1 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -228,6 +228,8 @@ class Bookmark2TagTest extends TestBase /** * Fetch the most popular tags in descending order + * + * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags */ public function testGetPopularTagsOrder() { @@ -254,6 +256,9 @@ class Bookmark2TagTest extends TestBase + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags + */ public function testGetPopularTagsLimit() { $user = $this->addUser(); @@ -289,6 +294,9 @@ class Bookmark2TagTest extends TestBase + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags + */ public function testGetPopularTagsDays() { $user = $this->addUser(); @@ -323,6 +331,122 @@ class Bookmark2TagTest extends TestBase $this->assertContains(array('tag' => 'two', 'bCount' => '2'), $arTags); $this->assertContains(array('tag' => 'three', 'bCount' => '2'), $arTags); } + + + + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags + */ + public function testGetPopularTagsExcludesSystemTags() + { + $user = $this->addUser(); + $this->addTagBookmark($user, array('one', 'system:test')); + $this->addTagBookmark($user, array('one', 'system:unittest')); + $this->addTagBookmark($user, array('one', 'sys:unittest')); + + $arTags = $this->b2ts->getPopularTags(); + $this->assertInternalType('array', $arTags); + $this->assertEquals(2, count($arTags)); + $this->assertEquals( + array( + array('tag' => 'one', 'bCount' => '3'), + array('tag' => 'sys:unittest', 'bCount' => '1'), + ), + $arTags + ); + } + + + + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags + */ + public function testGetPopularTagsUserTags() + { + $user1 = $this->addUser(); + $user2 = $this->addUser(); + $user3 = $this->addUser(); + $this->addTagBookmark($user1, array('one')); + $this->addTagBookmark($user2, array('one', 'two')); + $this->addTagBookmark($user2, array('two')); + $this->addTagBookmark($user3, array('one', 'three')); + + $arTags = $this->b2ts->getPopularTags($user1); + $this->assertEquals(1, count($arTags)); + $this->assertEquals( + array( + array('tag' => 'one', 'bCount' => '1'), + ), + $arTags + ); + + $arTags = $this->b2ts->getPopularTags($user2); + $this->assertEquals(2, count($arTags)); + $this->assertEquals( + array( + array('tag' => 'two', 'bCount' => '2'), + array('tag' => 'one', 'bCount' => '1'), + ), + $arTags + ); + + $arTags = $this->b2ts->getPopularTags(array($user2, $user3)); + $this->assertEquals(3, count($arTags)); + $this->assertContains(array('tag' => 'one', 'bCount' => '2'), $arTags); + $this->assertContains(array('tag' => 'two', 'bCount' => '2'), $arTags); + $this->assertContains(array('tag' => 'three', 'bCount' => '1'), $arTags); + } + + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags + */ + public function testGetPopularTagsPublicOnly() + { + $user1 = $this->addUser(); + $this->addBookmark($user1, null, 0, array('one')); + $this->addBookmark($user1, null, 1, array('one', 'two')); + $this->addBookmark($user1, null, 2, array('three')); + + $arTags = $this->b2ts->getPopularTags(); + $this->assertEquals(1, count($arTags)); + $this->assertEquals( + array( + array('tag' => 'one', 'bCount' => '1'), + ), + $arTags + ); + + $user1 = $this->addUser(); + $this->addBookmark($user1, null, 0, array('one')); + $this->addBookmark($user1, null, 1, array('one', 'two')); + $this->addBookmark($user1, null, 2, array('three')); + + $arTags = $this->b2ts->getPopularTags($user1); + $this->assertEquals(1, count($arTags)); + $this->assertEquals( + array( + array('tag' => 'one', 'bCount' => '1'), + ), + $arTags + ); + } + + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags + */ + public function testGetPopularTagsUserPrivatesWhenLoggedIn() + { + $user1 = $this->addUser(); + $this->addBookmark($user1, null, 0, array('one')); + $this->addBookmark($user1, null, 1, array('one', 'two')); + $this->addBookmark($user1, null, 2, array('three')); + + $arTags = $this->b2ts->getPopularTags($user1, 10, $user1); + $this->assertEquals(3, count($arTags)); + $this->assertContains(array('tag' => 'one', 'bCount' => '2'), $arTags); + $this->assertContains(array('tag' => 'two', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'three', 'bCount' => '1'), $arTags); + } } if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') { -- cgit v1.2.3 From 66c60880d26df7161e8bbe46d52b058e04f7ea05 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 23 Mar 2011 19:00:25 +0100 Subject: rename three to thr to make the code look nicer --- tests/Bookmark2TagTest.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'tests/Bookmark2TagTest.php') diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index 8ee3fc1..a83a826 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -108,11 +108,11 @@ class Bookmark2TagTest extends TestBase /** - * Test getTagsForBookmark() when the bookmark has three tags + * Test getTagsForBookmark() when the bookmark has thr tags * * @return void */ - public function testGetTagsForBookmarkThree() + public function testGetTagsForBookmarkThr() { $this->addBookmark(null, null, 0, array('forz', 'barz')); @@ -235,7 +235,7 @@ class Bookmark2TagTest extends TestBase { $user = $this->addUser(); $this->addTagBookmark($user, array('one', 'two')); - $this->addTagBookmark($user, array('one', 'three')); + $this->addTagBookmark($user, array('one', 'thr')); $this->addTagBookmark($user, array('one', 'two')); $arTags = $this->b2ts->getPopularTags(); @@ -248,7 +248,7 @@ class Bookmark2TagTest extends TestBase array( array('tag' => 'one', 'bCount' => '3'), array('tag' => 'two', 'bCount' => '2'), - array('tag' => 'three', 'bCount' => '1') + array('tag' => 'thr', 'bCount' => '1') ), $arTags ); @@ -263,7 +263,7 @@ class Bookmark2TagTest extends TestBase { $user = $this->addUser(); $this->addTagBookmark($user, array('one', 'two')); - $this->addTagBookmark($user, array('one', 'three')); + $this->addTagBookmark($user, array('one', 'thr')); $this->addTagBookmark($user, array('one', 'two')); $arTags = $this->b2ts->getPopularTags(); @@ -301,16 +301,16 @@ class Bookmark2TagTest extends TestBase { $user = $this->addUser(); $this->addTagBookmark($user, array('one', 'two'), 'today'); - $this->addTagBookmark($user, array('one', 'three'), 'today'); + $this->addTagBookmark($user, array('one', 'thr'), 'today'); $this->addTagBookmark($user, array('one', 'two'), '-1 day 1 hour'); - $this->addTagBookmark($user, array('one', 'three'), '-3 days 1 hour'); + $this->addTagBookmark($user, array('one', 'thr'), '-3 days 1 hour'); $arTags = $this->b2ts->getPopularTags(null, 10, null, 1); $this->assertInternalType('array', $arTags); $this->assertEquals(3, count($arTags)); $this->assertContains(array('tag' => 'one', 'bCount' => '2'), $arTags); $this->assertContains(array('tag' => 'two', 'bCount' => '1'), $arTags); - $this->assertContains(array('tag' => 'three', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'thr', 'bCount' => '1'), $arTags); $arTags = $this->b2ts->getPopularTags(null, 10, null, 2); $this->assertInternalType('array', $arTags); @@ -319,7 +319,7 @@ class Bookmark2TagTest extends TestBase array( array('tag' => 'one', 'bCount' => '3'), array('tag' => 'two', 'bCount' => '2'), - array('tag' => 'three', 'bCount' => '1'), + array('tag' => 'thr', 'bCount' => '1'), ), $arTags ); @@ -329,7 +329,7 @@ class Bookmark2TagTest extends TestBase $this->assertEquals(3, count($arTags)); $this->assertContains(array('tag' => 'one', 'bCount' => '4'), $arTags); $this->assertContains(array('tag' => 'two', 'bCount' => '2'), $arTags); - $this->assertContains(array('tag' => 'three', 'bCount' => '2'), $arTags); + $this->assertContains(array('tag' => 'thr', 'bCount' => '2'), $arTags); } @@ -369,7 +369,7 @@ class Bookmark2TagTest extends TestBase $this->addTagBookmark($user1, array('one')); $this->addTagBookmark($user2, array('one', 'two')); $this->addTagBookmark($user2, array('two')); - $this->addTagBookmark($user3, array('one', 'three')); + $this->addTagBookmark($user3, array('one', 'thr')); $arTags = $this->b2ts->getPopularTags($user1); $this->assertEquals(1, count($arTags)); @@ -394,7 +394,7 @@ class Bookmark2TagTest extends TestBase $this->assertEquals(3, count($arTags)); $this->assertContains(array('tag' => 'one', 'bCount' => '2'), $arTags); $this->assertContains(array('tag' => 'two', 'bCount' => '2'), $arTags); - $this->assertContains(array('tag' => 'three', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'thr', 'bCount' => '1'), $arTags); } /** @@ -405,7 +405,7 @@ class Bookmark2TagTest extends TestBase $user1 = $this->addUser(); $this->addBookmark($user1, null, 0, array('one')); $this->addBookmark($user1, null, 1, array('one', 'two')); - $this->addBookmark($user1, null, 2, array('three')); + $this->addBookmark($user1, null, 2, array('thr')); $arTags = $this->b2ts->getPopularTags(); $this->assertEquals(1, count($arTags)); @@ -419,7 +419,7 @@ class Bookmark2TagTest extends TestBase $user1 = $this->addUser(); $this->addBookmark($user1, null, 0, array('one')); $this->addBookmark($user1, null, 1, array('one', 'two')); - $this->addBookmark($user1, null, 2, array('three')); + $this->addBookmark($user1, null, 2, array('thr')); $arTags = $this->b2ts->getPopularTags($user1); $this->assertEquals(1, count($arTags)); @@ -439,13 +439,13 @@ class Bookmark2TagTest extends TestBase $user1 = $this->addUser(); $this->addBookmark($user1, null, 0, array('one')); $this->addBookmark($user1, null, 1, array('one', 'two')); - $this->addBookmark($user1, null, 2, array('three')); + $this->addBookmark($user1, null, 2, array('thr')); $arTags = $this->b2ts->getPopularTags($user1, 10, $user1); $this->assertEquals(3, count($arTags)); $this->assertContains(array('tag' => 'one', 'bCount' => '2'), $arTags); $this->assertContains(array('tag' => 'two', 'bCount' => '1'), $arTags); - $this->assertContains(array('tag' => 'three', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'thr', 'bCount' => '1'), $arTags); } } -- cgit v1.2.3 From cb28cd3371e215646765f6d1d06263a54a5526f1 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 23 Mar 2011 19:11:38 +0100 Subject: unittest for getAdminTags as well as CS and docblock fixes on it --- src/SemanticScuttle/Service/Bookmark2Tag.php | 30 +++++++++++++++++++++++++--- tests/Bookmark2TagTest.php | 20 +++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) (limited to 'tests/Bookmark2TagTest.php') diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index e3997dd..d367b62 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -454,15 +454,37 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService return $output; } - function &getAdminTags($limit = 30, $logged_on_user = NULL, $days = NULL) { + + + /** + * Returns the tags used by admin users + * + * @param integer $limit Number of tags to return + * @param integer $logged_on_user ID of the user that's currently logged in. + * If the logged in user equals the $user to find + * tags for, tags of private bookmarks are + * returned. + * @param integer $days Bookmarks have to be changed in the last X days + * if their tags shall count* + * + * @return array Array of found tags. Each tag entry is an array with two keys, + * 'tag' (tag name) and 'bCount'. + * + * @see getPopularTags() + */ + public function getAdminTags( + $limit = 30, $logged_on_user = null, $days = null + ) { // look for admin ids - $userservice = SemanticScuttle_Service_Factory :: get('User'); - $adminIds = $userservice->getAdminIds(); + $userservice = SemanticScuttle_Service_Factory::get('User'); + $adminIds = $userservice->getAdminIds(); // ask for their tags return $this->getPopularTags($adminIds, $limit, $logged_on_user, $days); } + + function &getContactTags($user, $limit = 30, $logged_on_user = NULL, $days = NULL) { // look for contact ids $userservice = SemanticScuttle_Service_Factory :: get('User'); @@ -477,6 +499,8 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService return $this->getPopularTags($contacts, $limit, $logged_on_user, $days); } + + /** * The the most popular tags and their usage count * diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index a83a826..d85cf73 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -56,6 +56,7 @@ class Bookmark2TagTest extends TestBase protected function setUp() { $this->us = SemanticScuttle_Service_Factory::get('User'); + $this->us->deleteAll(); $this->bs = SemanticScuttle_Service_Factory::get('Bookmark'); $this->bs->deleteAll(); $this->b2ts= SemanticScuttle_Service_Factory::get('Bookmark2Tag'); @@ -447,6 +448,25 @@ class Bookmark2TagTest extends TestBase $this->assertContains(array('tag' => 'two', 'bCount' => '1'), $arTags); $this->assertContains(array('tag' => 'thr', 'bCount' => '1'), $arTags); } + + + public function testGetAdminTags() + { + $admin1 = $this->addUser('admin1'); + $admin2 = $this->addUser('admin2'); + $user1 = $this->addUser(); + $this->addBookmark($admin1, null, 0, array('admintag', 'admintag1')); + $this->addBookmark($admin2, null, 0, array('admintag', 'admintag2')); + $this->addBookmark($user1, null, 0, array('usertag')); + + $GLOBALS['admin_users'] = array('admin1', 'admin2'); + + $arTags = $this->b2ts->getAdminTags(4); + $this->assertEquals(3, count($arTags)); + $this->assertContains(array('tag' => 'admintag', 'bCount' => '2'), $arTags); + $this->assertContains(array('tag' => 'admintag1', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'admintag2', 'bCount' => '1'), $arTags); + } } if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') { -- cgit v1.2.3 From 637e276ac7dc0e9acdbb79ed68415c1770ce7a3f Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 24 Mar 2011 08:36:54 +0100 Subject: unittest for Bookmark2Tag::getContactTags, CS and docblock --- src/SemanticScuttle/Service/Bookmark2Tag.php | 31 ++++++++++++-- tests/Bookmark2TagTest.php | 62 +++++++++++++++++++++++++--- 2 files changed, 83 insertions(+), 10 deletions(-) (limited to 'tests/Bookmark2TagTest.php') diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index d367b62..478b47e 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -485,13 +485,33 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService - function &getContactTags($user, $limit = 30, $logged_on_user = NULL, $days = NULL) { + + /** + * Returns the tags used by users that are part of the user's watchlist, + * and the current user's own tags. + * + * @param integer $user ID of the user to get the watchlist from + * @param integer $limit Number of tags to return + * @param integer $logged_on_user ID of the user that's currently logged in. + * If set, that user is added to the list of + * people to get the tags from + * @param integer $days Bookmarks have to be changed in the last X days + * if their tags shall count* + * + * @return array Array of found tags. Each tag entry is an array with two keys, + * 'tag' (tag name) and 'bCount'. + * + * @see getPopularTags() + */ + public function getContactTags( + $user, $limit = 30, $logged_on_user = null, $days = null + ) { // look for contact ids - $userservice = SemanticScuttle_Service_Factory :: get('User'); + $userservice = SemanticScuttle_Service_Factory::get('User'); $contacts = $userservice->getWatchlist($user); - // add the user (to show him/her also his/her tags) - if(!is_null($logged_on_user)) { + // add the user (to show him also his own tags) + if (!is_null($logged_on_user)) { $contacts[] = $logged_on_user; } @@ -516,6 +536,9 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService * * @return array Array of found tags. Each tag entry is an array with two keys, * 'tag' (tag name) and 'bCount'. + * + * @see getAdminTags() + * @see getContactTags() */ public function getPopularTags( $user = null, $limit = 30, $logged_on_user = null, $days = null diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index d85cf73..ad64bf6 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -74,7 +74,7 @@ class Bookmark2TagTest extends TestBase /** * Test getTagsForBookmark() when the bookmark has no tags * - * @return void + * @covers SemanticScuttle_Service_Bookmark2Tag::getTagsForBookmark */ public function testGetTagsForBookmarkNone() { @@ -92,7 +92,7 @@ class Bookmark2TagTest extends TestBase /** * Test getTagsForBookmark() when the bookmark has one tag * - * @return void + * @covers SemanticScuttle_Service_Bookmark2Tag::getTagsForBookmark */ public function testGetTagsForBookmarkOne() { @@ -109,9 +109,9 @@ class Bookmark2TagTest extends TestBase /** - * Test getTagsForBookmark() when the bookmark has thr tags + * Test getTagsForBookmark() when the bookmark has three tags * - * @return void + * @covers SemanticScuttle_Service_Bookmark2Tag::getTagsForBookmark */ public function testGetTagsForBookmarkThr() { @@ -132,7 +132,7 @@ class Bookmark2TagTest extends TestBase /** * Test getTagsForBookmarks() when no bookmarks have tags. * - * @return void + * @covers SemanticScuttle_Service_Bookmark2Tag::getTagsForBookmarks */ public function testGetTagsForBookmarksNone() { @@ -155,7 +155,7 @@ class Bookmark2TagTest extends TestBase /** * Test getTagsForBookmarks() when most bookmarks have tags. * - * @return void + * @covers SemanticScuttle_Service_Bookmark2Tag::getTagsForBookmarks */ public function testGetTagsForBookmarksMost() { @@ -450,6 +450,9 @@ class Bookmark2TagTest extends TestBase } + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getAdminTags + */ public function testGetAdminTags() { $admin1 = $this->addUser('admin1'); @@ -467,6 +470,53 @@ class Bookmark2TagTest extends TestBase $this->assertContains(array('tag' => 'admintag1', 'bCount' => '1'), $arTags); $this->assertContains(array('tag' => 'admintag2', 'bCount' => '1'), $arTags); } + + + + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getContactTags + */ + public function testGetContactTagsWatchlistOnly() + { + $user1 = $this->addUser(); + $user2 = $this->addUser(); + $user3 = $this->addUser(); + $this->us->setCurrentUserId($user1); + $this->us->setWatchStatus($user2); + //user1 watches user2 now + + $this->addBookmark($user1, null, 0, array('usertag', 'usertag1')); + $this->addBookmark($user2, null, 0, array('usertag', 'usertag2')); + $this->addBookmark($user3, null, 0, array('usertag', 'usertag3')); + + $arTags = $this->b2ts->getContactTags($user1, 10); + $this->assertEquals(2, count($arTags)); + $this->assertContains(array('tag' => 'usertag', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'usertag2', 'bCount' => '1'), $arTags); + } + + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getContactTags + */ + public function testGetContactTagsIncludingUser() + { + $user1 = $this->addUser(); + $user2 = $this->addUser(); + $user3 = $this->addUser(); + $this->us->setCurrentUserId($user1); + $this->us->setWatchStatus($user2); + //user1 watches user2 now + + $this->addBookmark($user1, null, 0, array('usertag', 'usertag1')); + $this->addBookmark($user2, null, 0, array('usertag', 'usertag2')); + $this->addBookmark($user3, null, 0, array('usertag', 'usertag3')); + + $arTags = $this->b2ts->getContactTags($user1, 10, $user1); + $this->assertEquals(3, count($arTags)); + $this->assertContains(array('tag' => 'usertag', 'bCount' => '2'), $arTags); + $this->assertContains(array('tag' => 'usertag1', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'usertag2', 'bCount' => '1'), $arTags); + } } if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') { -- cgit v1.2.3 From 30f84b3ca3242f00926f30c08ece4405be8b61fc Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 24 Mar 2011 19:07:50 +0100 Subject: fix privacy protection issue when fetching tags of several users --- src/SemanticScuttle/Service/Bookmark2Tag.php | 2 +- tests/Bookmark2TagTest.php | 69 ++++++++++++++++++++-------- 2 files changed, 50 insertions(+), 21 deletions(-) (limited to 'tests/Bookmark2TagTest.php') diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index b69cfd4..21ea0d5 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -565,7 +565,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService $query .= ' OR B.uId = ' . $this->db->sql_escape($u) . ' AND B.bId = T.bId'; } - $query .= ' )'; + $query .= ' )' . $privacy; } else { $query .= ' B.uId = ' . $this->db->sql_escape($user) . ' AND B.bId = T.bId' . $privacy; diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index ad64bf6..e2020dc 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -37,6 +37,26 @@ class Bookmark2TagTest extends TestBase protected $tts; + /** + * Create a bookmark. Like addBookmark(), just with other paramter order + * to make some tests in that class easier to write. + * + * @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 + ); + } + + /** * Used to run this test class standalone @@ -207,25 +227,6 @@ 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 @@ -398,10 +399,12 @@ class Bookmark2TagTest extends TestBase $this->assertContains(array('tag' => 'thr', 'bCount' => '1'), $arTags); } + + /** * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags */ - public function testGetPopularTagsPublicOnly() + public function testGetPopularTagsPublicOnlyNoUser() { $user1 = $this->addUser(); $this->addBookmark($user1, null, 0, array('one')); @@ -416,7 +419,13 @@ class Bookmark2TagTest extends TestBase ), $arTags ); + } + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags + */ + public function testGetPopularTagsPublicOnlySingleUser() + { $user1 = $this->addUser(); $this->addBookmark($user1, null, 0, array('one')); $this->addBookmark($user1, null, 1, array('one', 'two')); @@ -432,6 +441,26 @@ class Bookmark2TagTest extends TestBase ); } + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags + */ + public function testGetPopularTagsPublicOnlySeveralUsers() + { + $user1 = $this->addUser(); + $user2 = $this->addUser(); + $this->addBookmark($user1, null, 0, array('one')); + $this->addBookmark($user1, null, 1, array('one', 'two')); + $this->addBookmark($user1, null, 2, array('thr')); + $this->addBookmark($user2, null, 0, array('fou')); + $this->addBookmark($user2, null, 1, array('fiv')); + $this->addBookmark($user2, null, 2, array('six')); + + $arTags = $this->b2ts->getPopularTags(array($user1, $user2)); + $this->assertEquals(2, count($arTags)); + $this->assertContains(array('tag' => 'one', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'fou', 'bCount' => '1'), $arTags); + } + /** * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags */ -- cgit v1.2.3 From e667feb0ca9ff30a063149a2ce20b3398585dd4f Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 25 Mar 2011 07:44:07 +0100 Subject: beginsWith-parameter for getPopulartags, getContactTags and getAdminTags --- src/SemanticScuttle/Service/Bookmark2Tag.php | 25 ++++++++--- tests/Bookmark2TagTest.php | 64 ++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 5 deletions(-) (limited to 'tests/Bookmark2TagTest.php') diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index beb4185..1dc0ffe 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -466,6 +466,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService * returned. * @param integer $days Bookmarks have to be changed in the last X days * if their tags shall count + * @param string $beginsWith The tag name shall begin with that string * * @return array Array of found tags. Each tag entry is an array with two keys, * 'tag' (tag name) and 'bCount'. @@ -473,14 +474,16 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService * @see getPopularTags() */ public function getAdminTags( - $limit = 30, $logged_on_user = null, $days = null + $limit = 30, $logged_on_user = null, $days = null, $beginsWith = null ) { // look for admin ids $userservice = SemanticScuttle_Service_Factory::get('User'); $adminIds = $userservice->getAdminIds(); // ask for their tags - return $this->getPopularTags($adminIds, $limit, $logged_on_user, $days); + return $this->getPopularTags( + $adminIds, $limit, $logged_on_user, $days, $beginsWith + ); } @@ -497,6 +500,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService * people to get the tags from * @param integer $days Bookmarks have to be changed in the last X days * if their tags shall count + * @param string $beginsWith The tag name shall begin with that string * * @return array Array of found tags. Each tag entry is an array with two keys, * 'tag' (tag name) and 'bCount'. @@ -504,7 +508,8 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService * @see getPopularTags() */ public function getContactTags( - $user, $limit = 30, $logged_on_user = null, $days = null + $user, $limit = 30, $logged_on_user = null, $days = null, + $beginsWith = null ) { // look for contact ids $userservice = SemanticScuttle_Service_Factory::get('User'); @@ -516,7 +521,9 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService } // ask for their tags - return $this->getPopularTags($contacts, $limit, $logged_on_user, $days); + return $this->getPopularTags( + $contacts, $limit, $logged_on_user, $days, $beginsWith + ); } @@ -533,6 +540,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService * returned. * @param integer $days Bookmarks have to be changed in the last X days * if their tags shall count + * @param string $beginsWith The tag name shall begin with that string * * @return array Array of found tags. Each tag entry is an array with two keys, * 'tag' (tag name) and 'bCount'. @@ -541,7 +549,8 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService * @see getContactTags() */ public function getPopularTags( - $user = null, $limit = 30, $logged_on_user = null, $days = null + $user = null, $limit = 30, $logged_on_user = null, $days = null, + $beginsWith = null ) { // Only count the tags that are visible to the current user. if (($user != $logged_on_user) || is_null($user) || ($user === false)) { @@ -577,6 +586,12 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService . '"'; } + if (!is_null($beginsWith)) { + $query .= ' AND T.tag LIKE \'' + . $this->db->sql_escape($beginsWith) + . '%\''; + } + $query .= ' AND LEFT(T.tag, 7) <> "system:"' . ' GROUP BY T.tag' . ' ORDER BY bCount DESC, tag'; diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index e2020dc..ffd83c3 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -334,6 +334,31 @@ class Bookmark2TagTest extends TestBase $this->assertContains(array('tag' => 'thr', 'bCount' => '2'), $arTags); } + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags + */ + public function testGetPopularTagsBeginsWith() + { + $user = $this->addUser(); + $this->addTagBookmark($user, array('one', 'two')); + $this->addTagBookmark($user, array('one', 'thr')); + $this->addTagBookmark($user, array('one', 'two')); + $this->addTagBookmark($user, array('one', 'thr')); + + $arTags = $this->b2ts->getPopularTags(null, 10, null, null, 'o'); + $this->assertEquals(1, count($arTags)); + $this->assertContains(array('tag' => 'one', 'bCount' => '4'), $arTags); + + $arTags = $this->b2ts->getPopularTags(null, 10, null, null, 'tw'); + $this->assertEquals(1, count($arTags)); + $this->assertContains(array('tag' => 'two', 'bCount' => '2'), $arTags); + + $arTags = $this->b2ts->getPopularTags(null, 10, null, null, 't'); + $this->assertEquals(2, count($arTags)); + $this->assertContains(array('tag' => 'two', 'bCount' => '2'), $arTags); + $this->assertContains(array('tag' => 'thr', 'bCount' => '2'), $arTags); + } + /** @@ -500,6 +525,23 @@ class Bookmark2TagTest extends TestBase $this->assertContains(array('tag' => 'admintag2', 'bCount' => '1'), $arTags); } + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getAdminTags + */ + public function testGetAdminTagsBeginsWith() + { + $admin1 = $this->addUser('admin1'); + $this->addBookmark($admin1, null, 0, array('admintag', 'admintag1')); + $this->addBookmark($admin1, null, 0, array('tester', 'testos')); + + $GLOBALS['admin_users'] = array('admin1'); + + $arTags = $this->b2ts->getAdminTags(4, null, null, 'test'); + $this->assertEquals(2, count($arTags)); + $this->assertContains(array('tag' => 'tester', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'testos', 'bCount' => '1'), $arTags); + } + /** @@ -546,6 +588,28 @@ class Bookmark2TagTest extends TestBase $this->assertContains(array('tag' => 'usertag1', 'bCount' => '1'), $arTags); $this->assertContains(array('tag' => 'usertag2', 'bCount' => '1'), $arTags); } + + /** + * @covers SemanticScuttle_Service_Bookmark2Tag::getContactTags + */ + public function testGetContactTagsBeginsWith() + { + $user1 = $this->addUser(); + $this->addBookmark($user1, null, 0, array('usertag', 'usertag1')); + $this->addBookmark($user1, null, 0, array('usable', 'undefined')); + $this->addBookmark($user1, null, 0, array('fußbad', 'usable')); + + $arTags = $this->b2ts->getContactTags($user1, 10, $user1, null, 'user'); + $this->assertEquals(2, count($arTags)); + $this->assertContains(array('tag' => 'usertag', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'usertag1', 'bCount' => '1'), $arTags); + + $arTags = $this->b2ts->getContactTags($user1, 10, $user1, null, 'us'); + $this->assertEquals(3, count($arTags)); + $this->assertContains(array('tag' => 'usertag', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'usertag1', 'bCount' => '1'), $arTags); + $this->assertContains(array('tag' => 'usable', 'bCount' => '2'), $arTags); + } } if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') { -- cgit v1.2.3 From d6e99db40dc88de1782099b30941075ebc8dfa97 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 25 Mar 2011 08:00:32 +0100 Subject: do not generate invalid SQL when called with a not-so valid array --- src/SemanticScuttle/Service/Bookmark2Tag.php | 6 ++++-- tests/Bookmark2TagTest.php | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'tests/Bookmark2TagTest.php') diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index 1dc0ffe..a10cb61 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -571,8 +571,10 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService } else if (is_array($user)) { $query .= ' (1 = 0'; //tricks foreach ($user as $u) { - $query .= ' OR B.uId = ' . $this->db->sql_escape($u) - . ' AND B.bId = T.bId'; + if (is_numeric($u)) { + $query .= ' OR B.uId = ' . $this->db->sql_escape($u) + . ' AND B.bId = T.bId'; + } } $query .= ' )' . $privacy; } else { diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index ffd83c3..fff4222 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -426,6 +426,23 @@ class Bookmark2TagTest extends TestBase + /** + * This may happen when the method is called with a problematic user array. + * In that case we may not generate invalid SQL or so. + * + * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags + */ + public function testGetPopularTagsUserArrayWithNull() + { + $user1 = $this->addUser(); + $this->addTagBookmark($user1, array('one')); + + $arTags = $this->b2ts->getPopularTags(array(null)); + $this->assertEquals(0, count($arTags)); + } + + + /** * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags */ -- cgit v1.2.3 From bdebe6598c52a74f7040e3a11198b3554fa58f54 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 12 Apr 2011 09:29:59 +0200 Subject: use bootstrap file declared in phpunit.xml and do not include it in every single test file. also get rid of the PHPUnit_MAIN_METHOD declarations since using phpunit directly is preferred --- tests/AllTests.php | 25 ++----------------------- tests/Api/ExportCsvTest.php | 25 ------------------------- tests/Api/PostsAddTest.php | 25 ------------------------- tests/Api/PostsDeleteTest.php | 25 ------------------------- tests/Api/PostsUpdateTest.php | 25 ------------------------- tests/Bookmark2TagTest.php | 24 ------------------------ tests/BookmarkTest.php | 26 -------------------------- tests/CommonDescriptionTest.php | 25 ------------------------- tests/SearchHistoryTest.php | 27 --------------------------- tests/Tag2TagTest.php | 25 ------------------------- tests/TagTest.php | 26 -------------------------- tests/TagsCacheTest.php | 23 ----------------------- tests/UserArrayTest.php | 2 -- tests/UserTest.php | 29 ----------------------------- tests/VoteTest.php | 25 ------------------------- tests/ajax/GetAdminLinkedTagsTest.php | 26 -------------------------- tests/ajax/GetAdminTagsTest.php | 2 -- tests/ajax/GetContactTagsTest.php | 2 -- 18 files changed, 2 insertions(+), 385 deletions(-) (limited to 'tests/Bookmark2TagTest.php') diff --git a/tests/AllTests.php b/tests/AllTests.php index 4afcc6b..9e825e8 100644 --- a/tests/AllTests.php +++ b/tests/AllTests.php @@ -12,23 +12,15 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'AllTests::main'); -} - -require_once 'prepare.php'; /** * SemanticScuttle unit tests. * * To launch this tests, you need PHPUnit 3. * Run them with: - * $ php tests/AllTests.php + * $ cd tests; phpunit . * or single files like: - * $ php tests/BookmarkTest.php - * - * You also may use phpunit directly: - * $ phpunit tests/AllTests.php + * $ cd tests; phpunit BookmarkTest.php * * @category Bookmarking * @package SemanticScuttle @@ -40,14 +32,6 @@ require_once 'prepare.php'; */ class AllTests extends PHPUnit_Framework_TestSuite { - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run(self::suite()); - } - - - public static function suite() { $suite = new AllTests(); @@ -74,9 +58,4 @@ class AllTests extends PHPUnit_Framework_TestSuite { } } - -if (PHPUnit_MAIN_METHOD == 'AllTests::main') { - AllTests::main(); -} - ?> \ No newline at end of file diff --git a/tests/Api/ExportCsvTest.php b/tests/Api/ExportCsvTest.php index 2bff8a5..681f0de 100644 --- a/tests/Api/ExportCsvTest.php +++ b/tests/Api/ExportCsvTest.php @@ -12,14 +12,8 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Api_ExportCsvTest::main'); -} - /** * Unit tests for the SemanticScuttle csv export API * @@ -39,21 +33,6 @@ class Api_ExportCsvTest extends TestBaseApi - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite(__CLASS__) - ); - } - - - /** * Test if authentication is required when sending no auth data */ @@ -280,8 +259,4 @@ class Api_ExportCsvTest extends TestBaseApi return $ar; } } - -if (PHPUnit_MAIN_METHOD == 'Api_ExportCsvTest::main') { - Api_ExportCsvTest::main(); -} ?> \ No newline at end of file diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index 1f21d04..53aa8e7 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -12,14 +12,8 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Api_PostsAddTest::main'); -} - /** * Unit tests for the SemanticScuttle post addition API. * @@ -37,21 +31,6 @@ class Api_PostsAddTest extends TestBaseApi - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite(__CLASS__) - ); - } - - - /** * Test if authentication is required when sending no auth data */ @@ -428,8 +407,4 @@ TXT; $this->assertEquals($title2, $data['bookmarks'][0]['bTitle']); } } - -if (PHPUnit_MAIN_METHOD == 'Api_PostsAddTest::main') { - Api_PostsAddTest::main(); -} ?> \ No newline at end of file diff --git a/tests/Api/PostsDeleteTest.php b/tests/Api/PostsDeleteTest.php index d9fb6cd..7ba1285 100644 --- a/tests/Api/PostsDeleteTest.php +++ b/tests/Api/PostsDeleteTest.php @@ -12,14 +12,8 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Api_PostsDeleteTest::main'); -} - /** * Unit tests for the SemanticScuttle post deletion API. * @@ -37,21 +31,6 @@ class Api_PostsDeleteTest extends TestBaseApi - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite(__CLASS__) - ); - } - - - /** * Test if authentication is required when sending no auth data */ @@ -296,8 +275,4 @@ class Api_PostsDeleteTest extends TestBaseApi } } - -if (PHPUnit_MAIN_METHOD == 'Api_PostsDeleteTest::main') { - Api_PostsDeleteTest::main(); -} ?> \ No newline at end of file diff --git a/tests/Api/PostsUpdateTest.php b/tests/Api/PostsUpdateTest.php index c497a55..51f8be2 100644 --- a/tests/Api/PostsUpdateTest.php +++ b/tests/Api/PostsUpdateTest.php @@ -12,14 +12,8 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Api_PostsUpdateTest::main'); -} - /** * Unit tests for the SemanticScuttle last-update time API. * @@ -37,21 +31,6 @@ class Api_PostsUpdateTest extends TestBaseApi - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite(__CLASS__) - ); - } - - - /** * Test if authentication is required when sending no auth data */ @@ -128,8 +107,4 @@ class Api_PostsUpdateTest extends TestBaseApi } } - -if (PHPUnit_MAIN_METHOD == 'Api_PostsUpdateTest::main') { - Api_PostsUpdateTest::main(); -} ?> \ No newline at end of file diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index fff4222..789540f 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Bookmark2TagTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle bookmark-tag combination service. @@ -58,21 +53,6 @@ class Bookmark2TagTest extends TestBase - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite(__CLASS__) - ); - } - - - protected function setUp() { $this->us = SemanticScuttle_Service_Factory::get('User'); @@ -628,8 +608,4 @@ class Bookmark2TagTest extends TestBase $this->assertContains(array('tag' => 'usable', 'bCount' => '2'), $arTags); } } - -if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') { - Bookmark2TagTest::main(); -} ?> \ No newline at end of file diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index f54fe9a..e7ce488 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'BookmarkTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle bookmark service. @@ -37,22 +32,6 @@ class BookmarkTest extends TestBase protected $tts; - - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite(__CLASS__) - ); - } - - - protected function setUp() { $this->us = SemanticScuttle_Service_Factory::get('User'); @@ -1344,10 +1323,5 @@ class BookmarkTest extends TestBase -} - - -if (PHPUnit_MAIN_METHOD == 'BookmarkTest::main') { - BookmarkTest::main(); } ?> diff --git a/tests/CommonDescriptionTest.php b/tests/CommonDescriptionTest.php index 94f431d..7748cb3 100644 --- a/tests/CommonDescriptionTest.php +++ b/tests/CommonDescriptionTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'CommonDescriptionTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle common description service. @@ -39,21 +34,6 @@ class CommonDescriptionTest extends TestBase protected $cds; - - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite(__CLASS__) - ); - } - - protected function setUp() { $this->us =SemanticScuttle_Service_Factory::get('User'); @@ -128,9 +108,4 @@ class CommonDescriptionTest extends TestBase } } - - -if (PHPUnit_MAIN_METHOD == 'CommonDescriptionTest::main') { - CommonDescriptionTest::main(); -} ?> diff --git a/tests/SearchHistoryTest.php b/tests/SearchHistoryTest.php index 69d1efa..f05dd29 100644 --- a/tests/SearchHistoryTest.php +++ b/tests/SearchHistoryTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'SearchHistoryTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle search history service. @@ -38,22 +33,6 @@ class SearchHistoryTest extends TestBase protected $shs; - - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite(__CLASS__) - ); - } - - - /** * Set up all services * @@ -391,10 +370,4 @@ class SearchHistoryTest extends TestBase $this->assertEquals(0, $this->shs->countSearches()); } } - - -if (PHPUnit_MAIN_METHOD == 'SearchHistoryTest::main') { - SearchHistoryTest::main(); -} - ?> diff --git a/tests/Tag2TagTest.php b/tests/Tag2TagTest.php index 033fc91..0b73864 100644 --- a/tests/Tag2TagTest.php +++ b/tests/Tag2TagTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Tag2TagTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle tag2tag service. @@ -37,22 +32,6 @@ class Tag2TagTest extends TestBase protected $tts; - - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite(__CLASS__) - ); - } - - - protected function setUp() { $this->us =SemanticScuttle_Service_Factory::get('User'); @@ -550,8 +529,4 @@ class Tag2TagTest extends TestBase }*/ } - -if (PHPUnit_MAIN_METHOD == 'Tag2TagTest::main') { - Tag2TagTest::main(); -} ?> diff --git a/tests/TagTest.php b/tests/TagTest.php index 25d1a77..96f3f14 100644 --- a/tests/TagTest.php +++ b/tests/TagTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'TagTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle tag service. @@ -34,22 +29,6 @@ class TagTest extends TestBase protected $ts; - - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite(__CLASS__) - ); - } - - - protected function setUp() { $this->ts =SemanticScuttle_Service_Factory::get('Tag'); @@ -109,9 +88,4 @@ class TagTest extends TestBase } } - - -if (PHPUnit_MAIN_METHOD == 'TagTest::main') { - TagTest::main(); -} ?> diff --git a/tests/TagsCacheTest.php b/tests/TagsCacheTest.php index 94200dd..1f69b58 100644 --- a/tests/TagsCacheTest.php +++ b/tests/TagsCacheTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'TagsCacheTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle tags cache service. @@ -38,19 +33,6 @@ class TagsCacheTest extends PHPUnit_Framework_TestCase - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite(__CLASS__) - ); - } - protected function setUp() { $this->us =SemanticScuttle_Service_Factory::get('User'); @@ -207,9 +189,4 @@ class TagsCacheTest extends PHPUnit_Framework_TestCase $this->assertEquals(array(), $tcs->getSynonyms('d', 1)); } } - -if (PHPUnit_MAIN_METHOD == 'TagsCacheTest::main') { - TagsCacheTest::main(); -} - ?> diff --git a/tests/UserArrayTest.php b/tests/UserArrayTest.php index cb53f15..a60e37f 100644 --- a/tests/UserArrayTest.php +++ b/tests/UserArrayTest.php @@ -11,8 +11,6 @@ * @link http://sourceforge.net/projects/semanticscuttle */ -require_once 'prepare.php'; - /** * Unit tests for the SemanticScuttle user array model. * diff --git a/tests/UserTest.php b/tests/UserTest.php index 49f3730..2f57112 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -12,11 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'UserTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle user service. @@ -31,24 +26,6 @@ require_once 'prepare.php'; */ class UserTest extends TestBase { - - - - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite(__CLASS__) - ); - } - - - protected function setUp() { $this->us = SemanticScuttle_Service_Factory::get('User'); @@ -200,10 +177,4 @@ class UserTest extends TestBase } } - - -if (PHPUnit_MAIN_METHOD == 'UserTest::main') { - UserTest::main(); -} - ?> \ No newline at end of file diff --git a/tests/VoteTest.php b/tests/VoteTest.php index 1623826..0073678 100644 --- a/tests/VoteTest.php +++ b/tests/VoteTest.php @@ -10,11 +10,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'VoteTest::main'); -} - -require_once 'prepare.php'; /** * Unit tests for the SemanticScuttle voting system. @@ -43,21 +38,6 @@ class VoteTest extends TestBase - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite('VoteTest') - ); - } - - - public function setUp() { $GLOBALS['enableVoting'] = true; @@ -553,9 +533,4 @@ class VoteTest extends TestBase } }//class VoteTest extends TestBase - - -if (PHPUnit_MAIN_METHOD == 'VoteTest::main') { - VoteTest::main(); -} ?> \ No newline at end of file diff --git a/tests/ajax/GetAdminLinkedTagsTest.php b/tests/ajax/GetAdminLinkedTagsTest.php index aded834..43cb17a 100644 --- a/tests/ajax/GetAdminLinkedTagsTest.php +++ b/tests/ajax/GetAdminLinkedTagsTest.php @@ -12,14 +12,8 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'ajax_GetAdminLinkedTagsTest::main'); -} - /** * Unit tests for the ajax linked admin tags script * @@ -34,22 +28,6 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi protected $urlPart = 'ajax/getadminlinkedtags.php'; - - /** - * Used to run this test class standalone - * - * @return void - */ - public static function main() - { - require_once 'PHPUnit/TextUI/TestRunner.php'; - PHPUnit_TextUI_TestRunner::run( - new PHPUnit_Framework_TestSuite(__CLASS__) - ); - } - - - /** * Verify that we get the configured root tags if * we do not pass any parameters @@ -139,8 +117,4 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi $this->assertEquals('adminsubtag', $data[0]->data->title); } } - -if (PHPUnit_MAIN_METHOD == 'ajax_GetAdminLinkedTagsTest::main') { - ajax_GetAdminLinkedTagsTest::main(); -} ?> \ No newline at end of file diff --git a/tests/ajax/GetAdminTagsTest.php b/tests/ajax/GetAdminTagsTest.php index 80d702f..8bf8a83 100644 --- a/tests/ajax/GetAdminTagsTest.php +++ b/tests/ajax/GetAdminTagsTest.php @@ -12,8 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; /** diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php index 559040f..268ed66 100644 --- a/tests/ajax/GetContactTagsTest.php +++ b/tests/ajax/GetContactTagsTest.php @@ -12,8 +12,6 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ - -require_once dirname(__FILE__) . '/../prepare.php'; require_once 'HTTP/Request2.php'; /** -- cgit v1.2.3