mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
2e930b17ff
* feat: initial migration to Laravel 10 * style: fix StyleCI findings
88 lines
2.2 KiB
PHP
88 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Actions\Models\List\Playlist;
|
|
|
|
use App\Actions\Models\List\Playlist\InsertTrackAfterAction;
|
|
use App\Models\List\Playlist;
|
|
use App\Models\List\Playlist\PlaylistTrack;
|
|
use App\Models\Wiki\Video;
|
|
use Exception;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Class InsertTrackAfterTest.
|
|
*/
|
|
class InsertTrackAfterTest extends TestCase
|
|
{
|
|
use WithFaker;
|
|
|
|
/**
|
|
* The Insert Track After Action shall set the track as the playlist's last track if inserting after the last track.
|
|
*
|
|
* @return void
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function testLastTrack(): void
|
|
{
|
|
$playlist = Playlist::factory()
|
|
->tracks($this->faker->numberBetween(2, 9))
|
|
->createOne();
|
|
|
|
$last = $playlist->last;
|
|
|
|
$track = PlaylistTrack::factory()
|
|
->for($playlist)
|
|
->for(Video::factory())
|
|
->createOne();
|
|
|
|
$action = new InsertTrackAfterAction();
|
|
|
|
$action->insertAfter($playlist, $track, $last);
|
|
|
|
static::assertTrue($playlist->last()->is($track));
|
|
|
|
static::assertTrue($last->next()->is($track));
|
|
|
|
static::assertTrue($track->previous()->is($last));
|
|
static::assertTrue($track->next()->doesntExist());
|
|
}
|
|
|
|
/**
|
|
* The Insert Track After Action shall set the track as the first track's next track if inserting after it.
|
|
*
|
|
* @return void
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function testFirstTrack(): void
|
|
{
|
|
$playlist = Playlist::factory()
|
|
->tracks($this->faker->numberBetween(2, 9))
|
|
->createOne();
|
|
|
|
$first = $playlist->first;
|
|
|
|
$next = $first->next;
|
|
|
|
$track = PlaylistTrack::factory()
|
|
->for($playlist)
|
|
->for(Video::factory())
|
|
->createOne();
|
|
|
|
$action = new InsertTrackAfterAction();
|
|
|
|
$action->insertAfter($playlist, $track, $first);
|
|
|
|
static::assertTrue($playlist->first()->is($first));
|
|
|
|
static::assertTrue($first->next()->is($track));
|
|
|
|
static::assertTrue($track->previous()->is($first));
|
|
static::assertTrue($track->next()->is($next));
|
|
}
|
|
}
|