| 1 | <?php |
||
| 2 | |||
| 3 | namespace LeKoala\Mailgun\Test; |
||
| 4 | |||
| 5 | use LeKoala\EmailTemplates\Email\BetterEmail; |
||
| 6 | use LeKoala\EmailTemplates\Models\EmailTemplate; |
||
|
0 ignored issues
–
show
|
|||
| 7 | use SilverStripe\Security\Member; |
||
| 8 | use LeKoala\Mailgun\MailgunHelper; |
||
|
0 ignored issues
–
show
The type
LeKoala\Mailgun\MailgunHelper was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 9 | use SilverStripe\Core\Environment; |
||
| 10 | use SilverStripe\Dev\SapphireTest; |
||
| 11 | use SilverStripe\Control\Email\Email; |
||
| 12 | use SilverStripe\Control\Email\Mailer; |
||
| 13 | use Mailgun\Model\Domain\IndexResponse; |
||
|
0 ignored issues
–
show
The type
Mailgun\Model\Domain\IndexResponse was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 14 | use SilverStripe\Core\Injector\Injector; |
||
| 15 | use SilverStripe\Control\Email\SwiftMailer; |
||
|
0 ignored issues
–
show
The type
SilverStripe\Control\Email\SwiftMailer was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 16 | use LeKoala\EmailTemplates\Tasks\EmailImportTask; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Test for EmailTemplates |
||
| 20 | * |
||
| 21 | * @group EmailTemplates |
||
| 22 | */ |
||
| 23 | class EmailTemplatesTest extends SapphireTest |
||
| 24 | { |
||
| 25 | protected static $fixture_file = 'EmailTemplatesTest.yml'; |
||
| 26 | |||
| 27 | protected function setUp(): void |
||
| 28 | { |
||
| 29 | parent::setUp(); |
||
| 30 | } |
||
| 31 | |||
| 32 | protected function tearDown(): void |
||
| 33 | { |
||
| 34 | parent::tearDown(); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return Member |
||
| 39 | */ |
||
| 40 | public static function getTestMember() |
||
| 41 | { |
||
| 42 | return Member::get()->filter('Email', '[email protected]')->first(); |
||
| 43 | } |
||
| 44 | |||
| 45 | public function testCheckContentForErrors() |
||
| 46 | { |
||
| 47 | $withErrors = 'Some string here <% if $Test %>with a test<% end_if %>'; |
||
| 48 | |||
| 49 | $this->assertNotEmpty(EmailImportTask::checkContentForErrors($withErrors)); |
||
| 50 | |||
| 51 | $withoutErrors = 'This template <b>is fine</b>'; |
||
| 52 | $this->assertEmpty(EmailImportTask::checkContentForErrors($withoutErrors)); |
||
| 53 | } |
||
| 54 | |||
| 55 | public function testDataIsApplied() |
||
| 56 | { |
||
| 57 | $tpl = EmailTemplate::getByCode('Default'); |
||
| 58 | |||
| 59 | $email = $tpl->getEmail(); |
||
| 60 | |||
| 61 | $this->assertEquals("Default Subject", $email->getSubject()); |
||
| 62 | } |
||
| 63 | |||
| 64 | public function testMakeCode() |
||
| 65 | { |
||
| 66 | $path1 = 'SilverStripe\Control\Email\ChangePasswordEmail'; |
||
| 67 | $this->assertEquals('ChangePassword', BetterEmail::makeTemplateCode($path1)); |
||
| 68 | |||
| 69 | $path2 = 'MyEmail'; |
||
| 70 | $this->assertEquals('My', BetterEmail::makeTemplateCode($path2)); |
||
| 71 | } |
||
| 72 | |||
| 73 | public function testHasDefaultTemplate() |
||
| 74 | { |
||
| 75 | $tpl = BetterEmail::config()->template; |
||
| 76 | |||
| 77 | $em = new BetterEmail(); |
||
| 78 | $this->assertEquals($em->getHTMLTemplate(), $tpl); |
||
| 79 | } |
||
| 80 | |||
| 81 | public function testChangePasswordEmailIsChanged() |
||
| 82 | { |
||
| 83 | $member = self::getTestMember(); |
||
| 84 | |||
| 85 | $tpl = BetterEmail::config()->template; |
||
| 86 | |||
| 87 | $email = Email::create(); |
||
| 88 | $this->assertInstanceOf(BetterEmail::class, $email); |
||
| 89 | |||
| 90 | $changePasswordEmail = $email |
||
| 91 | ->setHTMLTemplate('SilverStripe\\Control\\Email\\ChangePasswordEmail') |
||
| 92 | ->setData($member) |
||
| 93 | ->setTo($member->Email) |
||
| 94 | ->setSubject("Your password has been changed"); |
||
| 95 | |||
| 96 | // Make sure we got the replacement provided by the system |
||
| 97 | // ChangePasswordEmail does not have a common layout with our email templates otherwise |
||
| 98 | $this->assertEquals($tpl, $email->getHTMLTemplate()); |
||
| 99 | |||
| 100 | // Make sure subject is not changed by further stuff |
||
| 101 | $this->assertEquals("Hey, your password has been changed", $changePasswordEmail->getSubject()); |
||
| 102 | } |
||
| 103 | } |
||
| 104 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths