Skip to content

Commit

Permalink
Fix content type switching for error pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Oct 3, 2023
1 parent f77e019 commit ffd03d7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="./tests/bootstrap.php" colors="true" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="./tests/bootstrap.php" colors="true" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" backupStaticProperties="false">
<testsuites>
<testsuite name="CakePdf Plugin Tests">
<directory>./tests/TestCase</directory>
Expand Down
18 changes: 17 additions & 1 deletion src/View/PdfView.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,23 @@ public function __construct(
}

/**
* @inheritDoc
* Set the response content-type based on the view's contentType()
*
* @return void
*/
protected function setContentType(): void
{
parent::setContentType();

if ($this->templatePath === 'Error') {
$this->response = $this->response->withType('html');
}
}

/**
* Mime-type this view class renders as.
*
* @return string 'application/pdf'
*/
public static function contentType(): string
{
Expand Down
4 changes: 1 addition & 3 deletions tests/TestCase/View/PdfViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ public function testRenderTemplateWithNoOutput()
*/
public function testRenderErrorTemplate()
{
$request = new ServerRequest();
$response = new Response();
$this->View = new PdfView($request, $response, null, ['templatePath' => 'Error']);
$this->View = new PdfView(viewOptions: ['templatePath' => 'Error']);

$this->assertSame('', $this->View->getSubDir());
$this->assertSame('', $this->View->getLayoutPath());
Expand Down

0 comments on commit ffd03d7

Please sign in to comment.