From 99d49a56ba0bf7b930f774a8b98a4227433777d4 Mon Sep 17 00:00:00 2001 From: rugk Date: Mon, 21 Jan 2019 23:49:33 +0100 Subject: [PATCH] Fix PHPunit tests --- tst/ConfigurationTestGenerator.php | 1 + tst/ControllerTest.php | 8 ++++++++ tst/JsonApiTest.php | 3 +++ tst/RequestTest.php | 8 ++++++++ 4 files changed, 20 insertions(+) diff --git a/tst/ConfigurationTestGenerator.php b/tst/ConfigurationTestGenerator.php index ccf7c829..0aaec88a 100755 --- a/tst/ConfigurationTestGenerator.php +++ b/tst/ConfigurationTestGenerator.php @@ -507,6 +507,7 @@ EOT; $code .= PHP_EOL . <<<'EOT' $this->_model->create(Helper::getPasteId(), Helper::getPaste()); $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_GET[Helper::getPasteId()] = ''; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; EOT; break; diff --git a/tst/ControllerTest.php b/tst/ControllerTest.php index 432c829f..6c6f5758 100644 --- a/tst/ControllerTest.php +++ b/tst/ControllerTest.php @@ -680,6 +680,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase public function testReadInvalidId() { $_SERVER['QUERY_STRING'] = 'foo'; + $_GET["foo"] = ''; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; ob_start(); new Controller; @@ -696,6 +697,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase public function testReadNonexisting() { $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_GET[Helper::getPasteId()] = ''; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; ob_start(); new Controller; @@ -714,6 +716,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase $expiredPaste = Helper::getPaste(array('expire_date' => 1344803344)); $this->_model->create(Helper::getPasteId(), $expiredPaste); $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_GET[Helper::getPasteId()] = ''; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; ob_start(); new Controller; @@ -732,6 +735,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase $paste = Helper::getPaste(array('burnafterreading' => true)); $this->_model->create(Helper::getPasteId(), $paste); $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_GET[Helper::getPasteId()] = ''; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; ob_start(); new Controller; @@ -760,6 +764,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase $paste = Helper::getPaste(); $this->_model->create(Helper::getPasteId(), $paste); $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_GET[Helper::getPasteId()] = ''; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; ob_start(); new Controller; @@ -790,6 +795,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase ); $this->_model->create(Helper::getPasteId(), $paste); $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_GET[Helper::getPasteId()] = ''; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; ob_start(); new Controller; @@ -897,6 +903,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); $_POST['deletetoken'] = 'burnafterreading'; $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_GET[Helper::getPasteId()] = ''; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['REQUEST_METHOD'] = 'POST'; ob_start(); @@ -917,6 +924,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); $_POST['deletetoken'] = 'burnafterreading'; $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_GET[Helper::getPasteId()] = ''; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['REQUEST_METHOD'] = 'POST'; ob_start(); diff --git a/tst/JsonApiTest.php b/tst/JsonApiTest.php index 1f8d53ac..6914d3fb 100644 --- a/tst/JsonApiTest.php +++ b/tst/JsonApiTest.php @@ -82,6 +82,7 @@ class JsonApiTest extends PHPUnit_Framework_TestCase file_put_contents($file, http_build_query($paste)); Request::setInputStream($file); $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_GET[Helper::getPasteId()] = ''; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['REQUEST_METHOD'] = 'PUT'; $_SERVER['REMOTE_ADDR'] = '::1'; @@ -117,6 +118,7 @@ class JsonApiTest extends PHPUnit_Framework_TestCase ))); Request::setInputStream($file); $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_GET[Helper::getPasteId()] = ''; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['REQUEST_METHOD'] = 'DELETE'; ob_start(); @@ -164,6 +166,7 @@ class JsonApiTest extends PHPUnit_Framework_TestCase unset($paste['attachmentname']); $this->_model->create(Helper::getPasteId(), $paste); $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_GET[Helper::getPasteId()] = ''; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; ob_start(); new Controller; diff --git a/tst/RequestTest.php b/tst/RequestTest.php index a647224d..b23104f5 100644 --- a/tst/RequestTest.php +++ b/tst/RequestTest.php @@ -66,6 +66,7 @@ class RequestTest extends PHPUnit_Framework_TestCase $id = $this->getRandomId(); $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['QUERY_STRING'] = $id; + $_GET[$id] = ''; $request = new Request; $this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertEquals($id, $request->getParam('pasteid')); @@ -120,6 +121,7 @@ class RequestTest extends PHPUnit_Framework_TestCase $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01'; $_SERVER['QUERY_STRING'] = $id; + $_GET[$id] = ''; $request = new Request; $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call'); $this->assertEquals($id, $request->getParam('pasteid')); @@ -133,6 +135,7 @@ class RequestTest extends PHPUnit_Framework_TestCase $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['QUERY_STRING'] = $id; + $_GET = [$id => '']; $_POST['deletetoken'] = 'bar'; $request = new Request; $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call'); @@ -148,6 +151,7 @@ class RequestTest extends PHPUnit_Framework_TestCase $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['HTTP_ACCEPT'] = 'text/html,text/html; charset=UTF-8,application/xhtml+xml, application/xml;q=0.9,*/*;q=0.8, text/csv,application/json'; $_SERVER['QUERY_STRING'] = $id; + $_GET[$id] = ''; $request = new Request; $this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertEquals($id, $request->getParam('pasteid')); @@ -161,6 +165,7 @@ class RequestTest extends PHPUnit_Framework_TestCase $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['HTTP_ACCEPT'] = 'application/xhtml+xml,text/html,text/html; charset=UTF-8, application/xml;q=0.9,*/*;q=0.8, text/csv,application/json'; $_SERVER['QUERY_STRING'] = $id; + $_GET[$id] = ''; $request = new Request; $this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertEquals($id, $request->getParam('pasteid')); @@ -174,6 +179,7 @@ class RequestTest extends PHPUnit_Framework_TestCase $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['HTTP_ACCEPT'] = 'text/plain,text/csv, application/xml;q=0.9, application/json, text/html,text/html; charset=UTF-8,application/xhtml+xml, */*;q=0.8'; $_SERVER['QUERY_STRING'] = $id; + $_GET[$id] = ''; $request = new Request; $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call'); $this->assertEquals($id, $request->getParam('pasteid')); @@ -187,6 +193,7 @@ class RequestTest extends PHPUnit_Framework_TestCase $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['HTTP_ACCEPT'] = 'text/plain,text/csv, application/xml;q=0.9, */*;q=0.8'; $_SERVER['QUERY_STRING'] = $id; + $_GET[$id] = ''; $request = new Request; $this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertEquals($id, $request->getParam('pasteid')); @@ -205,6 +212,7 @@ class RequestTest extends PHPUnit_Framework_TestCase shuffle($queryParams); $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['QUERY_STRING'] = implode('&', $queryParams); + $_GET[$id] = ''; $request = new Request; $this->assertEquals($id, $request->getParam('pasteid')); }