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/ajax/GetAdminLinkedTagsTest.php | 20 +++----------------- tests/ajax/GetAdminTagsTest.php | 30 +++++------------------------- tests/ajax/GetContactTagsTest.php | 26 +++++--------------------- 3 files changed, 13 insertions(+), 63 deletions(-) (limited to 'tests/ajax') 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