Skip to content
Permalink
Browse files

Fix failing tests.

Don't always collapse headers when header() is called. Also update the
tests to include the automatic content-type header setting.
  • Loading branch information...
markstory committed Nov 19, 2016
1 parent fd50f0a commit 9e43757455bfdfcc386e78425119a35a7417f002
@@ -714,7 +714,10 @@ protected function getSimpleHeaders()
$out = [];
foreach ($this->headers as $key => $values) {
$header = $this->headerNames[strtolower($key)];
$out[$header] = implode(',', $values);
if (count($values) === 1) {
$values = $values[0];
}
$out[$header] = $values;
}
return $out;
@@ -92,7 +92,11 @@ public function testToCakeHeaders()
{
$psr = new PsrResponse('php://memory', 200, ['X-testing' => 'value']);
$result = ResponseTransformer::toCake($psr);
$this->assertSame(['X-testing' => 'value'], $result->header());
$expected = [
'Content-Type' => 'text/html; charset=UTF-8',
'X-testing' => 'value'
];
$this->assertSame($expected, $result->header());
}
/**
@@ -104,7 +108,11 @@ public function testToCakeHeaderMultiple()
{
$psr = new PsrResponse('php://memory', 200, ['X-testing' => ['value', 'value2']]);
$result = ResponseTransformer::toCake($psr);
$this->assertSame(['X-testing' => ['value', 'value2']], $result->header());
$expected = [
'Content-Type' => 'text/html; charset=UTF-8',
'X-testing' => ['value', 'value2'],
];
$this->assertSame($expected, $result->header());
}
/**
@@ -265,24 +273,6 @@ public function testToPsrContentType()
$this->assertSame('text/html; charset=utf-8', $result->getHeaderLine('Content-Type'));
}
/**
* Test conversion omitting content-type on 304 and 204 status codes
*
* @return void
*/
public function testToPsrContentTypeStatusOmission()
{
$cake = new CakeResponse();
$cake->type('html');
$cake->statusCode(304);
$result = ResponseTransformer::toPsr($cake);
$this->assertSame('', $result->getHeaderLine('Content-Type'));
$cake->statusCode(204);
$result = ResponseTransformer::toPsr($cake);
$this->assertSame('', $result->getHeaderLine('Content-Type'));
}
/**
* Test conversion omitting content-type on 304 and 204 status codes
*
@@ -320,9 +310,9 @@ public function testToPsrHeaders()
]);
$result = ResponseTransformer::toPsr($cake);
$expected = [
'Content-Type' => ['text/html; charset=UTF-8'],
'X-testing' => ['one', 'two'],
'Location' => ['http://example.com/testing'],
'Content-Type' => ['text/html; charset=UTF-8'],
];
$this->assertSame($expected, $result->getHeaders());
}
@@ -285,7 +285,7 @@ public function testHeader()
$this->assertEquals($headers, $response->header());
$response->header('Access-Control-Allow-Origin', ['domain1', 'domain2']);
$headers += ['Access-Control-Allow-Origin' => 'domain1,domain2'];
$headers += ['Access-Control-Allow-Origin' => ['domain1', 'domain2']];
$this->assertEquals($headers, $response->header());
}

0 comments on commit 9e43757

Please sign in to comment.
You can’t perform that action at this time.