createOne(); $response = $this->get(route('video.show', ['video' => $video])); $response->assertForbidden(); } /** * If the video is soft-deleted, the user shall receive a not found exception. * * @return void */ public function testCannotStreamSoftDeletedVideo(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Feature::activate(AllowVideoStreams::class); $video = Video::factory()->trashed()->createOne(); $response = $this->get(route('video.show', ['video' => $video])); $response->assertNotFound(); } /** * If view recording is disabled, the video show route shall not record a view for the video. * * @return void */ public function testViewRecordingNotAllowed(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Feature::activate(AllowVideoStreams::class); Feature::deactivate(FeatureConstants::ALLOW_VIEW_RECORDING); $video = Video::factory()->createOne(); $this->get(route('video.show', ['video' => $video])); static::assertEquals(0, $video->views()->count()); } /** * Users with the bypass feature flag permission shall be permitted to stream video * even if the Allow Video Streams feature is disabled. * * @return void */ public function testVideoStreamingPermittedForBypass(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Feature::activate(AllowVideoStreams::class, $this->faker->boolean()); /** @var StreamingMethod $streamingMethod */ $streamingMethod = Arr::random(StreamingMethod::cases()); Config::set(VideoConstants::STREAMING_METHOD_QUALIFIED, $streamingMethod->value); $video = Video::factory()->createOne(); $user = User::factory()->withPermissions(SpecialPermission::BYPASS_FEATURE_FLAGS->value)->createOne(); Sanctum::actingAs($user); $response = $this->get(route('video.show', ['video' => $video])); $response->assertSuccessful(); } /** * If view recording is enabled, the video show route shall record a view for the video. * * @return void */ public function testViewRecordingIsAllowed(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Feature::activate(AllowVideoStreams::class); Feature::activate(FeatureConstants::ALLOW_VIEW_RECORDING); $video = Video::factory()->createOne(); $this->get(route('video.show', ['video' => $video])); static::assertEquals(1, $video->views()->count()); } /** * If view recording is enabled, the video show route shall record a view for the video. * * @return void */ public function testViewRecordingCooldown(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Feature::activate(AllowVideoStreams::class); Feature::activate(FeatureConstants::ALLOW_VIEW_RECORDING); $video = Video::factory()->createOne(); Collection::times($this->faker->randomDigitNotNull(), function () use ($video) { $this->get(route('video.show', ['video' => $video])); }); static::assertEquals(1, $video->views()->count()); } /** * If the streaming method is set to an unexpected value, the user shall receive an error. * * @return void */ public function testInvalidStreamingMethodError(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Feature::activate(AllowVideoStreams::class); Config::set(VideoConstants::STREAMING_METHOD_QUALIFIED, $this->faker->word()); $video = Video::factory()->createOne(); $response = $this->get(route('video.show', ['video' => $video])); $response->assertServerError(); } /** * If the streaming method is set to 'response', the video shall be streamed through a Symfony StreamedResponse. * * @return void */ public function testStreamedThroughResponse(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Feature::activate(AllowVideoStreams::class); Config::set(VideoConstants::STREAMING_METHOD_QUALIFIED, StreamingMethod::RESPONSE->value); $video = Video::factory()->createOne(); $response = $this->get(route('video.show', ['video' => $video])); static::assertInstanceOf(StreamedResponse::class, $response->baseResponse); } /** * If the streaming method is set to 'nginx', the video shall be streamed through a nginx internal redirect. * * @return void */ public function testStreamedThroughNginxRedirect(): void { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); Feature::activate(AllowVideoStreams::class); Config::set(VideoConstants::STREAMING_METHOD_QUALIFIED, StreamingMethod::NGINX->value); $video = Video::factory()->createOne(); $response = $this->get(route('video.show', ['video' => $video])); $response->assertHeader('X-Accel-Redirect'); } }