'Admin', 'slug' => 'admin']); $this->admin = User::factory()->create(); $this->admin->roles()->attach($adminRole); } public function test_t_helper_returns_humanized_key_when_not_found() { $this->assertEquals('Home', t('nav.home')); $this->assertEquals('My awesome page', t('cms::my_awesome_page')); } public function test_t_helper_returns_db_override_when_present() { Translation::create([ 'locale' => 'en', 'group' => 'cms', 'key' => 'navigation.home', 'value' => 'Dashboard Home' ]); $this->assertEquals('Dashboard Home', t('cms::navigation.home')); } public function test_admin_can_manage_translations() { $response = $this->actingAs($this->admin) ->postJson(route('admin.translations.update'), [ 'locale' => 'en', 'group' => 'cms', 'key' => 'test.key', 'value' => 'Test Value' ]); $response->assertStatus(200); $this->assertDatabaseHas('translations', [ 'locale' => 'en', 'group' => 'cms', 'key' => 'test.key', 'value' => 'Test Value' ]); $this->assertEquals('Test Value', t('cms::test.key')); } public function test_locale_switching_via_middleware() { Translation::create([ 'locale' => 'es', 'group' => 'cms', 'key' => 'welcome', 'value' => 'Bienvenido' ]); // Mock session $this->withSession(['locale' => 'es']) ->get(route('admin.dashboard')); $this->assertEquals('Bienvenido', t('cms::welcome', [], 'es')); } }