/**
  * @runInSeparateProcess
  */
 public function testRespondsPlainTextWithHttpCode404()
 {
     (new NotFound())->respond();
     $this->assertContains('Content-Type: text/plain; charset=utf-8', xdebug_get_headers());
     $this->assertEquals(Http::NOT_FOUND, http_response_code());
     $this->expectOutputString('Not Found.');
 }
 public function test_send_headers()
 {
     SecureHeaders::fromFile($this->configPath)->send();
     $headers = xdebug_get_headers();
     $this->assertContains('X-Content-Type-Options: nosniff', $headers);
     $this->assertContains('Referrer-Policy: strict-origin-when-cross-origin', $headers);
 }
 /**
  * @runInSeparateProcess
  */
 public function testRespondsPlainTextWithHttpCode401()
 {
     (new Unauthorized())->respond();
     $this->assertContains('Content-Type: text/plain; charset=utf-8', xdebug_get_headers());
     $this->assertEquals(Http::UNAUTHORIZED, http_response_code());
     $this->expectOutputString('Unauthorized.');
 }
 /**
  * @runInSeparateProcess
  */
 public function testRespondsPlainTextWithHttpCode403()
 {
     (new Forbidden())->respond();
     $this->assertContains('Content-Type: text/plain; charset=utf-8', xdebug_get_headers());
     $this->assertEquals(Http::FORBIDDEN, http_response_code());
     $this->expectOutputString("Forbidden!");
 }
 /**
  * @runInSeparateProcess
  * @dataProvider locationCodeProvider
  */
 public function testSendsLocationAndHttpCodeHeaderWhenResponding($location, $httpCode, $expectedHeader, $expectedCode)
 {
     $redirect = new Redirect($location, $httpCode);
     $redirect->respond();
     $this->assertContains($expectedHeader, xdebug_get_headers());
     $this->assertEquals($expectedCode, http_response_code());
 }
 /**
  * @runInSeparateProcess
  */
 public function testRespondsPlainTextWithHttpCode405()
 {
     (new MethodNotAllowed())->respond();
     $this->assertContains('Content-Type: text/plain; charset=utf-8', xdebug_get_headers());
     $this->assertEquals(Http::METHOD_NOT_ALLOWED, http_response_code());
     $this->expectOutputString('Method not allowed.');
 }
 /**
  * @runInSeparateProcess
  * @outputBuffering disabled
  */
 public function testProtectedController()
 {
     if (!function_exists('xdebug_get_headers')) {
         $this->markTestSkipped('Xdebug not installed');
     }
     $autoloader = new Autoloader();
     $autoloader->register();
     $autoloader->addNamespaces([['Linna\\FOO', dirname(__DIR__) . '/FOO']]);
     //config options
     $session = new Session();
     $session->start();
     $password = new Password();
     $storedPassword = $password->hash('password');
     //attemp first login
     $login = new Login($session, $password);
     $login->login('root', 'password', $storedUser = '******', $storedPassword, 1);
     $loginLogged = $login->logged;
     $model = new FOOModel();
     $controller1 = new FOOProtectedController($model, $login);
     $controllerTest1 = $controller1->test;
     $login->logout();
     $loginNoLogged = $login->logged;
     ob_start();
     $controller2 = new FOOProtectedController($model, $login);
     $headers_list = xdebug_get_headers();
     ob_end_clean();
     $this->assertEquals(true, $loginLogged);
     $this->assertEquals(false, $loginNoLogged);
     $this->assertEquals(true, $controllerTest1);
     $this->assertEquals(true, in_array('Location: http://localhost', $headers_list));
     $session->destroy();
 }
 /**
  * @runInSeparateProcess
  */
 public function testRespondsPlainTextWithHttpCode500()
 {
     (new InternalServerError())->respond();
     $this->assertContains('Content-Type: text/plain; charset=utf-8', xdebug_get_headers());
     $this->assertEquals(Http::INTERNAL_SERVER_ERROR, http_response_code());
     $this->expectOutputString("Internal server error.");
 }
 /**
  * @test
  */
 public function shouldShowCaptcha()
 {
     $this->oneClickCaptchaService->showCaptcha();
     $headers = xdebug_get_headers();
     $this->assertEquals("Expires: Thu, 19 Nov 1981 08:52:00 GMT", $headers[1]);
     $this->assertEquals("Pragma: public", $headers[2]);
     $this->assertEquals("Cache-Control: public", $headers[3]);
 }
 /**
  * コンテンツタイプを出力
  * 
  * @return void
  */
 public function testHeader()
 {
     $this->markTestIncomplete('このテストは、まだ実装されていません。');
     $this->BcMobile->header();
     $result = xdebug_get_headers();
     $expected = 'Content-type: application/xhtml+xml';
     $this->assertEquals($expected, $result[0]);
 }
 /**
  * @runInSeparateProcess
  */
 public function testResponseObjectReturnsAllowedHeaderWhenWrongMethodUsed()
 {
     $request = $this->container['request'];
     $request->setSupportedRequestMethods(array($request::POST, $request::PUT, $request::DELETE));
     $response = $this->container['response'];
     $this->response->send($response::METHOD_NOT_ALLOWED_CODE);
     $this->assertContains('Allow: POST, PUT, DELETE', xdebug_get_headers());
 }
 /**
  * @runInSeparateProcess
  */
 public function testRespondsPlainTextWithHttpCode400()
 {
     $messages = ['This is a unit test.', 'I am testing the output.'];
     (new BadRequest($messages))->respond();
     $this->assertContains('Content-Type: text/plain; charset=utf-8', xdebug_get_headers());
     $this->assertEquals(Http::BAD_REQUEST, http_response_code());
     $this->expectOutputString("This is a unit test.\nI am testing the output.");
 }
 /**
  * @runInSeparateProcess
  */
 public function testJson()
 {
     $response = new Response($this->makeRequest());
     $response->setJson(['a' => 'b']);
     $this->expectOutputString(json_encode(['a' => 'b', 'c' => 'd']));
     $response->json(['c' => 'd']);
     $this->assertContains('Content-type: application/json', xdebug_get_headers());
 }
 /**
  * @runInSeparateProcess
  */
 public function testRespondsJsonWithHttpCode500()
 {
     $messages = ['This is a unit test.', 'I am testing the output.'];
     (new BadJsonRequest($messages))->respond();
     $this->assertContains('Content-Type: application/json; charset=utf-8', xdebug_get_headers());
     $this->assertEquals(Http::BAD_REQUEST, http_response_code());
     $this->expectOutputString('{"messages":["This is a unit test.","I am testing the output."]}');
 }
Exemple #15
0
 /**
  * @test
  * @requires PHP > 5.3
  * @runInSeparateProcess
  */
 public function testHeaderResponseAttributes()
 {
     $this->qrCode->setFormat('png')->setHeaderResponse();
     $this->assertEquals(['Content-Type: image/png'], \xdebug_get_headers());
     $this->qrCode->setFormat('jpg')->setHeaderResponse();
     $this->assertEquals(['Content-Type: image/jpeg'], \xdebug_get_headers());
     $this->qrCode->setFormat('gif')->setHeaderResponse();
     $this->assertEquals(['Content-Type: image/gif'], \xdebug_get_headers());
 }
Exemple #16
0
 public static function doTest($response)
 {
     $writer = new ezcMvcHttpResponseWriter($response);
     ob_start();
     $writer->handleResponse();
     $contents = ob_get_contents();
     ob_end_clean();
     return array(xdebug_get_headers(), $contents);
 }
Exemple #17
0
 /**
  * @covers ::Header
  * @runInSeparateProcess
  */
 public function testHeader()
 {
     $header = 'a test header';
     ob_start();
     $this->assertEquals($this->testObj, $this->testObj->Header($header));
     $headers = xdebug_get_headers();
     ob_end_clean();
     $this->assertContains($header, $headers);
 }
Exemple #18
0
 /**
  * @runInSeparateProcess
  */
 public function testSendsRedirectLocationHeader()
 {
     if (!function_exists('xdebug_get_headers')) {
         $this->markTestSkipped('Requires ext/xdebug to be installed.');
     }
     $this->redirector->redirect('http://www.example.com');
     $this->assertContains('Location: http://www.example.com/', xdebug_get_headers());
     header_remove();
 }
Exemple #19
0
 /**
  * @runInSeparateProcess
  */
 public function testRedirect()
 {
     $data = array('name' => 'foo', 'email' => '*****@*****.**', 'message' => 'baz');
     $this->cb_args = array();
     $kontact = new Kontact($this->schema, $this->cb);
     $kontact->process($data, 'qux');
     $this->assertEquals(array('Location: qux?err=0&data%5Bname%5D=foo&data%5Bemail%5D=foo%40bar.com&data%5Bmessage%5D=baz'), xdebug_get_headers());
     $this->assertEquals(array(0, $data), $this->cb_args);
 }
 public function testSendMessageGzipCompression()
 {
     $communication = new PluginFusioninventoryCommunication();
     $communication->setMessage('<foo><bar/></foo>');
     $this->expectOutputString(gzencode($this->output));
     $communication->sendMessage('gzip');
     $headers = xdebug_get_headers();
     $this->assertContains('Content-Type: application/x-compress-gzip', $headers);
 }
Exemple #21
0
 /**
  * @runInSeparateProcess
  */
 public function testHeaderIsSent()
 {
     if (!function_exists('xdebug_get_headers')) {
         $this->markTestSkipped('Requires ext/xdebug to be installed.');
     }
     $header = new CsrfToken(array('token' => 'foo'));
     $header->send();
     $this->assertContains('X-CSRFToken: foo', xdebug_get_headers());
     header_remove();
 }
 public static function checkHeader($needle)
 {
     $haystack = xdebug_get_headers();
     foreach ($haystack as $key => $value) {
         if (strpos($value, $needle) !== false) {
             return true;
         }
     }
     return false;
 }
