1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerTest\Glue\CartsRestApi\Plugin\GlueApplication; |
9
|
|
|
|
10
|
|
|
use Codeception\Test\Unit; |
11
|
|
|
use Generated\Shared\Transfer\RestCheckoutDataTransfer; |
12
|
|
|
use Spryker\Glue\CartsRestApi\Plugin\GlueApplication\CartByRestCheckoutDataResourceRelationshipPlugin; |
13
|
|
|
use Spryker\Glue\GlueApplication\Rest\JsonApi\RestResourceBuilder; |
14
|
|
|
use SprykerTest\Glue\CartsRestApi\CartRestApiGlueTester; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Auto-generated group annotations |
18
|
|
|
* |
19
|
|
|
* @group SprykerTest |
20
|
|
|
* @group Glue |
21
|
|
|
* @group CartsRestApi |
22
|
|
|
* @group Plugin |
23
|
|
|
* @group GlueApplication |
24
|
|
|
* @group CartByRestCheckoutDataResourceRelationshipPluginTest |
25
|
|
|
* Add your own group annotations below this line |
26
|
|
|
*/ |
27
|
|
|
class CartByRestCheckoutDataResourceRelationshipPluginTest extends Unit |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @uses \Spryker\Glue\CartsRestApi\CartsRestApiConfig::RESOURCE_CARTS |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected const RESOURCE_CARTS = 'carts'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @uses \Spryker\Glue\GlueApplication\Plugin\Application\GlueApplicationApplicationPlugin::SERVICE_RESOURCE_BUILDER |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected const SERVICE_RESOURCE_BUILDER = 'resource_builder'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected const QUOTE_UUID = 'test_cart_uuid'; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var \SprykerTest\Glue\CartsRestApi\CartRestApiGlueTester |
50
|
|
|
*/ |
51
|
|
|
protected CartRestApiGlueTester $tester; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function _before(): void |
57
|
|
|
{ |
58
|
|
|
parent::_before(); |
59
|
|
|
|
60
|
|
|
$this->tester->getContainer()->set( |
61
|
|
|
static::SERVICE_RESOURCE_BUILDER, |
62
|
|
|
new RestResourceBuilder(), |
|
|
|
|
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return void |
68
|
|
|
*/ |
69
|
|
|
public function testAddResourceRelationshipsWillAddCartsResource(): void |
70
|
|
|
{ |
71
|
|
|
// Arrange |
72
|
|
|
$restCheckoutDataTransfer = $this->tester->getRestCheckoutDataTransfer([ |
73
|
|
|
RestCheckoutDataTransfer::QUOTE => $this->tester->createQuoteTransfer(static::QUOTE_UUID), |
74
|
|
|
]); |
75
|
|
|
$restCheckoutDataResource = $this->tester->createCheckoutDataRestResource() |
76
|
|
|
->setPayload($restCheckoutDataTransfer); |
77
|
|
|
|
78
|
|
|
// Act |
79
|
|
|
(new CartByRestCheckoutDataResourceRelationshipPlugin())->addResourceRelationships( |
80
|
|
|
[$restCheckoutDataResource], |
81
|
|
|
$this->tester->getRestRequestMock(true), |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
// Assert |
85
|
|
|
$this->assertCount(1, $restCheckoutDataResource->getRelationshipByType(static::RESOURCE_CARTS)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
|
|
public function testAddResourceRelationshipsWillNotAddCartResourcesWithoutQuoteInRestCheckoutDataPayload(): void |
92
|
|
|
{ |
93
|
|
|
// Arrange |
94
|
|
|
$restCheckoutDataTransfer = $this->tester->getRestCheckoutDataTransfer(); |
95
|
|
|
$restCheckoutDataResource = $this->tester->createCheckoutDataRestResource() |
96
|
|
|
->setPayload($restCheckoutDataTransfer); |
97
|
|
|
|
98
|
|
|
// Act |
99
|
|
|
(new CartByRestCheckoutDataResourceRelationshipPlugin())->addResourceRelationships( |
100
|
|
|
[$restCheckoutDataResource], |
101
|
|
|
$this->tester->getRestRequestMock(true), |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
// Assert |
105
|
|
|
$this->assertEmpty($restCheckoutDataResource->getRelationships()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return void |
110
|
|
|
*/ |
111
|
|
|
public function testAddResourceRelationshipsWillNotAddCartsResourcesIfRestCheckoutDataTransferIsNotProvided(): void |
112
|
|
|
{ |
113
|
|
|
// Arrange |
114
|
|
|
$restCheckoutDataResource = $this->tester->createCheckoutDataRestResource(); |
115
|
|
|
|
116
|
|
|
// Act |
117
|
|
|
(new CartByRestCheckoutDataResourceRelationshipPlugin())->addResourceRelationships( |
118
|
|
|
[$restCheckoutDataResource], |
119
|
|
|
$this->tester->getRestRequestMock(true), |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
// Assert |
123
|
|
|
$this->assertEmpty($restCheckoutDataResource->getRelationships()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
public function testAddResourceRelationshipsWillNotAddCartsResourcesForGuestUser(): void |
130
|
|
|
{ |
131
|
|
|
// Arrange |
132
|
|
|
$restCheckoutDataTransfer = $this->tester->getRestCheckoutDataTransfer([ |
133
|
|
|
RestCheckoutDataTransfer::QUOTE => $this->tester->createQuoteTransfer(static::QUOTE_UUID), |
134
|
|
|
]); |
135
|
|
|
$restCheckoutDataResource = $this->tester->createCheckoutDataRestResource() |
136
|
|
|
->setPayload($restCheckoutDataTransfer); |
137
|
|
|
|
138
|
|
|
// Act |
139
|
|
|
(new CartByRestCheckoutDataResourceRelationshipPlugin())->addResourceRelationships( |
140
|
|
|
[$restCheckoutDataResource], |
141
|
|
|
$this->tester->getRestRequestMock(), |
142
|
|
|
); |
143
|
|
|
|
144
|
|
|
// Assert |
145
|
|
|
$this->assertEmpty($restCheckoutDataResource->getRelationships()); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|