diff --git a/composer.json b/composer.json index 66b7a86..ce5e4a6 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ "escolalms/settings": "^0.1.2", "escolalms/consultations": "^0", "escolalms/webinar": "^0", + "escolalms/youtube": "^0", "escolalms/csv-users": "^0.1.0", "escolalms/assign-without-account": "^0", "orchestra/testbench": "^5.0|^6.0", diff --git a/src/EscolaLmsTemplatesEmailServiceProvider.php b/src/EscolaLmsTemplatesEmailServiceProvider.php index 7b93bf6..056fd77 100644 --- a/src/EscolaLmsTemplatesEmailServiceProvider.php +++ b/src/EscolaLmsTemplatesEmailServiceProvider.php @@ -21,10 +21,12 @@ use EscolaLms\TemplatesEmail\Providers\CsvUsersTemplatesServiceProvider; use EscolaLms\TemplatesEmail\Providers\TemplateServiceProvider; use EscolaLms\TemplatesEmail\Providers\WebinarTemplatesServiceProvider; +use EscolaLms\TemplatesEmail\Providers\YoutubeTemplatesServiceProvider; use EscolaLms\TemplatesEmail\Rules\MjmlRule; use EscolaLms\TemplatesEmail\Services\Contracts\MjmlServiceContract; use EscolaLms\TemplatesEmail\Services\MjmlService; use EscolaLms\Webinar\EscolaLmsWebinarServiceProvider; +use EscolaLms\Youtube\EscolaLmsYoutubeServiceProvider; use Illuminate\Support\ServiceProvider; /** @@ -73,6 +75,9 @@ class_exists(EscolaLmsTemplatesServiceProvider::class) && if (class_exists(\EscolaLms\Cart\EscolaLmsCartServiceProvider::class)) { $this->app->register(CartTemplatesServiceProvider::class); } + if (class_exists(EscolaLmsYoutubeServiceProvider::class)) { + $this->app->register(YoutubeTemplatesServiceProvider::class); + } $this->app->register(TemplateServiceProvider::class); diff --git a/src/Providers/YoutubeTemplatesServiceProvider.php b/src/Providers/YoutubeTemplatesServiceProvider.php new file mode 100644 index 0000000..629e290 --- /dev/null +++ b/src/Providers/YoutubeTemplatesServiceProvider.php @@ -0,0 +1,17 @@ + $faker->email(), + ]); + } + + public static function variablesFromEvent(EventWrapper $event): array + { + return array_merge(parent::variablesFromEvent($event), [ + self::VAR_USER_EMAIL => $event->getUser()->email + ]); + } + + public static function requiredVariables(): array + { + return []; + } + + public static function requiredVariablesInSection(string $sectionKey): array + { + return []; + } + + public static function assignableClass(): ?string + { + return null; + } +} diff --git a/src/Youtube/YtProblemVariables.php b/src/Youtube/YtProblemVariables.php new file mode 100644 index 0000000..d24b518 --- /dev/null +++ b/src/Youtube/YtProblemVariables.php @@ -0,0 +1,15 @@ + __('Problem with Yt integration'), + 'content' => self::wrapWithMjml(__('

Hello!

There was a problem with youtube integration. Please verify it.

')), + ]; + } +} diff --git a/tests/Api/YoutubeTest.php b/tests/Api/YoutubeTest.php new file mode 100644 index 0000000..21fb52d --- /dev/null +++ b/tests/Api/YoutubeTest.php @@ -0,0 +1,65 @@ +markTestSkipped('Youtube package not installed'); + } + $this->seed(PermissionTableSeeder::class); + } + + public function testVerifyEmailAfterWrongYt() + { + Event::fake(); + Mail::fake(); + + $email = $this->faker->email; + Config::set('services.youtube.email', $email); + $ytServiceContract = app(YoutubeServiceContract::class); + try { + $ytServiceContract->generateYTStream(new YTBroadcastDto()); + } catch (\Exception $ex) { + // + } + $user = new User([ + 'email' => $email + ]); + Event::assertDispatched(YtProblem::class, function (YtProblem $event) use ($user) { + return $event->getUser()->email === $user->email; + }); + $listener = app(TemplateEventListener::class); + $listener->handle(new YtProblem($user)); + + Mail::assertSent(EmailMailable::class, function (EmailMailable $mailable) use ($user) { + $this->assertEquals(__('Problem with Yt integration'), $mailable->subject); + $this->assertTrue($mailable->hasTo($user->email)); + return true; + }); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 39115af..d31de1d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -17,6 +17,7 @@ use EscolaLms\TemplatesEmail\EscolaLmsTemplatesEmailServiceProvider; use EscolaLms\TemplatesEmail\Services\Contracts\MjmlServiceContract; use EscolaLms\TemplatesEmail\Services\MjmlService; +use EscolaLms\Youtube\EscolaLmsYoutubeServiceProvider; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Config; use Laravel\Passport\Passport; @@ -55,6 +56,9 @@ protected function getPackageProviders($app) EscolaLmsTemplatesServiceProvider::class, EscolaLmsTemplatesEmailServiceProvider::class, ]; + if (class_exists(EscolaLmsYoutubeServiceProvider::class)) { + $providers[] = EscolaLmsYoutubeServiceProvider::class; + } if (class_exists(\EscolaLms\Auth\EscolaLmsAuthServiceProvider::class)) { $providers[] = EscolaLmsAuthServiceProvider::class; }