From 426f73e6e31e18bf3a2efa097c39cc1d313d78ac Mon Sep 17 00:00:00 2001 From: Nicolas Roggli Date: Thu, 25 Aug 2022 15:04:41 +0200 Subject: [PATCH] Correction error in full api render, added test --- src/View/PhpWordView.php | 4 ++-- tests/TestCase/View/PhpWordViewTest.php | 16 ++++++++++++++++ .../TestApp/Template/Imprimaturs/docx/view.ctp | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/test_app/TestApp/Template/Imprimaturs/docx/view.ctp diff --git a/src/View/PhpWordView.php b/src/View/PhpWordView.php index 22c71fb..df6c7fd 100644 --- a/src/View/PhpWordView.php +++ b/src/View/PhpWordView.php @@ -114,7 +114,7 @@ public function render($view = null, $layout = null) $this->PhpWord = new PhpWord(); $this->_ext = '.ctp'; $content = parent::render($view, false); - if ($this->response->type() == 'text/html') { + if ($this->response->getType() == 'text/html') { return $content; } $this->Blocks->set('content', $this->output()); @@ -158,7 +158,7 @@ protected function serialize() protected function output() { $writer = IOFactory::createWriter($this->PhpWord, 'Word2007'); - if (!isset($$writer)) { + if (!isset($writer)) { throw new Exception('Word writer not found'); } diff --git a/tests/TestCase/View/PhpWordViewTest.php b/tests/TestCase/View/PhpWordViewTest.php index 3db7ac3..fba5d08 100644 --- a/tests/TestCase/View/PhpWordViewTest.php +++ b/tests/TestCase/View/PhpWordViewTest.php @@ -54,4 +54,20 @@ public function testRenderCustomFilename() $this->view->getResponse()->getHeaderLine('Content-Disposition') ); } + + /** + * TestRenderFull + */ + public function testRenderFull() + { + $this->view->render(false); + $this->assertSame( + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + $this->view->getResponse()->getType() + ); + $this->assertContains( + 'filename="blank"', + $this->view->getResponse()->getHeaderLine('Content-Disposition') + ); + } } diff --git a/tests/test_app/TestApp/Template/Imprimaturs/docx/view.ctp b/tests/test_app/TestApp/Template/Imprimaturs/docx/view.ctp new file mode 100644 index 0000000..5c5a8b8 --- /dev/null +++ b/tests/test_app/TestApp/Template/Imprimaturs/docx/view.ctp @@ -0,0 +1,3 @@ +PhpWord->addSection(); +$section->addText('Hello World!');