summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2011-05-02 18:07:15 +0200
committerChristian Weiske <cweiske@cweiske.de>2011-05-02 18:07:15 +0200
commit8be81abfe6193e221afcdc35582d34505797a7b8 (patch)
tree95ae7e30d40596f27875adb2f96a15fc827f9f86 /tests
parentf629d081ddf52e3cb83ffbfc973a97adc691790c (diff)
parent40b4674e471f8b0fbdc77a26eec86018e2ab03ea (diff)
downloadsemanticscuttle-8be81abfe6193e221afcdc35582d34505797a7b8.tar.gz
semanticscuttle-8be81abfe6193e221afcdc35582d34505797a7b8.tar.bz2
merge master
Diffstat (limited to 'tests')
-rw-r--r--tests/AllTests.php25
-rw-r--r--tests/Api/ExportCsvTest.php25
-rw-r--r--tests/Api/OpenSearchTest.php76
-rw-r--r--tests/Api/PostsAddTest.php46
-rw-r--r--tests/Api/PostsDeleteTest.php25
-rw-r--r--tests/Api/PostsUpdateTest.php25
-rw-r--r--tests/Bookmark2TagTest.php441
-rw-r--r--tests/BookmarkTest.php26
-rw-r--r--tests/CommonDescriptionTest.php25
-rw-r--r--tests/FactoryTest.php13
-rw-r--r--tests/SearchHistoryTest.php27
-rw-r--r--tests/Tag2TagTest.php25
-rw-r--r--tests/TagTest.php26
-rw-r--r--tests/TagsCacheTest.php23
-rw-r--r--tests/TestBase.php5
-rw-r--r--tests/TestBaseApi.php24
-rw-r--r--tests/UserArrayTest.php66
-rw-r--r--tests/UserTest.php29
-rw-r--r--tests/VoteTest.php25
-rw-r--r--tests/ajax/GetAdminLinkedTagsTest.php120
-rw-r--r--tests/ajax/GetAdminTagsTest.php71
-rw-r--r--tests/ajax/GetContactTagsTest.php100
-rw-r--r--tests/phpunit.xml15
-rw-r--r--tests/www/searchTest.php68
24 files changed, 984 insertions, 367 deletions
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
*
@@ -40,21 +34,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
*/
public function testAuthWithoutAuthData()
@@ -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/OpenSearchTest.php b/tests/Api/OpenSearchTest.php
new file mode 100644
index 0000000..050713b
--- /dev/null
+++ b/tests/Api/OpenSearchTest.php
@@ -0,0 +1,76 @@
+<?php
+
+
+class Api_OpenSearchTest extends TestBaseApi
+{
+ protected $urlPart = '';
+
+
+ public function testOpenSearchAvailable()
+ {
+ $req = $this->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');
+
+ $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'
+ );
+ }
+
+ public function testOpenSearchContentType()
+ {
+ $res = $this->getRequest('api/opensearch.php')->send();
+ $this->assertEquals(
+ 'text/xml; charset=utf-8',
+ $res->getHeader('content-type')
+ );
+ }
+
+ 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
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index 3c1177f..24cc600 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.
*
@@ -38,28 +32,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__)
- );
- }
-
-
- public function setUp()
- {
- parent::setUp();
- $this->bs->deleteAll();
- }
-
-
-
- /**
* Test if authentication is required when sending no auth data
*/
public function testAuthWithoutAuthData()
@@ -89,6 +61,8 @@ class Api_PostsAddTest extends TestBaseApi
*/
public function testAddBookmarkPost()
{
+ $this->bs->deleteAll();
+
$bmUrl = 'http://example.org/tag-1';
$bmTags = array('foo', 'bar', 'baz');
$bmDatetime = '2010-09-08T03:02:01Z';
@@ -149,6 +123,8 @@ TXT;
*/
public function testAddBookmarkGet()
{
+ $this->bs->deleteAll();
+
$bmUrl = 'http://example.org/tag-1';
$bmTags = array('foo', 'bar', 'baz');
$bmDatetime = '2010-09-08T03:02:01Z';
@@ -208,6 +184,8 @@ TXT;
*/
public function testUrlDescEnough()
{
+ $this->bs->deleteAll();
+
list($req, $uId) = $this->getAuthRequest();
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->addPostParameter('url', 'http://example.org/tag2');
@@ -242,6 +220,8 @@ TXT;
*/
public function testUrlRequired()
{
+ $this->bs->deleteAll();
+
list($req, $uId) = $this->getAuthRequest();
$req->setMethod(HTTP_Request2::METHOD_POST);
//$req->addPostParameter('url', 'http://example.org/tag2');
@@ -276,6 +256,8 @@ TXT;
*/
public function testDescriptionRequired()
{
+ $this->bs->deleteAll();
+
list($req, $uId) = $this->getAuthRequest();
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->addPostParameter('url', 'http://example.org/tag2');
@@ -310,6 +292,8 @@ TXT;
*/
public function testReplaceNo()
{
+ $this->bs->deleteAll();
+
$url = 'http://example.org/tag2';
$title1 = 'foo bar 1';
$title2 = 'bar 2 foo';
@@ -376,6 +360,8 @@ TXT;
*/
public function testReplaceYes()
{
+ $this->bs->deleteAll();
+
$url = 'http://example.org/tag2';
$title1 = 'foo bar 1';
$title2 = 'bar 2 foo';
@@ -625,8 +611,4 @@ TXT;
}
-
-if (PHPUnit_MAIN_METHOD == 'Api_PostsAddTest::main') {
- Api_PostsAddTest::main();
-}
?>
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.
*
@@ -38,21 +32,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
*/
public function testAuthWithoutAuthData()
@@ -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.
*
@@ -38,21 +32,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
*/
public function testAuthWithoutAuthData()
@@ -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 1823c60..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.
@@ -37,17 +32,22 @@ class Bookmark2TagTest extends TestBase
protected $tts;
-
/**
- * Used to run this test class standalone
+ * Create a bookmark. Like addBookmark(), just with other paramter order
+ * to make some tests in that class easier to write.
*
- * @return void
+ * @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
*/
- public static function main()
+ protected function addTagBookmark($user, $tags, $date = null, $title = null)
{
- require_once 'PHPUnit/TextUI/TestRunner.php';
- PHPUnit_TextUI_TestRunner::run(
- new PHPUnit_Framework_TestSuite(__CLASS__)
+ return $this->addBookmark(
+ $user, null, 0, $tags, $title, $date
);
}
@@ -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');
@@ -73,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()
{
@@ -91,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()
{
@@ -110,9 +111,9 @@ class Bookmark2TagTest extends TestBase
/**
* Test getTagsForBookmark() when the bookmark has three tags
*
- * @return void
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getTagsForBookmark
*/
- public function testGetTagsForBookmarkThree()
+ public function testGetTagsForBookmarkThr()
{
$this->addBookmark(null, null, 0, array('forz', 'barz'));
@@ -131,7 +132,7 @@ class Bookmark2TagTest extends TestBase
/**
* Test getTagsForBookmarks() when no bookmarks have tags.
*
- * @return void
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getTagsForBookmarks
*/
public function testGetTagsForBookmarksNone()
{
@@ -154,7 +155,7 @@ class Bookmark2TagTest extends TestBase
/**
* Test getTagsForBookmarks() when most bookmarks have tags.
*
- * @return void
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getTagsForBookmarks
*/
public function testGetTagsForBookmarksMost()
{
@@ -204,9 +205,407 @@ class Bookmark2TagTest extends TestBase
}
}
}
-}
-if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') {
- Bookmark2TagTest::main();
+
+
+ /**
+ * Fetch the most popular tags in descending order
+ *
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags
+ */
+ public function testGetPopularTagsOrder()
+ {
+ $user = $this->addUser();
+ $this->addTagBookmark($user, array('one', 'two'));
+ $this->addTagBookmark($user, array('one', 'thr'));
+ $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' => 'thr', 'bCount' => '1')
+ ),
+ $arTags
+ );
+ }
+
+
+
+ /**
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags
+ */
+ public function testGetPopularTagsLimit()
+ {
+ $user = $this->addUser();
+ $this->addTagBookmark($user, array('one', 'two'));
+ $this->addTagBookmark($user, array('one', 'thr'));
+ $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
+ );
+ }
+
+
+
+ /**
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags
+ */
+ public function testGetPopularTagsDays()
+ {
+ $user = $this->addUser();
+ $this->addTagBookmark($user, array('one', 'two'), 'today');
+ $this->addTagBookmark($user, array('one', 'thr'), 'today');
+ $this->addTagBookmark($user, array('one', 'two'), '-1 day 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' => 'thr', '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' => 'thr', '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' => '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);
+ }
+
+
+
+ /**
+ * @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', 'thr'));
+
+ $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' => 'thr', 'bCount' => '1'), $arTags);
+ }
+
+
+
+ /**
+ * 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
+ */
+ public function testGetPopularTagsPublicOnlyNoUser()
+ {
+ $user1 = $this->addUser();
+ $this->addBookmark($user1, null, 0, array('one'));
+ $this->addBookmark($user1, null, 1, array('one', 'two'));
+ $this->addBookmark($user1, null, 2, array('thr'));
+
+ $arTags = $this->b2ts->getPopularTags();
+ $this->assertEquals(1, count($arTags));
+ $this->assertEquals(
+ array(
+ array('tag' => 'one', 'bCount' => '1'),
+ ),
+ $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'));
+ $this->addBookmark($user1, null, 2, array('thr'));
+
+ $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 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
+ */
+ 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('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' => 'thr', 'bCount' => '1'), $arTags);
+ }
+
+
+ /**
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getAdminTags
+ */
+ 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);
+ }
+
+ /**
+ * @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);
+ }
+
+
+
+ /**
+ * @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);
+ }
+
+ /**
+ * @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);
+ }
}
?> \ 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');
@@ -1345,9 +1324,4 @@ 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/FactoryTest.php b/tests/FactoryTest.php
new file mode 100644
index 0000000..980e92e
--- /dev/null
+++ b/tests/FactoryTest.php
@@ -0,0 +1,13 @@
+<?php
+
+class FactoryTest extends TestBase
+{
+ public function testGetDb()
+ {
+ $this->assertInstanceOf(
+ 'sql_db',
+ SemanticScuttle_Service_Factory::getDb()
+ );
+ }
+}
+?> \ No newline at end of file
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/TestBase.php b/tests/TestBase.php
index 5a61b7b..095f32d 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;
diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php
index 9759db5..23e1812 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.
*
@@ -89,7 +91,8 @@ class TestBaseApi extends TestBase
* the request object with authentication details, so that
* the user is logged in.
*
- * Only usable for API requests, not "normal" HTTP page requests
+ * 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)
@@ -166,6 +169,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
* is sent, and the user allowed unittestmode in config.php.
diff --git a/tests/UserArrayTest.php b/tests/UserArrayTest.php
new file mode 100644
index 0000000..a60e37f
--- /dev/null
+++ b/tests/UserArrayTest.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+
+/**
+ * Unit tests for the SemanticScuttle user array model.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @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
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
new file mode 100644
index 0000000..43cb17a
--- /dev/null
+++ b/tests/ajax/GetAdminLinkedTagsTest.php
@@ -0,0 +1,120 @@
+<?php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @author Eric Dane <ericdane@users.sourceforge.net>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+require_once 'HTTP/Request2.php';
+
+/**
+ * Unit tests for the ajax linked admin tags script
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @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';
+
+
+ /**
+ * 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->assertResponseJson200($res);
+ $data = json_decode($res->getBody());
+ $this->assertInternalType('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->assertResponseJson200($res);
+
+ $data = json_decode($res->getBody());
+ $this->assertInternalType('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->assertResponseJson200($res);
+
+ $data = json_decode($res->getBody());
+ $this->assertInternalType('array', $data);
+
+ //we should have only one subtag now, the admin one
+ $this->assertEquals(1, count($data));
+ $this->assertEquals('adminsubtag', $data[0]->data->title);
+ }
+}
+?> \ No newline at end of file
diff --git a/tests/ajax/GetAdminTagsTest.php b/tests/ajax/GetAdminTagsTest.php
index 5c941e8..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';
/**
@@ -45,11 +43,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));
@@ -57,6 +51,69 @@ 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();
+ $data = json_decode($res->getBody());
+ $this->assertResponseJson200($res);
+ $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->assertResponseJson200($res);
+ $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->assertResponseJson200($res);
+ $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->assertResponseJson200($res);
+ $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);
+ }
+
}
diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php
new file mode 100644
index 0000000..268ed66
--- /dev/null
+++ b/tests/ajax/GetContactTagsTest.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @author Eric Dane <ericdane@users.sourceforge.net>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+require_once 'HTTP/Request2.php';
+
+/**
+ * Unit tests for the ajax getcontacttags.php script
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @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->assertResponseJson200($res);
+ $data = json_decode($res->getBody());
+ $this->assertInternalType('array', $data);
+ $this->assertEquals(0, count($data));
+ }
+
+
+ public function testUserLoggedInWatchlist()
+ {
+ 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->assertResponseJson200($res);
+ $data = json_decode($res->getBody());
+ $this->assertInternalType('array', $data);
+ $this->assertEquals(3, count($data));
+ $this->assertContains('public', $data);
+ $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->assertResponseJson200($res);
+ $data = json_decode($res->getBody());
+ $this->assertInternalType('array', $data);
+ $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->assertResponseJson200($res);
+ $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->assertResponseJson200($res);
+ $data = json_decode($res->getBody());
+ $this->assertInternalType('array', $data);
+ $this->assertEquals(3, count($data));
+ }
+}
+
+
+?> \ No newline at end of file
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
new file mode 100644
index 0000000..3956445
--- /dev/null
+++ b/tests/phpunit.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<phpunit strict="true" colors="true"
+ bootstrap="prepare.php"
+>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../src/SemanticScuttle/</directory>
+ <directory suffix=".php">../data/templates/</directory>
+ <directory suffix=".php">../www/</directory>
+ <exclude>
+ <directory suffix=".php">../src/SemanticScuttle/db/</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+</phpunit> \ No newline at end of file
diff --git a/tests/www/searchTest.php b/tests/www/searchTest.php
new file mode 100644
index 0000000..1220667
--- /dev/null
+++ b/tests/www/searchTest.php
@@ -0,0 +1,68 @@
+<?php
+
+class www_SearchTest extends TestBaseApi
+{
+ protected $urlPart = 'search.php';
+
+
+ /**
+ * Some browsers using opensearch do "urlencode" on the terms,
+ * for example Firefox. Multiple terms separated with space
+ * appear as "foo+bar" in the URL.
+ */
+ public function testMultipleTermsUrlEncoded()
+ {
+ $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', false
+ );
+
+ $res = $this->getRequest('/all/baz+bat')->send();
+ $this->assertSelectCount(
+ '.xfolkentry', false, $res->getBody(),
+ 'Bookmarks found', false
+ );
+ }
+
+
+ /**
+ * 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%20bar')->send();
+ $this->assertSelectCount(
+ '.xfolkentry', true, $res->getBody(),
+ 'No bookmark found', false
+ );
+
+ $res = $this->getRequest('/all/baz bat')->send();
+ $this->assertSelectCount(
+ '.xfolkentry', false, $res->getBody(),
+ 'Bookmarks found', false
+ );
+ }
+
+
+ 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