From be126cc958212ed74fe916eabcb1e6ac928df5e4 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 8 Oct 2010 17:43:05 +0200 Subject: tests for getadminlinkedtags --- tests/TestBase.php | 28 ++++++ tests/ajax/GetAdminLinkedTagsTest.php | 160 ++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 tests/ajax/GetAdminLinkedTagsTest.php (limited to 'tests') diff --git a/tests/TestBase.php b/tests/TestBase.php index 402330b..c0acd58 100644 --- a/tests/TestBase.php +++ b/tests/TestBase.php @@ -104,6 +104,34 @@ class TestBase extends PHPUnit_Framework_TestCase return $uid; } + + + /** + * Retrieves the UID of an admin user. + * If that user does not exist in the database, it is created. + * + * @return integer UID of admin user + */ + protected function getAdminUser() + { + if (count($GLOBALS['admin_users']) == 0) { + $this->fail('No admin users configured'); + } + $adminUserName = reset($GLOBALS['admin_users']); + + $us = SemanticScuttle_Service_Factory::get('User'); + $uid = $us->getIdFromUser($adminUserName); + if ($uid === null) { + //that user does not exist in the database; create it + $uid = $us->addUser( + $adminUserName, + rand(), + 'unittest-admin-' . $adminUserName . '@example.org' + ); + } + + return $uid; + } } ?> \ No newline at end of file diff --git a/tests/ajax/GetAdminLinkedTagsTest.php b/tests/ajax/GetAdminLinkedTagsTest.php new file mode 100644 index 0000000..d8ec447 --- /dev/null +++ b/tests/ajax/GetAdminLinkedTagsTest.php @@ -0,0 +1,160 @@ + + * @author Christian Weiske + * @author Eric Dane + * @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 + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +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 + */ + public function testRootTags() + { + $req = $this->getRequest(); + $res = $req->send(); + + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + + $data = json_decode($res->getBody()); + $this->assertType('array', $data); + + //same number of elements as the menu2Tags array + $this->assertEquals( + count($GLOBALS['menu2Tags']), + count($data) + ); + + //and the same contents + foreach ($data as $tagObj) { + $tagName = $tagObj->data->title; + $this->assertContains($tagName, $GLOBALS['menu2Tags']); + } + } + + /** + * Verify that we get subtags of a given tag + */ + public function testSubTags() + { + $t2t = SemanticScuttle_Service_Factory::get('Tag2Tag'); + $t2t->deleteAll(); + + $menu2Tag = reset($GLOBALS['menu2Tags']); + //we have a subtag now + $this->addBookmark( + $this->getAdminUser(), + null, + 0, + $menu2Tag . '>adminsubtag' + ); + + $res = $this->getRequest('?tag=' . $menu2Tag)->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + + $data = json_decode($res->getBody()); + $this->assertType('array', $data); + + //only one subtag + $this->assertEquals(1, count($data)); + $this->assertEquals('adminsubtag', $data[0]->data->title); + } + + /** + * Verify that we only get admin tags, not tags from + * non-admin people + */ + public function testOnlyAdminTags() + { + $t2t = SemanticScuttle_Service_Factory::get('Tag2Tag'); + $t2t->deleteAll(); + + $menu2Tag = reset($GLOBALS['menu2Tags']); + //we have a subtag now + $this->addBookmark( + $this->getAdminUser(), + null, + 0, + $menu2Tag . '>adminsubtag' + ); + //add another bookmark now, but for a normal user + $this->addBookmark( + null, + null, + 0, + $menu2Tag . '>normalsubtag' + ); + + $res = $this->getRequest('?tag=' . $menu2Tag)->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + + $data = json_decode($res->getBody()); + $this->assertType('array', $data); + + //we should have only one subtag now, the admin one + $this->assertEquals(1, count($data)); + $this->assertEquals('adminsubtag', $data[0]->data->title); + } +} + +if (PHPUnit_MAIN_METHOD == 'ajax_GetAdminLinkedTagsTest::main') { + ajax_GetAdminLinkedTagsTest::main(); +} +?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 975809a8347929c9eae9c6a8bf3beb8d92af63ef Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 15 Mar 2011 19:18:57 +0100 Subject: unit test for the new SemanticScuttle_Model_UserArray class --- tests/UserArrayTest.php | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/UserArrayTest.php (limited to 'tests') diff --git a/tests/UserArrayTest.php b/tests/UserArrayTest.php new file mode 100644 index 0000000..cb53f15 --- /dev/null +++ b/tests/UserArrayTest.php @@ -0,0 +1,68 @@ + + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +require_once 'prepare.php'; + +/** + * Unit tests for the SemanticScuttle user array model. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class UserArrayTest extends PHPUnit_Framework_TestCase +{ + + public function testGetNameLongName() + { + $this->assertEquals( + 'John Doe', + SemanticScuttle_Model_UserArray::getName( + array( + 'name' => 'John Doe', + 'username' => 'jdoe' + ) + ) + ); + } + + public function testGetNameUsernameIfNameIsEmpty() + { + $this->assertEquals( + 'jdoe', + SemanticScuttle_Model_UserArray::getName( + array( + 'name' => '', + 'username' => 'jdoe' + ) + ) + ); + } + + public function testGetNameUsernameIfNameIsNotSet() + { + $this->assertEquals( + 'jdoe', + SemanticScuttle_Model_UserArray::getName( + array( + 'username' => 'jdoe' + ) + ) + ); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf 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 ++++++++++++++++++++++++++++++++++++++++++++++ tests/TestBase.php | 5 +-- 2 files changed, 85 insertions(+), 2 deletions(-) (limited to 'tests') 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') { diff --git a/tests/TestBase.php b/tests/TestBase.php index 6006f4e..3e2e213 100644 --- a/tests/TestBase.php +++ b/tests/TestBase.php @@ -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; -- cgit v1.2.3-54-g00ecf 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') 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-54-g00ecf From 821c17d9e378ecd702a219dfa8392d4d48df3cd0 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 23 Mar 2011 08:54:40 +0100 Subject: exclude tests directory from coverage --- tests/phpunit.xml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/phpunit.xml (limited to 'tests') diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 0000000..734fa95 --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1,8 @@ + + + + + . + + + \ No newline at end of file -- cgit v1.2.3-54-g00ecf 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') 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-54-g00ecf 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') 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-54-g00ecf 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') 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-54-g00ecf 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') 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-54-g00ecf From 3828cfe6d6bb64df763276fa2bc2c4da6ccb06dd Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 24 Mar 2011 08:41:02 +0100 Subject: replace assertType with assertInternalType to please phpunit --- tests/ajax/GetAdminLinkedTagsTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/ajax/GetAdminLinkedTagsTest.php b/tests/ajax/GetAdminLinkedTagsTest.php index d8ec447..2552ea0 100644 --- a/tests/ajax/GetAdminLinkedTagsTest.php +++ b/tests/ajax/GetAdminLinkedTagsTest.php @@ -66,7 +66,7 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi ); $data = json_decode($res->getBody()); - $this->assertType('array', $data); + $this->assertInternalType('array', $data); //same number of elements as the menu2Tags array $this->assertEquals( @@ -106,7 +106,7 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi ); $data = json_decode($res->getBody()); - $this->assertType('array', $data); + $this->assertInternalType('array', $data); //only one subtag $this->assertEquals(1, count($data)); @@ -146,7 +146,7 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi ); $data = json_decode($res->getBody()); - $this->assertType('array', $data); + $this->assertInternalType('array', $data); //we should have only one subtag now, the admin one $this->assertEquals(1, count($data)); -- cgit v1.2.3-54-g00ecf 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') 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-54-g00ecf 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') 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-54-g00ecf 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') 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-54-g00ecf From db71e63467a26afb8265979f8c8071935ec349b4 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 25 Mar 2011 19:26:21 +0100 Subject: begin with ajax unittests - but they do not work yet --- tests/TestBaseApi.php | 36 +++++++++++++++++++ tests/ajax/GetContactTagsTest.php | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 tests/ajax/GetContactTagsTest.php (limited to 'tests') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index dacdecd..b7c1921 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -84,6 +84,9 @@ class TestBaseApi extends TestBase * the request object with authentication details, so that * the user is logged in. * + * Useful for HTTP API methods only, cannot be used with + * "normal" HTML pages since they do not support HTTP auth. + * * @param string $urlSuffix Suffix for the URL * @param mixed $auth If user authentication is needed (true/false) * or array with username and password @@ -109,5 +112,38 @@ class TestBaseApi extends TestBase return array($req, $uid); } + + + /** + * Creates a user and a HTTP_Request2 object, does a normal login + * and prepares the cookies for the HTTP request object so that + * the user is seen as logged in when requesting any HTML page. + * + * Useful for testing HTML pages or ajax URLs. + * + * @param string $urlSuffix Suffix for the URL + * @param mixed $auth If user authentication is needed (true/false) + * or array with username and password + * + * @return array(HTTP_Request2, integer) HTTP request object and user id + * + * @uses getRequest() + */ + protected function getLoggedInRequest($urlSuffix = null, $auth = true) + { + $req = $this->getRequest($urlSuffix); + if (is_array($auth)) { + list($username, $password) = $auth; + } else { + $username = 'testuser'; + $password = 'testpassword'; + } + $uid = $this->addUser($username, $password); + + //FIXME: login via the login form, check if it worked + //FIXME: prepare new request with cookie + return array($req, $uid); + } + } ?> \ No newline at end of file diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php new file mode 100644 index 0000000..7f46888 --- /dev/null +++ b/tests/ajax/GetContactTagsTest.php @@ -0,0 +1,73 @@ + + * @author Christian Weiske + * @author Eric Dane + * @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'; + +/** + * Unit tests for the ajax getcontacttags.php script + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class ajax_GetContactTagsTest extends TestBaseApi +{ + protected $urlPart = 'ajax/getcontacttags.php'; + + + /** + * If no user is logged in, no data are returned + */ + public function testNoUserLoggedIn() + { + $res = $this->getRequest()->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(0, count($data)); + } + + + public function testUserLoggedIn() + { + list($req, $uId) = $this->getAuthRequest(); + $this->addBookmark($uId, null, 0, array('public')); + $this->addBookmark($uId, null, 1, array('shared')); + $this->addBookmark($uId, null, 2, array('private')); + + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(3, count($data)); + $this->assertContains('public', $data); + $this->assertContains('shared', $data); + $this->assertContains('private', $data); + } +} + + +?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 0f9d06c6644f634b436549f0d5e56fc96ebd361c Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 26 Mar 2011 10:00:18 +0100 Subject: first working unittest for ajax/getcontacttags with login! --- tests/TestBaseApi.php | 19 ++++++++++++++++--- tests/ajax/GetContactTagsTest.php | 20 ++++++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index b7c1921..2af228a 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -131,7 +131,6 @@ class TestBaseApi extends TestBase */ protected function getLoggedInRequest($urlSuffix = null, $auth = true) { - $req = $this->getRequest($urlSuffix); if (is_array($auth)) { list($username, $password) = $auth; } else { @@ -140,8 +139,22 @@ class TestBaseApi extends TestBase } $uid = $this->addUser($username, $password); - //FIXME: login via the login form, check if it worked - //FIXME: prepare new request with cookie + $req = new HTTP_Request2( + $GLOBALS['unittestUrl'] . '/login.php', + HTTP_Request2::METHOD_POST + ); + $cookies = $req->setCookieJar()->getCookieJar(); + $req->addPostParameter('username', $username); + $req->addPostParameter('password', $password); + $req->addPostParameter('submitted', 'Log In'); + $res = $req->send(); + + //after login, we normally get redirected + $this->assertEquals(302, $res->getStatus(), 'Login failure'); + + $req = $this->getRequest($urlSuffix); + $req->setCookieJar($cookies); + return array($req, $uid); } diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php index 7f46888..757dce9 100644 --- a/tests/ajax/GetContactTagsTest.php +++ b/tests/ajax/GetContactTagsTest.php @@ -47,13 +47,17 @@ class ajax_GetContactTagsTest extends TestBaseApi } - public function testUserLoggedIn() + public function testUserLoggedInWatchlist() { - list($req, $uId) = $this->getAuthRequest(); - $this->addBookmark($uId, null, 0, array('public')); - $this->addBookmark($uId, null, 1, array('shared')); - $this->addBookmark($uId, null, 2, array('private')); - + list($req, $uId) = $this->getLoggedInRequest(); + $this->addBookmark($uId, null, 0, array('public', 'public2')); + + $user2 = $this->addUser(); + $this->us->setCurrentUserId($uId); + $this->us->setWatchStatus($user2); + //uId watches user2 now + $this->addBookmark($user2, null, 0, array('user2tag')); + $res = $req->send(); $this->assertEquals(200, $res->getStatus()); $this->assertEquals( @@ -64,8 +68,8 @@ class ajax_GetContactTagsTest extends TestBaseApi $this->assertInternalType('array', $data); $this->assertEquals(3, count($data)); $this->assertContains('public', $data); - $this->assertContains('shared', $data); - $this->assertContains('private', $data); + $this->assertContains('public2', $data); + $this->assertContains('user2tag', $data); } } -- cgit v1.2.3-54-g00ecf From 78654369e918126c137b5aa4ba709a7bc0a27b43 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 26 Mar 2011 11:54:47 +0100 Subject: test for beginsWith parameter and a bugfix :) --- tests/ajax/GetContactTagsTest.php | 17 +++++++++++++++++ www/ajax/getcontacttags.php | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php index 757dce9..6e40444 100644 --- a/tests/ajax/GetContactTagsTest.php +++ b/tests/ajax/GetContactTagsTest.php @@ -71,6 +71,23 @@ class ajax_GetContactTagsTest extends TestBaseApi $this->assertContains('public2', $data); $this->assertContains('user2tag', $data); } + + public function testParameterBeginsWith() + { + list($req, $uId) = $this->getLoggedInRequest('?beginsWith=bar'); + $this->addBookmark($uId, null, 0, array('foobar', 'barmann')); + + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(1, count($data)); + $this->assertContains('barmann', $data); + } } diff --git a/www/ajax/getcontacttags.php b/www/ajax/getcontacttags.php index 1377fea..d353226 100644 --- a/www/ajax/getcontacttags.php +++ b/www/ajax/getcontacttags.php @@ -36,7 +36,7 @@ if (isset($_GET['beginsWith']) && strlen(trim($_GET['beginsWith']))) { } $listTags = SemanticScuttle_Service_Factory::get('Bookmark2Tag')->getContactTags( - $currentUserId, $limit, $currentUserId, $beginsWith + $currentUserId, $limit, $currentUserId, null, $beginsWith ); $tags = array(); foreach ($listTags as $t) { -- cgit v1.2.3-54-g00ecf From 0935c984991defbc3b7d8549ffa020371d5688f3 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 26 Mar 2011 13:55:46 +0100 Subject: test the limit parameter --- tests/ajax/GetContactTagsTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php index 6e40444..682173b 100644 --- a/tests/ajax/GetContactTagsTest.php +++ b/tests/ajax/GetContactTagsTest.php @@ -88,6 +88,30 @@ class ajax_GetContactTagsTest extends TestBaseApi $this->assertEquals(1, count($data)); $this->assertContains('barmann', $data); } + + public function testParameterLimit() + { + list($req, $uId) = $this->getLoggedInRequest('?limit=2'); + $this->addBookmark($uId, null, 0, array('foo', 'bar', 'baz', 'omg')); + + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(2, count($data)); + + $req2 = $this->getRequest('?limit=3'); + $req2->setCookieJar($req->getCookieJar()); + $res = $req2->send(); + $this->assertEquals(200, $res->getStatus()); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(3, count($data)); + } } -- cgit v1.2.3-54-g00ecf From 361c18469af5f6782e622420797c4acd5fa70b97 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 26 Mar 2011 15:09:22 +0100 Subject: add new feature: allow unit test mode enabling via HTTP GET parameter --- data/config.default.php | 8 ++++++ src/SemanticScuttle/header.php | 16 ++++++++++- tests/TestBase.php | 63 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/data/config.default.php b/data/config.default.php index 3d60b91..af79891 100644 --- a/data/config.default.php +++ b/data/config.default.php @@ -735,4 +735,12 @@ $authEmailSuffix = null; */ $unittestUrl = null; +/** + * Allow "unittestMode=1" in URLs. + * Should only be enabled on development systems + * + * @var boolean + */ +$allowUnittestMode = false; + ?> diff --git a/src/SemanticScuttle/header.php b/src/SemanticScuttle/header.php index 9c5f7da..75e5204 100644 --- a/src/SemanticScuttle/header.php +++ b/src/SemanticScuttle/header.php @@ -39,6 +39,20 @@ set_include_path( require_once $datadir . '/config.default.php'; require_once $datadir . '/config.php'; +if (isset($_GET['unittestMode']) && $_GET['unittestMode'] == 1 +) { + if ($allowUnittestMode !== true) { + header('HTTP/1.0 400 Bad Request'); + die("Unittestmode is not allowed\n"); + } + + $unittestConfigFile = $datadir . '/config.unittest.php'; + if (file_exists($unittestConfigFile)) { + require_once $unittestConfigFile; + } + define('HTTP_UNIT_TEST_MODE', true); + define('UNIT_TEST_MODE', true); +} if (defined('UNIT_TEST_MODE')) { //make local config vars global - needed for unit tests //run with phpunit @@ -118,7 +132,7 @@ $tplVars['currentUser'] = $currentUser; $tplVars['userservice'] = $userservice; // 6 // Force UTF-8 behaviour for server (cannot be moved into top.inc.php which is not included into every file) -if (!defined('UNIT_TEST_MODE')) { +if (!defined('UNIT_TEST_MODE') || defined('HTTP_UNIT_TEST_MODE')) { //API files define that, so we need a way to support both of them if (!isset($httpContentType)) { if (DEBUG_MODE) { diff --git a/tests/TestBase.php b/tests/TestBase.php index 3e2e213..b85c189 100644 --- a/tests/TestBase.php +++ b/tests/TestBase.php @@ -22,6 +22,18 @@ */ class TestBase extends PHPUnit_Framework_TestCase { + /** + * Clean up after test + */ + public function tearDown() + { + if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) { + unlink($GLOBALS['datadir'] . '/config.unittest.php'); + } + } + + + /** * Create a new bookmark. * @@ -80,8 +92,25 @@ class TestBase extends PHPUnit_Framework_TestCase * @param string $password Password * * @return integer ID of user + * + * @uses addUserData() */ protected function addUser($username = null, $password = null) + { + return reset($this->addUserData($username, $password)); + } + + + + /** + * Creates a new user in the database and returns id, username and password. + * + * @param string $username Username + * @param string $password Password + * + * @return array ID of user, Name of user, password of user + */ + protected function addUserData($username = null, $password = null) { $us = SemanticScuttle_Service_Factory::get('User'); $rand = rand(); @@ -98,7 +127,7 @@ class TestBase extends PHPUnit_Framework_TestCase $password, 'unittest-' . $rand . '@example.org' ); - return $uid; + return array($uid, $username, $password); } @@ -129,6 +158,38 @@ class TestBase extends PHPUnit_Framework_TestCase return $uid; } + + + /** + * Writes a special unittest configuration file. + * The unittest config file is read when a GET request with unittestMode=1 + * is sent, and the user allowed unittestmode in config.php. + * + * @param array $arConfig Array with config names as key and their value as + * value + * + * @return void + */ + protected function setUnittestConfig($arConfig) + { + $str = '<' . "?php\r\n"; + foreach ($arConfig as $name => $value) { + $str .= '$' . $name . ' = ' + . var_export($value, true) . ";\n"; + } + + if (!is_dir($GLOBALS['datadir'])) { + $this->fail( + 'datadir not set or not a directory: ' . $GLOBALS['datadir'] + ); + } + + $this->assertInternalType( + 'integer', + file_put_contents($GLOBALS['datadir'] . '/config.unittest.php', $str), + 'Writing config.unittest.php failed' + ); + } } ?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf From a756799ef4df0449244d41c2ecc7133c3fb8ce70 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 26 Mar 2011 17:04:00 +0100 Subject: move setUnittestConfig to TestBaseApi since it makes only sense to use it there --- tests/TestBase.php | 44 ---------------------------- tests/TestBaseApi.php | 44 ++++++++++++++++++++++++++++ tests/ajax/GetAdminTagsTest.php | 63 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 44 deletions(-) create mode 100644 tests/ajax/GetAdminTagsTest.php (limited to 'tests') diff --git a/tests/TestBase.php b/tests/TestBase.php index b85c189..095f32d 100644 --- a/tests/TestBase.php +++ b/tests/TestBase.php @@ -22,18 +22,6 @@ */ class TestBase extends PHPUnit_Framework_TestCase { - /** - * Clean up after test - */ - public function tearDown() - { - if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) { - unlink($GLOBALS['datadir'] . '/config.unittest.php'); - } - } - - - /** * Create a new bookmark. * @@ -158,38 +146,6 @@ class TestBase extends PHPUnit_Framework_TestCase return $uid; } - - - /** - * Writes a special unittest configuration file. - * The unittest config file is read when a GET request with unittestMode=1 - * is sent, and the user allowed unittestmode in config.php. - * - * @param array $arConfig Array with config names as key and their value as - * value - * - * @return void - */ - protected function setUnittestConfig($arConfig) - { - $str = '<' . "?php\r\n"; - foreach ($arConfig as $name => $value) { - $str .= '$' . $name . ' = ' - . var_export($value, true) . ";\n"; - } - - if (!is_dir($GLOBALS['datadir'])) { - $this->fail( - 'datadir not set or not a directory: ' . $GLOBALS['datadir'] - ); - } - - $this->assertInternalType( - 'integer', - file_put_contents($GLOBALS['datadir'] . '/config.unittest.php', $str), - 'Writing config.unittest.php failed' - ); - } } ?> \ No newline at end of file diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 2af228a..2341ea1 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -57,6 +57,18 @@ class TestBaseApi extends TestBase + /** + * Clean up after test + */ + public function tearDown() + { + if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) { + unlink($GLOBALS['datadir'] . '/config.unittest.php'); + } + } + + + /** * Gets a HTTP request object. * Uses $this->url plus $urlSuffix as request URL. @@ -158,5 +170,37 @@ class TestBaseApi extends TestBase return array($req, $uid); } + + + /** + * Writes a special unittest configuration file. + * The unittest config file is read when a GET request with unittestMode=1 + * is sent, and the user allowed unittestmode in config.php. + * + * @param array $arConfig Array with config names as key and their value as + * value + * + * @return void + */ + protected function setUnittestConfig($arConfig) + { + $str = '<' . "?php\r\n"; + foreach ($arConfig as $name => $value) { + $str .= '$' . $name . ' = ' + . var_export($value, true) . ";\n"; + } + + if (!is_dir($GLOBALS['datadir'])) { + $this->fail( + 'datadir not set or not a directory: ' . $GLOBALS['datadir'] + ); + } + + $this->assertInternalType( + 'integer', + file_put_contents($GLOBALS['datadir'] . '/config.unittest.php', $str), + 'Writing config.unittest.php failed' + ); + } } ?> \ No newline at end of file diff --git a/tests/ajax/GetAdminTagsTest.php b/tests/ajax/GetAdminTagsTest.php new file mode 100644 index 0000000..5c941e8 --- /dev/null +++ b/tests/ajax/GetAdminTagsTest.php @@ -0,0 +1,63 @@ + + * @author Christian Weiske + * @author Eric Dane + * @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'; + +/** + * Unit tests for the ajax getadmintags.php script + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class ajax_GetAdminTagsTest extends TestBaseApi +{ + protected $urlPart = 'ajax/getadmintags.php'; + + + public function testTags() + { + list($user1, $uname1) = $this->addUserData(); + $user2 = $this->addUser(); + $this->addBookmark($user1, null, 0, array('admintag', 'admintag2')); + $this->addBookmark($user2, null, 0, array('lusertag', 'lusertag2')); + + $this->setUnittestConfig( + array( + 'admin_users' => array($uname1) + ) + ); + + $req = $this->getRequest('?unittestMode=1'); + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(2, count($data)); + $this->assertContains('admintag', $data); + $this->assertContains('admintag2', $data); + } + +} + + +?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 1dfff5d3d81fdb67e4c78136168801a488fcf139 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 28 Mar 2011 08:01:02 +0200 Subject: add tests for getadmintags beginsWith and limit parameters --- tests/ajax/GetAdminTagsTest.php | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'tests') diff --git a/tests/ajax/GetAdminTagsTest.php b/tests/ajax/GetAdminTagsTest.php index 5c941e8..6afe45c 100644 --- a/tests/ajax/GetAdminTagsTest.php +++ b/tests/ajax/GetAdminTagsTest.php @@ -57,6 +57,85 @@ class ajax_GetAdminTagsTest extends TestBaseApi $this->assertContains('admintag2', $data); } + public function testParameterBeginsWith() + { + list($user1, $uname1) = $this->addUserData(); + $this->addBookmark($user1, null, 0, array('foo', 'foobar', 'bar')); + + $this->setUnittestConfig( + array( + 'admin_users' => array($uname1) + ) + ); + + $req = $this->getRequest('?unittestMode=1&beginsWith=foo'); + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(2, count($data)); + $this->assertContains('foo', $data); + $this->assertContains('foobar', $data); + } + + + + public function testParameterLimit() + { + list($user1, $uname1) = $this->addUserData(); + list($user2, $uname2) = $this->addUserData(); + $this->addBookmark($user1, null, 0, array('foo', 'foobar')); + $this->addBookmark($user2, null, 0, array('foo', 'bar')); + + $this->setUnittestConfig( + array( + 'admin_users' => array($uname1, $uname2) + ) + ); + + $req = $this->getRequest('?unittestMode=1&limit=1'); + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(1, count($data)); + $this->assertContains('foo', $data); + + $req = $this->getRequest('?unittestMode=1&limit=2'); + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(2, count($data)); + $this->assertContains('foo', $data); + + $req = $this->getRequest('?unittestMode=1&limit=3'); + $res = $req->send(); + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + $data = json_decode($res->getBody()); + $this->assertInternalType('array', $data); + $this->assertEquals(3, count($data)); + $this->assertContains('foo', $data); + $this->assertContains('foobar', $data); + $this->assertContains('bar', $data); + } + } -- cgit v1.2.3-54-g00ecf From a5bd7789297378be3fb8dc3814c6649ea82a88d8 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 28 Mar 2011 08:34:12 +0200 Subject: introduce assertResponseJson200 for API/ajax tests and use it --- tests/TestBaseApi.php | 19 +++++++++++++++++++ tests/ajax/GetAdminLinkedTagsTest.php | 20 +++----------------- tests/ajax/GetAdminTagsTest.php | 30 +++++------------------------- tests/ajax/GetContactTagsTest.php | 26 +++++--------------------- 4 files changed, 32 insertions(+), 63 deletions(-) (limited to 'tests') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 2341ea1..f054973 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -172,6 +172,25 @@ class TestBaseApi extends TestBase + /** + * Verifies that the HTTP response has status code 200 and + * content-type application/json; charset=utf-8 + * + * @param HTTP_Request2_Response $res HTTP Response object + * + * @return void + */ + protected function assertResponseJson200(HTTP_Request2_Response $res) + { + $this->assertEquals(200, $res->getStatus()); + $this->assertEquals( + 'application/json; charset=utf-8', + $res->getHeader('content-type') + ); + } + + + /** * Writes a special unittest configuration file. * The unittest config file is read when a GET request with unittestMode=1 diff --git a/tests/ajax/GetAdminLinkedTagsTest.php b/tests/ajax/GetAdminLinkedTagsTest.php index 2552ea0..aded834 100644 --- a/tests/ajax/GetAdminLinkedTagsTest.php +++ b/tests/ajax/GetAdminLinkedTagsTest.php @@ -58,13 +58,7 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi { $req = $this->getRequest(); $res = $req->send(); - - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); - + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); @@ -99,11 +93,7 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi ); $res = $this->getRequest('?tag=' . $menu2Tag)->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); @@ -139,11 +129,7 @@ class ajax_GetAdminLinkedTagsTest extends TestBaseApi ); $res = $this->getRequest('?tag=' . $menu2Tag)->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); diff --git a/tests/ajax/GetAdminTagsTest.php b/tests/ajax/GetAdminTagsTest.php index 6afe45c..80d702f 100644 --- a/tests/ajax/GetAdminTagsTest.php +++ b/tests/ajax/GetAdminTagsTest.php @@ -45,11 +45,7 @@ class ajax_GetAdminTagsTest extends TestBaseApi $req = $this->getRequest('?unittestMode=1'); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(2, count($data)); @@ -70,12 +66,8 @@ class ajax_GetAdminTagsTest extends TestBaseApi $req = $this->getRequest('?unittestMode=1&beginsWith=foo'); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); $data = json_decode($res->getBody()); + $this->assertResponseJson200($res); $this->assertInternalType('array', $data); $this->assertEquals(2, count($data)); $this->assertContains('foo', $data); @@ -99,11 +91,7 @@ class ajax_GetAdminTagsTest extends TestBaseApi $req = $this->getRequest('?unittestMode=1&limit=1'); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(1, count($data)); @@ -111,11 +99,7 @@ class ajax_GetAdminTagsTest extends TestBaseApi $req = $this->getRequest('?unittestMode=1&limit=2'); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(2, count($data)); @@ -123,11 +107,7 @@ class ajax_GetAdminTagsTest extends TestBaseApi $req = $this->getRequest('?unittestMode=1&limit=3'); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(3, count($data)); diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php index 682173b..559040f 100644 --- a/tests/ajax/GetContactTagsTest.php +++ b/tests/ajax/GetContactTagsTest.php @@ -36,11 +36,7 @@ class ajax_GetContactTagsTest extends TestBaseApi public function testNoUserLoggedIn() { $res = $this->getRequest()->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(0, count($data)); @@ -59,11 +55,7 @@ class ajax_GetContactTagsTest extends TestBaseApi $this->addBookmark($user2, null, 0, array('user2tag')); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(3, count($data)); @@ -78,11 +70,7 @@ class ajax_GetContactTagsTest extends TestBaseApi $this->addBookmark($uId, null, 0, array('foobar', 'barmann')); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(1, count($data)); @@ -95,11 +83,7 @@ class ajax_GetContactTagsTest extends TestBaseApi $this->addBookmark($uId, null, 0, array('foo', 'bar', 'baz', 'omg')); $res = $req->send(); - $this->assertEquals(200, $res->getStatus()); - $this->assertEquals( - 'application/json; charset=utf-8', - $res->getHeader('content-type') - ); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(2, count($data)); @@ -107,7 +91,7 @@ class ajax_GetContactTagsTest extends TestBaseApi $req2 = $this->getRequest('?limit=3'); $req2->setCookieJar($req->getCookieJar()); $res = $req2->send(); - $this->assertEquals(200, $res->getStatus()); + $this->assertResponseJson200($res); $data = json_decode($res->getBody()); $this->assertInternalType('array', $data); $this->assertEquals(3, count($data)); -- cgit v1.2.3-54-g00ecf From 90f29d6e671f4c24f75bdc4774f223c53bf0a46c Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 12 Apr 2011 08:47:44 +0200 Subject: first test for service factory --- src/SemanticScuttle/Service/Factory.php | 3 ++- tests/FactoryTest.php | 13 +++++++++++++ tests/phpunit.xml | 12 ++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 tests/FactoryTest.php (limited to 'tests') diff --git a/src/SemanticScuttle/Service/Factory.php b/src/SemanticScuttle/Service/Factory.php index d7ff1d4..b661cdb 100644 --- a/src/SemanticScuttle/Service/Factory.php +++ b/src/SemanticScuttle/Service/Factory.php @@ -107,6 +107,7 @@ class SemanticScuttle_Service_Factory /** * Loads self::$db if it is not loaded already. + * Dies if the connection could not be established. * * @return void */ @@ -141,7 +142,7 @@ class SemanticScuttle_Service_Factory /** * Returns sql database object * - * @return void + * @return sql_db Database instance */ public static function getDb() { diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php new file mode 100644 index 0000000..980e92e --- /dev/null +++ b/tests/FactoryTest.php @@ -0,0 +1,13 @@ +assertInstanceOf( + 'sql_db', + SemanticScuttle_Service_Factory::getDb() + ); + } +} +?> \ No newline at end of file diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 734fa95..86b7b60 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -1,8 +1,12 @@ - + - - . - + + ../src/SemanticScuttle/ + ../data/templates/ + ../www/ + \ No newline at end of file -- cgit v1.2.3-54-g00ecf 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') 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-54-g00ecf From 542824a9ba6da477c0e1969b1c8815d0561dfcdf Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 14 Apr 2011 16:53:09 +0200 Subject: include HTTP_Request2 in api base file --- tests/TestBaseApi.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index f054973..8ed41cd 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -11,6 +11,8 @@ * @link http://sourceforge.net/projects/semanticscuttle */ +require_once 'HTTP/Request2.php'; + /** * Base unittest class for web API tests. * -- cgit v1.2.3-54-g00ecf From f5ac88ea87723f68d600470140102113ef3838bb Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 14 Apr 2011 16:53:46 +0200 Subject: test that opensearch link is the main page HTML head --- tests/Api/OpenSearchTest.php | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/Api/OpenSearchTest.php (limited to 'tests') diff --git a/tests/Api/OpenSearchTest.php b/tests/Api/OpenSearchTest.php new file mode 100644 index 0000000..346f026 --- /dev/null +++ b/tests/Api/OpenSearchTest.php @@ -0,0 +1,52 @@ +getRequest(); + $xhtml = $req->send()->getBody(); + + $xml = simplexml_load_string($xhtml); + $xml->registerXPathNamespace('h', reset($xml->getDocNamespaces())); + + $this->assertInstanceOf( + 'SimpleXMLElement', $xml, + 'SemanticScuttle main page XHTML could not be loaded - maybe invalid?' + ); + + $arElements = $xml->xpath( + '//h:head/h:link' + . '[@rel="search" and @type="application/opensearchdescription+xml"]' + ); + $this->assertEquals( + 1, count($arElements), + 'OpenSearch link in HTML is missing' + ); + $searchDescUrl = (string)$arElements[0]['href']; + $this->assertNotNull($searchDescUrl, 'Search description URL is empty'); + + //FIXME: verify that URL exists + $req = new HTTP_Request2($searchDescUrl); + $res = $req->send(); + $this->assertEquals( + 200, $res->getStatus(), + 'HTTP response status code is not 200' + ); + + $this->assertEquals( + $GLOBALS['unittestUrl'] . 'api/opensearch.php', + $searchDescUrl, + 'OpenSearch URL found, but it is not the expected one.' + . ' It may be that you misconfigured the "unittestUrl" setting' + ); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf From dbccc1781e374f36225a3bdbc37b6f43d698a0b5 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 14 Apr 2011 16:55:51 +0200 Subject: remove fixme --- tests/Api/OpenSearchTest.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/Api/OpenSearchTest.php b/tests/Api/OpenSearchTest.php index 346f026..72b4e4d 100644 --- a/tests/Api/OpenSearchTest.php +++ b/tests/Api/OpenSearchTest.php @@ -31,7 +31,6 @@ class Api_OpenSearchTest extends TestBaseApi $searchDescUrl = (string)$arElements[0]['href']; $this->assertNotNull($searchDescUrl, 'Search description URL is empty'); - //FIXME: verify that URL exists $req = new HTTP_Request2($searchDescUrl); $res = $req->send(); $this->assertEquals( -- cgit v1.2.3-54-g00ecf From 8a87a245b8bba49abd6ad7f9f457c421b09d9e30 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 14 Apr 2011 16:58:47 +0200 Subject: test opensearch api content type --- tests/Api/OpenSearchTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/Api/OpenSearchTest.php b/tests/Api/OpenSearchTest.php index 72b4e4d..a242319 100644 --- a/tests/Api/OpenSearchTest.php +++ b/tests/Api/OpenSearchTest.php @@ -6,7 +6,6 @@ class Api_OpenSearchTest extends TestBaseApi protected $urlPart = ''; - public function testOpenSearchAvailable() { $req = $this->getRequest(); @@ -46,6 +45,15 @@ class Api_OpenSearchTest extends TestBaseApi ); } + public function testOpenSearchContentType() + { + $res = $this->getRequest('api/opensearch.php')->send(); + $this->assertEquals( + 'text/xml; charset=utf-8', + $res->getHeader('content-type') + ); + } + } ?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 5d22905ce7eb97d60c3dafddc3e96136a2b94436 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 14 Apr 2011 17:04:57 +0200 Subject: verify we get the correct search URL --- tests/Api/OpenSearchTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests') diff --git a/tests/Api/OpenSearchTest.php b/tests/Api/OpenSearchTest.php index a242319..050713b 100644 --- a/tests/Api/OpenSearchTest.php +++ b/tests/Api/OpenSearchTest.php @@ -54,6 +54,23 @@ class Api_OpenSearchTest extends TestBaseApi ); } + public function testOpenSearchSearchUrl() + { + $xml = $this->getRequest('api/opensearch.php')->send()->getBody(); + $x = simplexml_load_string($xml); + $x->registerXPathNamespace('os', reset($x->getDocNamespaces())); + + $arElements = $x->xpath('//os:Url[@type="text/html"]'); + $this->assertEquals( + 1, count($arElements), + 'Url in OpenSearch description is missing' + ); + $this->assertEquals( + $GLOBALS['unittestUrl'] . 'search.php/all/{searchTerms}', + (string)$arElements[0]['template'] + ); + } + } ?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf From a25838b267f76c027318df268797842b52d6ecea Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 15 Apr 2011 07:55:06 +0200 Subject: Fix bug #3097187: Using opensearch with two tags does not work in Firefox --- doc/ChangeLog | 1 + tests/www/searchTest.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ www/search.php | 10 +++++---- 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 tests/www/searchTest.php (limited to 'tests') diff --git a/doc/ChangeLog b/doc/ChangeLog index 273e84b..a7374e2 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -6,6 +6,7 @@ ChangeLog for SemantiScuttle - Switch to jQuery and drop dojo - Fix bug #3187177: Wrong URL / Export XML Bookmarks - Fix bug in getTagsForBookmarks() that fetched all tags +- Fix bug #3097187: Using opensearch with two tags does not work in Firefox - Implement request #3054906: Show user's full name instead of nickname - Implement patch #3059829: update FR_CA translation - Show error message on mysqli connection errors diff --git a/tests/www/searchTest.php b/tests/www/searchTest.php new file mode 100644 index 0000000..81eb2cc --- /dev/null +++ b/tests/www/searchTest.php @@ -0,0 +1,53 @@ +addBookmark(null, null, 0, null, 'unittest foo bar'); + $res = $this->getRequest('/all/foo+bar')->send(); + $this->assertSelectCount( + '.xfolkentry', true, $res->getBody(), + 'No bookmark found' + ); + + $res = $this->getRequest('/all/baz+bat')->send(); + $this->assertSelectCount( + '.xfolkentry', false, $res->getBody(), + 'Bookmarks found' + ); + } + + + /** + * Some browsers using opensearch do "rawurlencode" on the terms, + * for example Opera. Multiple terms separated with space + * appear as "foo%20bar" in the URL. + */ + public function testMultipleTermsRawUrlEncoded() + { + $this->addBookmark(null, null, 0, null, 'unittest foo bar'); + $res = $this->getRequest('/all/foo bar')->send(); + $this->assertSelectCount( + '.xfolkentry', true, $res->getBody(), + 'No bookmark found' + ); + + $res = $this->getRequest('/all/baz bat')->send(); + $this->assertSelectCount( + '.xfolkentry', false, $res->getBody(), + 'Bookmarks found' + ); + } + +} + +?> \ No newline at end of file diff --git a/www/search.php b/www/search.php index 3cff550..a5c13e3 100644 --- a/www/search.php +++ b/www/search.php @@ -40,8 +40,8 @@ if (POST_TERMS != '') { } /* Service creation: only useful services are created */ -$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); -$searchhistoryservice =SemanticScuttle_Service_Factory::get('SearchHistory'); +$bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark'); +$searchhistoryservice = SemanticScuttle_Service_Factory::get('SearchHistory'); /* Managing current logged user */ $currentUserId = $userservice->getCurrentUserId(); @@ -53,11 +53,13 @@ if(count($exploded) == 4) { list($url, $range, $terms, $page) = $exploded; } else if (count($exploded) == 2) { list($url, $range) = $exploded; - $terms = $page= NULL; + $terms = $page = NULL; } else { list($url, $range, $terms) = $exploded; - $page= NULL; + $page = NULL; } +//some OpenSearch clients need that +$terms = urldecode($terms); $tplVars['loadjs'] = true; -- cgit v1.2.3-54-g00ecf From b2c48977bb34f4f59eba06f5b363f281deae2ef0 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 15 Apr 2011 07:56:50 +0200 Subject: use xml parser, not html --- tests/www/searchTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/www/searchTest.php b/tests/www/searchTest.php index 81eb2cc..e783a49 100644 --- a/tests/www/searchTest.php +++ b/tests/www/searchTest.php @@ -16,13 +16,13 @@ class www_SearchTest extends TestBaseApi $res = $this->getRequest('/all/foo+bar')->send(); $this->assertSelectCount( '.xfolkentry', true, $res->getBody(), - 'No bookmark found' + 'No bookmark found', false ); $res = $this->getRequest('/all/baz+bat')->send(); $this->assertSelectCount( '.xfolkentry', false, $res->getBody(), - 'Bookmarks found' + 'Bookmarks found', false ); } @@ -38,13 +38,13 @@ class www_SearchTest extends TestBaseApi $res = $this->getRequest('/all/foo bar')->send(); $this->assertSelectCount( '.xfolkentry', true, $res->getBody(), - 'No bookmark found' + 'No bookmark found', false ); $res = $this->getRequest('/all/baz bat')->send(); $this->assertSelectCount( '.xfolkentry', false, $res->getBody(), - 'Bookmarks found' + 'Bookmarks found', false ); } -- cgit v1.2.3-54-g00ecf From 0f0a95998e373420549251be86407f9ca478fc1d Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 15 Apr 2011 08:00:26 +0200 Subject: use correct url --- tests/www/searchTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/www/searchTest.php b/tests/www/searchTest.php index e783a49..cd7b2a5 100644 --- a/tests/www/searchTest.php +++ b/tests/www/searchTest.php @@ -35,7 +35,7 @@ class www_SearchTest extends TestBaseApi public function testMultipleTermsRawUrlEncoded() { $this->addBookmark(null, null, 0, null, 'unittest foo bar'); - $res = $this->getRequest('/all/foo bar')->send(); + $res = $this->getRequest('/all/foo%20bar')->send(); $this->assertSelectCount( '.xfolkentry', true, $res->getBody(), 'No bookmark found', false -- cgit v1.2.3-54-g00ecf From a1989cff0675642146e0ba52aac4c6b10cdd9ae5 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 15 Apr 2011 19:15:57 +0200 Subject: add test to search for multiple tags, which fails currently --- tests/www/searchTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/www/searchTest.php b/tests/www/searchTest.php index cd7b2a5..1220667 100644 --- a/tests/www/searchTest.php +++ b/tests/www/searchTest.php @@ -48,6 +48,21 @@ class www_SearchTest extends TestBaseApi ); } + + public function testMultipleTags() + { + $this->markTestSkipped( + 'FIXME: SemanticScuttle currently does not search multiple tags' + ); + + $this->addBookmark(null, null, 0, array('foo', 'bar')); + $res = $this->getRequest('/all/foo+bar')->send(); + $this->assertSelectCount( + '.xfolkentry', true, $res->getBody(), + 'No bookmark found', false + ); + } + } ?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 40b4674e471f8b0fbdc77a26eec86018e2ab03ea Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 15 Apr 2011 19:22:19 +0200 Subject: exclude database layer files from coverage --- tests/phpunit.xml | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 86b7b60..3956445 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -7,6 +7,9 @@ ../src/SemanticScuttle/ ../data/templates/ ../www/ + + ../src/SemanticScuttle/db/ + \ No newline at end of file -- cgit v1.2.3-54-g00ecf