Files
animethemes-server/tests/Unit/Rules/Wiki/Submission/Video/VideoCodecStreamTest.php
T
Kyrch 46dca69a82 tests: enabled the validation rules features flags for the tests (#621)
* tests: enabled the validation rules features flags for the tests

* tests: fixed array feature to string
2024-03-09 02:14:04 +01:00

112 lines
3.8 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\VideoCodecStreamRule;
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 VideoCodecStreamTest.
*/
class VideoCodecStreamTest extends TestCase
{
use WithFaker;
/**
* The Video Codec Stream Rule shall fail if the video codec is not vp9.
*
* @return void
*/
public function testFailsWhenCodecIsNotVp9(): void
{
Feature::activate(FeatureConstants::VIDEO_CODEC_STREAM, 'vp9');
$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',
'codec_name' => $this->faker->randomDigitNot(2),
],
],
])),
]);
$validator = Validator::make(
['file' => $file],
['file' => new VideoCodecStreamRule()],
);
static::assertFalse($validator->passes());
Process::assertRan(SubmissionRule::formatFfprobeCommand($file));
}
/**
* The Video Codec Stream Rule shall pass if the video codec is vp9.
*
* @return void
*/
public function testPassesWhenCodecIsVp9(): void
{
Feature::activate(FeatureConstants::VIDEO_CODEC_STREAM, 'vp9');
$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',
'codec_name' => 'vp9',
],
],
])),
]);
$validator = Validator::make(
['file' => $file],
['file' => new VideoCodecStreamRule()],
);
static::assertTrue($validator->passes());
Process::assertRan(SubmissionRule::formatFfprobeCommand($file));
}
}