createOne(); $response = $this->get(route('videoscript.show', ['videoscript' => $script])); $response->assertForbidden(); } /** * Users with the bypass feature flag permission shall be permitted to download scripts * even if the Allow Script Downloading feature is disabled. */ public function testVideoStreamingPermittedForBypass(): void { Feature::activate(AllowScriptDownloading::class, $this->faker->boolean()); $fs = Storage::fake(Config::get(VideoConstants::SCRIPT_DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.txt'); $fsFile = $fs->putFile('', $file); $script = VideoScript::factory()->createOne([ VideoScript::ATTRIBUTE_PATH => $fsFile, ]); $user = User::factory()->withPermissions(SpecialPermission::BYPASS_FEATURE_FLAGS->value)->createOne(); Sanctum::actingAs($user); $response = $this->get(route('videoscript.show', ['videoscript' => $script])); $response->assertDownload($script->path); } /** * If the script is soft-deleted, the user shall receive a not found exception. */ public function testCannotStreamSoftDeletedVideo(): void { Feature::activate(AllowScriptDownloading::class); $script = VideoScript::factory()->trashed()->createOne(); $response = $this->get(route('videoscript.show', ['videoscript' => $script])); $response->assertNotFound(); } /** * If script downloading is enabled, the script is downloaded from storage through the response. */ public function testDownloadedThroughResponse(): void { Feature::activate(AllowScriptDownloading::class); $fs = Storage::fake(Config::get(VideoConstants::SCRIPT_DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.txt'); $fsFile = $fs->putFile('', $file); $script = VideoScript::factory()->createOne([ VideoScript::ATTRIBUTE_PATH => $fsFile, ]); $response = $this->get(route('videoscript.show', ['videoscript' => $script])); $response->assertDownload($script->path); } }