Completed
Push — master ( 12acd0...0a5e06 )
by
unknown
10s
created

test_if_middleware_sets_custom_language()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 18
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 18
loc 18
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace App\Containers\Localization\UI\API\Tests\Functional;
4
5
use App\Containers\Localization\Tests\ApiTestCase;
6
use Illuminate\Support\Facades\Config;
7
8
/**
9
 * Class CheckLocalizationMiddlewareTest.
10
 *
11
 * @group localization
12
 * @group api
13
 */
14
class CheckLocalizationMiddlewareTest extends ApiTestCase
15
{
16
17
    // the endpoint to be called within this test (e.g., [email protected]/users)
18
    protected $endpoint = '[email protected]/localizations';
19
20
    // fake some access rights
21
    protected $access = [
22
        'permissions' => '',
23
        'roles'       => '',
24
    ];
25
26
    /**
27
     * @test
28
     */
29 View Code Duplication
    public function test_if_middleware_sets_default_app_language()
0 ignored issues
show
Duplication introduced by Johannes Schobel
This method seems to be duplicated in your project.

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.

Loading history...
30
    {
31
        $data = [];
32
        $requestHeaders = [];
33
34
        // send the HTTP request
35
        $response = $this->makeCall($data, $requestHeaders);
36
37
        // assert the response status
38
        $response->assertStatus(200);
39
40
        $defaultLanguage = Config::get('app.locale');
41
42
        // check if the header is properly set
43
        $response->assertHeader('content-language', $defaultLanguage);
44
    }
45
46 View Code Duplication
    public function test_if_middleware_sets_custom_language()
0 ignored issues
show
Duplication introduced by Johannes Schobel
This method seems to be duplicated in your project.

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.

Loading history...
47
    {
48
        $language = 'fr';
49
50
        $data = [];
51
        $requestHeaders = [
52
            'accept-language' => $language,
53
        ];
54
55
        // send the HTTP request
56
        $response = $this->makeCall($data, $requestHeaders);
57
58
        // assert the response status
59
        $response->assertStatus(200);
60
61
        // check if the header is properly set
62
        $response->assertHeader('content-language', $language);
63
    }
64
65
    public function test_if_middleware_throws_error_on_wrong_language()
66
    {
67
        $language = 'xxx';
68
69
        $data = [];
70
        $requestHeaders = [
71
            'accept-language' => $language,
72
        ];
73
74
        // send the HTTP request
75
        $response = $this->makeCall($data, $requestHeaders);
76
77
        // assert the response status
78
        $response->assertStatus(412);
79
    }
80
81
}
82