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
136 lines
3.4 KiB
PHP
136 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Actions\Models\List\Playlist;
|
|
|
|
use App\Actions\Models\List\Playlist\RemoveTrackAction;
|
|
use App\Models\List\Playlist;
|
|
use Exception;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Class RemoveTrackTest.
|
|
*/
|
|
class RemoveTrackTest extends TestCase
|
|
{
|
|
use WithFaker;
|
|
|
|
/**
|
|
* The Remove Track Action shall remove the sole track.
|
|
*
|
|
* @return void
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function testRemoveSole(): void
|
|
{
|
|
$playlist = Playlist::factory()
|
|
->tracks(1)
|
|
->createOne();
|
|
|
|
$first = $playlist->first;
|
|
|
|
$action = new RemoveTrackAction();
|
|
|
|
$action->remove($playlist, $first);
|
|
|
|
static::assertTrue($playlist->first()->doesntExist());
|
|
static::assertTrue($playlist->last()->doesntExist());
|
|
|
|
static::assertTrue($first->previous()->doesntExist());
|
|
static::assertTrue($first->next()->doesntExist());
|
|
}
|
|
|
|
/**
|
|
* The Remove Track Action shall remove the first track and set the second track as first.
|
|
*
|
|
* @return void
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function testRemoveFirst(): void
|
|
{
|
|
$playlist = Playlist::factory()
|
|
->tracks($this->faker->numberBetween(3, 9))
|
|
->createOne();
|
|
|
|
$first = $playlist->first;
|
|
$second = $first->next;
|
|
|
|
$action = new RemoveTrackAction();
|
|
|
|
$action->remove($playlist, $first);
|
|
|
|
static::assertTrue($playlist->first()->is($second));
|
|
|
|
static::assertTrue($first->previous()->doesntExist());
|
|
static::assertTrue($first->next()->doesntExist());
|
|
|
|
static::assertTrue($second->previous()->doesntExist());
|
|
}
|
|
|
|
/**
|
|
* The Remove Track Action shall remove the last track and set the penultimate track as last.
|
|
*
|
|
* @return void
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function testRemoveLast(): void
|
|
{
|
|
$playlist = Playlist::factory()
|
|
->tracks($this->faker->numberBetween(3, 9))
|
|
->createOne();
|
|
|
|
$last = $playlist->last;
|
|
$previous = $last->previous;
|
|
|
|
$action = new RemoveTrackAction();
|
|
|
|
$action->remove($playlist, $last);
|
|
|
|
static::assertTrue($playlist->last()->is($previous));
|
|
|
|
static::assertTrue($last->previous()->doesntExist());
|
|
static::assertTrue($last->next()->doesntExist());
|
|
|
|
static::assertTrue($previous->next()->doesntExist());
|
|
}
|
|
|
|
/**
|
|
* The Remove Track Action shall remove the second track and fill next and previous relations.
|
|
*
|
|
* @return void
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function testRemoveSecond(): void
|
|
{
|
|
$playlist = Playlist::factory()
|
|
->tracks(3)
|
|
->createOne();
|
|
|
|
$first = $playlist->first;
|
|
$second = $first->next;
|
|
$third = $playlist->last;
|
|
|
|
$action = new RemoveTrackAction();
|
|
|
|
$action->remove($playlist, $second);
|
|
|
|
static::assertTrue($playlist->first()->is($first));
|
|
static::assertTrue($playlist->last()->is($third));
|
|
|
|
static::assertTrue($first->previous()->doesntExist());
|
|
static::assertTrue($first->next()->is($third));
|
|
|
|
static::assertTrue($second->previous()->doesntExist());
|
|
static::assertTrue($second->next()->doesntExist());
|
|
|
|
static::assertTrue($third->previous()->is($first));
|
|
static::assertTrue($third->next()->doesntExist());
|
|
}
|
|
}
|