1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Containers\Localization\Tests\Unit; |
4
|
|
|
|
5
|
|
|
use App\Containers\Localization\Tasks\GetAllLocalizationsTask; |
6
|
|
|
use App\Containers\Localization\Tests\TestCase; |
7
|
|
|
use App\Containers\Localization\Values\Localization; |
8
|
|
|
use Illuminate\Support\Facades\App; |
9
|
|
|
use Illuminate\Support\Facades\Config; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class GetLocalizationsTest. |
13
|
|
|
* |
14
|
|
|
* @group localization |
15
|
|
|
* @group unit |
16
|
|
|
*/ |
17
|
|
|
class GetLocalizationsTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @test |
22
|
|
|
*/ |
23
|
|
|
public function test_if_all_supported_languages_are_returned() |
24
|
|
|
{ |
25
|
|
|
$class = App::make(GetAllLocalizationsTask::class); |
26
|
|
|
$localizations = $class->run(); |
27
|
|
|
|
28
|
|
|
$configuredLocalizations = Config::get('localization-container.supported_languages', []); |
29
|
|
|
|
30
|
|
|
// assert that they have the same amount of fields |
31
|
|
|
$this->assertEquals(count($configuredLocalizations), $localizations->count()); |
32
|
|
|
|
33
|
|
|
// now we check all localizations in particular |
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public function test_if_specific_locale_is_returned() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$class = App::make(GetAllLocalizationsTask::class); |
39
|
|
|
$localizations = $class->run(); |
40
|
|
|
|
41
|
|
|
$unsupportedLocale = new Localization('fr'); |
42
|
|
|
|
43
|
|
|
$this->assertContains($unsupportedLocale, $localizations, '', false, false, false); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
View Code Duplication |
public function test_if_specific_locale_with_regions_is_returned() |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$class = App::make(GetAllLocalizationsTask::class); |
49
|
|
|
$localizations = $class->run(); |
50
|
|
|
|
51
|
|
|
$unsupportedLocale = new Localization('en', ['en-GB', 'en-US']); |
52
|
|
|
|
53
|
|
|
$this->assertContains($unsupportedLocale, $localizations, '', false, false, false); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function test_if_wrong_locale_is_not_returned() |
57
|
|
|
{ |
58
|
|
|
$class = App::make(GetAllLocalizationsTask::class); |
59
|
|
|
$localizations = $class->run(); |
60
|
|
|
|
61
|
|
|
$unsupportedLocale = new Localization('xxx'); |
62
|
|
|
|
63
|
|
|
$this->assertNotContains($unsupportedLocale, $localizations, '', false, false, false); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.