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\Core\Model\PromotionCouponInterface; |
16
|
|
|
use Sylius\Component\Promotion\Model\PromotionInterface; |
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Anna Walasek <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
final class PromotionCouponApiTest extends JsonApiTestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
private static $authorizedHeaderWithAccept = [ |
28
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
29
|
|
|
'ACCEPT' => 'application/json', |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @test |
34
|
|
|
*/ |
35
|
|
|
public function it_does_not_allow_to_show_promotion_coupons_list_when_access_is_denied() |
36
|
|
|
{ |
37
|
|
|
$promotions = $this->loadFixturesFromFile('resources/promotions.yml'); |
38
|
|
|
$promotion = $promotions['promotion2']; |
39
|
|
|
|
40
|
|
|
$this->loadFixturesFromFile('resources/promotion_coupons.yml'); |
41
|
|
|
|
42
|
|
|
$this->client->request('GET', $this->getPromotionCouponsUrl($promotion)); |
43
|
|
|
|
44
|
|
|
$response = $this->client->getResponse(); |
45
|
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @test |
50
|
|
|
*/ |
51
|
|
|
public function it_allows_indexing_promotion_coupons() |
52
|
|
|
{ |
53
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
54
|
|
|
$promotions = $this->loadFixturesFromFile('resources/promotions.yml'); |
55
|
|
|
$promotion = $promotions['promotion2']; |
56
|
|
|
$this->loadFixturesFromFile('resources/promotion_coupons.yml'); |
57
|
|
|
|
58
|
|
|
$this->client->request('GET', $this->getPromotionCouponsUrl($promotion), [], [], static::$authorizedHeaderWithAccept); |
|
|
|
|
59
|
|
|
|
60
|
|
|
$response = $this->client->getResponse(); |
61
|
|
|
$this->assertResponse($response, 'promotion_coupon/index_response', Response::HTTP_OK); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @test |
66
|
|
|
*/ |
67
|
|
|
public function it_does_not_allow_to_show_promotion_when_it_does_not_exist() |
68
|
|
|
{ |
69
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
70
|
|
|
$promotions = $this->loadFixturesFromFile('resources/promotions.yml'); |
71
|
|
|
$promotion = $promotions['promotion2']; |
72
|
|
|
|
73
|
|
|
$this->client->request('GET', sprintf('/api/v1/promotions/%s/coupons/-1', $promotion->getCode()), [], [], static::$authorizedHeaderWithAccept); |
|
|
|
|
74
|
|
|
|
75
|
|
|
$response = $this->client->getResponse(); |
76
|
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @test |
81
|
|
|
*/ |
82
|
|
|
public function it_allows_showing_promotion_coupon() |
83
|
|
|
{ |
84
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
85
|
|
|
$promotions = $this->loadFixturesFromFile('resources/promotions.yml'); |
86
|
|
|
$promotion = $promotions['promotion2']; |
87
|
|
|
|
88
|
|
|
$promotion_coupons = $this->loadFixturesFromFile('resources/promotion_coupons.yml'); |
|
|
|
|
89
|
|
|
$coupon = $promotion_coupons['promotionCoupon1']; |
|
|
|
|
90
|
|
|
|
91
|
|
|
$this->client->request('GET', $this->getPromotionCouponUrl($promotion, $coupon), [], [], static::$authorizedHeaderWithAccept); |
|
|
|
|
92
|
|
|
|
93
|
|
|
$response = $this->client->getResponse(); |
94
|
|
|
$this->assertResponse($response, 'promotion_coupon/show_response', Response::HTTP_OK); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param PromotionInterface $promotion |
99
|
|
|
* @param PromotionCouponInterface|null $coupon |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
private function getPromotionCouponUrl(PromotionInterface $promotion, PromotionCouponInterface $coupon = null) |
104
|
|
|
{ |
105
|
|
|
return sprintf('/api/v1/promotions/%s/coupons/%s', $promotion->getCode(), $coupon->getCode()); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param PromotionInterface $promotion |
110
|
|
|
* |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
private function getPromotionCouponsUrl(PromotionInterface $promotion) |
114
|
|
|
{ |
115
|
|
|
return sprintf('/api/v1/promotions/%s/coupons/', $promotion->getCode()); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
Late static binding only has effect in subclasses. A
final
class cannot be extended anymore so late static binding cannot occurr. Consider replacingstatic::
withself::
.To learn more about late static binding, please refer to the PHP core documentation.