From 9c82a3f41285f0356d9d2d594ae4aa53e20969e1 Mon Sep 17 00:00:00 2001 From: Fernando Gutierrez Date: Tue, 8 Oct 2024 11:27:34 -0600 Subject: [PATCH] 1.0.1 - Fixed an error setting a from recipent --- .gitattributes | 2 ++ composer.json | 4 ++-- src/Console/MakeThemeMessage.php | 10 +++++----- src/Mailable.php | 21 ++++++++++++++------- tests/Feature/MailTest.php | 26 ++++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 14 deletions(-) diff --git a/.gitattributes b/.gitattributes index 4556693..e2ff5b6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,4 +9,6 @@ phpunit.xml.dist export-ignore # Others .editorconfig export-ignore +.prettierrc export-ignore CHANGELOG-* export-ignore +CHANGELOG export-ignore diff --git a/composer.json b/composer.json index 1a4dd06..9bbd096 100755 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Kirby Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.", "license": "MIT", "type": "kirby-plugin", - "version": "1.0.0", + "version": "1.0.1", "keywords": [ "kirby", "kirby-4", @@ -52,7 +52,7 @@ "kirby-plugin-path": "tests/Fixtures/site/plugins" }, "scripts": { - "test": "vendor/bin/phpunit" + "test": "vendor/bin/pest" }, "minimum-stability": "dev", "prefer-stable": true diff --git a/src/Console/MakeThemeMessage.php b/src/Console/MakeThemeMessage.php index fba1bc8..f23f553 100644 --- a/src/Console/MakeThemeMessage.php +++ b/src/Console/MakeThemeMessage.php @@ -14,11 +14,11 @@ public function __invoke(CLI $cli): void $fake = $cli->arg('fake') === true; $name = $cli->argOrPrompt('theme', 'Enter a courier theme name:'); $file = $this->path($kirby).'/themes/'.$name.'.css'; - // - // if (! $fake) { - $cli->make($file, __DIR__.'/stubs/theme.stub'); - // } - // + + if (! $fake) { + $cli->make($file, __DIR__.'/stubs/theme.stub'); + } + $cli->success('Courier theme was created.'); } diff --git a/src/Mailable.php b/src/Mailable.php index bd220cb..51b0884 100644 --- a/src/Mailable.php +++ b/src/Mailable.php @@ -79,12 +79,6 @@ abstract class Mailable implements Sendable public function __construct() { - $this->setAddress( - App::instance()->option('beebmx.kirby-courier.from.address', 'hello@example.com'), - App::instance()->option('beebmx.kirby-courier.from.name', 'Example'), - 'from' - ); - $this->subject = App::instance()->option('beebmx.kirby-courier.message.subject', 'Message from courier'); $this->logo = $this->getLogo(); @@ -125,6 +119,14 @@ public function from(string $address, ?string $name = null): static return $this->setAddress($address, $name, 'from'); } + /** + * Determine if the given recipient is set on the mailable. + */ + public function hasFrom(array|string $address, ?string $name = null): bool + { + return $this->hasRecipient($address, $name, 'from'); + } + /** * Set the recipients of the message. */ @@ -419,6 +421,12 @@ protected function buildFrom(): array return $this->buildFromPreset(['from', 'fromName']); } + $this->setAddress( + App::instance()->option('beebmx.kirby-courier.from.address', 'hello@example.com'), + App::instance()->option('beebmx.kirby-courier.from.name', 'Example'), + 'from' + ); + return [ 'from' => $this->from[0]['address'], 'fromName' => $this->from[0]['name'], @@ -432,7 +440,6 @@ protected function buildRecipients(): array 'cc' => [], 'bcc' => [], 'replyTo' => [], - ]; foreach ($recipients as $type => $value) { diff --git a/tests/Feature/MailTest.php b/tests/Feature/MailTest.php index a9d9527..4753423 100644 --- a/tests/Feature/MailTest.php +++ b/tests/Feature/MailTest.php @@ -17,6 +17,32 @@ ->toBeInstanceOf(Email::class); }); + it('set a email with default from recipent', function () { + $message = (new Message); + + expect($message->send(true)) + ->from() + ->toEqual('hello@example.com'); + }); + + it('can set from recipent', function () { + $message = (new Message) + ->from('john@doe.co'); + + expect($message) + ->hasFrom('john@doe.co') + ->toBeTrue(); + }); + + it('send a email with from recipent', function () { + $message = (new Message) + ->from('john@doe.co'); + + expect($message->send(true)) + ->from() + ->toEqual('john@doe.co'); + }); + it('can set single recipent', function () { $message = (new Message) ->to('john@doe.co');