mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-25 19:19:28 +01:00
* feat: use process facade for FFmpeg routines * style: fix StyleCI findings
98 lines
3.5 KiB
PHP
98 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Rules\Wiki\Submission\Format;
|
|
|
|
use App\Rules\Wiki\Submission\Format\ExtraneousChaptersFormatRule;
|
|
use App\Rules\Wiki\Submission\SubmissionRule;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Process;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Class ExtraneousChaptersFormatTest.
|
|
*/
|
|
class ExtraneousChaptersFormatTest extends TestCase
|
|
{
|
|
use WithFaker;
|
|
|
|
/**
|
|
* The Extraneous Chapters Format Rule shall fail if the chapter data is not empty.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testFailsWhenChapterDataIsNotEmpty(): void
|
|
{
|
|
$file = UploadedFile::fake()->create($this->faker->word().'.webm', $this->faker->randomDigitNotNull());
|
|
|
|
Process::fake([
|
|
SubmissionRule::formatLoudnessCommand($file) => Process::result(errorOutput: json_encode([
|
|
'input_i' => $this->faker->randomFloat(),
|
|
'input_tp' => $this->faker->randomFloat(),
|
|
'input_lra' => $this->faker->randomFloat(),
|
|
'input_thresh' => $this->faker->randomFloat(),
|
|
'output_i' => $this->faker->randomFloat(),
|
|
'output_tp' => $this->faker->randomFloat(),
|
|
'output_lra' => $this->faker->randomFloat(),
|
|
'output_thresh' => $this->faker->randomFloat(),
|
|
'normalization_type' => 'dynamic',
|
|
'target_offset' => $this->faker->randomFloat(),
|
|
])),
|
|
SubmissionRule::formatFfprobeCommand($file) => Process::result(json_encode([
|
|
'chapters' => [
|
|
$this->faker->word() => $this->faker->word(),
|
|
],
|
|
])),
|
|
]);
|
|
|
|
$validator = Validator::make(
|
|
['file' => $file],
|
|
['file' => new ExtraneousChaptersFormatRule()],
|
|
);
|
|
|
|
static::assertFalse($validator->passes());
|
|
|
|
Process::assertRan(SubmissionRule::formatFfprobeCommand($file));
|
|
}
|
|
|
|
/**
|
|
* The Extraneous Chapters Format Rule shall pass if the chapter data is empty.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testPassesWhenChapterDataIsEmpty(): void
|
|
{
|
|
$file = UploadedFile::fake()->create($this->faker->word().'.webm', $this->faker->randomDigitNotNull());
|
|
|
|
Process::fake([
|
|
SubmissionRule::formatLoudnessCommand($file) => Process::result(errorOutput: json_encode([
|
|
'input_i' => $this->faker->randomFloat(),
|
|
'input_tp' => $this->faker->randomFloat(),
|
|
'input_lra' => $this->faker->randomFloat(),
|
|
'input_thresh' => $this->faker->randomFloat(),
|
|
'output_i' => $this->faker->randomFloat(),
|
|
'output_tp' => $this->faker->randomFloat(),
|
|
'output_lra' => $this->faker->randomFloat(),
|
|
'output_thresh' => $this->faker->randomFloat(),
|
|
'normalization_type' => 'dynamic',
|
|
'target_offset' => $this->faker->randomFloat(),
|
|
])),
|
|
SubmissionRule::formatFfprobeCommand($file) => Process::result(json_encode([
|
|
'chapters' => [],
|
|
])),
|
|
]);
|
|
|
|
$validator = Validator::make(
|
|
['file' => $file],
|
|
['file' => new ExtraneousChaptersFormatRule()],
|
|
);
|
|
|
|
static::assertTrue($validator->passes());
|
|
|
|
Process::assertRan(SubmissionRule::formatFfprobeCommand($file));
|
|
}
|
|
}
|