Skip to content

Commit

Permalink
Merge pull request #4 from fr3nch13/dev
Browse files Browse the repository at this point in the history
Ensuring subdir is set, so it acts like before.
  • Loading branch information
fr3nch13 committed Sep 7, 2023
2 parents d532b36 + 5553cea commit 65d780a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/View/CsvView.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function initialize(): void
parent::initialize();

$this->setLayout('Fr3nch13/Excel.csv/default');
$this->setSubDir('csv');

$this->getResponse()->setTypeMap('csv', ['text/csv; charset=UTF-8']);
$this->setResponse($this->getResponse()->withType('csv'));
Expand Down
1 change: 1 addition & 0 deletions src/View/ExcelView.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function initialize(): void
parent::initialize();

$this->setLayout('Fr3nch13/Excel.xlsx/default');
$this->setSubDir('xlsx');

$this->getResponse()->setTypeMap('xlsx', ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
$this->setResponse($this->getResponse()->withType('xlsx'));
Expand Down
1 change: 1 addition & 0 deletions src/View/PdfView.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function initialize(): void
parent::initialize();

$this->setLayout('Fr3nch13/Excel.pdf/default');
$this->setSubDir('pdf');

$this->getResponse()->setTypeMap('pdf', ['application/pdf']);
$this->setResponse($this->getResponse()->withType('pdf'));
Expand Down
12 changes: 12 additions & 0 deletions templates/csv/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

/**
* @var \Fr3nch13\Excel\View\CsvView $this
*
* Used to test the finding of templates for the View.
* This is the sample file where you can manipulate the output.
*/

echo $this->fetch('content');
12 changes: 12 additions & 0 deletions templates/pdf/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

/**
* @var \Fr3nch13\Excel\View\PdfView $this
*
* Used to test the finding of templates for the View.
* This is the sample file where you can manipulate the output.
*/

echo $this->fetch('content');
12 changes: 12 additions & 0 deletions templates/xlsx/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

/**
* @var \Fr3nch13\Excel\View\ExcelView $this
*
* Used to test the finding of templates for the View.
* This is the sample file where you can manipulate the output.
*/

echo $this->fetch('content');
7 changes: 5 additions & 2 deletions tests/TestCase/View/CsvViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function testLayout(): void
*/
public function testFileNames(): void
{
$this->View->setTemplate('base');
$this->View->setTemplate('Fr3nch13/Excel.test');
$this->View->render();

$filenames = $this->View->getFileNames();
Expand All @@ -99,8 +99,11 @@ public function testFileNames(): void
'/templates/layout/csv/default.php',
str_replace(PLUGIN_ROOT, '', $filenames['layout'])
);

// since there are no routes, the Request can't route to a controller.
// here, we're ensuring the subdir is set.
$this->assertSame(
'/vendor/fr3nch13/cakephp-pta/tests/test_app/templates/base.php',
'/templates/csv/test.php',
str_replace(PLUGIN_ROOT, '', $filenames['template'])
);
}
Expand Down
7 changes: 5 additions & 2 deletions tests/TestCase/View/ExcelViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function testLayout(): void
*/
public function testFileNames(): void
{
$this->View->setTemplate('base');
$this->View->setTemplate('Fr3nch13/Excel.test');
$this->View->render();

$filenames = $this->View->getFileNames();
Expand All @@ -99,8 +99,11 @@ public function testFileNames(): void
'/templates/layout/xlsx/default.php',
str_replace(PLUGIN_ROOT, '', $filenames['layout'])
);

// since there are no routes, the Request can't route to a controller.
// here, we're ensuring the subdir is set.
$this->assertSame(
'/vendor/fr3nch13/cakephp-pta/tests/test_app/templates/base.php',
'/templates/xlsx/test.php',
str_replace(PLUGIN_ROOT, '', $filenames['template'])
);
}
Expand Down
7 changes: 5 additions & 2 deletions tests/TestCase/View/PdfViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function testLayout(): void
*/
public function testFileNames(): void
{
$this->View->setTemplate('base');
$this->View->setTemplate('Fr3nch13/Excel.test');
$this->View->render();

$filenames = $this->View->getFileNames();
Expand All @@ -99,8 +99,11 @@ public function testFileNames(): void
'/templates/layout/pdf/default.php',
str_replace(PLUGIN_ROOT, '', $filenames['layout'])
);

// since there are no routes, the Request can't route to a controller.
// here, we're ensuring the subdir is set.
$this->assertSame(
'/vendor/fr3nch13/cakephp-pta/tests/test_app/templates/base.php',
'/templates/pdf/test.php',
str_replace(PLUGIN_ROOT, '', $filenames['template'])
);
}
Expand Down

0 comments on commit 65d780a

Please sign in to comment.