'supported_languages', 'value' => [ ['name' => 'English', 'abbreviation' => 'en'], ['name' => 'Spanish', 'abbreviation' => 'es'], ], 'group' => 'general' ]); $adminRole = Role::create(['name' => 'Admin', 'slug' => 'admin']); $permission = Permission::create([ 'name' => 'Manage Translations', 'slug' => 'manage-translations', 'resource' => 'translations', 'action' => 'manage' ]); $adminRole->permissions()->attach($permission); $this->admin = User::factory()->create(); $this->admin->roles()->attach($adminRole); } /** @test */ public function it_can_translate_a_text_block() { // Mock the translation service via the controller's dependency if possible, // but here we just test the endpoint which uses TranslationProviderService. // TranslationProviderService uses 'mock' driver by default if no keys are set. $response = $this->actingAs($this->admin) ->postJson(route('admin.translate'), [ 'text' => 'Hello world', 'from' => 'en', 'to' => 'es' ]); $response->assertStatus(200); $response->assertJsonStructure(['translated', 'from', 'to']); // Mock driver returns the original text + [MOCK-es] $this->assertEquals('[es] Hello world', $response->json('translated')); } /** @test */ public function it_fails_if_unauthorized() { $user = User::factory()->create(); $response = $this->actingAs($user) ->postJson(route('admin.translate'), [ 'text' => 'Hello world', 'from' => 'en', 'to' => 'es' ]); $response->assertStatus(403); } }