-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add template for new imported user (#15)
* Add template for new imported user * Add csv-users to require-dev * Change csv-users test
- Loading branch information
Showing
6 changed files
with
115 additions
and
0 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
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,29 @@ | ||
<?php | ||
|
||
namespace EscolaLms\TemplatesEmail\CsvUsers; | ||
|
||
use EscolaLms\TemplatesEmail\Auth\ResetPasswordVariables; | ||
use Illuminate\Support\Facades\Lang; | ||
|
||
class ImportedNewUserVariables extends ResetPasswordVariables | ||
{ | ||
public static function defaultSectionsContent(): array | ||
{ | ||
return [ | ||
'title' => Lang::get('User Import Notification'), | ||
'content' => self::wrapWithMjml( | ||
'<mj-text>' | ||
. '<p>' | ||
. Lang::get('You are receiving this email because you have been added to the system.') | ||
. '</p>' | ||
. '</mj-text>' | ||
. '<mj-button href="' . self::VAR_ACTION_LINK . '">' . Lang::get('Set Password') . '</mj-button>' | ||
. '<mj-text>' | ||
. '<p>' | ||
. Lang::get('This link will expire in :count minutes.', ['count' => self::VAR_ACTION_LINK_EXPIRATION]) | ||
. '</p>' | ||
. '</mj-text>' | ||
) | ||
]; | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace EscolaLms\TemplatesEmail\Providers; | ||
|
||
use EscolaLms\CsvUsers\Events\EscolaLmsImportedNewUserTemplateEvent; | ||
use EscolaLms\Templates\Facades\Template; | ||
use EscolaLms\TemplatesEmail\Core\EmailChannel; | ||
use EscolaLms\TemplatesEmail\CsvUsers\ImportedNewUserVariables; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class CsvUsersTemplatesServiceProvider extends ServiceProvider | ||
{ | ||
public function boot() | ||
{ | ||
Template::register(EscolaLmsImportedNewUserTemplateEvent::class, EmailChannel::class, ImportedNewUserVariables::class); | ||
} | ||
} |
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,60 @@ | ||
<?php | ||
|
||
namespace EscolaLms\TemplatesEmail\Tests\Services; | ||
|
||
use EscolaLms\Core\Tests\CreatesUsers; | ||
use EscolaLms\CsvUsers\Events\EscolaLmsImportedNewUserTemplateEvent; | ||
use EscolaLms\CsvUsers\Services\Contracts\CsvUserServiceContract; | ||
use EscolaLms\Templates\Listeners\TemplateEventListener; | ||
use EscolaLms\TemplatesEmail\Core\EmailMailable; | ||
use EscolaLms\TemplatesEmail\Tests\TestCase; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Support\Facades\Mail; | ||
use Illuminate\Support\Facades\Notification; | ||
|
||
class CsvUsersTest extends TestCase | ||
{ | ||
use CreatesUsers, DatabaseTransactions; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
if (!class_exists(\EscolaLms\CsvUsers\EscolaLmsCsvUsersServiceProvider::class)) { | ||
$this->markTestSkipped('Auth package not installed'); | ||
} | ||
} | ||
|
||
public function testImportNewUserNotification(): void | ||
{ | ||
Notification::fake(); | ||
Event::fake(); | ||
Mail::fake(); | ||
|
||
$userToImport = collect([ | ||
'email' => '[email protected]', | ||
'first_name' => 'Import', | ||
'last_name' => 'User', | ||
]); | ||
|
||
$service = app(CsvUserServiceContract::class); | ||
$user = $service->saveUserFromImport($userToImport, 'http://localhost/set-password'); | ||
|
||
Event::assertDispatched(EscolaLmsImportedNewUserTemplateEvent::class, | ||
function (EscolaLmsImportedNewUserTemplateEvent $event) use ($userToImport) { | ||
return $event->getUser()->email === $userToImport['email']; | ||
}); | ||
|
||
$listener = app(TemplateEventListener::class); | ||
$listener->handle(new EscolaLmsImportedNewUserTemplateEvent($user,'http://localhost/set-password')); | ||
|
||
Mail::assertSent(EmailMailable::class, function (EmailMailable $mailable) use ($user) { | ||
$this->assertEquals('User Import Notification', $mailable->subject); | ||
$this->assertTrue($mailable->hasTo($user->email)); | ||
$this->assertStringContainsString('token=' . $user->password_reset_token, $mailable->getHtml()); | ||
$this->assertStringContainsString('email=' . $user->email, $mailable->getHtml()); | ||
$this->assertStringContainsString('http://localhost/set-password', $mailable->getHtml()); | ||
return true; | ||
}); | ||
} | ||
} |
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