Completed
Push — checkout-optimisation ( 40d0de )
by Kamil
21:30
created

TaxRateApiTest::getTaxRateUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Tests\Controller;
13
14
use Lakion\ApiTestCase\JsonApiTestCase;
15
use Sylius\Component\Taxation\Model\TaxRateInterface;
16
use Symfony\Component\HttpFoundation\Response;
17
18
/**
19
 * @author Anna Walasek <[email protected]>
20
 */
21
final class TaxRateApiTest extends JsonApiTestCase
22
{
23
    /**
24
     * @var array
25
     */
26
    private static $authorizedHeaderWithAccept = [
27
        'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
28
        'ACCEPT' => 'application/json',
29
    ];
30
31
    /**
32
     * @test
33
     */
34
    public function it_does_not_allow_to_show_tax_rates_list_when_access_is_denied()
35
    {
36
        $this->loadFixturesFromFile('resources/tax_categories.yml');
37
        $this->loadFixturesFromFile('resources/zones.yml');
38
        $this->loadFixturesFromFile('resources/tax_rates.yml');
39
40
        $this->client->request('GET', '/api/v1/tax-rates/');
41
42
        $response = $this->client->getResponse();
43
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
44
    }
45
46
    /**
47
     * @test
48
     */
49
    public function it_allows_indexing_tax_rates()
50
    {
51
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
52
        $this->loadFixturesFromFile('resources/tax_categories.yml');
53
        $this->loadFixturesFromFile('resources/zones.yml');
54
        $this->loadFixturesFromFile('resources/tax_rates.yml');
55
56
        $this->client->request('GET', '/api/v1/tax-rates/', [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\TaxRateApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
57
58
        $response = $this->client->getResponse();
59
        $this->assertResponse($response, 'tax_rate/index_response', Response::HTTP_OK);
60
    }
61
62
    /**
63
     * @test
64
     */
65
    public function it_does_not_allow_to_show_tax_rate_when_it_does_not_exist()
66
    {
67
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
68
69
        $this->client->request('GET', '/api/v1/tax-rates/-1', [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\TaxRateApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
70
71
        $response = $this->client->getResponse();
72
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
73
    }
74
75
    /**
76
     * @test
77
     */
78
    public function it_allows_showing_tax_rate()
79
    {
80
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
81
        $this->loadFixturesFromFile('resources/tax_categories.yml');
82
        $this->loadFixturesFromFile('resources/zones.yml');
83
        $taxRates = $this->loadFixturesFromFile('resources/tax_rates.yml');
84
        $taxRate = $taxRates['sales_tax'];
85
86
        $this->client->request('GET', $this->getTaxRateUrl($taxRate), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\TaxRateApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
87
88
        $response = $this->client->getResponse();
89
        $this->assertResponse($response, 'tax_rate/show_response', Response::HTTP_OK);
90
    }
91
92
    /**
93
     * @param TaxRateInterface $taxRate
94
     *
95
     * @return string
96
     */
97
    private function getTaxRateUrl(TaxRateInterface $taxRate)
98
    {
99
        return '/api/v1/tax-rates/' . $taxRate->getCode();
100
    }
101
}
102