mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-25 11:09:17 +01:00
* tests: enabled the validation rules features flags for the tests * tests: fixed array feature to string
112 lines
3.9 KiB
PHP
112 lines
3.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Rules\Wiki\Submission\Video;
|
|
|
|
use App\Constants\FeatureConstants;
|
|
use App\Rules\Wiki\Submission\SubmissionRule;
|
|
use App\Rules\Wiki\Submission\Video\VideoPixelFormatStreamRule;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Process;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Laravel\Pennant\Feature;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Class VideoPixelFormatStreamTest.
|
|
*/
|
|
class VideoPixelFormatStreamTest extends TestCase
|
|
{
|
|
use WithFaker;
|
|
|
|
/**
|
|
* The Video Pixel Format Stream Rule shall fail if the pixel format is not yuv420p.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testFailsWhenCodecIsNotYuv420p(): void
|
|
{
|
|
Feature::activate(FeatureConstants::VIDEO_PIXEL_FORMAT_STREAM, 'yuv420p');
|
|
|
|
$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([
|
|
'streams' => [
|
|
0 => [
|
|
'codec_type' => 'video',
|
|
'pix_fmt' => $this->faker->randomDigitNot(2),
|
|
],
|
|
],
|
|
])),
|
|
]);
|
|
|
|
$validator = Validator::make(
|
|
['file' => $file],
|
|
['file' => new VideoPixelFormatStreamRule()],
|
|
);
|
|
|
|
static::assertFalse($validator->passes());
|
|
|
|
Process::assertRan(SubmissionRule::formatFfprobeCommand($file));
|
|
}
|
|
|
|
/**
|
|
* The Video Pixel Format Stream Rule shall pass if the pixel format is yuv420p.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testPassesWhenCodecIsVp9(): void
|
|
{
|
|
Feature::activate(FeatureConstants::VIDEO_PIXEL_FORMAT_STREAM, 'yuv420p');
|
|
|
|
$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([
|
|
'streams' => [
|
|
0 => [
|
|
'codec_type' => 'video',
|
|
'pix_fmt' => 'yuv420p',
|
|
],
|
|
],
|
|
])),
|
|
]);
|
|
|
|
$validator = Validator::make(
|
|
['file' => $file],
|
|
['file' => new VideoPixelFormatStreamRule()],
|
|
);
|
|
|
|
static::assertTrue($validator->passes());
|
|
|
|
Process::assertRan(SubmissionRule::formatFfprobeCommand($file));
|
|
}
|
|
}
|