|
| 1 | +<?php |
| 2 | + |
| 3 | +use Illuminate\Support\Facades\App; |
| 4 | +use Relaticle\Flowforge\FlowforgeServiceProvider; |
| 5 | + |
| 6 | +test('translation files exist for supported languages', function () { |
| 7 | + $englishPath = __DIR__ . '/../../resources/lang/en/flowforge.php'; |
| 8 | + $dutchPath = __DIR__ . '/../../resources/lang/nl/flowforge.php'; |
| 9 | + |
| 10 | + expect(file_exists($englishPath))->toBeTrue(); |
| 11 | + expect(file_exists($dutchPath))->toBeTrue(); |
| 12 | +}); |
| 13 | + |
| 14 | +test('english translation file contains required keys', function () { |
| 15 | + $translations = require __DIR__ . '/../../resources/lang/en/flowforge.php'; |
| 16 | + |
| 17 | + $requiredKeys = [ |
| 18 | + 'loading_more_cards', |
| 19 | + 'no_cards_in_column', |
| 20 | + 'cards_count', |
| 21 | + ]; |
| 22 | + |
| 23 | + foreach ($requiredKeys as $key) { |
| 24 | + expect($translations)->toHaveKey($key) |
| 25 | + ->and($translations[$key])->not->toBeEmpty(); |
| 26 | + } |
| 27 | +}); |
| 28 | + |
| 29 | +test('dutch translation file contains same keys as english', function () { |
| 30 | + $englishTranslations = require __DIR__ . '/../../resources/lang/en/flowforge.php'; |
| 31 | + $dutchTranslations = require __DIR__ . '/../../resources/lang/nl/flowforge.php'; |
| 32 | + |
| 33 | + expect(array_keys($dutchTranslations))->toEqual(array_keys($englishTranslations)); |
| 34 | +}); |
| 35 | + |
| 36 | +test('translation keys resolve correctly', function () { |
| 37 | + App::setLocale('en'); |
| 38 | + |
| 39 | + expect(__('flowforge::flowforge.loading_more_cards'))->toBe('Loading more cards...') |
| 40 | + ->and(__('flowforge::flowforge.no_cards_in_column', ['cardLabel' => 'tasks']))->toBe('No tasks in this column'); |
| 41 | +}); |
| 42 | + |
| 43 | +test('dutch translations resolve correctly', function () { |
| 44 | + App::setLocale('nl'); |
| 45 | + |
| 46 | + expect(__('flowforge::flowforge.loading_more_cards'))->toBe('Meer kaarten laden...') |
| 47 | + ->and(__('flowforge::flowforge.no_cards_in_column', ['cardLabel' => 'taken']))->toBe('Geen taken in deze kolom'); |
| 48 | +}); |
| 49 | + |
| 50 | +test('card count pluralization works correctly', function () { |
| 51 | + App::setLocale('en'); |
| 52 | + |
| 53 | + // Test singular |
| 54 | + $singular = trans_choice('flowforge::flowforge.cards_count', 1, ['card' => 'card', 'cards' => 'cards']); |
| 55 | + expect($singular)->toBe('card'); |
| 56 | + |
| 57 | + // Test plural |
| 58 | + $plural = trans_choice('flowforge::flowforge.cards_count', 5, ['card' => 'card', 'cards' => 'cards']); |
| 59 | + expect($plural)->toBe('cards'); |
| 60 | + |
| 61 | + // Test zero |
| 62 | + $zero = trans_choice('flowforge::flowforge.cards_count', 0, ['card' => 'card', 'cards' => 'cards']); |
| 63 | + expect($zero)->toBe('cards'); |
| 64 | +}); |
| 65 | + |
| 66 | +test('service provider has translation support enabled', function () { |
| 67 | + // Check if the service provider enables translations via hasTranslations() |
| 68 | + $serviceProviderPath = __DIR__ . '/../../src/FlowforgeServiceProvider.php'; |
| 69 | + $content = file_get_contents($serviceProviderPath); |
| 70 | + |
| 71 | + expect($content)->toContain('$package->hasTranslations()'); |
| 72 | +}); |
0 commit comments