Test Failed
Push — master ( 44764d...6dc399 )
by Mike
04:21
created
unit-tests/Tests/Version4/Products.php 1 patch
Spacing   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 use \WP_REST_Request;
14 14
 use \WC_REST_Unit_Test_Case;
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 *
32 32
 	 * @param object $factory Factory object.
33 33
 	 */
34
-	public static function wpSetUpBeforeClass( $factory ) {
34
+	public static function wpSetUpBeforeClass($factory) {
35 35
 		self::$user = $factory->user->create(
36 36
 			array(
37 37
 				'role' => 'administrator',
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	public function setUp() {
46 46
 		parent::setUp();
47
-		wp_set_current_user( self::$user );
47
+		wp_set_current_user(self::$user);
48 48
 	}
49 49
 
50 50
 	/**
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
 	 */
55 55
 	public function test_register_routes() {
56 56
 		$routes = $this->server->get_routes();
57
-		$this->assertArrayHasKey( '/wc/v4/products', $routes );
58
-		$this->assertArrayHasKey( '/wc/v4/products/(?P<id>[\d]+)', $routes );
59
-		$this->assertArrayHasKey( '/wc/v4/products/batch', $routes );
57
+		$this->assertArrayHasKey('/wc/v4/products', $routes);
58
+		$this->assertArrayHasKey('/wc/v4/products/(?P<id>[\d]+)', $routes);
59
+		$this->assertArrayHasKey('/wc/v4/products/batch', $routes);
60 60
 	}
61 61
 
62 62
 	/**
@@ -66,18 +66,18 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function test_get_products() {
68 68
 		ProductHelper::create_external_product();
69
-		sleep( 1 ); // So both products have different timestamps.
69
+		sleep(1); // So both products have different timestamps.
70 70
 		ProductHelper::create_simple_product();
71
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products' ) );
71
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products'));
72 72
 		$products = $response->get_data();
73 73
 
74
-		$this->assertEquals( 200, $response->get_status() );
74
+		$this->assertEquals(200, $response->get_status());
75 75
 
76
-		$this->assertEquals( 2, count( $products ) );
77
-		$this->assertEquals( 'Dummy Product', $products[0]['name'] );
78
-		$this->assertEquals( 'DUMMY SKU', $products[0]['sku'] );
79
-		$this->assertEquals( 'Dummy External Product', $products[1]['name'] );
80
-		$this->assertEquals( 'DUMMY EXTERNAL SKU', $products[1]['sku'] );
76
+		$this->assertEquals(2, count($products));
77
+		$this->assertEquals('Dummy Product', $products[0]['name']);
78
+		$this->assertEquals('DUMMY SKU', $products[0]['sku']);
79
+		$this->assertEquals('Dummy External Product', $products[1]['name']);
80
+		$this->assertEquals('DUMMY EXTERNAL SKU', $products[1]['sku']);
81 81
 	}
82 82
 
83 83
 	/**
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
 	 * @since 3.5.0
87 87
 	 */
88 88
 	public function test_get_products_without_permission() {
89
-		wp_set_current_user( 0 );
89
+		wp_set_current_user(0);
90 90
 		ProductHelper::create_simple_product();
91
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products' ) );
92
-		$this->assertEquals( 401, $response->get_status() );
91
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products'));
92
+		$this->assertEquals(401, $response->get_status());
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,10 +99,10 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	public function test_get_product() {
101 101
 		$simple   = ProductHelper::create_external_product();
102
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products/' . $simple->get_id() ) );
102
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products/' . $simple->get_id()));
103 103
 		$product  = $response->get_data();
104 104
 
105
-		$this->assertEquals( 200, $response->get_status() );
105
+		$this->assertEquals(200, $response->get_status());
106 106
 		$this->assertContains(
107 107
 			array(
108 108
 				'id'            => $simple->get_id(),
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
 	 * @since 3.5.0
123 123
 	 */
124 124
 	public function test_get_product_without_permission() {
125
-		wp_set_current_user( 0 );
125
+		wp_set_current_user(0);
126 126
 		$product  = ProductHelper::create_simple_product();
127
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products/' . $product->get_id() ) );
128
-		$this->assertEquals( 401, $response->get_status() );
127
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products/' . $product->get_id()));
128
+		$this->assertEquals(401, $response->get_status());
129 129
 	}
130 130
 
131 131
 	/**
@@ -136,14 +136,14 @@  discard block
 block discarded – undo
136 136
 	public function test_delete_product() {
137 137
 		$product = ProductHelper::create_simple_product();
138 138
 
139
-		$request = new WP_REST_Request( 'DELETE', '/wc/v4/products/' . $product->get_id() );
140
-		$request->set_param( 'force', true );
141
-		$response = $this->server->dispatch( $request );
142
-		$this->assertEquals( 200, $response->get_status() );
139
+		$request = new WP_REST_Request('DELETE', '/wc/v4/products/' . $product->get_id());
140
+		$request->set_param('force', true);
141
+		$response = $this->server->dispatch($request);
142
+		$this->assertEquals(200, $response->get_status());
143 143
 
144
-		$response   = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products' ) );
144
+		$response   = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products'));
145 145
 		$variations = $response->get_data();
146
-		$this->assertEquals( 0, count( $variations ) );
146
+		$this->assertEquals(0, count($variations));
147 147
 	}
148 148
 
149 149
 	/**
@@ -152,12 +152,12 @@  discard block
 block discarded – undo
152 152
 	 * @since 3.5.0
153 153
 	 */
154 154
 	public function test_delete_product_without_permission() {
155
-		wp_set_current_user( 0 );
155
+		wp_set_current_user(0);
156 156
 		$product = ProductHelper::create_simple_product();
157
-		$request = new WP_REST_Request( 'DELETE', '/wc/v4/products/' . $product->get_id() );
158
-		$request->set_param( 'force', true );
159
-		$response = $this->server->dispatch( $request );
160
-		$this->assertEquals( 401, $response->get_status() );
157
+		$request = new WP_REST_Request('DELETE', '/wc/v4/products/' . $product->get_id());
158
+		$request->set_param('force', true);
159
+		$response = $this->server->dispatch($request);
160
+		$this->assertEquals(401, $response->get_status());
161 161
 	}
162 162
 
163 163
 	/**
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
 	 * @since 3.5.0
167 167
 	 */
168 168
 	public function test_delete_product_with_invalid_id() {
169
-		wp_set_current_user( 0 );
170
-		$request = new WP_REST_Request( 'DELETE', '/wc/v4/products/0' );
171
-		$request->set_param( 'force', true );
172
-		$response = $this->server->dispatch( $request );
173
-		$this->assertEquals( 404, $response->get_status() );
169
+		wp_set_current_user(0);
170
+		$request = new WP_REST_Request('DELETE', '/wc/v4/products/0');
171
+		$request->set_param('force', true);
172
+		$response = $this->server->dispatch($request);
173
+		$this->assertEquals(404, $response->get_status());
174 174
 	}
175 175
 
176 176
 	/**
@@ -181,15 +181,15 @@  discard block
 block discarded – undo
181 181
 	public function test_update_product() {
182 182
 		// test simple products.
183 183
 		$product      = ProductHelper::create_simple_product();
184
-		$response     = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products/' . $product->get_id() ) );
184
+		$response     = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products/' . $product->get_id()));
185 185
 		$data         = $response->get_data();
186
-		$date_created = date( 'Y-m-d\TH:i:s', current_time( 'timestamp' ) );
186
+		$date_created = date('Y-m-d\TH:i:s', current_time('timestamp'));
187 187
 
188
-		$this->assertEquals( 'DUMMY SKU', $data['sku'] );
189
-		$this->assertEquals( 10, $data['regular_price'] );
190
-		$this->assertEmpty( $data['sale_price'] );
188
+		$this->assertEquals('DUMMY SKU', $data['sku']);
189
+		$this->assertEquals(10, $data['regular_price']);
190
+		$this->assertEmpty($data['sale_price']);
191 191
 
192
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/products/' . $product->get_id() );
192
+		$request = new WP_REST_Request('PUT', '/wc/v4/products/' . $product->get_id());
193 193
 		$request->set_body_params(
194 194
 			array(
195 195
 				'sku'          => 'FIXED-SKU',
@@ -205,29 +205,29 @@  discard block
 block discarded – undo
205 205
 				),
206 206
 			)
207 207
 		);
208
-		$response = $this->server->dispatch( $request );
208
+		$response = $this->server->dispatch($request);
209 209
 		$data     = $response->get_data();
210 210
 
211
-		$this->assertContains( 'Testing', $data['description'] );
212
-		$this->assertEquals( '8', $data['price'] );
213
-		$this->assertEquals( '8', $data['sale_price'] );
214
-		$this->assertEquals( '10', $data['regular_price'] );
215
-		$this->assertEquals( 'FIXED-SKU', $data['sku'] );
216
-		$this->assertEquals( $date_created, $data['date_created'] );
217
-		$this->assertContains( 'Dr1Bczxq4q', $data['images'][0]['src'] );
218
-		$this->assertContains( 'test upload image', $data['images'][0]['alt'] );
219
-		$product->delete( true );
211
+		$this->assertContains('Testing', $data['description']);
212
+		$this->assertEquals('8', $data['price']);
213
+		$this->assertEquals('8', $data['sale_price']);
214
+		$this->assertEquals('10', $data['regular_price']);
215
+		$this->assertEquals('FIXED-SKU', $data['sku']);
216
+		$this->assertEquals($date_created, $data['date_created']);
217
+		$this->assertContains('Dr1Bczxq4q', $data['images'][0]['src']);
218
+		$this->assertContains('test upload image', $data['images'][0]['alt']);
219
+		$product->delete(true);
220 220
 
221 221
 		// test variable product (variations are tested in product-variations.php).
222 222
 		$product  = ProductHelper::create_variation_product();
223
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products/' . $product->get_id() ) );
223
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products/' . $product->get_id()));
224 224
 		$data     = $response->get_data();
225 225
 
226
-		foreach ( array( 'small', 'large' ) as $term_name ) {
227
-			$this->assertContains( $term_name, $data['attributes'][0]['options'] );
226
+		foreach (array('small', 'large') as $term_name) {
227
+			$this->assertContains($term_name, $data['attributes'][0]['options']);
228 228
 		}
229 229
 
230
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/products/' . $product->get_id() );
230
+		$request = new WP_REST_Request('PUT', '/wc/v4/products/' . $product->get_id());
231 231
 		$request->set_body_params(
232 232
 			array(
233 233
 				'attributes' => array(
@@ -253,37 +253,37 @@  discard block
 block discarded – undo
253 253
 				),
254 254
 			)
255 255
 		);
256
-		$response = $this->server->dispatch( $request );
256
+		$response = $this->server->dispatch($request);
257 257
 		$data     = $response->get_data();
258 258
 
259
-		$this->assertEquals( array( 'small' ), $data['attributes'][0]['options'] );
259
+		$this->assertEquals(array('small'), $data['attributes'][0]['options']);
260 260
 
261
-		foreach ( array( 'red', 'yellow' ) as $term_name ) {
262
-			$this->assertContains( $term_name, $data['attributes'][1]['options'] );
261
+		foreach (array('red', 'yellow') as $term_name) {
262
+			$this->assertContains($term_name, $data['attributes'][1]['options']);
263 263
 		}
264 264
 
265
-		$product->delete( true );
265
+		$product->delete(true);
266 266
 
267 267
 		// test external product.
268 268
 		$product  = ProductHelper::create_external_product();
269
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products/' . $product->get_id() ) );
269
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products/' . $product->get_id()));
270 270
 		$data     = $response->get_data();
271 271
 
272
-		$this->assertEquals( 'Buy external product', $data['button_text'] );
273
-		$this->assertEquals( 'http://woocommerce.com', $data['external_url'] );
272
+		$this->assertEquals('Buy external product', $data['button_text']);
273
+		$this->assertEquals('http://woocommerce.com', $data['external_url']);
274 274
 
275
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/products/' . $product->get_id() );
275
+		$request = new WP_REST_Request('PUT', '/wc/v4/products/' . $product->get_id());
276 276
 		$request->set_body_params(
277 277
 			array(
278 278
 				'button_text'  => 'Test API Update',
279 279
 				'external_url' => 'http://automattic.com',
280 280
 			)
281 281
 		);
282
-		$response = $this->server->dispatch( $request );
282
+		$response = $this->server->dispatch($request);
283 283
 		$data     = $response->get_data();
284 284
 
285
-		$this->assertEquals( 'Test API Update', $data['button_text'] );
286
-		$this->assertEquals( 'http://automattic.com', $data['external_url'] );
285
+		$this->assertEquals('Test API Update', $data['button_text']);
286
+		$this->assertEquals('http://automattic.com', $data['external_url']);
287 287
 	}
288 288
 
289 289
 	/**
@@ -292,16 +292,16 @@  discard block
 block discarded – undo
292 292
 	 * @since 3.5.0
293 293
 	 */
294 294
 	public function test_update_product_without_permission() {
295
-		wp_set_current_user( 0 );
295
+		wp_set_current_user(0);
296 296
 		$product = ProductHelper::create_simple_product();
297
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/products/' . $product->get_id() );
297
+		$request = new WP_REST_Request('PUT', '/wc/v4/products/' . $product->get_id());
298 298
 		$request->set_body_params(
299 299
 			array(
300 300
 				'sku' => 'FIXED-SKU-NO-PERMISSION',
301 301
 			)
302 302
 		);
303
-		$response = $this->server->dispatch( $request );
304
-		$this->assertEquals( 401, $response->get_status() );
303
+		$response = $this->server->dispatch($request);
304
+		$this->assertEquals(401, $response->get_status());
305 305
 	}
306 306
 
307 307
 	/**
@@ -310,14 +310,14 @@  discard block
 block discarded – undo
310 310
 	 * @since 3.5.0
311 311
 	 */
312 312
 	public function test_update_product_with_invalid_id() {
313
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/products/0' );
313
+		$request = new WP_REST_Request('PUT', '/wc/v4/products/0');
314 314
 		$request->set_body_params(
315 315
 			array(
316 316
 				'sku' => 'FIXED-SKU-INVALID-ID',
317 317
 			)
318 318
 		);
319
-		$response = $this->server->dispatch( $request );
320
-		$this->assertEquals( 404, $response->get_status() );
319
+		$response = $this->server->dispatch($request);
320
+		$this->assertEquals(404, $response->get_status());
321 321
 	}
322 322
 
323 323
 	/**
@@ -327,18 +327,18 @@  discard block
 block discarded – undo
327 327
 	 */
328 328
 	public function test_create_product() {
329 329
 
330
-		$request = new WP_REST_Request( 'POST', '/wc/v4/products/shipping_classes' );
330
+		$request = new WP_REST_Request('POST', '/wc/v4/products/shipping_classes');
331 331
 		$request->set_body_params(
332 332
 			array(
333 333
 				'name' => 'Test',
334 334
 			)
335 335
 		);
336
-		$response          = $this->server->dispatch( $request );
336
+		$response          = $this->server->dispatch($request);
337 337
 		$data              = $response->get_data();
338 338
 		$shipping_class_id = $data['id'];
339 339
 
340 340
 		// Create simple.
341
-		$request = new WP_REST_Request( 'POST', '/wc/v4/products' );
341
+		$request = new WP_REST_Request('POST', '/wc/v4/products');
342 342
 		$request->set_body_params(
343 343
 			array(
344 344
 				'type'           => 'simple',
@@ -348,19 +348,19 @@  discard block
 block discarded – undo
348 348
 				'shipping_class' => 'test',
349 349
 			)
350 350
 		);
351
-		$response = $this->server->dispatch( $request );
351
+		$response = $this->server->dispatch($request);
352 352
 		$data     = $response->get_data();
353 353
 
354
-		$this->assertEquals( '10', $data['price'] );
355
-		$this->assertEquals( '10', $data['regular_price'] );
356
-		$this->assertTrue( $data['purchasable'] );
357
-		$this->assertEquals( 'DUMMY SKU SIMPLE API', $data['sku'] );
358
-		$this->assertEquals( 'Test Simple Product', $data['name'] );
359
-		$this->assertEquals( 'simple', $data['type'] );
360
-		$this->assertEquals( $shipping_class_id, $data['shipping_class_id'] );
354
+		$this->assertEquals('10', $data['price']);
355
+		$this->assertEquals('10', $data['regular_price']);
356
+		$this->assertTrue($data['purchasable']);
357
+		$this->assertEquals('DUMMY SKU SIMPLE API', $data['sku']);
358
+		$this->assertEquals('Test Simple Product', $data['name']);
359
+		$this->assertEquals('simple', $data['type']);
360
+		$this->assertEquals($shipping_class_id, $data['shipping_class_id']);
361 361
 
362 362
 		// Create external.
363
-		$request = new WP_REST_Request( 'POST', '/wc/v4/products' );
363
+		$request = new WP_REST_Request('POST', '/wc/v4/products');
364 364
 		$request->set_body_params(
365 365
 			array(
366 366
 				'type'          => 'external',
@@ -371,20 +371,20 @@  discard block
 block discarded – undo
371 371
 				'external_url'  => 'https://wordpress.org',
372 372
 			)
373 373
 		);
374
-		$response = $this->server->dispatch( $request );
374
+		$response = $this->server->dispatch($request);
375 375
 		$data     = $response->get_data();
376 376
 
377
-		$this->assertEquals( '10', $data['price'] );
378
-		$this->assertEquals( '10', $data['regular_price'] );
379
-		$this->assertFalse( $data['purchasable'] );
380
-		$this->assertEquals( 'DUMMY SKU EXTERNAL API', $data['sku'] );
381
-		$this->assertEquals( 'Test External Product', $data['name'] );
382
-		$this->assertEquals( 'external', $data['type'] );
383
-		$this->assertEquals( 'Test Button', $data['button_text'] );
384
-		$this->assertEquals( 'https://wordpress.org', $data['external_url'] );
377
+		$this->assertEquals('10', $data['price']);
378
+		$this->assertEquals('10', $data['regular_price']);
379
+		$this->assertFalse($data['purchasable']);
380
+		$this->assertEquals('DUMMY SKU EXTERNAL API', $data['sku']);
381
+		$this->assertEquals('Test External Product', $data['name']);
382
+		$this->assertEquals('external', $data['type']);
383
+		$this->assertEquals('Test Button', $data['button_text']);
384
+		$this->assertEquals('https://wordpress.org', $data['external_url']);
385 385
 
386 386
 		// Create variable.
387
-		$request = new WP_REST_Request( 'POST', '/wc/v4/products' );
387
+		$request = new WP_REST_Request('POST', '/wc/v4/products');
388 388
 		$request->set_body_params(
389 389
 			array(
390 390
 				'type'       => 'variable',
@@ -404,17 +404,17 @@  discard block
 block discarded – undo
404 404
 				),
405 405
 			)
406 406
 		);
407
-		$response = $this->server->dispatch( $request );
407
+		$response = $this->server->dispatch($request);
408 408
 		$data     = $response->get_data();
409 409
 
410
-		$this->assertEquals( 'DUMMY SKU VARIABLE API', $data['sku'] );
411
-		$this->assertEquals( 'Test Variable Product', $data['name'] );
412
-		$this->assertEquals( 'variable', $data['type'] );
413
-		$this->assertEquals( array( 'small', 'medium' ), $data['attributes'][0]['options'] );
410
+		$this->assertEquals('DUMMY SKU VARIABLE API', $data['sku']);
411
+		$this->assertEquals('Test Variable Product', $data['name']);
412
+		$this->assertEquals('variable', $data['type']);
413
+		$this->assertEquals(array('small', 'medium'), $data['attributes'][0]['options']);
414 414
 
415
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products' ) );
415
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products'));
416 416
 		$products = $response->get_data();
417
-		$this->assertEquals( 3, count( $products ) );
417
+		$this->assertEquals(3, count($products));
418 418
 	}
419 419
 
420 420
 	/**
@@ -423,17 +423,17 @@  discard block
 block discarded – undo
423 423
 	 * @since 3.5.0
424 424
 	 */
425 425
 	public function test_create_product_without_permission() {
426
-		wp_set_current_user( 0 );
426
+		wp_set_current_user(0);
427 427
 
428
-		$request = new WP_REST_Request( 'POST', '/wc/v4/products' );
428
+		$request = new WP_REST_Request('POST', '/wc/v4/products');
429 429
 		$request->set_body_params(
430 430
 			array(
431 431
 				'name'          => 'Test Product',
432 432
 				'regular_price' => '12',
433 433
 			)
434 434
 		);
435
-		$response = $this->server->dispatch( $request );
436
-		$this->assertEquals( 401, $response->get_status() );
435
+		$response = $this->server->dispatch($request);
436
+		$this->assertEquals(401, $response->get_status());
437 437
 	}
438 438
 
439 439
 	/**
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
 	public function test_products_batch() {
445 445
 		$product   = ProductHelper::create_simple_product();
446 446
 		$product_2 = ProductHelper::create_simple_product();
447
-		$request   = new WP_REST_Request( 'POST', '/wc/v4/products/batch' );
447
+		$request   = new WP_REST_Request('POST', '/wc/v4/products/batch');
448 448
 		$request->set_body_params(
449 449
 			array(
450 450
 				'update' => array(
@@ -473,22 +473,22 @@  discard block
 block discarded – undo
473 473
 				),
474 474
 			)
475 475
 		);
476
-		$response = $this->server->dispatch( $request );
476
+		$response = $this->server->dispatch($request);
477 477
 		$data     = $response->get_data();
478 478
 
479
-		$this->assertContains( 'Updated description.', $data['update'][0]['description'] );
480
-		$this->assertEquals( 'DUMMY SKU BATCH TEST 1', $data['create'][0]['sku'] );
481
-		$this->assertEquals( 'DUMMY SKU BATCH TEST 2', $data['create'][1]['sku'] );
482
-		$this->assertEquals( 'Test Button', $data['create'][0]['button_text'] );
483
-		$this->assertEquals( 'external', $data['create'][0]['type'] );
484
-		$this->assertEquals( 'simple', $data['create'][1]['type'] );
485
-		$this->assertEquals( $product_2->get_id(), $data['delete'][0]['previous']['id'] );
479
+		$this->assertContains('Updated description.', $data['update'][0]['description']);
480
+		$this->assertEquals('DUMMY SKU BATCH TEST 1', $data['create'][0]['sku']);
481
+		$this->assertEquals('DUMMY SKU BATCH TEST 2', $data['create'][1]['sku']);
482
+		$this->assertEquals('Test Button', $data['create'][0]['button_text']);
483
+		$this->assertEquals('external', $data['create'][0]['type']);
484
+		$this->assertEquals('simple', $data['create'][1]['type']);
485
+		$this->assertEquals($product_2->get_id(), $data['delete'][0]['previous']['id']);
486 486
 
487
-		$request  = new WP_REST_Request( 'GET', '/wc/v4/products' );
488
-		$response = $this->server->dispatch( $request );
487
+		$request  = new WP_REST_Request('GET', '/wc/v4/products');
488
+		$response = $this->server->dispatch($request);
489 489
 		$data     = $response->get_data();
490 490
 
491
-		$this->assertEquals( 3, count( $data ) );
491
+		$this->assertEquals(3, count($data));
492 492
 	}
493 493
 
494 494
 	/**
@@ -498,9 +498,9 @@  discard block
 block discarded – undo
498 498
 	 * @since 3.5.0
499 499
 	 */
500 500
 	public function test_products_filter_post_status() {
501
-		for ( $i = 0; $i < 8; $i++ ) {
501
+		for ($i = 0; $i < 8; $i++) {
502 502
 			$product = ProductHelper::create_simple_product();
503
-			if ( 0 === $i % 2 ) {
503
+			if (0 === $i % 2) {
504 504
 				wp_update_post(
505 505
 					array(
506 506
 						'ID'          => $product->get_id(),
@@ -511,33 +511,33 @@  discard block
 block discarded – undo
511 511
 		}
512 512
 
513 513
 		// Test filtering with status=publish.
514
-		$request = new WP_REST_Request( 'GET', '/wc/v4/products' );
515
-		$request->set_param( 'status', 'publish' );
516
-		$response = $this->server->dispatch( $request );
514
+		$request = new WP_REST_Request('GET', '/wc/v4/products');
515
+		$request->set_param('status', 'publish');
516
+		$response = $this->server->dispatch($request);
517 517
 		$products = $response->get_data();
518 518
 
519
-		$this->assertEquals( 4, count( $products ) );
520
-		foreach ( $products as $product ) {
521
-			$this->assertEquals( 'publish', $product['status'] );
519
+		$this->assertEquals(4, count($products));
520
+		foreach ($products as $product) {
521
+			$this->assertEquals('publish', $product['status']);
522 522
 		}
523 523
 
524 524
 		// Test filtering with status=draft.
525
-		$request = new WP_REST_Request( 'GET', '/wc/v4/products' );
526
-		$request->set_param( 'status', 'draft' );
527
-		$response = $this->server->dispatch( $request );
525
+		$request = new WP_REST_Request('GET', '/wc/v4/products');
526
+		$request->set_param('status', 'draft');
527
+		$response = $this->server->dispatch($request);
528 528
 		$products = $response->get_data();
529 529
 
530
-		$this->assertEquals( 4, count( $products ) );
531
-		foreach ( $products as $product ) {
532
-			$this->assertEquals( 'draft', $product['status'] );
530
+		$this->assertEquals(4, count($products));
531
+		foreach ($products as $product) {
532
+			$this->assertEquals('draft', $product['status']);
533 533
 		}
534 534
 
535 535
 		// Test filtering with no filters - which should return 'any' (all 8).
536
-		$request  = new WP_REST_Request( 'GET', '/wc/v4/products' );
537
-		$response = $this->server->dispatch( $request );
536
+		$request  = new WP_REST_Request('GET', '/wc/v4/products');
537
+		$response = $this->server->dispatch($request);
538 538
 		$products = $response->get_data();
539 539
 
540
-		$this->assertEquals( 8, count( $products ) );
540
+		$this->assertEquals(8, count($products));
541 541
 	}
542 542
 
543 543
 	/**
@@ -547,11 +547,11 @@  discard block
 block discarded – undo
547 547
 	 */
548 548
 	public function test_product_schema() {
549 549
 		$product    = ProductHelper::create_simple_product();
550
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v4/products/' . $product->get_id() );
551
-		$response   = $this->server->dispatch( $request );
550
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v4/products/' . $product->get_id());
551
+		$response   = $this->server->dispatch($request);
552 552
 		$data       = $response->get_data();
553 553
 		$properties = $data['schema']['properties'];
554
-		$this->assertEquals( 65, count( $properties ) );
554
+		$this->assertEquals(65, count($properties));
555 555
 	}
556 556
 
557 557
 	/**
@@ -561,10 +561,10 @@  discard block
 block discarded – undo
561 561
 	 */
562 562
 	public function test_get_products_by_category() {
563 563
 		// Create one product with a category.
564
-		$category = wp_insert_term( 'Some Category', 'product_cat' );
564
+		$category = wp_insert_term('Some Category', 'product_cat');
565 565
 
566 566
 		$product = new \WC_Product_Simple();
567
-		$product->set_category_ids( array( $category['term_id'] ) );
567
+		$product->set_category_ids(array($category['term_id']));
568 568
 		$product->save();
569 569
 
570 570
 		// Create one product without category, i.e. Uncategorized.
@@ -575,25 +575,25 @@  discard block
 block discarded – undo
575 575
 		$query_params = array(
576 576
 			'category' => (string) $category['term_id'],
577 577
 		);
578
-		$request      = new WP_REST_Request( 'GET', '/wc/v4/products' );
579
-		$request->set_query_params( $query_params );
580
-		$response          = $this->server->dispatch( $request );
578
+		$request      = new WP_REST_Request('GET', '/wc/v4/products');
579
+		$request->set_query_params($query_params);
580
+		$response          = $this->server->dispatch($request);
581 581
 		$response_products = $response->get_data();
582 582
 
583
-		$this->assertEquals( 200, $response->get_status() );
584
-		foreach ( $response_products as $response_product ) {
585
-			$this->assertEquals( $product->get_id(), $response_product['id'] );
586
-			$this->assertEquals( $product->get_category_ids(), wp_list_pluck( $response_product['categories'], 'id' ) );
583
+		$this->assertEquals(200, $response->get_status());
584
+		foreach ($response_products as $response_product) {
585
+			$this->assertEquals($product->get_id(), $response_product['id']);
586
+			$this->assertEquals($product->get_category_ids(), wp_list_pluck($response_product['categories'], 'id'));
587 587
 		}
588 588
 
589 589
 		// Test product without categories.
590
-		$request          = new WP_REST_Request( 'GET', '/wc/v4/products/' . $product_2->get_id() );
591
-		$response         = $this->server->dispatch( $request );
590
+		$request          = new WP_REST_Request('GET', '/wc/v4/products/' . $product_2->get_id());
591
+		$response         = $this->server->dispatch($request);
592 592
 		$response_product = $response->get_data();
593 593
 
594
-		$this->assertEquals( 200, $response->get_status() );
595
-		$this->assertCount( 1, $response_product['categories'], print_r( $response_product, true ) );
596
-		$this->assertEquals( 'uncategorized', $response_product['categories'][0]['slug'] );
594
+		$this->assertEquals(200, $response->get_status());
595
+		$this->assertCount(1, $response_product['categories'], print_r($response_product, true));
596
+		$this->assertEquals('uncategorized', $response_product['categories'][0]['slug']);
597 597
 
598 598
 	}
599 599
 
@@ -609,29 +609,29 @@  discard block
 block discarded – undo
609 609
 		$variable = ProductHelper::create_variation_product();
610 610
 
611 611
 		$product_ids_for_type = array(
612
-			'simple'   => array( $simple->get_id() ),
613
-			'external' => array( $external->get_id() ),
614
-			'grouped'  => array( $grouped->get_id() ),
615
-			'variable' => array( $variable->get_id() ),
612
+			'simple'   => array($simple->get_id()),
613
+			'external' => array($external->get_id()),
614
+			'grouped'  => array($grouped->get_id()),
615
+			'variable' => array($variable->get_id()),
616 616
 		);
617 617
 
618
-		foreach ( $grouped->get_children() as $additional_product ) {
618
+		foreach ($grouped->get_children() as $additional_product) {
619 619
 			$product_ids_for_type['simple'][] = $additional_product;
620 620
 		}
621 621
 
622
-		foreach ( $product_ids_for_type as $product_type => $product_ids ) {
622
+		foreach ($product_ids_for_type as $product_type => $product_ids) {
623 623
 			$query_params = array(
624 624
 				'type' => $product_type,
625 625
 			);
626
-			$request      = new WP_REST_Request( 'GET', '/wc/v4/products' );
627
-			$request->set_query_params( $query_params );
628
-			$response          = $this->server->dispatch( $request );
626
+			$request      = new WP_REST_Request('GET', '/wc/v4/products');
627
+			$request->set_query_params($query_params);
628
+			$response          = $this->server->dispatch($request);
629 629
 			$response_products = $response->get_data();
630 630
 
631
-			$this->assertEquals( 200, $response->get_status() );
632
-			$this->assertEquals( count( $product_ids ), count( $response_products ) );
633
-			foreach ( $response_products as $response_product ) {
634
-				$this->assertContains( $response_product['id'], $product_ids_for_type[ $product_type ], 'REST API: ' . $product_type . ' not found correctly' );
631
+			$this->assertEquals(200, $response->get_status());
632
+			$this->assertEquals(count($product_ids), count($response_products));
633
+			foreach ($response_products as $response_product) {
634
+				$this->assertContains($response_product['id'], $product_ids_for_type[$product_type], 'REST API: ' . $product_type . ' not found correctly');
635 635
 			}
636 636
 		}
637 637
 	}
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
 	public function test_get_featured_products() {
645 645
 		// Create a featured product.
646 646
 		$feat_product = ProductHelper::create_simple_product();
647
-		$feat_product->set_featured( true );
647
+		$feat_product->set_featured(true);
648 648
 		$feat_product->save();
649 649
 
650 650
 		// Create a non-featured product.
@@ -654,27 +654,27 @@  discard block
 block discarded – undo
654 654
 		$query_params = array(
655 655
 			'featured' => 'true',
656 656
 		);
657
-		$request      = new WP_REST_Request( 'GET', '/wc/v4/products' );
658
-		$request->set_query_params( $query_params );
659
-		$response          = $this->server->dispatch( $request );
657
+		$request      = new WP_REST_Request('GET', '/wc/v4/products');
658
+		$request->set_query_params($query_params);
659
+		$response          = $this->server->dispatch($request);
660 660
 		$response_products = $response->get_data();
661 661
 
662
-		$this->assertEquals( 200, $response->get_status() );
663
-		foreach ( $response_products as $response_product ) {
664
-			$this->assertEquals( $feat_product->get_id(), $response_product['id'], 'REST API: Featured product not found correctly' );
662
+		$this->assertEquals(200, $response->get_status());
663
+		foreach ($response_products as $response_product) {
664
+			$this->assertEquals($feat_product->get_id(), $response_product['id'], 'REST API: Featured product not found correctly');
665 665
 		}
666 666
 
667 667
 		$query_params = array(
668 668
 			'featured' => 'false',
669 669
 		);
670
-		$request      = new WP_REST_Request( 'GET', '/wc/v4/products' );
671
-		$request->set_query_params( $query_params );
672
-		$response          = $this->server->dispatch( $request );
670
+		$request      = new WP_REST_Request('GET', '/wc/v4/products');
671
+		$request->set_query_params($query_params);
672
+		$response          = $this->server->dispatch($request);
673 673
 		$response_products = $response->get_data();
674 674
 
675
-		$this->assertEquals( 200, $response->get_status() );
676
-		foreach ( $response_products as $response_product ) {
677
-			$this->assertEquals( $nonfeat_product->get_id(), $response_product['id'], 'REST API: Featured product not found correctly' );
675
+		$this->assertEquals(200, $response->get_status());
676
+		foreach ($response_products as $response_product) {
677
+			$this->assertEquals($nonfeat_product->get_id(), $response_product['id'], 'REST API: Featured product not found correctly');
678 678
 		}
679 679
 	}
680 680
 
@@ -684,23 +684,23 @@  discard block
 block discarded – undo
684 684
 	 * @since 3.5.0
685 685
 	 */
686 686
 	public function test_get_products_by_shipping_class() {
687
-		$shipping_class_1 = wp_insert_term( 'Bulky', 'product_shipping_class' );
687
+		$shipping_class_1 = wp_insert_term('Bulky', 'product_shipping_class');
688 688
 
689 689
 		$product_1 = new \WC_Product_Simple();
690
-		$product_1->set_shipping_class_id( $shipping_class_1['term_id'] );
690
+		$product_1->set_shipping_class_id($shipping_class_1['term_id']);
691 691
 		$product_1->save();
692 692
 
693 693
 		$query_params = array(
694 694
 			'shipping_class' => (string) $shipping_class_1['term_id'],
695 695
 		);
696
-		$request      = new WP_REST_Request( 'GET', '/wc/v4/products' );
697
-		$request->set_query_params( $query_params );
698
-		$response          = $this->server->dispatch( $request );
696
+		$request      = new WP_REST_Request('GET', '/wc/v4/products');
697
+		$request->set_query_params($query_params);
698
+		$response          = $this->server->dispatch($request);
699 699
 		$response_products = $response->get_data();
700 700
 
701
-		$this->assertEquals( 200, $response->get_status() );
702
-		foreach ( $response_products as $response_product ) {
703
-			$this->assertEquals( $product_1->get_id(), $response_product['id'] );
701
+		$this->assertEquals(200, $response->get_status());
702
+		foreach ($response_products as $response_product) {
703
+			$this->assertEquals($product_1->get_id(), $response_product['id']);
704 704
 		}
705 705
 	}
706 706
 
@@ -710,11 +710,11 @@  discard block
 block discarded – undo
710 710
 	 * @since 3.5.0
711 711
 	 */
712 712
 	public function test_get_products_by_tag() {
713
-		$test_tag_1 = wp_insert_term( 'Tag 1', 'product_tag' );
713
+		$test_tag_1 = wp_insert_term('Tag 1', 'product_tag');
714 714
 
715 715
 		// Product with a tag.
716 716
 		$product = ProductHelper::create_simple_product();
717
-		$product->set_tag_ids( array( $test_tag_1['term_id'] ) );
717
+		$product->set_tag_ids(array($test_tag_1['term_id']));
718 718
 		$product->save();
719 719
 
720 720
 		// Product without a tag.
@@ -723,14 +723,14 @@  discard block
 block discarded – undo
723 723
 		$query_params = array(
724 724
 			'tag' => (string) $test_tag_1['term_id'],
725 725
 		);
726
-		$request      = new WP_REST_Request( 'GET', '/wc/v4/products' );
727
-		$request->set_query_params( $query_params );
728
-		$response          = $this->server->dispatch( $request );
726
+		$request      = new WP_REST_Request('GET', '/wc/v4/products');
727
+		$request->set_query_params($query_params);
728
+		$response          = $this->server->dispatch($request);
729 729
 		$response_products = $response->get_data();
730 730
 
731
-		$this->assertEquals( 200, $response->get_status() );
732
-		foreach ( $response_products as $response_product ) {
733
-			$this->assertEquals( $product->get_id(), $response_product['id'] );
731
+		$this->assertEquals(200, $response->get_status());
732
+		foreach ($response_products as $response_product) {
733
+			$this->assertEquals($product->get_id(), $response_product['id']);
734 734
 		}
735 735
 	}
736 736
 
@@ -746,15 +746,15 @@  discard block
 block discarded – undo
746 746
 		$variable_product = ProductHelper::create_variation_product();
747 747
 
748 748
 		// Terms created by variable product.
749
-		$term_large = get_term_by( 'slug', 'large', 'pa_size' );
750
-		$term_small = get_term_by( 'slug', 'small', 'pa_size' );
749
+		$term_large = get_term_by('slug', 'large', 'pa_size');
750
+		$term_small = get_term_by('slug', 'small', 'pa_size');
751 751
 
752 752
 		// Simple product without attribute.
753 753
 		$product_1 = ProductHelper::create_simple_product();
754 754
 
755 755
 		// Simple product with attribute size = large.
756 756
 		$product_2 = ProductHelper::create_simple_product();
757
-		$product_2->set_attributes( array( 'pa_size' => 'large' ) );
757
+		$product_2->set_attributes(array('pa_size' => 'large'));
758 758
 		$product_2->save();
759 759
 
760 760
 		// Link the product to the term.
@@ -772,19 +772,19 @@  discard block
 block discarded – undo
772 772
 			$variable_product->get_id(),
773 773
 			$product_2->get_id(),
774 774
 		);
775
-		$query_params         = array(
775
+		$query_params = array(
776 776
 			'attribute'      => 'pa_size',
777 777
 			'attribute_term' => (string) $term_large->term_id,
778 778
 		);
779
-		$request              = new WP_REST_Request( 'GET', '/wc/v4/products' );
780
-		$request->set_query_params( $query_params );
781
-		$response          = $this->server->dispatch( $request );
779
+		$request = new WP_REST_Request('GET', '/wc/v4/products');
780
+		$request->set_query_params($query_params);
781
+		$response          = $this->server->dispatch($request);
782 782
 		$response_products = $response->get_data();
783 783
 
784
-		$this->assertEquals( 200, $response->get_status() );
785
-		$this->assertEquals( count( $expected_product_ids ), count( $response_products ) );
786
-		foreach ( $response_products as $response_product ) {
787
-			$this->assertContains( $response_product['id'], $expected_product_ids );
784
+		$this->assertEquals(200, $response->get_status());
785
+		$this->assertEquals(count($expected_product_ids), count($response_products));
786
+		foreach ($response_products as $response_product) {
787
+			$this->assertContains($response_product['id'], $expected_product_ids);
788 788
 		}
789 789
 
790 790
 		// Products with attribute size == small.
@@ -795,15 +795,15 @@  discard block
 block discarded – undo
795 795
 			'attribute'      => 'pa_size',
796 796
 			'attribute_term' => (string) $term_small->term_id,
797 797
 		);
798
-		$request              = new WP_REST_Request( 'GET', '/wc/v4/products' );
799
-		$request->set_query_params( $query_params );
800
-		$response          = $this->server->dispatch( $request );
798
+		$request = new WP_REST_Request('GET', '/wc/v4/products');
799
+		$request->set_query_params($query_params);
800
+		$response          = $this->server->dispatch($request);
801 801
 		$response_products = $response->get_data();
802 802
 
803
-		$this->assertEquals( 200, $response->get_status() );
804
-		$this->assertEquals( count( $expected_product_ids ), count( $response_products ) );
805
-		foreach ( $response_products as $response_product ) {
806
-			$this->assertContains( $response_product['id'], $expected_product_ids );
803
+		$this->assertEquals(200, $response->get_status());
804
+		$this->assertEquals(count($expected_product_ids), count($response_products));
805
+		foreach ($response_products as $response_product) {
806
+			$this->assertContains($response_product['id'], $expected_product_ids);
807 807
 		}
808 808
 	}
809 809
 
@@ -812,8 +812,8 @@  discard block
 block discarded – undo
812 812
 	 */
813 813
 	public function test_product_schema_embed() {
814 814
 		$product    = ProductHelper::create_simple_product();
815
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v4/products/' . $product->get_id() );
816
-		$response   = $this->server->dispatch( $request );
815
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v4/products/' . $product->get_id());
816
+		$response   = $this->server->dispatch($request);
817 817
 		$data       = $response->get_data();
818 818
 		$properties = $data['schema']['properties'];
819 819
 
@@ -827,12 +827,12 @@  discard block
 block discarded – undo
827 827
 			'short_description',
828 828
 		);
829 829
 
830
-		foreach ( $properties as $property_key => $property ) {
831
-			if ( in_array( $property_key, $properties_to_embed, true ) ) {
832
-				$this->assertEquals( array( 'view', 'edit', 'embed' ), $property['context'] );
830
+		foreach ($properties as $property_key => $property) {
831
+			if (in_array($property_key, $properties_to_embed, true)) {
832
+				$this->assertEquals(array('view', 'edit', 'embed'), $property['context']);
833 833
 			}
834 834
 		}
835 835
 
836
-		$product->delete( true );
836
+		$product->delete(true);
837 837
 	}
838 838
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/ProductVariations.php 1 patch
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 use \WP_REST_Request;
14 14
 use \WC_REST_Unit_Test_Case;
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @param object $factory Factory object.
30 30
 	 */
31
-	public static function wpSetUpBeforeClass( $factory ) {
31
+	public static function wpSetUpBeforeClass($factory) {
32 32
 		self::$user = $factory->user->create(
33 33
 			array(
34 34
 				'role' => 'administrator',
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	public function setUp() {
43 43
 		parent::setUp();
44
-		wp_set_current_user( self::$user );
44
+		wp_set_current_user(self::$user);
45 45
 	}
46 46
 
47 47
 	/**
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 	 */
52 52
 	public function test_register_routes() {
53 53
 		$routes = $this->server->get_routes();
54
-		$this->assertArrayHasKey( '/wc/v4/products/(?P<product_id>[\d]+)/variations', $routes );
55
-		$this->assertArrayHasKey( '/wc/v4/products/(?P<product_id>[\d]+)/variations/(?P<id>[\d]+)', $routes );
56
-		$this->assertArrayHasKey( '/wc/v4/products/(?P<product_id>[\d]+)/variations/batch', $routes );
54
+		$this->assertArrayHasKey('/wc/v4/products/(?P<product_id>[\d]+)/variations', $routes);
55
+		$this->assertArrayHasKey('/wc/v4/products/(?P<product_id>[\d]+)/variations/(?P<id>[\d]+)', $routes);
56
+		$this->assertArrayHasKey('/wc/v4/products/(?P<product_id>[\d]+)/variations/batch', $routes);
57 57
 	}
58 58
 
59 59
 	/**
@@ -63,12 +63,12 @@  discard block
 block discarded – undo
63 63
 	 */
64 64
 	public function test_get_variations() {
65 65
 		$product    = ProductHelper::create_variation_product();
66
-		$response   = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products/' . $product->get_id() . '/variations' ) );
66
+		$response   = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products/' . $product->get_id() . '/variations'));
67 67
 		$variations = $response->get_data();
68
-		$this->assertEquals( 200, $response->get_status() );
69
-		$this->assertEquals( 2, count( $variations ) );
70
-		$this->assertEquals( 'DUMMY SKU VARIABLE LARGE', $variations[0]['sku'] );
71
-		$this->assertEquals( 'size', $variations[0]['attributes'][0]['name'] );
68
+		$this->assertEquals(200, $response->get_status());
69
+		$this->assertEquals(2, count($variations));
70
+		$this->assertEquals('DUMMY SKU VARIABLE LARGE', $variations[0]['sku']);
71
+		$this->assertEquals('size', $variations[0]['attributes'][0]['name']);
72 72
 	}
73 73
 
74 74
 	/**
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
 	 * @since 3.5.0
78 78
 	 */
79 79
 	public function test_get_variations_without_permission() {
80
-		wp_set_current_user( 0 );
80
+		wp_set_current_user(0);
81 81
 		$product  = ProductHelper::create_variation_product();
82
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products/' . $product->get_id() . '/variations' ) );
83
-		$this->assertEquals( 401, $response->get_status() );
82
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products/' . $product->get_id() . '/variations'));
83
+		$this->assertEquals(401, $response->get_status());
84 84
 	}
85 85
 
86 86
 	/**
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
 		$children     = $product->get_children();
94 94
 		$variation_id = $children[0];
95 95
 
96
-		$response  = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id ) );
96
+		$response  = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id));
97 97
 		$variation = $response->get_data();
98 98
 
99
-		$this->assertEquals( 200, $response->get_status() );
100
-		$this->assertEquals( $variation_id, $variation['id'] );
101
-		$this->assertEquals( 'size', $variation['attributes'][0]['name'] );
99
+		$this->assertEquals(200, $response->get_status());
100
+		$this->assertEquals($variation_id, $variation['id']);
101
+		$this->assertEquals('size', $variation['attributes'][0]['name']);
102 102
 	}
103 103
 
104 104
 	/**
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
 	 * @since 3.5.0
108 108
 	 */
109 109
 	public function test_get_variation_without_permission() {
110
-		wp_set_current_user( 0 );
110
+		wp_set_current_user(0);
111 111
 		$product      = ProductHelper::create_variation_product();
112 112
 		$children     = $product->get_children();
113 113
 		$variation_id = $children[0];
114
-		$response     = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id ) );
115
-		$this->assertEquals( 401, $response->get_status() );
114
+		$response     = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id));
115
+		$this->assertEquals(401, $response->get_status());
116 116
 	}
117 117
 
118 118
 	/**
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
 		$children     = $product->get_children();
126 126
 		$variation_id = $children[0];
127 127
 
128
-		$request = new WP_REST_Request( 'DELETE', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id );
129
-		$request->set_param( 'force', true );
130
-		$response = $this->server->dispatch( $request );
131
-		$this->assertEquals( 200, $response->get_status() );
128
+		$request = new WP_REST_Request('DELETE', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id);
129
+		$request->set_param('force', true);
130
+		$response = $this->server->dispatch($request);
131
+		$this->assertEquals(200, $response->get_status());
132 132
 
133
-		$response   = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products/' . $product->get_id() . '/variations' ) );
133
+		$response   = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products/' . $product->get_id() . '/variations'));
134 134
 		$variations = $response->get_data();
135
-		$this->assertEquals( 1, count( $variations ) );
135
+		$this->assertEquals(1, count($variations));
136 136
 	}
137 137
 
138 138
 	/**
@@ -141,15 +141,15 @@  discard block
 block discarded – undo
141 141
 	 * @since 3.5.0
142 142
 	 */
143 143
 	public function test_delete_variation_without_permission() {
144
-		wp_set_current_user( 0 );
144
+		wp_set_current_user(0);
145 145
 		$product      = ProductHelper::create_variation_product();
146 146
 		$children     = $product->get_children();
147 147
 		$variation_id = $children[0];
148 148
 
149
-		$request = new WP_REST_Request( 'DELETE', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id );
150
-		$request->set_param( 'force', true );
151
-		$response = $this->server->dispatch( $request );
152
-		$this->assertEquals( 401, $response->get_status() );
149
+		$request = new WP_REST_Request('DELETE', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id);
150
+		$request->set_param('force', true);
151
+		$response = $this->server->dispatch($request);
152
+		$this->assertEquals(401, $response->get_status());
153 153
 	}
154 154
 
155 155
 	/**
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
 	 * @since 3.5.0
159 159
 	 */
160 160
 	public function test_delete_variation_with_invalid_id() {
161
-		wp_set_current_user( 0 );
161
+		wp_set_current_user(0);
162 162
 		$product = ProductHelper::create_variation_product();
163
-		$request = new WP_REST_Request( 'DELETE', '/wc/v4/products/' . $product->get_id() . '/variations/0' );
164
-		$request->set_param( 'force', true );
165
-		$response = $this->server->dispatch( $request );
166
-		$this->assertEquals( 404, $response->get_status() );
163
+		$request = new WP_REST_Request('DELETE', '/wc/v4/products/' . $product->get_id() . '/variations/0');
164
+		$request->set_param('force', true);
165
+		$response = $this->server->dispatch($request);
166
+		$this->assertEquals(404, $response->get_status());
167 167
 	}
168 168
 
169 169
 	/**
@@ -176,15 +176,15 @@  discard block
 block discarded – undo
176 176
 		$children     = $product->get_children();
177 177
 		$variation_id = $children[0];
178 178
 
179
-		$response  = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id ) );
179
+		$response  = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id));
180 180
 		$variation = $response->get_data();
181 181
 
182
-		$this->assertEquals( 'DUMMY SKU VARIABLE SMALL', $variation['sku'] );
183
-		$this->assertEquals( 10, $variation['regular_price'] );
184
-		$this->assertEmpty( $variation['sale_price'] );
185
-		$this->assertEquals( 'small', $variation['attributes'][0]['option'] );
182
+		$this->assertEquals('DUMMY SKU VARIABLE SMALL', $variation['sku']);
183
+		$this->assertEquals(10, $variation['regular_price']);
184
+		$this->assertEmpty($variation['sale_price']);
185
+		$this->assertEquals('small', $variation['attributes'][0]['option']);
186 186
 
187
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id );
187
+		$request = new WP_REST_Request('PUT', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id);
188 188
 		$request->set_body_params(
189 189
 			array(
190 190
 				'sku'         => 'FIXED-\'SKU',
@@ -203,18 +203,18 @@  discard block
 block discarded – undo
203 203
 				),
204 204
 			)
205 205
 		);
206
-		$response  = $this->server->dispatch( $request );
206
+		$response  = $this->server->dispatch($request);
207 207
 		$variation = $response->get_data();
208 208
 
209
-		$this->assertTrue( isset( $variation['description'] ), print_r( $variation, true ) );
210
-		$this->assertContains( 'O_O', $variation['description'], print_r( $variation, true ) );
211
-		$this->assertEquals( '8', $variation['price'], print_r( $variation, true ) );
212
-		$this->assertEquals( '8', $variation['sale_price'], print_r( $variation, true ) );
213
-		$this->assertEquals( '10', $variation['regular_price'], print_r( $variation, true ) );
214
-		$this->assertEquals( 'FIXED-\'SKU', $variation['sku'], print_r( $variation, true ) );
215
-		$this->assertEquals( 'medium', $variation['attributes'][0]['option'], print_r( $variation, true ) );
216
-		$this->assertContains( 'Dr1Bczxq4q', $variation['image']['src'], print_r( $variation, true ) );
217
-		$this->assertContains( 'test upload image', $variation['image']['alt'], print_r( $variation, true ) );
209
+		$this->assertTrue(isset($variation['description']), print_r($variation, true));
210
+		$this->assertContains('O_O', $variation['description'], print_r($variation, true));
211
+		$this->assertEquals('8', $variation['price'], print_r($variation, true));
212
+		$this->assertEquals('8', $variation['sale_price'], print_r($variation, true));
213
+		$this->assertEquals('10', $variation['regular_price'], print_r($variation, true));
214
+		$this->assertEquals('FIXED-\'SKU', $variation['sku'], print_r($variation, true));
215
+		$this->assertEquals('medium', $variation['attributes'][0]['option'], print_r($variation, true));
216
+		$this->assertContains('Dr1Bczxq4q', $variation['image']['src'], print_r($variation, true));
217
+		$this->assertContains('test upload image', $variation['image']['alt'], print_r($variation, true));
218 218
 	}
219 219
 
220 220
 	/**
@@ -223,19 +223,19 @@  discard block
 block discarded – undo
223 223
 	 * @since 3.5.0
224 224
 	 */
225 225
 	public function test_update_variation_without_permission() {
226
-		wp_set_current_user( 0 );
226
+		wp_set_current_user(0);
227 227
 		$product      = ProductHelper::create_variation_product();
228 228
 		$children     = $product->get_children();
229 229
 		$variation_id = $children[0];
230 230
 
231
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id );
231
+		$request = new WP_REST_Request('PUT', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id);
232 232
 		$request->set_body_params(
233 233
 			array(
234 234
 				'sku' => 'FIXED-SKU-NO-PERMISSION',
235 235
 			)
236 236
 		);
237
-		$response = $this->server->dispatch( $request );
238
-		$this->assertEquals( 401, $response->get_status() );
237
+		$response = $this->server->dispatch($request);
238
+		$this->assertEquals(401, $response->get_status());
239 239
 	}
240 240
 
241 241
 	/**
@@ -245,14 +245,14 @@  discard block
 block discarded – undo
245 245
 	 */
246 246
 	public function test_update_variation_with_invalid_id() {
247 247
 		$product = ProductHelper::create_variation_product();
248
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/products/' . $product->get_id() . '/variations/0' );
248
+		$request = new WP_REST_Request('PUT', '/wc/v4/products/' . $product->get_id() . '/variations/0');
249 249
 		$request->set_body_params(
250 250
 			array(
251 251
 				'sku' => 'FIXED-SKU-NO-PERMISSION',
252 252
 			)
253 253
 		);
254
-		$response = $this->server->dispatch( $request );
255
-		$this->assertEquals( 404, $response->get_status() );
254
+		$response = $this->server->dispatch($request);
255
+		$this->assertEquals(404, $response->get_status());
256 256
 	}
257 257
 
258 258
 	/**
@@ -263,11 +263,11 @@  discard block
 block discarded – undo
263 263
 	public function test_create_variation() {
264 264
 		$product = ProductHelper::create_variation_product();
265 265
 
266
-		$response   = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products/' . $product->get_id() . '/variations' ) );
266
+		$response   = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products/' . $product->get_id() . '/variations'));
267 267
 		$variations = $response->get_data();
268
-		$this->assertEquals( 2, count( $variations ) );
268
+		$this->assertEquals(2, count($variations));
269 269
 
270
-		$request = new WP_REST_Request( 'POST', '/wc/v4/products/' . $product->get_id() . '/variations' );
270
+		$request = new WP_REST_Request('POST', '/wc/v4/products/' . $product->get_id() . '/variations');
271 271
 		$request->set_body_params(
272 272
 			array(
273 273
 				'sku'           => 'DUMMY SKU VARIABLE MEDIUM',
@@ -281,19 +281,19 @@  discard block
 block discarded – undo
281 281
 				),
282 282
 			)
283 283
 		);
284
-		$response  = $this->server->dispatch( $request );
284
+		$response  = $this->server->dispatch($request);
285 285
 		$variation = $response->get_data();
286 286
 
287
-		$this->assertContains( 'A medium size.', $variation['description'] );
288
-		$this->assertEquals( '12', $variation['price'] );
289
-		$this->assertEquals( '12', $variation['regular_price'] );
290
-		$this->assertTrue( $variation['purchasable'] );
291
-		$this->assertEquals( 'DUMMY SKU VARIABLE MEDIUM', $variation['sku'] );
292
-		$this->assertEquals( 'medium', $variation['attributes'][0]['option'] );
287
+		$this->assertContains('A medium size.', $variation['description']);
288
+		$this->assertEquals('12', $variation['price']);
289
+		$this->assertEquals('12', $variation['regular_price']);
290
+		$this->assertTrue($variation['purchasable']);
291
+		$this->assertEquals('DUMMY SKU VARIABLE MEDIUM', $variation['sku']);
292
+		$this->assertEquals('medium', $variation['attributes'][0]['option']);
293 293
 
294
-		$response   = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/products/' . $product->get_id() . '/variations' ) );
294
+		$response   = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/products/' . $product->get_id() . '/variations'));
295 295
 		$variations = $response->get_data();
296
-		$this->assertEquals( 3, count( $variations ) );
296
+		$this->assertEquals(3, count($variations));
297 297
 	}
298 298
 
299 299
 	/**
@@ -302,10 +302,10 @@  discard block
 block discarded – undo
302 302
 	 * @since 3.5.0
303 303
 	 */
304 304
 	public function test_create_variation_without_permission() {
305
-		wp_set_current_user( 0 );
305
+		wp_set_current_user(0);
306 306
 		$product = ProductHelper::create_variation_product();
307 307
 
308
-		$request = new WP_REST_Request( 'POST', '/wc/v4/products/' . $product->get_id() . '/variations' );
308
+		$request = new WP_REST_Request('POST', '/wc/v4/products/' . $product->get_id() . '/variations');
309 309
 		$request->set_body_params(
310 310
 			array(
311 311
 				'sku'           => 'DUMMY SKU VARIABLE MEDIUM',
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
 				),
320 320
 			)
321 321
 		);
322
-		$response = $this->server->dispatch( $request );
323
-		$this->assertEquals( 401, $response->get_status() );
322
+		$response = $this->server->dispatch($request);
323
+		$this->assertEquals(401, $response->get_status());
324 324
 	}
325 325
 
326 326
 	/**
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	public function test_product_variations_batch() {
332 332
 		$product  = ProductHelper::create_variation_product();
333 333
 		$children = $product->get_children();
334
-		$request  = new WP_REST_Request( 'POST', '/wc/v4/products/' . $product->get_id() . '/variations/batch' );
334
+		$request  = new WP_REST_Request('POST', '/wc/v4/products/' . $product->get_id() . '/variations/batch');
335 335
 		$request->set_body_params(
336 336
 			array(
337 337
 				'update' => array(
@@ -363,19 +363,19 @@  discard block
 block discarded – undo
363 363
 				),
364 364
 			)
365 365
 		);
366
-		$response = $this->server->dispatch( $request );
366
+		$response = $this->server->dispatch($request);
367 367
 		$data     = $response->get_data();
368 368
 
369
-		$this->assertContains( 'Updated description.', $data['update'][0]['description'] );
370
-		$this->assertEquals( 'DUMMY SKU VARIABLE MEDIUM', $data['create'][0]['sku'] );
371
-		$this->assertEquals( 'medium', $data['create'][0]['attributes'][0]['option'] );
372
-		$this->assertEquals( $children[1], $data['delete'][0]['previous']['id'] );
369
+		$this->assertContains('Updated description.', $data['update'][0]['description']);
370
+		$this->assertEquals('DUMMY SKU VARIABLE MEDIUM', $data['create'][0]['sku']);
371
+		$this->assertEquals('medium', $data['create'][0]['attributes'][0]['option']);
372
+		$this->assertEquals($children[1], $data['delete'][0]['previous']['id']);
373 373
 
374
-		$request  = new WP_REST_Request( 'GET', '/wc/v4/products/' . $product->get_id() . '/variations' );
375
-		$response = $this->server->dispatch( $request );
374
+		$request  = new WP_REST_Request('GET', '/wc/v4/products/' . $product->get_id() . '/variations');
375
+		$response = $this->server->dispatch($request);
376 376
 		$data     = $response->get_data();
377 377
 
378
-		$this->assertEquals( 2, count( $data ) );
378
+		$this->assertEquals(2, count($data));
379 379
 	}
380 380
 
381 381
 	/**
@@ -385,46 +385,46 @@  discard block
 block discarded – undo
385 385
 	 */
386 386
 	public function test_variation_schema() {
387 387
 		$product    = ProductHelper::create_simple_product();
388
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v4/products/' . $product->get_id() . '/variations' );
389
-		$response   = $this->server->dispatch( $request );
388
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v4/products/' . $product->get_id() . '/variations');
389
+		$response   = $this->server->dispatch($request);
390 390
 		$data       = $response->get_data();
391 391
 		$properties = $data['schema']['properties'];
392 392
 
393
-		$this->assertEquals( 40, count( $properties ) );
394
-		$this->assertArrayHasKey( 'id', $properties );
395
-		$this->assertArrayHasKey( 'date_created', $properties );
396
-		$this->assertArrayHasKey( 'date_modified', $properties );
397
-		$this->assertArrayHasKey( 'description', $properties );
398
-		$this->assertArrayHasKey( 'permalink', $properties );
399
-		$this->assertArrayHasKey( 'sku', $properties );
400
-		$this->assertArrayHasKey( 'price', $properties );
401
-		$this->assertArrayHasKey( 'regular_price', $properties );
402
-		$this->assertArrayHasKey( 'sale_price', $properties );
403
-		$this->assertArrayHasKey( 'date_on_sale_from', $properties );
404
-		$this->assertArrayHasKey( 'date_on_sale_to', $properties );
405
-		$this->assertArrayHasKey( 'on_sale', $properties );
406
-		$this->assertArrayHasKey( 'purchasable', $properties );
407
-		$this->assertArrayHasKey( 'virtual', $properties );
408
-		$this->assertArrayHasKey( 'downloadable', $properties );
409
-		$this->assertArrayHasKey( 'downloads', $properties );
410
-		$this->assertArrayHasKey( 'download_limit', $properties );
411
-		$this->assertArrayHasKey( 'download_expiry', $properties );
412
-		$this->assertArrayHasKey( 'tax_status', $properties );
413
-		$this->assertArrayHasKey( 'tax_class', $properties );
414
-		$this->assertArrayHasKey( 'manage_stock', $properties );
415
-		$this->assertArrayHasKey( 'stock_quantity', $properties );
416
-		$this->assertArrayHasKey( 'stock_status', $properties );
417
-		$this->assertArrayHasKey( 'backorders', $properties );
418
-		$this->assertArrayHasKey( 'backorders_allowed', $properties );
419
-		$this->assertArrayHasKey( 'backordered', $properties );
420
-		$this->assertArrayHasKey( 'weight', $properties );
421
-		$this->assertArrayHasKey( 'dimensions', $properties );
422
-		$this->assertArrayHasKey( 'shipping_class', $properties );
423
-		$this->assertArrayHasKey( 'shipping_class_id', $properties );
424
-		$this->assertArrayHasKey( 'image', $properties );
425
-		$this->assertArrayHasKey( 'attributes', $properties );
426
-		$this->assertArrayHasKey( 'menu_order', $properties );
427
-		$this->assertArrayHasKey( 'meta_data', $properties );
393
+		$this->assertEquals(40, count($properties));
394
+		$this->assertArrayHasKey('id', $properties);
395
+		$this->assertArrayHasKey('date_created', $properties);
396
+		$this->assertArrayHasKey('date_modified', $properties);
397
+		$this->assertArrayHasKey('description', $properties);
398
+		$this->assertArrayHasKey('permalink', $properties);
399
+		$this->assertArrayHasKey('sku', $properties);
400
+		$this->assertArrayHasKey('price', $properties);
401
+		$this->assertArrayHasKey('regular_price', $properties);
402
+		$this->assertArrayHasKey('sale_price', $properties);
403
+		$this->assertArrayHasKey('date_on_sale_from', $properties);
404
+		$this->assertArrayHasKey('date_on_sale_to', $properties);
405
+		$this->assertArrayHasKey('on_sale', $properties);
406
+		$this->assertArrayHasKey('purchasable', $properties);
407
+		$this->assertArrayHasKey('virtual', $properties);
408
+		$this->assertArrayHasKey('downloadable', $properties);
409
+		$this->assertArrayHasKey('downloads', $properties);
410
+		$this->assertArrayHasKey('download_limit', $properties);
411
+		$this->assertArrayHasKey('download_expiry', $properties);
412
+		$this->assertArrayHasKey('tax_status', $properties);
413
+		$this->assertArrayHasKey('tax_class', $properties);
414
+		$this->assertArrayHasKey('manage_stock', $properties);
415
+		$this->assertArrayHasKey('stock_quantity', $properties);
416
+		$this->assertArrayHasKey('stock_status', $properties);
417
+		$this->assertArrayHasKey('backorders', $properties);
418
+		$this->assertArrayHasKey('backorders_allowed', $properties);
419
+		$this->assertArrayHasKey('backordered', $properties);
420
+		$this->assertArrayHasKey('weight', $properties);
421
+		$this->assertArrayHasKey('dimensions', $properties);
422
+		$this->assertArrayHasKey('shipping_class', $properties);
423
+		$this->assertArrayHasKey('shipping_class_id', $properties);
424
+		$this->assertArrayHasKey('image', $properties);
425
+		$this->assertArrayHasKey('attributes', $properties);
426
+		$this->assertArrayHasKey('menu_order', $properties);
427
+		$this->assertArrayHasKey('meta_data', $properties);
428 428
 	}
429 429
 
430 430
 	/**
@@ -434,54 +434,54 @@  discard block
 block discarded – undo
434 434
 	 */
435 435
 	public function test_update_variation_manage_stock() {
436 436
 		$product = ProductHelper::create_variation_product();
437
-		$product->set_manage_stock( false );
437
+		$product->set_manage_stock(false);
438 438
 		$product->save();
439 439
 
440 440
 		$children     = $product->get_children();
441 441
 		$variation_id = $children[0];
442 442
 
443 443
 		// Set stock to true.
444
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id );
444
+		$request = new WP_REST_Request('PUT', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id);
445 445
 		$request->set_body_params(
446 446
 			array(
447 447
 				'manage_stock' => true,
448 448
 			)
449 449
 		);
450 450
 
451
-		$response  = $this->server->dispatch( $request );
451
+		$response  = $this->server->dispatch($request);
452 452
 		$variation = $response->get_data();
453 453
 
454
-		$this->assertEquals( 200, $response->get_status() );
455
-		$this->assertEquals( true, $variation['manage_stock'] );
454
+		$this->assertEquals(200, $response->get_status());
455
+		$this->assertEquals(true, $variation['manage_stock']);
456 456
 
457 457
 		// Set stock to false.
458
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id );
458
+		$request = new WP_REST_Request('PUT', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id);
459 459
 		$request->set_body_params(
460 460
 			array(
461 461
 				'manage_stock' => false,
462 462
 			)
463 463
 		);
464 464
 
465
-		$response  = $this->server->dispatch( $request );
465
+		$response  = $this->server->dispatch($request);
466 466
 		$variation = $response->get_data();
467 467
 
468
-		$this->assertEquals( 200, $response->get_status() );
469
-		$this->assertEquals( false, $variation['manage_stock'] );
468
+		$this->assertEquals(200, $response->get_status());
469
+		$this->assertEquals(false, $variation['manage_stock']);
470 470
 
471 471
 		// Set stock to false but parent is managing stock.
472
-		$product->set_manage_stock( true );
472
+		$product->set_manage_stock(true);
473 473
 		$product->save();
474
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id );
474
+		$request = new WP_REST_Request('PUT', '/wc/v4/products/' . $product->get_id() . '/variations/' . $variation_id);
475 475
 		$request->set_body_params(
476 476
 			array(
477 477
 				'manage_stock' => false,
478 478
 			)
479 479
 		);
480 480
 
481
-		$response  = $this->server->dispatch( $request );
481
+		$response  = $this->server->dispatch($request);
482 482
 		$variation = $response->get_data();
483 483
 
484
-		$this->assertEquals( 200, $response->get_status() );
485
-		$this->assertEquals( 'parent', $variation['manage_stock'] );
484
+		$this->assertEquals(200, $response->get_status());
485
+		$this->assertEquals('parent', $variation['manage_stock']);
486 486
 	}
487 487
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/PerformanceIndicators.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
13 13
 use \WP_REST_Request;
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 	public function test_register_routes() {
34 34
 		$routes = $this->server->get_routes();
35 35
 
36
-		$this->assertArrayHasKey( $this->endpoint, $routes );
37
-		$this->assertArrayHasKey( $this->endpoint . '/allowed', $routes );
36
+		$this->assertArrayHasKey($this->endpoint, $routes);
37
+		$this->assertArrayHasKey($this->endpoint . '/allowed', $routes);
38 38
 	}
39 39
 
40 40
 	/**
@@ -45,68 +45,68 @@  discard block
 block discarded – undo
45 45
 
46 46
 		// Populate all of the data. We'll create an order and a download.
47 47
 		$prod_download = new \WC_Product_Download();
48
-		$prod_download->set_file( plugin_dir_url( __FILE__ ) . '/assets/images/help.png' );
49
-		$prod_download->set_id( 1 );
48
+		$prod_download->set_file(plugin_dir_url(__FILE__) . '/assets/images/help.png');
49
+		$prod_download->set_id(1);
50 50
 
51 51
 		$product = new \WC_Product_Simple();
52
-		$product->set_name( 'Test Product' );
53
-		$product->set_downloadable( 'yes' );
54
-		$product->set_downloads( array( $prod_download ) );
55
-		$product->set_regular_price( 25 );
52
+		$product->set_name('Test Product');
53
+		$product->set_downloadable('yes');
54
+		$product->set_downloads(array($prod_download));
55
+		$product->set_regular_price(25);
56 56
 		$product->save();
57 57
 
58
-		$order = OrderHelper::create_order( 1, $product );
59
-		$order->set_status( 'completed' );
60
-		$order->set_total( 25 );
58
+		$order = OrderHelper::create_order(1, $product);
59
+		$order->set_status('completed');
60
+		$order->set_total(25);
61 61
 		$order->save();
62 62
 
63 63
 		$download = new \WC_Customer_Download();
64
-		$download->set_user_id( $this->user );
65
-		$download->set_order_id( $order->get_id() );
66
-		$download->set_product_id( $product->get_id() );
67
-		$download->set_download_id( $prod_download->get_id() );
64
+		$download->set_user_id($this->user);
65
+		$download->set_order_id($order->get_id());
66
+		$download->set_product_id($product->get_id());
67
+		$download->set_download_id($prod_download->get_id());
68 68
 		$download->save();
69 69
 
70 70
 		$object = new \WC_Customer_Download_Log();
71
-		$object->set_permission_id( $download->get_id() );
72
-		$object->set_user_id( $this->user );
73
-		$object->set_user_ip_address( '1.2.3.4' );
71
+		$object->set_permission_id($download->get_id());
72
+		$object->set_user_id($this->user);
73
+		$object->set_user_ip_address('1.2.3.4');
74 74
 		$object->save();
75 75
 
76 76
 		$object = new \WC_Customer_Download_Log();
77
-		$object->set_permission_id( $download->get_id() );
78
-		$object->set_user_id( $this->user );
79
-		$object->set_user_ip_address( '1.2.3.4' );
77
+		$object->set_permission_id($download->get_id());
78
+		$object->set_user_id($this->user);
79
+		$object->set_user_ip_address('1.2.3.4');
80 80
 		$object->save();
81 81
 
82 82
 		QueueHelper::run_all_pending();
83 83
 
84 84
 		$time    = time();
85
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
85
+		$request = new WP_REST_Request('GET', $this->endpoint);
86 86
 		$request->set_query_params(
87 87
 			array(
88
-				'before' => date( 'Y-m-d 23:59:59', $time ),
89
-				'after'  => date( 'Y-m-d H:00:00', $time - ( 7 * DAY_IN_SECONDS ) ),
88
+				'before' => date('Y-m-d 23:59:59', $time),
89
+				'after'  => date('Y-m-d H:00:00', $time - (7 * DAY_IN_SECONDS)),
90 90
 				'stats'  => 'orders/orders_count,downloads/download_count,test/bogus_stat',
91 91
 			)
92 92
 		);
93
-		$response = $this->server->dispatch( $request );
93
+		$response = $this->server->dispatch($request);
94 94
 		$reports  = $response->get_data();
95 95
 
96
-		$this->assertEquals( 200, $response->get_status() );
97
-		$this->assertEquals( 2, count( $reports ) );
96
+		$this->assertEquals(200, $response->get_status());
97
+		$this->assertEquals(2, count($reports));
98 98
 
99
-		$this->assertEquals( 'orders/orders_count', $reports[0]['stat'] );
100
-		$this->assertEquals( 'Amount of orders', $reports[0]['label'] );
101
-		$this->assertEquals( 1, $reports[0]['value'] );
102
-		$this->assertEquals( 'orders_count', $reports[0]['chart'] );
103
-		$this->assertEquals( '/analytics/orders', $response->data[0]['_links']['report'][0]['href'] );
99
+		$this->assertEquals('orders/orders_count', $reports[0]['stat']);
100
+		$this->assertEquals('Amount of orders', $reports[0]['label']);
101
+		$this->assertEquals(1, $reports[0]['value']);
102
+		$this->assertEquals('orders_count', $reports[0]['chart']);
103
+		$this->assertEquals('/analytics/orders', $response->data[0]['_links']['report'][0]['href']);
104 104
 
105
-		$this->assertEquals( 'downloads/download_count', $reports[1]['stat'] );
106
-		$this->assertEquals( 'Number of downloads', $reports[1]['label'] );
107
-		$this->assertEquals( 2, $reports[1]['value'] );
108
-		$this->assertEquals( 'download_count', $reports[1]['chart'] );
109
-		$this->assertEquals( '/analytics/downloads', $response->data[1]['_links']['report'][0]['href'] );
105
+		$this->assertEquals('downloads/download_count', $reports[1]['stat']);
106
+		$this->assertEquals('Number of downloads', $reports[1]['label']);
107
+		$this->assertEquals(2, $reports[1]['value']);
108
+		$this->assertEquals('download_count', $reports[1]['chart']);
109
+		$this->assertEquals('/analytics/downloads', $response->data[1]['_links']['report'][0]['href']);
110 110
 	}
111 111
 
112 112
 	/**
@@ -116,57 +116,57 @@  discard block
 block discarded – undo
116 116
 		global $wpdb;
117 117
 
118 118
 		$time    = time();
119
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
119
+		$request = new WP_REST_Request('GET', $this->endpoint);
120 120
 		$request->set_query_params(
121 121
 			array(
122
-				'before' => date( 'Y-m-d 23:59:59', $time ),
123
-				'after'  => date( 'Y-m-d H:00:00', $time - ( 7 * DAY_IN_SECONDS ) ),
122
+				'before' => date('Y-m-d 23:59:59', $time),
123
+				'after'  => date('Y-m-d H:00:00', $time - (7 * DAY_IN_SECONDS)),
124 124
 			)
125 125
 		);
126
-		$response = $this->server->dispatch( $request );
126
+		$response = $this->server->dispatch($request);
127 127
 		$reports  = $response->get_data();
128 128
 
129
-		$this->assertEquals( 500, $response->get_status() );
129
+		$this->assertEquals(500, $response->get_status());
130 130
 	}
131 131
 
132 132
 	/**
133 133
 	 * Test getting without valid permissions.
134 134
 	 */
135 135
 	public function test_get_indicators_without_permission() {
136
-		wp_set_current_user( 0 );
137
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
138
-		$this->assertEquals( 401, $response->get_status() );
136
+		wp_set_current_user(0);
137
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
138
+		$this->assertEquals(401, $response->get_status());
139 139
 	}
140 140
 
141 141
 	/**
142 142
 	 * Test schema.
143 143
 	 */
144 144
 	public function test_indicators_schema() {
145
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
146
-		$response   = $this->server->dispatch( $request );
145
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
146
+		$response   = $this->server->dispatch($request);
147 147
 		$data       = $response->get_data();
148 148
 		$properties = $data['schema']['properties'];
149 149
 
150
-		$this->assertEquals( 5, count( $properties ) );
151
-		$this->assertArrayHasKey( 'stat', $properties );
152
-		$this->assertArrayHasKey( 'chart', $properties );
153
-		$this->assertArrayHasKey( 'label', $properties );
154
-		$this->assertArrayHasKey( 'format', $properties );
155
-		$this->assertArrayHasKey( 'value', $properties );
150
+		$this->assertEquals(5, count($properties));
151
+		$this->assertArrayHasKey('stat', $properties);
152
+		$this->assertArrayHasKey('chart', $properties);
153
+		$this->assertArrayHasKey('label', $properties);
154
+		$this->assertArrayHasKey('format', $properties);
155
+		$this->assertArrayHasKey('value', $properties);
156 156
 	}
157 157
 
158 158
 	/**
159 159
 	 * Test schema for /allowed indicators endpoint.
160 160
 	 */
161 161
 	public function test_indicators_schema_allowed() {
162
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint . '/allowed' );
163
-		$response   = $this->server->dispatch( $request );
162
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint . '/allowed');
163
+		$response   = $this->server->dispatch($request);
164 164
 		$data       = $response->get_data();
165 165
 		$properties = $data['schema']['properties'];
166 166
 
167
-		$this->assertEquals( 3, count( $properties ) );
168
-		$this->assertArrayHasKey( 'stat', $properties );
169
-		$this->assertArrayHasKey( 'chart', $properties );
170
-		$this->assertArrayHasKey( 'label', $properties );
167
+		$this->assertEquals(3, count($properties));
168
+		$this->assertArrayHasKey('stat', $properties);
169
+		$this->assertArrayHasKey('chart', $properties);
170
+		$this->assertArrayHasKey('label', $properties);
171 171
 	}
172 172
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/RevenueStats.php 1 patch
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
14 14
 use \WP_REST_Request;
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	public function test_register_routes() {
44 44
 		$routes = $this->server->get_routes();
45 45
 
46
-		$this->assertArrayHasKey( $this->endpoint, $routes );
46
+		$this->assertArrayHasKey($this->endpoint, $routes);
47 47
 	}
48 48
 
49 49
 	/**
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	public function test_get_reports() {
55 55
 		// @todo update after report interface is done.
56
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
56
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
57 57
 		$data     = $response->get_data();
58 58
 
59
-		$this->assertEquals( 200, $response->get_status() );
60
-		$this->assertEquals( 2, count( $data ) ); // @todo Update results after implement report interface.
59
+		$this->assertEquals(200, $response->get_status());
60
+		$this->assertEquals(2, count($data)); // @todo Update results after implement report interface.
61 61
 		// $this->assertEquals( array(), $reports ); // @todo Update results after implement report interface.
62 62
 	}
63 63
 
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
 	 * @since 3.5.0
68 68
 	 */
69 69
 	public function test_get_reports_without_permission() {
70
-		wp_set_current_user( 0 );
71
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
72
-		$this->assertEquals( 401, $response->get_status() );
70
+		wp_set_current_user(0);
71
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
72
+		$this->assertEquals(401, $response->get_status());
73 73
 	}
74 74
 
75 75
 	/**
@@ -78,49 +78,49 @@  discard block
 block discarded – undo
78 78
 	 * @since 3.5.0
79 79
 	 */
80 80
 	public function test_reports_schema() {
81
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
82
-		$response   = $this->server->dispatch( $request );
81
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
82
+		$response   = $this->server->dispatch($request);
83 83
 		$data       = $response->get_data();
84 84
 		$properties = $data['schema']['properties'];
85 85
 
86
-		$this->assertEquals( 2, count( $properties ) );
87
-		$this->assertArrayHasKey( 'totals', $properties );
88
-		$this->assertArrayHasKey( 'intervals', $properties );
86
+		$this->assertEquals(2, count($properties));
87
+		$this->assertArrayHasKey('totals', $properties);
88
+		$this->assertArrayHasKey('intervals', $properties);
89 89
 
90 90
 		$totals = $properties['totals']['properties'];
91
-		$this->assertEquals( 11, count( $totals ) );
92
-		$this->assertArrayHasKey( 'gross_revenue', $totals );
93
-		$this->assertArrayHasKey( 'net_revenue', $totals );
94
-		$this->assertArrayHasKey( 'coupons', $totals );
95
-		$this->assertArrayHasKey( 'coupons_count', $totals );
96
-		$this->assertArrayHasKey( 'shipping', $totals );
97
-		$this->assertArrayHasKey( 'taxes', $totals );
98
-		$this->assertArrayHasKey( 'refunds', $totals );
99
-		$this->assertArrayHasKey( 'orders_count', $totals );
100
-		$this->assertArrayHasKey( 'num_items_sold', $totals );
101
-		$this->assertArrayHasKey( 'products', $totals );
102
-		$this->assertArrayHasKey( 'segments', $totals );
91
+		$this->assertEquals(11, count($totals));
92
+		$this->assertArrayHasKey('gross_revenue', $totals);
93
+		$this->assertArrayHasKey('net_revenue', $totals);
94
+		$this->assertArrayHasKey('coupons', $totals);
95
+		$this->assertArrayHasKey('coupons_count', $totals);
96
+		$this->assertArrayHasKey('shipping', $totals);
97
+		$this->assertArrayHasKey('taxes', $totals);
98
+		$this->assertArrayHasKey('refunds', $totals);
99
+		$this->assertArrayHasKey('orders_count', $totals);
100
+		$this->assertArrayHasKey('num_items_sold', $totals);
101
+		$this->assertArrayHasKey('products', $totals);
102
+		$this->assertArrayHasKey('segments', $totals);
103 103
 
104 104
 		$intervals = $properties['intervals']['items']['properties'];
105
-		$this->assertEquals( 6, count( $intervals ) );
106
-		$this->assertArrayHasKey( 'interval', $intervals );
107
-		$this->assertArrayHasKey( 'date_start', $intervals );
108
-		$this->assertArrayHasKey( 'date_start_gmt', $intervals );
109
-		$this->assertArrayHasKey( 'date_end', $intervals );
110
-		$this->assertArrayHasKey( 'date_end_gmt', $intervals );
111
-		$this->assertArrayHasKey( 'subtotals', $intervals );
105
+		$this->assertEquals(6, count($intervals));
106
+		$this->assertArrayHasKey('interval', $intervals);
107
+		$this->assertArrayHasKey('date_start', $intervals);
108
+		$this->assertArrayHasKey('date_start_gmt', $intervals);
109
+		$this->assertArrayHasKey('date_end', $intervals);
110
+		$this->assertArrayHasKey('date_end_gmt', $intervals);
111
+		$this->assertArrayHasKey('subtotals', $intervals);
112 112
 
113 113
 		$subtotals = $properties['intervals']['items']['properties']['subtotals']['properties'];
114
-		$this->assertEquals( 10, count( $subtotals ) );
115
-		$this->assertArrayHasKey( 'gross_revenue', $subtotals );
116
-		$this->assertArrayHasKey( 'net_revenue', $subtotals );
117
-		$this->assertArrayHasKey( 'coupons', $subtotals );
118
-		$this->assertArrayHasKey( 'coupons_count', $subtotals );
119
-		$this->assertArrayHasKey( 'shipping', $subtotals );
120
-		$this->assertArrayHasKey( 'taxes', $subtotals );
121
-		$this->assertArrayHasKey( 'refunds', $subtotals );
122
-		$this->assertArrayHasKey( 'orders_count', $subtotals );
123
-		$this->assertArrayHasKey( 'num_items_sold', $subtotals );
124
-		$this->assertArrayHasKey( 'segments', $subtotals );
114
+		$this->assertEquals(10, count($subtotals));
115
+		$this->assertArrayHasKey('gross_revenue', $subtotals);
116
+		$this->assertArrayHasKey('net_revenue', $subtotals);
117
+		$this->assertArrayHasKey('coupons', $subtotals);
118
+		$this->assertArrayHasKey('coupons_count', $subtotals);
119
+		$this->assertArrayHasKey('shipping', $subtotals);
120
+		$this->assertArrayHasKey('taxes', $subtotals);
121
+		$this->assertArrayHasKey('refunds', $subtotals);
122
+		$this->assertArrayHasKey('orders_count', $subtotals);
123
+		$this->assertArrayHasKey('num_items_sold', $subtotals);
124
+		$this->assertArrayHasKey('segments', $subtotals);
125 125
 	}
126 126
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/Coupons.php 1 patch
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
13 13
 use \WP_REST_Request;
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	public function test_register_routes() {
35 35
 		$routes = $this->server->get_routes();
36 36
 
37
-		$this->assertArrayHasKey( $this->endpoint, $routes );
37
+		$this->assertArrayHasKey($this->endpoint, $routes);
38 38
 	}
39 39
 
40 40
 	/**
@@ -43,59 +43,59 @@  discard block
 block discarded – undo
43 43
 	public function test_get_reports() {
44 44
 		// Simple product.
45 45
 		$product = new \WC_Product_Simple();
46
-		$product->set_name( 'Test Product' );
47
-		$product->set_regular_price( 25 );
46
+		$product->set_name('Test Product');
47
+		$product->set_regular_price(25);
48 48
 		$product->save();
49 49
 
50 50
 		// Coupons.
51 51
 		$coupon_1_amount = 1; // by default in create_coupon.
52
-		$coupon_1        = CouponHelper::create_coupon( 'coupon_1' );
52
+		$coupon_1        = CouponHelper::create_coupon('coupon_1');
53 53
 
54 54
 		$coupon_2_amount = 2;
55
-		$coupon_2        = CouponHelper::create_coupon( 'coupon_2' );
56
-		$coupon_2->set_amount( $coupon_2_amount );
55
+		$coupon_2        = CouponHelper::create_coupon('coupon_2');
56
+		$coupon_2->set_amount($coupon_2_amount);
57 57
 		$coupon_2->save();
58 58
 
59 59
 		// Order without coupon.
60
-		$order = OrderHelper::create_order( 1, $product );
61
-		$order->set_status( 'completed' );
62
-		$order->set_total( 100 ); // $25 x 4.
60
+		$order = OrderHelper::create_order(1, $product);
61
+		$order->set_status('completed');
62
+		$order->set_total(100); // $25 x 4.
63 63
 		$order->save();
64 64
 
65 65
 		// Order with 1 coupon.
66
-		$order_1c = OrderHelper::create_order( 1, $product );
67
-		$order_1c->set_status( 'completed' );
68
-		$order_1c->apply_coupon( $coupon_1 );
66
+		$order_1c = OrderHelper::create_order(1, $product);
67
+		$order_1c->set_status('completed');
68
+		$order_1c->apply_coupon($coupon_1);
69 69
 		$order_1c->calculate_totals();
70 70
 		$order_1c->save();
71 71
 
72 72
 		// Order with 2 coupons.
73
-		$order_2c = OrderHelper::create_order( 1, $product );
74
-		$order_2c->set_status( 'completed' );
75
-		$order_2c->apply_coupon( $coupon_1 );
76
-		$order_2c->apply_coupon( $coupon_2 );
73
+		$order_2c = OrderHelper::create_order(1, $product);
74
+		$order_2c->set_status('completed');
75
+		$order_2c->apply_coupon($coupon_1);
76
+		$order_2c->apply_coupon($coupon_2);
77 77
 		$order_2c->calculate_totals();
78 78
 		$order_2c->save();
79 79
 
80 80
 		QueueHelper::run_all_pending();
81 81
 
82
-		$response       = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
82
+		$response       = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
83 83
 		$coupon_reports = $response->get_data();
84 84
 
85
-		$this->assertEquals( 200, $response->get_status() );
86
-		$this->assertEquals( 2, count( $coupon_reports ) );
85
+		$this->assertEquals(200, $response->get_status());
86
+		$this->assertEquals(2, count($coupon_reports));
87 87
 
88
-		$this->assertEquals( $coupon_2->get_id(), $coupon_reports[0]['coupon_id'] );
89
-		$this->assertEquals( 1 * $coupon_2_amount, $coupon_reports[0]['amount'] );
90
-		$this->assertEquals( 1, $coupon_reports[0]['orders_count'] );
91
-		$this->assertArrayHasKey( '_links', $coupon_reports[0] );
92
-		$this->assertArrayHasKey( 'coupon', $coupon_reports[0]['_links'] );
88
+		$this->assertEquals($coupon_2->get_id(), $coupon_reports[0]['coupon_id']);
89
+		$this->assertEquals(1 * $coupon_2_amount, $coupon_reports[0]['amount']);
90
+		$this->assertEquals(1, $coupon_reports[0]['orders_count']);
91
+		$this->assertArrayHasKey('_links', $coupon_reports[0]);
92
+		$this->assertArrayHasKey('coupon', $coupon_reports[0]['_links']);
93 93
 
94
-		$this->assertEquals( $coupon_1->get_id(), $coupon_reports[1]['coupon_id'] );
95
-		$this->assertEquals( 2 * $coupon_1_amount, $coupon_reports[1]['amount'] );
96
-		$this->assertEquals( 2, $coupon_reports[1]['orders_count'] );
97
-		$this->assertArrayHasKey( '_links', $coupon_reports[1] );
98
-		$this->assertArrayHasKey( 'coupon', $coupon_reports[1]['_links'] );
94
+		$this->assertEquals($coupon_1->get_id(), $coupon_reports[1]['coupon_id']);
95
+		$this->assertEquals(2 * $coupon_1_amount, $coupon_reports[1]['amount']);
96
+		$this->assertEquals(2, $coupon_reports[1]['orders_count']);
97
+		$this->assertArrayHasKey('_links', $coupon_reports[1]);
98
+		$this->assertArrayHasKey('coupon', $coupon_reports[1]['_links']);
99 99
 	}
100 100
 
101 101
 	/**
@@ -104,75 +104,75 @@  discard block
 block discarded – undo
104 104
 	public function test_get_reports_coupons_param() {
105 105
 		// Simple product.
106 106
 		$product = new \WC_Product_Simple();
107
-		$product->set_name( 'Test Product' );
108
-		$product->set_regular_price( 25 );
107
+		$product->set_name('Test Product');
108
+		$product->set_regular_price(25);
109 109
 		$product->save();
110 110
 
111 111
 		// Coupons.
112 112
 		$coupon_1_amount = 1; // by default in create_coupon.
113
-		$coupon_1        = CouponHelper::create_coupon( 'coupon_1' );
113
+		$coupon_1        = CouponHelper::create_coupon('coupon_1');
114 114
 
115 115
 		$coupon_2_amount = 2;
116
-		$coupon_2        = CouponHelper::create_coupon( 'coupon_2' );
117
-		$coupon_2->set_amount( $coupon_2_amount );
116
+		$coupon_2        = CouponHelper::create_coupon('coupon_2');
117
+		$coupon_2->set_amount($coupon_2_amount);
118 118
 		$coupon_2->save();
119 119
 
120 120
 		// Order with 1 coupon.
121
-		$order_1c = OrderHelper::create_order( 1, $product );
122
-		$order_1c->set_status( 'completed' );
123
-		$order_1c->apply_coupon( $coupon_1 );
121
+		$order_1c = OrderHelper::create_order(1, $product);
122
+		$order_1c->set_status('completed');
123
+		$order_1c->apply_coupon($coupon_1);
124 124
 		$order_1c->calculate_totals();
125 125
 		$order_1c->save();
126 126
 
127 127
 		QueueHelper::run_all_pending();
128 128
 
129
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
129
+		$request = new WP_REST_Request('GET', $this->endpoint);
130 130
 		$request->set_query_params(
131 131
 			array(
132 132
 				'coupons' => $coupon_1->get_id() . ',' . $coupon_2->get_id(),
133 133
 			)
134 134
 		);
135
-		$response       = $this->server->dispatch( $request );
135
+		$response       = $this->server->dispatch($request);
136 136
 		$coupon_reports = $response->get_data();
137 137
 
138
-		$this->assertEquals( 200, $response->get_status() );
139
-		$this->assertEquals( 2, count( $coupon_reports ) );
138
+		$this->assertEquals(200, $response->get_status());
139
+		$this->assertEquals(2, count($coupon_reports));
140 140
 
141
-		$this->assertEquals( $coupon_2->get_id(), $coupon_reports[0]['coupon_id'] );
142
-		$this->assertEquals( 0, $coupon_reports[0]['amount'] );
143
-		$this->assertEquals( 0, $coupon_reports[0]['orders_count'] );
144
-		$this->assertArrayHasKey( '_links', $coupon_reports[0] );
145
-		$this->assertArrayHasKey( 'coupon', $coupon_reports[0]['_links'] );
141
+		$this->assertEquals($coupon_2->get_id(), $coupon_reports[0]['coupon_id']);
142
+		$this->assertEquals(0, $coupon_reports[0]['amount']);
143
+		$this->assertEquals(0, $coupon_reports[0]['orders_count']);
144
+		$this->assertArrayHasKey('_links', $coupon_reports[0]);
145
+		$this->assertArrayHasKey('coupon', $coupon_reports[0]['_links']);
146 146
 
147
-		$this->assertEquals( $coupon_1->get_id(), $coupon_reports[1]['coupon_id'] );
148
-		$this->assertEquals( $coupon_1_amount, $coupon_reports[1]['amount'] );
149
-		$this->assertEquals( 1, $coupon_reports[1]['orders_count'] );
150
-		$this->assertArrayHasKey( '_links', $coupon_reports[1] );
151
-		$this->assertArrayHasKey( 'coupon', $coupon_reports[1]['_links'] );
147
+		$this->assertEquals($coupon_1->get_id(), $coupon_reports[1]['coupon_id']);
148
+		$this->assertEquals($coupon_1_amount, $coupon_reports[1]['amount']);
149
+		$this->assertEquals(1, $coupon_reports[1]['orders_count']);
150
+		$this->assertArrayHasKey('_links', $coupon_reports[1]);
151
+		$this->assertArrayHasKey('coupon', $coupon_reports[1]['_links']);
152 152
 	}
153 153
 
154 154
 	/**
155 155
 	 * Test getting reports without valid permissions.
156 156
 	 */
157 157
 	public function test_get_reports_without_permission() {
158
-		wp_set_current_user( 0 );
159
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
160
-		$this->assertEquals( 401, $response->get_status() );
158
+		wp_set_current_user(0);
159
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
160
+		$this->assertEquals(401, $response->get_status());
161 161
 	}
162 162
 
163 163
 	/**
164 164
 	 * Test reports schema.
165 165
 	 */
166 166
 	public function test_reports_schema() {
167
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
168
-		$response   = $this->server->dispatch( $request );
167
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
168
+		$response   = $this->server->dispatch($request);
169 169
 		$data       = $response->get_data();
170 170
 		$properties = $data['schema']['properties'];
171 171
 
172
-		$this->assertEquals( 4, count( $properties ) );
173
-		$this->assertArrayHasKey( 'coupon_id', $properties );
174
-		$this->assertArrayHasKey( 'amount', $properties );
175
-		$this->assertArrayHasKey( 'orders_count', $properties );
176
-		$this->assertArrayHasKey( 'extended_info', $properties );
172
+		$this->assertEquals(4, count($properties));
173
+		$this->assertArrayHasKey('coupon_id', $properties);
174
+		$this->assertArrayHasKey('amount', $properties);
175
+		$this->assertArrayHasKey('orders_count', $properties);
176
+		$this->assertArrayHasKey('extended_info', $properties);
177 177
 	}
178 178
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/Orders.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
14 14
 use \WP_REST_Request;
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	public function test_register_routes() {
40 40
 		$routes = $this->server->get_routes();
41 41
 
42
-		$this->assertArrayHasKey( $this->endpoint, $routes );
42
+		$this->assertArrayHasKey($this->endpoint, $routes);
43 43
 	}
44 44
 
45 45
 	/**
@@ -50,36 +50,36 @@  discard block
 block discarded – undo
50 50
 	public function test_get_reports() {
51 51
 		// Populate all of the data.
52 52
 		$product = new \WC_Product_Simple();
53
-		$product->set_name( 'Test Product' );
54
-		$product->set_regular_price( 25 );
53
+		$product->set_name('Test Product');
54
+		$product->set_regular_price(25);
55 55
 		$product->save();
56 56
 
57
-		$order = OrderHelper::create_order( 1, $product );
58
-		$order->set_status( 'completed' );
59
-		$order->set_total( 100 ); // $25 x 4.
57
+		$order = OrderHelper::create_order(1, $product);
58
+		$order->set_status('completed');
59
+		$order->set_total(100); // $25 x 4.
60 60
 		$order->save();
61 61
 
62 62
 		QueueHelper::run_all_pending();
63 63
 
64
-		$expected_customer_id = \WC_Admin_Reports_Customers_Data_Store::get_customer_id_by_user_id( 1 );
64
+		$expected_customer_id = \WC_Admin_Reports_Customers_Data_Store::get_customer_id_by_user_id(1);
65 65
 
66
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
66
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
67 67
 		$reports  = $response->get_data();
68 68
 
69
-		$this->assertEquals( 200, $response->get_status() );
70
-		$this->assertEquals( 1, count( $reports ) );
69
+		$this->assertEquals(200, $response->get_status());
70
+		$this->assertEquals(1, count($reports));
71 71
 
72
-		$order_report = reset( $reports );
72
+		$order_report = reset($reports);
73 73
 
74
-		$this->assertEquals( $order->get_id(), $order_report['order_id'] );
75
-		$this->assertEquals( $order->get_order_number(), $order_report['order_number'] );
76
-		$this->assertEquals( date( 'Y-m-d H:i:s', $order->get_date_created()->getTimestamp() ), $order_report['date_created'] );
77
-		$this->assertEquals( $expected_customer_id, $order_report['customer_id'] );
78
-		$this->assertEquals( 4, $order_report['num_items_sold'] );
79
-		$this->assertEquals( 90.0, $order_report['net_total'] ); // 25 x 4 - 10 (shipping)
80
-		$this->assertEquals( 'new', $order_report['customer_type'] );
81
-		$this->assertArrayHasKey( '_links', $order_report );
82
-		$this->assertArrayHasKey( 'order', $order_report['_links'] );
74
+		$this->assertEquals($order->get_id(), $order_report['order_id']);
75
+		$this->assertEquals($order->get_order_number(), $order_report['order_number']);
76
+		$this->assertEquals(date('Y-m-d H:i:s', $order->get_date_created()->getTimestamp()), $order_report['date_created']);
77
+		$this->assertEquals($expected_customer_id, $order_report['customer_id']);
78
+		$this->assertEquals(4, $order_report['num_items_sold']);
79
+		$this->assertEquals(90.0, $order_report['net_total']); // 25 x 4 - 10 (shipping)
80
+		$this->assertEquals('new', $order_report['customer_type']);
81
+		$this->assertArrayHasKey('_links', $order_report);
82
+		$this->assertArrayHasKey('order', $order_report['_links']);
83 83
 	}
84 84
 
85 85
 	/**
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
 	 * @since 3.5.0
89 89
 	 */
90 90
 	public function test_get_reports_without_permission() {
91
-		wp_set_current_user( 0 );
92
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
93
-		$this->assertEquals( 401, $response->get_status() );
91
+		wp_set_current_user(0);
92
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
93
+		$this->assertEquals(401, $response->get_status());
94 94
 	}
95 95
 
96 96
 	/**
@@ -99,20 +99,20 @@  discard block
 block discarded – undo
99 99
 	 * @since 3.5.0
100 100
 	 */
101 101
 	public function test_reports_schema() {
102
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
103
-		$response   = $this->server->dispatch( $request );
102
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
103
+		$response   = $this->server->dispatch($request);
104 104
 		$data       = $response->get_data();
105 105
 		$properties = $data['schema']['properties'];
106 106
 
107
-		$this->assertEquals( 9, count( $properties ) );
108
-		$this->assertArrayHasKey( 'order_id', $properties );
109
-		$this->assertArrayHasKey( 'order_number', $properties );
110
-		$this->assertArrayHasKey( 'date_created', $properties );
111
-		$this->assertArrayHasKey( 'status', $properties );
112
-		$this->assertArrayHasKey( 'customer_id', $properties );
113
-		$this->assertArrayHasKey( 'net_total', $properties );
114
-		$this->assertArrayHasKey( 'num_items_sold', $properties );
115
-		$this->assertArrayHasKey( 'customer_type', $properties );
116
-		$this->assertArrayHasKey( 'extended_info', $properties );
107
+		$this->assertEquals(9, count($properties));
108
+		$this->assertArrayHasKey('order_id', $properties);
109
+		$this->assertArrayHasKey('order_number', $properties);
110
+		$this->assertArrayHasKey('date_created', $properties);
111
+		$this->assertArrayHasKey('status', $properties);
112
+		$this->assertArrayHasKey('customer_id', $properties);
113
+		$this->assertArrayHasKey('net_total', $properties);
114
+		$this->assertArrayHasKey('num_items_sold', $properties);
115
+		$this->assertArrayHasKey('customer_type', $properties);
116
+		$this->assertArrayHasKey('extended_info', $properties);
117 117
 	}
118 118
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/CustomerStats.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
14 14
 use \WP_REST_Request;
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	public function test_register_routes() {
39 39
 		$routes = $this->server->get_routes();
40 40
 
41
-		$this->assertArrayHasKey( $this->endpoint, $routes );
41
+		$this->assertArrayHasKey($this->endpoint, $routes);
42 42
 	}
43 43
 
44 44
 	/**
@@ -47,18 +47,18 @@  discard block
 block discarded – undo
47 47
 	 * @since 3.5.0
48 48
 	 */
49 49
 	public function test_reports_schema() {
50
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
51
-		$response   = $this->server->dispatch( $request );
50
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
51
+		$response   = $this->server->dispatch($request);
52 52
 		$data       = $response->get_data();
53 53
 		$properties = $data['schema']['properties'];
54 54
 
55
-		$this->assertCount( 1, $properties );
56
-		$this->assertArrayHasKey( 'totals', $properties );
57
-		$this->assertCount( 4, $properties['totals']['properties'] );
58
-		$this->assertArrayHasKey( 'customers_count', $properties['totals']['properties'] );
59
-		$this->assertArrayHasKey( 'avg_orders_count', $properties['totals']['properties'] );
60
-		$this->assertArrayHasKey( 'avg_total_spend', $properties['totals']['properties'] );
61
-		$this->assertArrayHasKey( 'avg_avg_order_value', $properties['totals']['properties'] );
55
+		$this->assertCount(1, $properties);
56
+		$this->assertArrayHasKey('totals', $properties);
57
+		$this->assertCount(4, $properties['totals']['properties']);
58
+		$this->assertArrayHasKey('customers_count', $properties['totals']['properties']);
59
+		$this->assertArrayHasKey('avg_orders_count', $properties['totals']['properties']);
60
+		$this->assertArrayHasKey('avg_total_spend', $properties['totals']['properties']);
61
+		$this->assertArrayHasKey('avg_avg_order_value', $properties['totals']['properties']);
62 62
 	}
63 63
 
64 64
 	/**
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
 	 * @since 3.5.0
68 68
 	 */
69 69
 	public function test_get_reports_without_permission() {
70
-		wp_set_current_user( 0 );
71
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
72
-		$this->assertEquals( 401, $response->get_status() );
70
+		wp_set_current_user(0);
71
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
72
+		$this->assertEquals(401, $response->get_status());
73 73
 	}
74 74
 
75 75
 	/**
@@ -81,52 +81,52 @@  discard block
 block discarded – undo
81 81
 		$test_customers = array();
82 82
 
83 83
 		// Create 10 test customers.
84
-		for ( $i = 1; $i <= 10; $i++ ) {
85
-			$test_customers[] = CustomerHelper::create_customer( "customer{$i}", 'password', "customer{$i}@example.com" );
84
+		for ($i = 1; $i <= 10; $i++) {
85
+			$test_customers[] = CustomerHelper::create_customer("customer{$i}", 'password', "customer{$i}@example.com");
86 86
 		}
87 87
 		// One differing name.
88
-		$test_customers[2]->set_first_name( 'Jeff' );
88
+		$test_customers[2]->set_first_name('Jeff');
89 89
 		$test_customers[2]->save();
90 90
 
91 91
 		// Create a test product for use in an order.
92 92
 		$product = new \WC_Product_Simple();
93
-		$product->set_name( 'Test Product' );
94
-		$product->set_regular_price( 25 );
93
+		$product->set_name('Test Product');
94
+		$product->set_regular_price(25);
95 95
 		$product->save();
96 96
 
97 97
 		// Place some test orders.
98
-		$order = OrderHelper::create_order( $test_customers[0]->get_id(), $product );
99
-		$order->set_status( 'completed' );
100
-		$order->set_total( 100 );
98
+		$order = OrderHelper::create_order($test_customers[0]->get_id(), $product);
99
+		$order->set_status('completed');
100
+		$order->set_total(100);
101 101
 		$order->save();
102 102
 
103
-		$order = OrderHelper::create_order( $test_customers[0]->get_id(), $product );
104
-		$order->set_status( 'completed' );
105
-		$order->set_total( 234 );
103
+		$order = OrderHelper::create_order($test_customers[0]->get_id(), $product);
104
+		$order->set_status('completed');
105
+		$order->set_total(234);
106 106
 		$order->save();
107 107
 
108
-		$order = OrderHelper::create_order( $test_customers[1]->get_id(), $product );
109
-		$order->set_status( 'completed' );
110
-		$order->set_total( 55 );
108
+		$order = OrderHelper::create_order($test_customers[1]->get_id(), $product);
109
+		$order->set_status('completed');
110
+		$order->set_total(55);
111 111
 		$order->save();
112 112
 
113
-		$order = OrderHelper::create_order( $test_customers[2]->get_id(), $product );
114
-		$order->set_status( 'completed' );
115
-		$order->set_total( 9.12 );
113
+		$order = OrderHelper::create_order($test_customers[2]->get_id(), $product);
114
+		$order->set_status('completed');
115
+		$order->set_total(9.12);
116 116
 		$order->save();
117 117
 
118 118
 		QueueHelper::run_all_pending();
119 119
 
120
-		$request  = new WP_REST_Request( 'GET', $this->endpoint );
121
-		$response = $this->server->dispatch( $request );
120
+		$request  = new WP_REST_Request('GET', $this->endpoint);
121
+		$response = $this->server->dispatch($request);
122 122
 		$reports  = $response->get_data();
123 123
 		$headers  = $response->get_headers();
124 124
 
125
-		$this->assertEquals( 200, $response->get_status() );
126
-		$this->assertEquals( 10, $reports['totals']->customers_count );
127
-		$this->assertEquals( 1.333, round( $reports['totals']->avg_orders_count, 3 ) );
128
-		$this->assertEquals( 132.707, round( $reports['totals']->avg_total_spend, 3 ) );
129
-		$this->assertEquals( 77.04, $reports['totals']->avg_avg_order_value );
125
+		$this->assertEquals(200, $response->get_status());
126
+		$this->assertEquals(10, $reports['totals']->customers_count);
127
+		$this->assertEquals(1.333, round($reports['totals']->avg_orders_count, 3));
128
+		$this->assertEquals(132.707, round($reports['totals']->avg_total_spend, 3));
129
+		$this->assertEquals(77.04, $reports['totals']->avg_avg_order_value);
130 130
 
131 131
 		// Test name parameter (case with no matches).
132 132
 		$request->set_query_params(
@@ -134,29 +134,29 @@  discard block
 block discarded – undo
134 134
 				'search' => 'Nota Customername',
135 135
 			)
136 136
 		);
137
-		$response = $this->server->dispatch( $request );
137
+		$response = $this->server->dispatch($request);
138 138
 		$reports  = $response->get_data();
139 139
 
140
-		$this->assertEquals( 200, $response->get_status() );
141
-		$this->assertEquals( 0, $reports['totals']->customers_count );
142
-		$this->assertEquals( 0, $reports['totals']->avg_orders_count );
143
-		$this->assertEquals( 0, $reports['totals']->avg_total_spend );
144
-		$this->assertEquals( 0, $reports['totals']->avg_avg_order_value );
140
+		$this->assertEquals(200, $response->get_status());
141
+		$this->assertEquals(0, $reports['totals']->customers_count);
142
+		$this->assertEquals(0, $reports['totals']->avg_orders_count);
143
+		$this->assertEquals(0, $reports['totals']->avg_total_spend);
144
+		$this->assertEquals(0, $reports['totals']->avg_avg_order_value);
145 145
 
146 146
 		// Test name and last_order parameters.
147 147
 		$request->set_query_params(
148 148
 			array(
149 149
 				'search'           => 'Jeff',
150
-				'last_order_after' => date( 'Y-m-d' ) . 'T00:00:00Z',
150
+				'last_order_after' => date('Y-m-d') . 'T00:00:00Z',
151 151
 			)
152 152
 		);
153
-		$response = $this->server->dispatch( $request );
153
+		$response = $this->server->dispatch($request);
154 154
 		$reports  = $response->get_data();
155 155
 
156
-		$this->assertEquals( 200, $response->get_status() );
157
-		$this->assertEquals( 1, $reports['totals']->customers_count );
158
-		$this->assertEquals( 1, $reports['totals']->avg_orders_count );
159
-		$this->assertEquals( 9.12, $reports['totals']->avg_total_spend );
160
-		$this->assertEquals( 9.12, $reports['totals']->avg_avg_order_value );
156
+		$this->assertEquals(200, $response->get_status());
157
+		$this->assertEquals(1, $reports['totals']->customers_count);
158
+		$this->assertEquals(1, $reports['totals']->avg_orders_count);
159
+		$this->assertEquals(9.12, $reports['totals']->avg_total_spend);
160
+		$this->assertEquals(9.12, $reports['totals']->avg_avg_order_value);
161 161
 	}
162 162
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/Customers.php 1 patch
Spacing   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
14 14
 use \WP_REST_Request;
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	public function test_register_routes() {
39 39
 		$routes = $this->server->get_routes();
40 40
 
41
-		$this->assertArrayHasKey( $this->endpoint, $routes );
41
+		$this->assertArrayHasKey($this->endpoint, $routes);
42 42
 	}
43 43
 
44 44
 	/**
@@ -46,21 +46,21 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 * @param array $schema Item to check schema.
48 48
 	 */
49
-	public function assert_report_item_schema( $schema ) {
50
-		$this->assertArrayHasKey( 'id', $schema );
51
-		$this->assertArrayHasKey( 'user_id', $schema );
52
-		$this->assertArrayHasKey( 'name', $schema );
53
-		$this->assertArrayHasKey( 'username', $schema );
54
-		$this->assertArrayHasKey( 'country', $schema );
55
-		$this->assertArrayHasKey( 'city', $schema );
56
-		$this->assertArrayHasKey( 'postcode', $schema );
57
-		$this->assertArrayHasKey( 'date_registered', $schema );
58
-		$this->assertArrayHasKey( 'date_registered_gmt', $schema );
59
-		$this->assertArrayHasKey( 'date_last_active', $schema );
60
-		$this->assertArrayHasKey( 'date_last_active_gmt', $schema );
61
-		$this->assertArrayHasKey( 'orders_count', $schema );
62
-		$this->assertArrayHasKey( 'total_spend', $schema );
63
-		$this->assertArrayHasKey( 'avg_order_value', $schema );
49
+	public function assert_report_item_schema($schema) {
50
+		$this->assertArrayHasKey('id', $schema);
51
+		$this->assertArrayHasKey('user_id', $schema);
52
+		$this->assertArrayHasKey('name', $schema);
53
+		$this->assertArrayHasKey('username', $schema);
54
+		$this->assertArrayHasKey('country', $schema);
55
+		$this->assertArrayHasKey('city', $schema);
56
+		$this->assertArrayHasKey('postcode', $schema);
57
+		$this->assertArrayHasKey('date_registered', $schema);
58
+		$this->assertArrayHasKey('date_registered_gmt', $schema);
59
+		$this->assertArrayHasKey('date_last_active', $schema);
60
+		$this->assertArrayHasKey('date_last_active_gmt', $schema);
61
+		$this->assertArrayHasKey('orders_count', $schema);
62
+		$this->assertArrayHasKey('total_spend', $schema);
63
+		$this->assertArrayHasKey('avg_order_value', $schema);
64 64
 	}
65 65
 
66 66
 	/**
@@ -69,13 +69,13 @@  discard block
 block discarded – undo
69 69
 	 * @since 3.5.0
70 70
 	 */
71 71
 	public function test_reports_schema() {
72
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
73
-		$response   = $this->server->dispatch( $request );
72
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
73
+		$response   = $this->server->dispatch($request);
74 74
 		$data       = $response->get_data();
75 75
 		$properties = $data['schema']['properties'];
76 76
 
77
-		$this->assertCount( 14, $properties );
78
-		$this->assert_report_item_schema( $properties );
77
+		$this->assertCount(14, $properties);
78
+		$this->assert_report_item_schema($properties);
79 79
 	}
80 80
 
81 81
 	/**
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
 	 * @since 3.5.0
85 85
 	 */
86 86
 	public function test_get_reports_without_permission() {
87
-		wp_set_current_user( 0 );
88
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
89
-		$this->assertEquals( 401, $response->get_status() );
87
+		wp_set_current_user(0);
88
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
89
+		$this->assertEquals(401, $response->get_status());
90 90
 	}
91 91
 
92 92
 	/**
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
 	 * @since 3.5.0
96 96
 	 */
97 97
 	public function test_update_registered_customer_with_bad_user_id() {
98
-		$result = \WC_Admin_Reports_Customers_Data_Store::update_registered_customer( 2 );
99
-		$this->assertFalse( $result );
98
+		$result = \WC_Admin_Reports_Customers_Data_Store::update_registered_customer(2);
99
+		$this->assertFalse($result);
100 100
 	}
101 101
 
102 102
 	/**
@@ -114,42 +114,42 @@  discard block
 block discarded – undo
114 114
 		);
115 115
 
116 116
 		// Admin user without orders should not be shown.
117
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
118
-		$request->set_query_params( array( 'per_page' => 10 ) );
119
-		$response = $this->server->dispatch( $request );
117
+		$request = new WP_REST_Request('GET', $this->endpoint);
118
+		$request->set_query_params(array('per_page' => 10));
119
+		$response = $this->server->dispatch($request);
120 120
 		$reports  = $response->get_data();
121 121
 		$headers  = $response->get_headers();
122 122
 
123
-		$this->assertEquals( 200, $response->get_status() );
124
-		$this->assertCount( 0, $reports );
123
+		$this->assertEquals(200, $response->get_status());
124
+		$this->assertCount(0, $reports);
125 125
 
126 126
 		// Creating an order with admin should return the admin.
127 127
 		$product = new \WC_Product_Simple();
128
-		$product->set_name( 'Test Product' );
129
-		$product->set_regular_price( 25 );
128
+		$product->set_name('Test Product');
129
+		$product->set_regular_price(25);
130 130
 		$product->save();
131 131
 
132
-		$order = OrderHelper::create_order( $admin_id, $product );
133
-		$order->set_status( 'processing' );
134
-		$order->set_total( 100 );
132
+		$order = OrderHelper::create_order($admin_id, $product);
133
+		$order->set_status('processing');
134
+		$order->set_total(100);
135 135
 		$order->save();
136 136
 
137 137
 		QueueHelper::run_all_pending();
138 138
 
139
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
140
-		$request->set_query_params( array( 'per_page' => 10 ) );
141
-		$response = $this->server->dispatch( $request );
139
+		$request = new WP_REST_Request('GET', $this->endpoint);
140
+		$request->set_query_params(array('per_page' => 10));
141
+		$response = $this->server->dispatch($request);
142 142
 		$reports  = $response->get_data();
143 143
 		$headers  = $response->get_headers();
144 144
 
145
-		$this->assertEquals( 200, $response->get_status() );
146
-		$this->assertCount( 1, $reports );
147
-		$this->assertEquals( $admin_id, $reports[0]['user_id'] );
145
+		$this->assertEquals(200, $response->get_status());
146
+		$this->assertCount(1, $reports);
147
+		$this->assertEquals($admin_id, $reports[0]['user_id']);
148 148
 
149 149
 		// Creating a customer should show up regardless of orders.
150
-		$customer = CustomerHelper::create_customer( 'customer', 'password', '[email protected]' );
150
+		$customer = CustomerHelper::create_customer('customer', 'password', '[email protected]');
151 151
 
152
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
152
+		$request = new WP_REST_Request('GET', $this->endpoint);
153 153
 		$request->set_query_params(
154 154
 			array(
155 155
 				'per_page' => 10,
@@ -157,14 +157,14 @@  discard block
 block discarded – undo
157 157
 				'orderby'  => 'username',
158 158
 			)
159 159
 		);
160
-		$response = $this->server->dispatch( $request );
160
+		$response = $this->server->dispatch($request);
161 161
 		$reports  = $response->get_data();
162 162
 		$headers  = $response->get_headers();
163 163
 
164
-		$this->assertEquals( 200, $response->get_status() );
165
-		$this->assertCount( 2, $reports );
166
-		$this->assertEquals( $customer->get_id(), $reports[0]['user_id'] );
167
-		$this->assertEquals( $admin_id, $reports[1]['user_id'] );
164
+		$this->assertEquals(200, $response->get_status());
165
+		$this->assertCount(2, $reports);
166
+		$this->assertEquals($customer->get_id(), $reports[0]['user_id']);
167
+		$this->assertEquals($admin_id, $reports[1]['user_id']);
168 168
 	}
169 169
 
170 170
 	/**
@@ -177,33 +177,33 @@  discard block
 block discarded – undo
177 177
 
178 178
 		$test_customers = array();
179 179
 
180
-		$customer_names = array( 'Alice', 'Betty', 'Catherine', 'Dan', 'Eric', 'Fred', 'Greg', 'Henry', 'Ivan', 'Justin' );
180
+		$customer_names = array('Alice', 'Betty', 'Catherine', 'Dan', 'Eric', 'Fred', 'Greg', 'Henry', 'Ivan', 'Justin');
181 181
 
182 182
 		// Create 10 test customers.
183
-		for ( $i = 1; $i <= 10; $i++ ) {
184
-			$name     = $customer_names[ $i - 1 ];
185
-			$email    = 'customer+' . strtolower( $name ) . '@example.com';
186
-			$customer = CustomerHelper::create_customer( "customer{$i}", 'password', $email );
187
-			$customer->set_first_name( $name );
183
+		for ($i = 1; $i <= 10; $i++) {
184
+			$name     = $customer_names[$i - 1];
185
+			$email    = 'customer+' . strtolower($name) . '@example.com';
186
+			$customer = CustomerHelper::create_customer("customer{$i}", 'password', $email);
187
+			$customer->set_first_name($name);
188 188
 			$customer->save();
189 189
 			$test_customers[] = $customer;
190 190
 		}
191 191
 
192 192
 		// Create a test product for use in an order.
193 193
 		$product = new \WC_Product_Simple();
194
-		$product->set_name( 'Test Product' );
195
-		$product->set_regular_price( 25 );
194
+		$product->set_name('Test Product');
195
+		$product->set_regular_price(25);
196 196
 		$product->save();
197 197
 
198 198
 		// Place an order for the first test customer.
199
-		$order = OrderHelper::create_order( $test_customers[0]->get_id(), $product );
200
-		$order->set_status( 'processing' );
201
-		$order->set_total( 100 );
199
+		$order = OrderHelper::create_order($test_customers[0]->get_id(), $product);
200
+		$order->set_status('processing');
201
+		$order->set_total(100);
202 202
 		$order->save();
203 203
 
204 204
 		QueueHelper::run_all_pending();
205 205
 
206
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
206
+		$request = new WP_REST_Request('GET', $this->endpoint);
207 207
 		$request->set_query_params(
208 208
 			array(
209 209
 				'per_page' => 5,
@@ -212,20 +212,20 @@  discard block
 block discarded – undo
212 212
 			)
213 213
 		);
214 214
 
215
-		$response = $this->server->dispatch( $request );
215
+		$response = $this->server->dispatch($request);
216 216
 		$reports  = $response->get_data();
217 217
 		$headers  = $response->get_headers();
218 218
 
219
-		$this->assertEquals( 200, $response->get_status() );
220
-		$this->assertCount( 5, $reports );
221
-		$this->assertArrayHasKey( 'X-WP-Total', $headers );
222
-		$this->assertEquals( 10, $headers['X-WP-Total'] );
223
-		$this->assertArrayHasKey( 'X-WP-TotalPages', $headers );
224
-		$this->assertEquals( 2, $headers['X-WP-TotalPages'] );
225
-		$this->assertEquals( $test_customers[0]->get_id(), $reports[0]['user_id'] );
226
-		$this->assertEquals( 1, $reports[0]['orders_count'] );
227
-		$this->assertEquals( 100, $reports[0]['total_spend'] );
228
-		$this->assert_report_item_schema( $reports[0] );
219
+		$this->assertEquals(200, $response->get_status());
220
+		$this->assertCount(5, $reports);
221
+		$this->assertArrayHasKey('X-WP-Total', $headers);
222
+		$this->assertEquals(10, $headers['X-WP-Total']);
223
+		$this->assertArrayHasKey('X-WP-TotalPages', $headers);
224
+		$this->assertEquals(2, $headers['X-WP-TotalPages']);
225
+		$this->assertEquals($test_customers[0]->get_id(), $reports[0]['user_id']);
226
+		$this->assertEquals(1, $reports[0]['orders_count']);
227
+		$this->assertEquals(100, $reports[0]['total_spend']);
228
+		$this->assert_report_item_schema($reports[0]);
229 229
 
230 230
 		// Test name parameter (case with no matches).
231 231
 		$request->set_query_params(
@@ -233,11 +233,11 @@  discard block
 block discarded – undo
233 233
 				'search' => 'Nota Customername',
234 234
 			)
235 235
 		);
236
-		$response = $this->server->dispatch( $request );
236
+		$response = $this->server->dispatch($request);
237 237
 		$reports  = $response->get_data();
238 238
 
239
-		$this->assertEquals( 200, $response->get_status() );
240
-		$this->assertCount( 0, $reports );
239
+		$this->assertEquals(200, $response->get_status());
240
+		$this->assertCount(0, $reports);
241 241
 
242 242
 		// Test name parameter (partial match).
243 243
 		$request->set_query_params(
@@ -245,11 +245,11 @@  discard block
 block discarded – undo
245 245
 				'search' => 're',
246 246
 			)
247 247
 		);
248
-		$response = $this->server->dispatch( $request );
248
+		$response = $this->server->dispatch($request);
249 249
 		$reports  = $response->get_data();
250 250
 
251
-		$this->assertEquals( 200, $response->get_status() );
252
-		$this->assertCount( 2, $reports );
251
+		$this->assertEquals(200, $response->get_status());
252
+		$this->assertCount(2, $reports);
253 253
 
254 254
 		// Test email search.
255 255
 		$request->set_query_params(
@@ -258,11 +258,11 @@  discard block
 block discarded – undo
258 258
 				'searchby' => 'email',
259 259
 			)
260 260
 		);
261
-		$response = $this->server->dispatch( $request );
261
+		$response = $this->server->dispatch($request);
262 262
 		$reports  = $response->get_data();
263 263
 
264
-		$this->assertEquals( 200, $response->get_status() );
265
-		$this->assertCount( 1, $reports );
264
+		$this->assertEquals(200, $response->get_status());
265
+		$this->assertCount(1, $reports);
266 266
 
267 267
 		// Test username search.
268 268
 		$request->set_query_params(
@@ -271,29 +271,29 @@  discard block
 block discarded – undo
271 271
 				'searchby' => 'username',
272 272
 			)
273 273
 		);
274
-		$response = $this->server->dispatch( $request );
274
+		$response = $this->server->dispatch($request);
275 275
 		$reports  = $response->get_data();
276 276
 
277
-		$this->assertEquals( 200, $response->get_status() );
277
+		$this->assertEquals(200, $response->get_status());
278 278
 		// customer1 and customer10.
279
-		$this->assertCount( 2, $reports );
279
+		$this->assertCount(2, $reports);
280 280
 
281 281
 		// Test name and last_order parameters.
282 282
 		$request->set_query_params(
283 283
 			array(
284 284
 				'search'           => 'Alice',
285
-				'last_order_after' => date( 'Y-m-d' ) . 'T00:00:00Z',
285
+				'last_order_after' => date('Y-m-d') . 'T00:00:00Z',
286 286
 			)
287 287
 		);
288
-		$response = $this->server->dispatch( $request );
288
+		$response = $this->server->dispatch($request);
289 289
 		$reports  = $response->get_data();
290 290
 
291
-		$this->assertEquals( 200, $response->get_status() );
292
-		$this->assertCount( 1, $reports );
291
+		$this->assertEquals(200, $response->get_status());
292
+		$this->assertCount(1, $reports);
293 293
 
294
-		$this->assertEquals( $test_customers[0]->get_id(), $reports[0]['user_id'] );
295
-		$this->assertEquals( 1, $reports[0]['orders_count'] );
296
-		$this->assertEquals( 100, $reports[0]['total_spend'] );
294
+		$this->assertEquals($test_customers[0]->get_id(), $reports[0]['user_id']);
295
+		$this->assertEquals(1, $reports[0]['orders_count']);
296
+		$this->assertEquals(100, $reports[0]['total_spend']);
297 297
 
298 298
 		$customer_id = $wpdb->get_col(
299 299
 			$wpdb->prepare(
@@ -309,11 +309,11 @@  discard block
 block discarded – undo
309 309
 			)
310 310
 		);
311 311
 
312
-		$response = $this->server->dispatch( $request );
312
+		$response = $this->server->dispatch($request);
313 313
 		$reports  = $response->get_data();
314
-		$this->assertEquals( 200, $response->get_status() );
315
-		$this->assertCount( 1, $reports );
316
-		$this->assertEquals( $test_customers[0]->get_id(), $reports[0]['user_id'] );
314
+		$this->assertEquals(200, $response->get_status());
315
+		$this->assertCount(1, $reports);
316
+		$this->assertEquals($test_customers[0]->get_id(), $reports[0]['user_id']);
317 317
 	}
318 318
 
319 319
 	/**
@@ -329,43 +329,43 @@  discard block
 block discarded – undo
329 329
 		);
330 330
 
331 331
 		// Test shipping name and empty billing name.
332
-		$order = OrderHelper::create_order( $customer );
333
-		$order->set_billing_first_name( '' );
334
-		$order->set_billing_last_name( '' );
335
-		$order->set_shipping_first_name( 'Daenerys' );
336
-		$order->set_shipping_last_name( 'Targaryen' );
337
-		$order->set_status( 'completed' );
338
-		$order->set_total( 100 );
332
+		$order = OrderHelper::create_order($customer);
333
+		$order->set_billing_first_name('');
334
+		$order->set_billing_last_name('');
335
+		$order->set_shipping_first_name('Daenerys');
336
+		$order->set_shipping_last_name('Targaryen');
337
+		$order->set_status('completed');
338
+		$order->set_total(100);
339 339
 		$order->save();
340 340
 
341 341
 		QueueHelper::run_all_pending();
342 342
 
343
-		$request  = new WP_REST_Request( 'GET', $this->endpoint );
344
-		$response = $this->server->dispatch( $request );
343
+		$request  = new WP_REST_Request('GET', $this->endpoint);
344
+		$response = $this->server->dispatch($request);
345 345
 		$reports  = $response->get_data();
346 346
 		$headers  = $response->get_headers();
347 347
 
348
-		$this->assertEquals( 200, $response->get_status() );
349
-		$this->assertCount( 1, $reports );
350
-		$this->assertEquals( 'Daenerys Targaryen', $reports[0]['name'] );
348
+		$this->assertEquals(200, $response->get_status());
349
+		$this->assertCount(1, $reports);
350
+		$this->assertEquals('Daenerys Targaryen', $reports[0]['name']);
351 351
 
352 352
 		// Test billing name.
353
-		$order->set_billing_first_name( 'Jon' );
354
-		$order->set_billing_last_name( 'Snow' );
353
+		$order->set_billing_first_name('Jon');
354
+		$order->set_billing_last_name('Snow');
355 355
 		$order->save();
356
-		do_action( 'woocommerce_update_customer', $customer );
356
+		do_action('woocommerce_update_customer', $customer);
357 357
 
358 358
 		QueueHelper::run_all_pending();
359 359
 
360
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
361
-		$request->set_query_params( array( 'orderby' => 'username' ) ); // Cache busting.
362
-		$response = $this->server->dispatch( $request );
360
+		$request = new WP_REST_Request('GET', $this->endpoint);
361
+		$request->set_query_params(array('orderby' => 'username')); // Cache busting.
362
+		$response = $this->server->dispatch($request);
363 363
 		$reports  = $response->get_data();
364 364
 		$headers  = $response->get_headers();
365 365
 
366
-		$this->assertEquals( 200, $response->get_status() );
367
-		$this->assertCount( 1, $reports );
368
-		$this->assertEquals( 'Jon Snow', $reports[0]['name'] );
366
+		$this->assertEquals(200, $response->get_status());
367
+		$this->assertCount(1, $reports);
368
+		$this->assertEquals('Jon Snow', $reports[0]['name']);
369 369
 
370 370
 		// Test user profile name.
371 371
 		wp_update_user(
@@ -375,18 +375,18 @@  discard block
 block discarded – undo
375 375
 				'last_name'  => 'Lanister',
376 376
 			)
377 377
 		);
378
-		do_action( 'woocommerce_update_customer', $customer );
378
+		do_action('woocommerce_update_customer', $customer);
379 379
 
380 380
 		QueueHelper::run_all_pending();
381 381
 
382
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
383
-		$request->set_query_params( array( 'orderby' => 'name' ) ); // Cache busting.
384
-		$response = $this->server->dispatch( $request );
382
+		$request = new WP_REST_Request('GET', $this->endpoint);
383
+		$request->set_query_params(array('orderby' => 'name')); // Cache busting.
384
+		$response = $this->server->dispatch($request);
385 385
 		$reports  = $response->get_data();
386 386
 		$headers  = $response->get_headers();
387 387
 
388
-		$this->assertEquals( 200, $response->get_status() );
389
-		$this->assertCount( 1, $reports );
390
-		$this->assertEquals( 'Tyrion Lanister', $reports[0]['name'] );
388
+		$this->assertEquals(200, $response->get_status());
389
+		$this->assertCount(1, $reports);
390
+		$this->assertEquals('Tyrion Lanister', $reports[0]['name']);
391 391
 	}
392 392
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Reports/TaxStats.php 1 patch
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4\Reports;
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 use \WooCommerce\RestApi\UnitTests\AbstractReportsTest;
14 14
 use \WP_REST_Request;
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	public function test_register_routes() {
37 37
 		$routes = $this->server->get_routes();
38 38
 
39
-		$this->assertArrayHasKey( $this->endpoint, $routes );
39
+		$this->assertArrayHasKey($this->endpoint, $routes);
40 40
 	}
41 41
 
42 42
 	/**
@@ -63,21 +63,21 @@  discard block
 block discarded – undo
63 63
 		);
64 64
 
65 65
 		$product = new \WC_Product_Simple();
66
-		$product->set_name( 'Test Product' );
67
-		$product->set_regular_price( 25 );
68
-		$product->set_tax_class( 'TestTax' );
66
+		$product->set_name('Test Product');
67
+		$product->set_regular_price(25);
68
+		$product->set_tax_class('TestTax');
69 69
 		$product->save();
70 70
 
71
-		update_option( 'woocommerce_calc_taxes', 'yes' );
72
-		$order = OrderHelper::create_order( 1, $product );
73
-		$order->set_status( 'completed' );
74
-		$order->set_total( 100 ); // $25 x 4.
71
+		update_option('woocommerce_calc_taxes', 'yes');
72
+		$order = OrderHelper::create_order(1, $product);
73
+		$order->set_status('completed');
74
+		$order->set_total(100); // $25 x 4.
75 75
 		$order->calculate_taxes();
76 76
 		$order->save();
77 77
 
78 78
 		// Add refunds to line items.
79
-		foreach ( $order->get_items() as $item_id => $item ) {
80
-			$refund    = array(
79
+		foreach ($order->get_items() as $item_id => $item) {
80
+			$refund = array(
81 81
 				'amount'     => 1,
82 82
 				'reason'     => 'Testing line item refund',
83 83
 				'order_id'   => $order->get_id(),
@@ -85,28 +85,28 @@  discard block
 block discarded – undo
85 85
 					$item_id => array(
86 86
 						'qty'          => 1,
87 87
 						'refund_total' => 1,
88
-						'refund_tax'   => array( $tax => 1 ),
88
+						'refund_tax'   => array($tax => 1),
89 89
 					),
90 90
 				),
91 91
 			);
92
-			$wc_refund = wc_create_refund( $refund );
92
+			$wc_refund = wc_create_refund($refund);
93 93
 		}
94 94
 
95 95
 		QueueHelper::run_all_pending();
96 96
 
97
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
97
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
98 98
 		$reports  = $response->get_data();
99 99
 
100
-		$this->assertEquals( 200, $response->get_status() );
101
-		$this->assertEquals( 2, count( $reports ) );
100
+		$this->assertEquals(200, $response->get_status());
101
+		$this->assertEquals(2, count($reports));
102 102
 
103
-		$tax_report = reset( $reports );
103
+		$tax_report = reset($reports);
104 104
 
105
-		$this->assertEquals( 1, $tax_report['tax_codes'] );
106
-		$this->assertEquals( 6.7, $tax_report['total_tax'] ); // 110 * 0.07 (tax rate) - 1 (refund)
107
-		$this->assertEquals( 6, $tax_report['order_tax'] ); // 100 * 0.07 (tax rate) - 1 (refund)
108
-		$this->assertEquals( 0.7, $tax_report['shipping_tax'] );
109
-		$this->assertEquals( 1, $tax_report['orders_count'] );
105
+		$this->assertEquals(1, $tax_report['tax_codes']);
106
+		$this->assertEquals(6.7, $tax_report['total_tax']); // 110 * 0.07 (tax rate) - 1 (refund)
107
+		$this->assertEquals(6, $tax_report['order_tax']); // 100 * 0.07 (tax rate) - 1 (refund)
108
+		$this->assertEquals(0.7, $tax_report['shipping_tax']);
109
+		$this->assertEquals(1, $tax_report['orders_count']);
110 110
 	}
111 111
 
112 112
 	/**
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
 	 * @since 3.5.0
116 116
 	 */
117 117
 	public function test_get_reports_without_permission() {
118
-		wp_set_current_user( 0 );
119
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
120
-		$this->assertEquals( 401, $response->get_status() );
118
+		wp_set_current_user(0);
119
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
120
+		$this->assertEquals(401, $response->get_status());
121 121
 	}
122 122
 
123 123
 	/**
@@ -126,38 +126,38 @@  discard block
 block discarded – undo
126 126
 	 * @since 3.5.0
127 127
 	 */
128 128
 	public function test_reports_schema() {
129
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
130
-		$response   = $this->server->dispatch( $request );
129
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
130
+		$response   = $this->server->dispatch($request);
131 131
 		$data       = $response->get_data();
132 132
 		$properties = $data['schema']['properties'];
133 133
 
134 134
 		$totals = $properties['totals']['properties'];
135 135
 
136
-		$this->assertEquals( 6, count( $totals ) );
137
-		$this->assertArrayHasKey( 'order_tax', $totals );
138
-		$this->assertArrayHasKey( 'orders_count', $totals );
139
-		$this->assertArrayHasKey( 'shipping_tax', $totals );
140
-		$this->assertArrayHasKey( 'tax_codes', $totals );
141
-		$this->assertArrayHasKey( 'total_tax', $totals );
142
-		$this->assertArrayHasKey( 'segments', $totals );
136
+		$this->assertEquals(6, count($totals));
137
+		$this->assertArrayHasKey('order_tax', $totals);
138
+		$this->assertArrayHasKey('orders_count', $totals);
139
+		$this->assertArrayHasKey('shipping_tax', $totals);
140
+		$this->assertArrayHasKey('tax_codes', $totals);
141
+		$this->assertArrayHasKey('total_tax', $totals);
142
+		$this->assertArrayHasKey('segments', $totals);
143 143
 
144 144
 		$intervals = $properties['intervals']['items']['properties'];
145
-		$this->assertEquals( 6, count( $intervals ) );
146
-		$this->assertArrayHasKey( 'interval', $intervals );
147
-		$this->assertArrayHasKey( 'date_start', $intervals );
148
-		$this->assertArrayHasKey( 'date_start_gmt', $intervals );
149
-		$this->assertArrayHasKey( 'date_end', $intervals );
150
-		$this->assertArrayHasKey( 'date_end_gmt', $intervals );
151
-		$this->assertArrayHasKey( 'subtotals', $intervals );
145
+		$this->assertEquals(6, count($intervals));
146
+		$this->assertArrayHasKey('interval', $intervals);
147
+		$this->assertArrayHasKey('date_start', $intervals);
148
+		$this->assertArrayHasKey('date_start_gmt', $intervals);
149
+		$this->assertArrayHasKey('date_end', $intervals);
150
+		$this->assertArrayHasKey('date_end_gmt', $intervals);
151
+		$this->assertArrayHasKey('subtotals', $intervals);
152 152
 
153 153
 		$subtotals = $properties['intervals']['items']['properties']['subtotals']['properties'];
154
-		$this->assertEquals( 6, count( $subtotals ) );
155
-		$this->assertArrayHasKey( 'order_tax', $subtotals );
156
-		$this->assertArrayHasKey( 'orders_count', $subtotals );
157
-		$this->assertArrayHasKey( 'shipping_tax', $subtotals );
158
-		$this->assertArrayHasKey( 'tax_codes', $subtotals );
159
-		$this->assertArrayHasKey( 'total_tax', $subtotals );
160
-		$this->assertArrayHasKey( 'segments', $subtotals );
154
+		$this->assertEquals(6, count($subtotals));
155
+		$this->assertArrayHasKey('order_tax', $subtotals);
156
+		$this->assertArrayHasKey('orders_count', $subtotals);
157
+		$this->assertArrayHasKey('shipping_tax', $subtotals);
158
+		$this->assertArrayHasKey('tax_codes', $subtotals);
159
+		$this->assertArrayHasKey('total_tax', $subtotals);
160
+		$this->assertArrayHasKey('segments', $subtotals);
161 161
 
162 162
 	}
163 163
 }
Please login to merge, or discard this patch.