From 326036a501795048cff49f2687c2f0da1402f194 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 28 Nov 2012 15:35:09 +0100 Subject: [PATCH] Excluded or removed tests relying on actual webserver routing The "sanitychecks" group excludes through phpunit.xml.dist. Removed RestfulService->testHttpErrorWithoutCache() since its not sufficiently isolated in terms of testing. Has been refactored in 3.x, but too intrusive to backport. Changes mainly necessary to get Travis builds passing, since we don't want to start mucking around with dynamically generated file-to-url mappings just to get *unit* tests passing - as opposed to integration-testing the whole environment incl. webserver. --- tests/WebserverRoutingTest.php | 2 ++ tests/api/RestfulServiceTest.php | 38 +++++--------------------------- 2 files changed, 8 insertions(+), 32 deletions(-) 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