summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/TestBaseApi.php19
-rw-r--r--tests/ajax/GetAdminLinkedTagsTest.php20
-rw-r--r--tests/ajax/GetAdminTagsTest.php30
-rw-r--r--tests/ajax/GetContactTagsTest.php26
4 files changed, 32 insertions, 63 deletions
diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php
index 2341ea1..f054973 100644
--- a/tests/TestBaseApi.php
+++ b/tests/TestBaseApi.php
@@ -173,6 +173,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/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));