-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: report preview is now rendered using the correct template (#46)
Closes #45
- Loading branch information
1 parent
a6f495d
commit 30de8b3
Showing
9 changed files
with
297 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace KirbyReporter\Report; | ||
|
||
use Kirby\Toolkit\Tpl; | ||
use KirbyReporter\Model\FormData; | ||
|
||
trait ReportMailTemplateParser | ||
{ | ||
private string $pluginName = 'gearsdigital/reporter-for-kirby'; | ||
|
||
public function parseTemplate(FormData $formData, string $type): string | ||
{ | ||
return Tpl::load($this->getReportTemplate($type), ['title' => $formData->getTitle(), 'fields' => $formData->getFormFields()]); | ||
} | ||
|
||
private function getReportTemplate(string $type): string | ||
{ | ||
$template = "report.${type}.php"; | ||
$templateRoot = kirby()->root('templates').DS."emails"; | ||
$pluginRoot = kirby()->plugin($this->pluginName); | ||
$templatePath = file_exists($templateRoot.DS.$template) ? $templateRoot : $pluginRoot->root().DS."templates/emails"; | ||
|
||
return $templatePath.DS."$template"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Issue Report from "<?= site()->title() ?? ''; ?>" by <?= kirby()->user()->nameOrEmail() ?? ''; ?> | ||
|
||
--- | ||
<?= $title ?? ''; ?> | ||
<b><?= $title ?? ''; ?></b> | ||
|
||
--- | ||
<?= $fields['description'] ?? ''; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace KirbyReporter\Traits; | ||
|
||
use Kirby\Toolkit\Tpl; | ||
use KirbyReporter\Model\FormData; | ||
use KirbyReporter\Report\ReportMailTemplateParser; | ||
use Mockery; | ||
use Mockery\Adapter\Phpunit\MockeryTestCase; | ||
|
||
class ReportMailTemplateParserTest extends MockeryTestCase | ||
{ | ||
|
||
private array $formData = [ | ||
'title' => 'Lorem', | ||
'formFields' => [ | ||
'description' => 'Test', | ||
], | ||
]; | ||
|
||
public function test_parse_report_mail_text_template(): void | ||
{ | ||
$mock = Mockery::mock('alias:'.Tpl::class); | ||
$mock->shouldReceive('load')->andReturn('my-loaded-text-template'); | ||
|
||
$formData = new FormData($this->formData); | ||
$parser = $this->getObjectForTrait(ReportMailTemplateParser::class); | ||
$parsedTemplate = $parser->parseTemplate($formData, 'text'); | ||
|
||
$this->assertTrue(is_string($parsedTemplate)); | ||
$this->assertEquals('my-loaded-text-template', $parsedTemplate); | ||
} | ||
|
||
public function test_parse_report_mail_html_template(): void | ||
{ | ||
$mock = Mockery::mock('alias:'.Tpl::class); | ||
$mock->shouldReceive('load')->andReturn('my-loaded-html-template'); | ||
|
||
$formData = new FormData($this->formData); | ||
$parser = $this->getObjectForTrait(ReportMailTemplateParser::class); | ||
$parsedTemplate = $parser->parseTemplate($formData, 'html'); | ||
|
||
$this->assertTrue(is_string($parsedTemplate)); | ||
$this->assertEquals('my-loaded-html-template', $parsedTemplate); | ||
} | ||
|
||
} |
Oops, something went wrong.