diff --git a/tests/WebserverRoutingTest.php b/tests/WebserverRoutingTest.php index fc82efc37..641dbe499 100644 --- a/tests/WebserverRoutingTest.php +++ b/tests/WebserverRoutingTest.php @@ -8,6 +8,8 @@ * @todo Exclude this test from a standard test run - not all test environments * might have a webserver installed, or have it accessible for HTTP requests * from localhost. + * + * @group sanitychecks * * @package sapphire * @subpackage tests diff --git a/tests/api/RestfulServiceTest.php b/tests/api/RestfulServiceTest.php index 76f943a4a..b2f503cd3 100644 --- a/tests/api/RestfulServiceTest.php +++ b/tests/api/RestfulServiceTest.php @@ -93,14 +93,14 @@ class RestfulServiceTest extends SapphireTest { * @expectedException PHPUnit_Framework_Error */ function testIncorrectData() { - $connection = new RestfulService(Director::absoluteBaseURL(), 0); - $test1 = $connection->request('RestfulServiceTest_Controller/invalid?usetestmanifest=1&flush=1'); + $connection = new RestfulServiceTest_MockRestfulService(Director::absoluteBaseURL(), 0); + $test1 = $connection->request('RestfulServiceTest_Controller/invalid'); $test1->xpath("\\fail"); } function testHttpErrorWithoutCache() { - $connection = new RestfulService(Director::absoluteBaseURL(), 0); - $response = $connection->request('RestfulServiceTest_Controller/httpErrorWithoutCache?usetestmanifest=1&flush=1'); + $connection = new RestfulServiceTest_MockRestfulService(Director::absoluteBaseURL(), 0); + $response = $connection->request('RestfulServiceTest_Controller/httpErrorWithoutCache'); $this->assertEquals(400, $response->getStatusCode()); $this->assertFalse($response->getCachedBody()); @@ -108,30 +108,6 @@ class RestfulServiceTest extends SapphireTest { } - function testHttpErrorWithCache() { - $subUrl = 'RestfulServiceTest_Controller/httpErrorWithCache?usetestmanifest=1&flush=1'; - $connection = new RestfulService(Director::absoluteBaseURL(), 0); - $this->createFakeCachedResponse($connection, $subUrl); - $response = $connection->request($subUrl); - - $this->assertEquals(400, $response->getStatusCode()); - $this->assertEquals("Cache response body",$response->getCachedBody()); - $this->assertContains("HTTP Error", $response->getBody()); - - } - - /** - * Simulate cached response file for testing error requests that are supposed to have cache files - */ - private function createFakeCachedResponse($connection, $subUrl) { - $fullUrl = $connection->getAbsoluteRequestURL($subUrl); - $cachedir = TEMP_FOLDER; // Default silverstripe cache - $cache_file = md5($fullUrl); // Encoded name of cache file - $cache_path = $cachedir."/xmlresponse_$cache_file"; - $cacheResponse = new RestfulService_Response("Cache response body"); - $store = serialize($cacheResponse); - file_put_contents($cache_path, $store); - } } class RestfulServiceTest_Controller extends Controller { @@ -218,7 +194,7 @@ XML; class RestfulServiceTest_MockRestfulService extends RestfulService { public $session = null; - + public function request($subURL = '', $method = "GET", $data = null, $headers = null) { if(!$this->session) { @@ -263,7 +239,6 @@ class RestfulServiceTest_MockRestfulService extends RestfulService { else $postVars = $data; $responseFromDirector = Director::test($url, $postVars, $this->session, $method, $body, $headers); - $response = new RestfulService_Response( $responseFromDirector->getBody(), $responseFromDirector->getStatusCode() @@ -271,5 +246,4 @@ class RestfulServiceTest_MockRestfulService extends RestfulService { return $response; } -} -?> +} \ No newline at end of file