Files
animethemes-server/tests/Feature/Events/Wiki/Video/ScriptTest.php
T
paranarimasu 8b6b196c99 feat(admin): migrate db dumps from github to platform (#465)
* feat: migrate encoding scripts from github to platform

* style: fix StyleCI finding

* fix: don't concatenate updated videos when attempting to attach entry on video upload

* fix(api): fix field dependencies & feat(admin): upload script from video detail screen
2022-09-24 00:01:37 -05:00

125 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Events\Wiki\Video;
use App\Events\Wiki\Video\Script\VideoScriptCreated;
use App\Events\Wiki\Video\Script\VideoScriptDeleted;
use App\Events\Wiki\Video\Script\VideoScriptRestored;
use App\Events\Wiki\Video\Script\VideoScriptUpdated;
use App\Models\Wiki\Video\VideoScript;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Event;
use Tests\TestCase;
/**
* Class ScriptTest.
*/
class ScriptTest extends TestCase
{
/**
* When a Script is created, a VideoScriptCreated event shall be dispatched.
*
* @return void
*/
public function testVideoScriptCreatedEventDispatched(): void
{
Event::fake();
VideoScript::factory()->createOne();
Event::assertDispatched(VideoScriptCreated::class);
}
/**
* When a Script is deleted, a VideoScriptDeleted event shall be dispatched.
*
* @return void
*/
public function testVideoScriptDeletedEventDispatched(): void
{
Event::fake();
$script = VideoScript::factory()->createOne();
$script->delete();
Event::assertDispatched(VideoScriptDeleted::class);
}
/**
* When a Script is restored, a VideoScriptRestored event shall be dispatched.
*
* @return void
*/
public function testVideoScriptRestoredEventDispatched(): void
{
Event::fake();
$script = VideoScript::factory()->createOne();
$script->restore();
Event::assertDispatched(VideoScriptRestored::class);
}
/**
* When a Script is restored, a VideoScriptUpdated event shall not be dispatched.
* Note: This is a customization that overrides default framework behavior.
* An updated event is fired on restore.
*
* @return void
*/
public function testVideoScriptRestoresQuietly(): void
{
Event::fake();
$script = VideoScript::factory()->createOne();
$script->restore();
Event::assertNotDispatched(VideoScriptUpdated::class);
}
/**
* When a Script is updated, a VideoScriptUpdated event shall be dispatched.
*
* @return void
*/
public function testVideoScriptUpdatedEventDispatched(): void
{
Event::fake();
$script = VideoScript::factory()->createOne();
$changes = VideoScript::factory()->makeOne();
$script->fill($changes->getAttributes());
$script->save();
Event::assertDispatched(VideoScriptUpdated::class);
}
/**
* The VideoScriptUpdated event shall contain embed fields.
*
* @return void
*/
public function testVideoScriptUpdatedEventEmbedFields(): void
{
Event::fake();
$script = VideoScript::factory()->createOne();
$changes = VideoScript::factory()->makeOne();
$script->fill($changes->getAttributes());
$script->save();
Event::assertDispatched(VideoScriptUpdated::class, function (VideoScriptUpdated $event) {
$message = $event->getDiscordMessage();
return ! empty(Arr::get($message->embed, 'fields'));
});
}
}