introduce assertResponseJson200 for API/ajax tests and use it
This commit is contained in:
parent
1dfff5d3d8
commit
a5bd778929
4 changed files with 32 additions and 63 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue