Skip to content

Commit

Permalink
Acceptance test for response header testing
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Oct 13, 2014
1 parent 2079ed0 commit dd8ba07
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Cli/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static function serveStaticFile($filePath) {
}

Headers::add("Content-type", $mime);
Headers::send();
return readfile($filePath);
}

Expand Down
1 change: 1 addition & 0 deletions src/Cli/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class Server {
public static $contentType = [
"css" => "text/css",
"js" => "application/javascript",
"txt" => "text/plain",
];

/**
Expand Down
3 changes: 3 additions & 0 deletions test/Acceptance/HTTPHeaders/src/Page/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!doctype html>
<script src="/Script/my-script.js"></script>
<p>This is the homepage</p>
2 changes: 2 additions & 0 deletions test/Acceptance/HTTPHeaders/src/Script/my-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This is a static JavaScript file.
console.log("Hello!");
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
use Behat\MinkExtension\Context\MinkContext;
use Behat\Gherkin\Node\TableNode;
use PHPUnit_Framework_Assert as PHPUnit;

class FeatureContext extends MinkContext {

/**
* @Then /^the response headers should include:$/
*/
public function theResponseHeadersShouldInclude(TableNode $table) {
$actualHeaders = $this->getSession()->getResponseHeaders();
$expectedHeaders = $table->getRowsHash();
$actualHeaders = array_change_key_case($actualHeaders, CASE_LOWER);
$expectedHeaders = array_change_key_case($expectedHeaders, CASE_LOWER);

array_shift($expectedHeaders);

foreach ($expectedHeaders as $key => $value) {
PHPUnit::assertArrayHasKey($key, $actualHeaders);
PHPUnit::assertContains($value, $actualHeaders[$key][0]);
}
}


}#
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Feature: Test that HTTP response headers are sent
In order to view static files
As a web browser
I should see the correct headers in the HTTP response

Scenario: Open homepage
Given I go to the homepage
Then I should see "This is the homepage"
And the response status code should be 200
And the response headers should include:
| Header name | Header value |
| Content-type | text/html |

Scenario: View file placed in www
Given I go to "/readme.txt"
Then the response should contain "Read Me"
And the response status code should be 200
And the response headers should include:
| Header name | Header value |
| Content-type | text/plain |
22 changes: 22 additions & 0 deletions test/Acceptance/HTTPHeaders/test/Acceptance/behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
default:
paths:
features: Features
bootstrap: %behat.paths.base%/Behat
extensions:
Behat\MinkExtension\Extension:
base_url: http://localhost:8089
goutte:
guzzle_parameters:
ssl.certificate_authority: false
curl.options:
CURLOPT_PORT: 8089
SensioLabs\Behat\PageObjectExtension\Extension: ~
context:
parameters:
screenshot_dir: %behat.paths.base%/Report
filters:
tags: ~@disabled
formatter:
name: pretty
parameters:
output_path: null,%behat.paths.base%/Report/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This is a static JavaScript file.
console.log("Hello!");
4 changes: 4 additions & 0 deletions test/Acceptance/HTTPHeaders/www/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Read Me
-------

This is a static file, saved directly in the www directory.

0 comments on commit dd8ba07

Please sign in to comment.