diff --git a/core/Tracker.php b/core/Tracker.php index 6ecad4b3b5243f9dd80de1b4b1699d368f990865..9d7af54c366da5fedf2ed72e09dc3576218a8ffb 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -669,7 +669,8 @@ class Tracker $request = $_GET + $_POST; if (array_key_exists('send_image', $request) && $request['send_image'] === '0') { - Common::sendHeader("HTTP/1.1 204 No Response"); + Common::sendResponseCode(204); + return; } diff --git a/tests/PHPUnit/Framework/Constraint/ResponseCode.php b/tests/PHPUnit/Framework/Constraint/ResponseCode.php index b934ea008f63521ecde0b77de3163a25cd99003d..c23b136a82075c22839e6cde627f94981020e311 100644 --- a/tests/PHPUnit/Framework/Constraint/ResponseCode.php +++ b/tests/PHPUnit/Framework/Constraint/ResponseCode.php @@ -9,6 +9,7 @@ namespace Piwik\Tests\Framework\Constraint; class ResponseCode extends \PHPUnit_Framework_Constraint { + private $actualCode; /** * @param integer $value Expected response code @@ -41,7 +42,9 @@ class ResponseCode extends \PHPUnit_Framework_Constraint $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); - return $this->value === (int) $responseCode; + $this->actualCode = (int) $responseCode; + + return $this->value === $this->actualCode; } /** @@ -51,6 +54,6 @@ class ResponseCode extends \PHPUnit_Framework_Constraint */ public function toString() { - return 'does not return response code ' . $this->exporter->export($this->value); + return 'does not return response code ' . $this->exporter->export($this->value) . ' it is ' . $this->actualCode; } }?> \ No newline at end of file diff --git a/tests/PHPUnit/System/TrackerTest.php b/tests/PHPUnit/System/TrackerTest.php index c3b7125eed0abb75ed71e61692bf346859d296a6..29ba0c95e5cb64773e264e1eac23bd2cac978bb7 100755 --- a/tests/PHPUnit/System/TrackerTest.php +++ b/tests/PHPUnit/System/TrackerTest.php @@ -69,4 +69,12 @@ class TrackerTest extends SystemTestCase $this->assertResponseCode(204, $url); } + public function test_response_ShouldSend400ResponseCode_IfSiteIdIsInvalid() + { + $url = $this->tracker->getUrlTrackPageView('Test'); + $url .= '&idsite=100'; + + $this->assertResponseCode(400, $url); + } + }