mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2024-12-23 22:39:33 -05:00
Fix PHPunit tests
This commit is contained in:
parent
7cb942aca3
commit
99d49a56ba
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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'));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user