Exemple #23
0
 /**
  * @runInSeparateProcess
  */
 public function test_send()
 {
     if (!function_exists('xdebug_get_headers')) {
         throw new Exception('Test skipped, missing required function xdebug_get_headers.');
     }
     $cookie = $this->getCookie();
     $cookie->setMaxAge(22);
     $cookie->send();
     $this->assertEquals(strtolower('set-cookie: ' . $cookie->toString()), strtolower(array_get(xdebug_get_headers(), 0)));
 }
 /**
  * Must run in separate process to avoid headers already sent errors.
  *
  * @runInSeparateProcess
  */
 public function test_that_header_is_sent()
 {
     $seconds = 10;
     $object = new Purgely_Surrogate_Control_Header($seconds);
     // Ensure that all properties are set correctly
     $object->send_header();
     // Get the headers that were sent
     if (function_exists('xdebug_get_headers')) {
         $this->assertEquals(array('Surrogate-Control: max-age=' . $seconds), xdebug_get_headers());
     }
 }
 /**
  * @runInSeparateProcess
  */
 public function testRespondsHtmlWithData()
 {
     $data = ['unit', 'test'];
     $templateEngine = $this->getMockBuilder(RendersTemplate::class)->setMethods(['renderWithData'])->getMock();
     $templateEngine->expects($this->once())->method('renderWithData')->willReturnCallback(function ($template, array $data) {
         return $template . ' - ' . join("\n", $data);
     });
     (new TemplatePage('/Unit/Test.tpl', $data, 'utf-8', $templateEngine))->respond();
     $this->assertContains('Content-Type: text/html; charset=utf-8', xdebug_get_headers());
     $this->expectOutputString("/Unit/Test.tpl - unit\ntest");
 }
 /** @test */
 public function it_returns_audio()
 {
     ob_start();
     $this->visit('securimage/audio');
     $audio = ob_get_contents();
     ob_end_clean();
     $headers = xdebug_get_headers();
     $this->assertContains('Content-type: audio/wav', $headers);
     $this->assertSessionHas('securimage_code_value.default');
     $this->assertSessionHas('securimage_code_audio.default');
 }
 /**
  * @runInSeparateProcess
  */
 public function testLoadLocation()
 {
     define('TEST_MODE', true);
     $location = 'http://example.com';
     $_conf = Conf::instance();
     $_conf->setProperty('userLocation', $location);
     $_conf->setProperty('display', 'location');
     $this->display->loadLocation();
     $headers_list = xdebug_get_headers();
     $this->assertContains("Location: {$location}", $headers_list);
 }
 /**
  * Check pdf file export
  * 
  * @preserveGlobalState disabled
  * @runInSeparateProcess
  */
 public function testExport()
 {
     $name = 'filename';
     $this->pdfBookletExporter->setContent($this->HTMLString);
     ob_start();
     $this->assertTrue($this->pdfBookletExporter->export($name));
     $pdfFileContent = ob_get_clean();
     $headers = xdebug_get_headers();
     $this->assertStringStartsWith('%PDF', $pdfFileContent);
     $this->assertTrue(in_array('Content-Type: application/pdf', $headers));
 }
Exemple #29
0
 /**
  * @runInSeparateProcess
  * @preserveGlobalState disabled
  */
 public function testFirephp()
 {
     $this->markTestSkipped('need install xdebug');
     $logger = new \Phalcon\Logger\Adapter\Firephp();
     $logger->getFormatter()->setShowBacktrace(false);
     $logger->info('info');
     $headers = xdebug_get_headers();
     $this->assertContains('X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2', $headers);
     $this->assertContains('X-Wf-1-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3', $headers);
     $this->assertContains('X-Wf-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1', $headers);
     $this->assertContains('X-Wf-1-1-1-1: 35|[{"Type":"INFO","Label":"info"},""]|', $headers);
 }
 /**
  * @runInSeparateProcess
  */
 public function testHeaderOutputWithGeneratedRoutes()
 {
     $routes = [new ReadRoute(new Literal('/get/this'), new GetRequestHandler()), new ReadRoute(new Literal('/get/that'), new HeadRequestHandler()), new ReadRoute(new Literal('/get/this/again'), new GetRequestHandler())];
     $config = $this->getMockBuilder(ConfiguresIceHawk::class)->getMockForAbstractClass();
     $requestInfo = new RequestInfo(['REQUEST_METHOD' => 'OPTIONS', 'REQUEST_URI' => '/get/that']);
     $config->method('getRequestInfo')->willReturn($requestInfo);
     $config->method('getWriteRoutes')->willReturn([]);
     $config->method('getReadRoutes')->willReturn($this->getGeneratedRoutes($routes));
     $optionsRequestHandler = new OptionsRequestHandler($config, new EventPublisher());
     $optionsRequestHandler->handleRequest();
     $this->assertContains('Allow: HEAD', xdebug_get_headers());
 }