mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-19 17:19:22 +02:00
85 lines
3.0 KiB
PHP
85 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Actions\Storage\Wiki\UploadedFileAction;
|
|
use App\Rules\Wiki\Submission\Format\ExtraneousMetadataFormatRule;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Process;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
uses(Illuminate\Foundation\Testing\WithFaker::class);
|
|
|
|
test('fails when extraneous metadata is present', function () {
|
|
$file = UploadedFile::fake()->create(fake()->word().'.webm', fake()->randomDigitNotNull());
|
|
|
|
Process::fake([
|
|
UploadedFileAction::formatLoudnessCommand($file) => Process::result(errorOutput: json_encode([
|
|
'input_i' => fake()->randomFloat(),
|
|
'input_tp' => fake()->randomFloat(),
|
|
'input_lra' => fake()->randomFloat(),
|
|
'input_thresh' => fake()->randomFloat(),
|
|
'output_i' => fake()->randomFloat(),
|
|
'output_tp' => fake()->randomFloat(),
|
|
'output_lra' => fake()->randomFloat(),
|
|
'output_thresh' => fake()->randomFloat(),
|
|
'normalization_type' => 'dynamic',
|
|
'target_offset' => fake()->randomFloat(),
|
|
])),
|
|
UploadedFileAction::formatFfprobeCommand($file) => Process::result(json_encode([
|
|
'format' => [
|
|
'tags' => [
|
|
'ENCODER' => 'Lavf{fake()->numberBetween()}',
|
|
'DURATION' => '00:01:30.098000000',
|
|
fake()->word() => fake()->word(),
|
|
],
|
|
],
|
|
])),
|
|
]);
|
|
|
|
$validator = Validator::make(
|
|
['file' => $file],
|
|
['file' => new ExtraneousMetadataFormatRule()],
|
|
);
|
|
|
|
$this->assertFalse($validator->passes());
|
|
|
|
Process::assertRan(UploadedFileAction::formatFfprobeCommand($file));
|
|
});
|
|
|
|
test('passes no extraneous metadata', function () {
|
|
$file = UploadedFile::fake()->create(fake()->word().'.webm', fake()->randomDigitNotNull());
|
|
|
|
Process::fake([
|
|
UploadedFileAction::formatLoudnessCommand($file) => Process::result(errorOutput: json_encode([
|
|
'input_i' => fake()->randomFloat(),
|
|
'input_tp' => fake()->randomFloat(),
|
|
'input_lra' => fake()->randomFloat(),
|
|
'input_thresh' => fake()->randomFloat(),
|
|
'output_i' => fake()->randomFloat(),
|
|
'output_tp' => fake()->randomFloat(),
|
|
'output_lra' => fake()->randomFloat(),
|
|
'output_thresh' => fake()->randomFloat(),
|
|
'normalization_type' => 'dynamic',
|
|
'target_offset' => fake()->randomFloat(),
|
|
])),
|
|
UploadedFileAction::formatFfprobeCommand($file) => Process::result(json_encode([
|
|
'format' => [
|
|
'tags' => [
|
|
'ENCODER' => 'Lavf{fake()->numberBetween()}',
|
|
'DURATION' => '00:01:30.098000000',
|
|
],
|
|
],
|
|
])),
|
|
]);
|
|
|
|
$validator = Validator::make(
|
|
['file' => $file],
|
|
['file' => new ExtraneousMetadataFormatRule()],
|
|
);
|
|
|
|
$this->assertTrue($validator->passes());
|
|
|
|
Process::assertRan(UploadedFileAction::formatFfprobeCommand($file));
|
|
});
|