Skip to content

Commit

Permalink
Feature/star 40 (#42)
Browse files Browse the repository at this point in the history
* Add Temp consutation and webnar to mail

* Add templates for events approved and reject

* Add variables to register temp

* Add setTimezone for datetimes

* Repair tests

* add assert to test

* add assert to test

* add assert to test

* add assert to test

* Add yt problem event temp

* Add event yt problem

Co-authored-by: Hubert Krzysztofiak <[email protected]>
  • Loading branch information
HerbertIV and Hubert Krzysztofiak authored May 11, 2022
1 parent 2186666 commit 392a7a9
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/EscolaLmsTemplatesEmailServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);

Expand Down
17 changes: 17 additions & 0 deletions src/Providers/YoutubeTemplatesServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace EscolaLms\TemplatesEmail\Providers;

use EscolaLms\TemplatesEmail\Core\EmailChannel;
use EscolaLms\TemplatesEmail\Youtube\YtProblemVariables;
use EscolaLms\Youtube\Events\YtProblem;
use Illuminate\Support\ServiceProvider;
use EscolaLms\Templates\Facades\Template;

class YoutubeTemplatesServiceProvider extends ServiceProvider
{
public function boot()
{
Template::register(YtProblem::class, EmailChannel::class, YtProblemVariables::class);
}
}
2 changes: 0 additions & 2 deletions src/Webinar/CommonWebinarVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public static function requiredVariables(): array
return [
self::VAR_USER_NAME,
self::VAR_WEBINAR_TITLE,
self::VAR_WEBINAR_PROPOSED_TERM,
];
}

Expand All @@ -50,7 +49,6 @@ public static function requiredVariablesInSection(string $sectionKey): array
return [
self::VAR_USER_NAME,
self::VAR_WEBINAR_TITLE,
self::VAR_WEBINAR_PROPOSED_TERM,
];
}
return [];
Expand Down
45 changes: 45 additions & 0 deletions src/Youtube/CommonYoutubeVariables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace EscolaLms\TemplatesEmail\Youtube;

use Carbon\Carbon;
use EscolaLms\Core\Models\User;
use EscolaLms\Templates\Events\EventWrapper;
use EscolaLms\TemplatesEmail\Core\EmailVariables;
use EscolaLms\Webinar\Models\Webinar;
use EscolaLms\Youtube\Facades\Youtube;

abstract class CommonYoutubeVariables extends EmailVariables
{
const VAR_USER_EMAIL = '@VarUserEmail';

public static function mockedVariables(?User $user = null): array
{
$faker = \Faker\Factory::create();
return array_merge(parent::mockedVariables(), [
self::VAR_USER_EMAIL => $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;
}
}
15 changes: 15 additions & 0 deletions src/Youtube/YtProblemVariables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace EscolaLms\TemplatesEmail\Youtube;

class YtProblemVariables extends CommonYoutubeVariables
{

public static function defaultSectionsContent(): array
{
return [
'title' => __('Problem with Yt integration'),
'content' => self::wrapWithMjml(__('<h1>Hello!</h1><p>There was a problem with youtube integration. Please verify it.</p>')),
];
}
}
65 changes: 65 additions & 0 deletions tests/Api/YoutubeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace EscolaLms\TemplatesEmail\Tests\Api;

use EscolaLms\Core\Models\User;
use EscolaLms\Core\Tests\CreatesUsers;
use EscolaLms\Templates\Database\Seeders\PermissionTableSeeder;
use EscolaLms\Templates\Listeners\TemplateEventListener;
use EscolaLms\Templates\Models\Template;
use EscolaLms\TemplatesEmail\Core\EmailChannel;
use EscolaLms\TemplatesEmail\Core\EmailMailable;
use EscolaLms\TemplatesEmail\Tests\TestCase;
use EscolaLms\Youtube\Dto\YTBroadcastDto;
use EscolaLms\Youtube\EscolaLmsYoutubeServiceProvider;
use EscolaLms\Youtube\Events\YtProblem;
use EscolaLms\Youtube\Services\Contracts\YoutubeServiceContract;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;

class YoutubeTest extends TestCase
{
use DatabaseTransactions, CreatesUsers, WithFaker;

public function setUp(): void
{
parent::setUp();
if (!class_exists(EscolaLmsYoutubeServiceProvider::class)) {
$this->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;
});
}
}
4 changes: 4 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 392a7a9

Please sign in to comment.