Skip to content

Commit

Permalink
Update for Cake 4.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Apr 27, 2019
1 parent c59ac6b commit d44a315
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 43 deletions.
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
"homepage": "http://github.com/friendsofcake/CakePdf",
"license": "MIT",
"require": {
"cakephp/cakephp": "^3.5"
"cakephp/cakephp": "4.x-dev"
},
"require-dev": {
"cakephp/chronos": "^1.1",
"phpunit/phpunit": "^5.7.14|^6.0",
"phpunit/phpunit": "^7.0",
"dompdf/dompdf": "^0.8",
"mpdf/mpdf": "^7.0",
"tecnickcom/tcpdf": "^6.2"
Expand All @@ -27,10 +26,13 @@
"autoload-dev": {
"psr-4": {
"Cake\\Test\\": "vendor/cakephp/cakephp/tests",
"CakePdf\\Test\\": "tests"
"CakePdf\\Test\\": "tests",
"MyPlugin\\": "tests/test_app/Plugin/MyPlugin/src"
}
},
"replace": {
"ceeram/cakepdf": "self.version"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
27 changes: 14 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
syntaxCheck="false">
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
>

<testsuites>
<testsuite name="CakePdf Plugin Tests">
Expand Down
16 changes: 9 additions & 7 deletions src/View/PdfView.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ class PdfView extends View
*
* @var string|null
*/
public $subDir = 'pdf';
protected $subDir = 'pdf';

/**
* The name of the layouts subfolder containing layouts for this View.
*
* @var string|null
*/
public $layoutPath = 'pdf';
protected $layoutPath = 'pdf';

/**
* CakePdf Instance
*
* @var \CakePdf\Pdf\CakePdf|null
*/
protected $_renderer = null;
protected $_renderer;

/**
* List of pdf configs collected from the associated controller.
Expand Down Expand Up @@ -67,13 +67,15 @@ public function __construct(
);

$this->response = $this->response->withType('pdf');
if (isset($viewOptions['templatePath']) && $viewOptions['templatePath'] == 'Error') {
$this->subDir = null;
$this->layoutPath = null;

if (isset($viewOptions['templatePath']) && $viewOptions['templatePath'] === 'Error') {
$this->subDir = '';
$this->layoutPath = '';
$this->response = $this->response->withType('html');

return;
}

if (!$this->pdfConfig) {
throw new Exception(__d('cakepdf', 'Controller attribute $pdfConfig is not correct or missing'));
}
Expand Down Expand Up @@ -102,7 +104,7 @@ public function renderer($config = null)
* @param string $layout The layout being rendered.
* @return string The rendered view.
*/
public function render($view = null, $layout = null)
public function render(?string $view = null, $layout = null): string
{
$content = parent::render($view, $layout);

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Pdf/CakePdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function testCustomTemplatePaths($config)
public function testPluginOutput($config)
{
$pdf = new CakePdf($config);
Plugin::load('MyPlugin', ['autoload' => true]);
$this->loadPlugins(['MyPlugin']);
$pdf->viewVars(['data' => 'testing']);
$pdf->template('MyPlugin.testing', 'MyPlugin.pdf');
$pdf->helpers('MyPlugin.MyTest');
Expand Down
23 changes: 11 additions & 12 deletions tests/TestCase/View/PdfViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public function setUp()
public function testConstruct()
{
if (version_compare(Configure::version(), '3.6.0', '<')) {
$result = $this->View->response->type();
$result = $this->View->getResponse()->type();
} else {
$result = $this->View->response->getType();
$result = $this->View->getResponse()->getType();
}
$this->assertEquals('application/pdf', $result);

Expand Down Expand Up @@ -98,7 +98,7 @@ public function testRenderWithDownload()
$this->assertContains('<h2>Rendered with default layout</h2>', $result);
$this->assertContains('Post data: This is the post', $result);

$this->assertContains('filename="posts.pdf"', $this->View->response->getHeaderLine('Content-Disposition'));
$this->assertContains('filename="posts.pdf"', $this->View->getResponse()->getHeaderLine('Content-Disposition'));
}

/**
Expand All @@ -117,7 +117,10 @@ public function testRenderWithFilename()
$this->assertContains('<h2>Rendered with default layout</h2>', $result);
$this->assertContains('Post data: This is the post', $result);

$this->assertContains('filename="booyah.pdf"', $this->View->response->getHeaderLine('Content-Disposition'));
$this->assertContains(
'filename="booyah.pdf"',
$this->View->getResponse()->getHeaderLine('Content-Disposition')
);
}

/**
Expand All @@ -139,16 +142,12 @@ public function testRenderErrorTemplate()
{
$request = new ServerRequest();
$response = new Response();
$this->View = new PdfView($request, $response, null, [ 'templatePath' => 'Error' ]);
$this->View = new PdfView($request, $response, null, ['templatePath' => 'Error']);

$this->assertNull($this->View->subDir);
$this->assertNull($this->View->layoutPath);
$this->assertSame('', $this->View->getSubDir());
$this->assertSame('', $this->View->getLayoutPath());

if (version_compare(Configure::version(), '3.6.0', '<')) {
$result = $this->View->response->type();
} else {
$result = $this->View->response->getType();
}
$result = $this->View->getResponse()->getType();
$this->assertEquals('text/html', $result);
}
}
10 changes: 5 additions & 5 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
'templates' => [$root . '/tests/test_app/Template/'],
]);

Plugin::load('CakePdf', [
'path' => dirname(dirname(__FILE__)) . DS,
'routes' => true,
'bootstrap' => true,
]);
// Plugin::load('CakePdf', [
// 'path' => dirname(dirname(__FILE__)) . DS,
// 'routes' => true,
// 'bootstrap' => true,
// ]);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit d44a315

Please sign in to comment.