summaryrefslogtreecommitdiffstatshomepage
path: root/tests/ajax
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ajax')
-rw-r--r--tests/ajax/GetAdminLinkedTagsTest.php120
-rw-r--r--tests/ajax/GetAdminTagsTest.php71
-rw-r--r--tests/ajax/GetContactTagsTest.php100
3 files changed, 284 insertions, 7 deletions
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