1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Xsolla\SDK\Tests\Integration\API; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @group api |
7
|
|
|
*/ |
8
|
|
|
class PromotionsTest extends AbstractAPITest |
9
|
|
|
{ |
10
|
|
|
protected static $promotionId; |
11
|
|
|
protected static $couponPromotionId; |
12
|
|
|
|
13
|
|
|
protected $promotion; |
14
|
|
|
|
15
|
|
|
public function setUp() |
16
|
|
|
{ |
17
|
|
|
parent::setUp(); |
18
|
|
|
$this->promotion = [ |
19
|
|
|
'technical_name' => uniqid('promotion_', false), |
20
|
|
|
'name' => [ |
21
|
|
|
'en' => 'name', |
22
|
|
|
], |
23
|
|
|
'description' => [ |
24
|
|
|
'en' => 'description', |
25
|
|
|
], |
26
|
|
|
'project_id' => static::$projectId, |
27
|
|
|
]; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testListPromotions() |
31
|
|
|
{ |
32
|
|
|
$response = static::$xsollaClient->ListPromotions(); |
33
|
|
|
static::assertInternalType('array', $response); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testCreatePromotion() |
37
|
|
|
{ |
38
|
|
|
$response = static::$xsollaClient->CreatePromotion([ |
39
|
|
|
'request' => $this->promotion, |
40
|
|
|
]); |
41
|
|
|
static::assertArrayHasKey('id', $response); |
42
|
|
|
static::$promotionId = $response['id']; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @depends testCreatePromotion |
47
|
|
|
*/ |
48
|
|
|
public function testGetPromotion() |
49
|
|
|
{ |
50
|
|
|
$response = static::$xsollaClient->GetPromotion([ |
51
|
|
|
'promotion_id' => static::$promotionId, |
52
|
|
|
]); |
53
|
|
|
static::assertInternalType('array', $response); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @depends testGetPromotion |
58
|
|
|
*/ |
59
|
|
|
public function testUpdatePromotion() |
60
|
|
|
{ |
61
|
|
|
$response = static::$xsollaClient->UpdatePromotion([ |
|
|
|
|
62
|
|
|
'promotion_id' => static::$promotionId, |
63
|
|
|
'request' => $this->promotion, |
64
|
|
|
]); |
65
|
|
|
static::assertSame(204, $response->getStatusCode()); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @depends testUpdatePromotion |
70
|
|
|
*/ |
71
|
|
|
public function testSetPromotionSubject() |
72
|
|
|
{ |
73
|
|
|
$response = static::$xsollaClient->SetPromotionSubject([ |
|
|
|
|
74
|
|
|
'promotion_id' => static::$promotionId, |
75
|
|
|
'request' => [ |
76
|
|
|
'purchase' => false, |
77
|
|
|
'items' => null, |
78
|
|
|
'packages' => [1], |
79
|
|
|
], |
80
|
|
|
]); |
81
|
|
|
static::assertSame(204, $response->getStatusCode()); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @depends testSetPromotionSubject |
86
|
|
|
*/ |
87
|
|
|
public function testGetPromotionSubject() |
88
|
|
|
{ |
89
|
|
|
$response = static::$xsollaClient->GetPromotionSubject([ |
90
|
|
|
'promotion_id' => static::$promotionId, |
91
|
|
|
]); |
92
|
|
|
static::assertInternalType('array', $response); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testSetPromotionPaymentSystems() |
96
|
|
|
{ |
97
|
|
|
static::markTestIncomplete('We haven\'t allowed payment systems for test project yet.'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @depends testGetPromotionSubject |
102
|
|
|
*/ |
103
|
|
|
public function testGetPromotionPaymentSystems() |
104
|
|
|
{ |
105
|
|
|
$response = static::$xsollaClient->GetPromotionPaymentSystems([ |
106
|
|
|
'promotion_id' => static::$promotionId, |
107
|
|
|
]); |
108
|
|
|
static::assertInternalType('array', $response); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @depends testGetPromotionPaymentSystems |
113
|
|
|
*/ |
114
|
|
|
public function testSetPromotionPeriods() |
115
|
|
|
{ |
116
|
|
|
$randomFutureTimestamp = mt_rand(time() + 60, 2147483647); |
117
|
|
|
$datetimeStart = \DateTime::createFromFormat('U', $randomFutureTimestamp, new \DateTimeZone('UTC')); |
118
|
|
|
$response = static::$xsollaClient->SetPromotionPeriods([ |
|
|
|
|
119
|
|
|
'promotion_id' => static::$promotionId, |
120
|
|
|
'request' => [ |
121
|
|
|
'periods' => [ |
122
|
|
|
[ |
123
|
|
|
'from' => $datetimeStart->format(\DateTime::ISO8601), |
124
|
|
|
'to' => $datetimeStart->modify('+ 1 second')->format(\DateTime::ISO8601), |
125
|
|
|
], |
126
|
|
|
], |
127
|
|
|
], |
128
|
|
|
]); |
129
|
|
|
static::assertSame(204, $response->getStatusCode()); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @depends testSetPromotionPeriods |
134
|
|
|
*/ |
135
|
|
|
public function testGetPromotionPeriods() |
136
|
|
|
{ |
137
|
|
|
$response = static::$xsollaClient->GetPromotionPeriods([ |
138
|
|
|
'promotion_id' => static::$promotionId, |
139
|
|
|
]); |
140
|
|
|
static::assertInternalType('array', $response); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @depends testGetPromotionPeriods |
145
|
|
|
*/ |
146
|
|
View Code Duplication |
public function testSetPromotionRewards() |
|
|
|
|
147
|
|
|
{ |
148
|
|
|
$response = static::$xsollaClient->SetPromotionRewards([ |
|
|
|
|
149
|
|
|
'promotion_id' => static::$promotionId, |
150
|
|
|
'request' => [ |
151
|
|
|
'purchase' => [ |
152
|
|
|
'discount_percent' => 10, |
153
|
|
|
], |
154
|
|
|
], |
155
|
|
|
]); |
156
|
|
|
static::assertSame(204, $response->getStatusCode()); |
|
|
|
|
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @depends testSetPromotionRewards |
161
|
|
|
*/ |
162
|
|
|
public function testGetPromotionRewards() |
163
|
|
|
{ |
164
|
|
|
$response = static::$xsollaClient->GetPromotionRewards([ |
165
|
|
|
'promotion_id' => static::$promotionId, |
166
|
|
|
]); |
167
|
|
|
static::assertInternalType('array', $response); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @depends testGetPromotionRewards |
172
|
|
|
*/ |
173
|
|
|
public function testReviewPromotion() |
174
|
|
|
{ |
175
|
|
|
$response = static::$xsollaClient->ReviewPromotion([ |
176
|
|
|
'promotion_id' => static::$promotionId, |
177
|
|
|
]); |
178
|
|
|
static::assertInternalType('array', $response); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @depends testReviewPromotion |
183
|
|
|
*/ |
184
|
|
|
public function testCreateCouponPromotion() |
185
|
|
|
{ |
186
|
|
|
$response = static::$xsollaClient->CreateCouponPromotion([ |
187
|
|
|
'request' => [ |
188
|
|
|
'campaign_code' => uniqid('xsolla_api_test_campaign_code_', false), |
189
|
|
|
'project_id' => self::$projectId, |
190
|
|
|
'campaign_names' => ['en' => 'xsolla_api_test_campaign_code'], |
191
|
|
|
'redeems_count_for_user' => 1, |
192
|
|
|
'campaign_redeems_count_for_user' => 1, |
193
|
|
|
'expiration_date' => (new \DateTime('+3day'))->format(DATE_RFC3339), |
194
|
|
|
], |
195
|
|
|
]); |
196
|
|
|
static::assertInternalType('array', $response); |
197
|
|
|
static::$couponPromotionId = $response['id']; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @depends testCreateCouponPromotion |
202
|
|
|
*/ |
203
|
|
View Code Duplication |
public function testGetCouponPromotions() |
|
|
|
|
204
|
|
|
{ |
205
|
|
|
$response = static::$xsollaClient->ListCouponPromotions([ |
206
|
|
|
'limit' => 20, |
207
|
|
|
'offset' => 0, |
208
|
|
|
]); |
209
|
|
|
static::assertInternalType('array', $response); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @depends testCreateCouponPromotion |
214
|
|
|
*/ |
215
|
|
View Code Duplication |
public function testUpdatePromotionCampaigns() |
|
|
|
|
216
|
|
|
{ |
217
|
|
|
$response = static::$xsollaClient->UpdatePromotionCampaigns([ |
|
|
|
|
218
|
|
|
'promotion_id' => static::$promotionId, |
219
|
|
|
'request' => [ |
220
|
|
|
'campaigns' => [static::$couponPromotionId], |
221
|
|
|
], |
222
|
|
|
]); |
223
|
|
|
static::assertSame(204, $response->getStatusCode()); |
|
|
|
|
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @depends testUpdatePromotionCampaigns |
228
|
|
|
*/ |
229
|
|
|
public function testTogglePromotion() |
230
|
|
|
{ |
231
|
|
|
$response = static::$xsollaClient->TogglePromotion([ |
|
|
|
|
232
|
|
|
'promotion_id' => static::$promotionId, |
233
|
|
|
]); |
234
|
|
|
static::assertSame(204, $response->getStatusCode()); |
|
|
|
|
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @depends testUpdatePromotionCampaigns |
239
|
|
|
*/ |
240
|
|
|
public function testDeletePromotion() |
241
|
|
|
{ |
242
|
|
|
$response = static::$xsollaClient->DeletePromotion([ |
|
|
|
|
243
|
|
|
'promotion_id' => static::$promotionId, |
244
|
|
|
]); |
245
|
|
|
static::assertSame(204, $response->getStatusCode()); |
|
|
|
|
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.