Completed
Push — master ( adb8dc...103e24 )
by Mike
04:42 queued 01:51
created
unit-tests/Tests/Blocks/products.php 1 patch
Spacing   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 
6 6
 namespace WooCommerce\RestApi\UnitTests\Tests\Blocks;
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 use \WP_REST_Request;
11 11
 use \WC_REST_Unit_Test_Case;
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	public function setUp() {
34 34
 		parent::setUp();
35 35
 
36
-		$this->user        = $this->factory->user->create(
36
+		$this->user = $this->factory->user->create(
37 37
 			array(
38 38
 				'role' => 'author',
39 39
 			)
@@ -43,20 +43,20 @@  discard block
 block discarded – undo
43 43
 				'role' => 'contributor',
44 44
 			)
45 45
 		);
46
-		$this->subscriber  = $this->factory->user->create(
46
+		$this->subscriber = $this->factory->user->create(
47 47
 			array(
48 48
 				'role' => 'subscriber',
49 49
 			)
50 50
 		);
51 51
 
52 52
 		// Create 3 product categories.
53
-		$parent           = wp_insert_term( 'Parent Category', 'product_cat' );
53
+		$parent           = wp_insert_term('Parent Category', 'product_cat');
54 54
 		$child            = wp_insert_term(
55 55
 			'Child Category',
56 56
 			'product_cat',
57
-			array( 'parent' => $parent['term_id'] )
57
+			array('parent' => $parent['term_id'])
58 58
 		);
59
-		$single           = wp_insert_term( 'Standalone Category', 'product_cat' );
59
+		$single           = wp_insert_term('Standalone Category', 'product_cat');
60 60
 		$this->categories = array(
61 61
 			'parent' => $parent,
62 62
 			'child'  => $child,
@@ -65,20 +65,20 @@  discard block
 block discarded – undo
65 65
 
66 66
 		// Create two products, one with 'parent', and one with 'single'.
67 67
 		$this->products    = array();
68
-		$this->products[0] = ProductHelper::create_simple_product( false );
69
-		$this->products[0]->set_category_ids( array( $parent['term_id'] ) );
68
+		$this->products[0] = ProductHelper::create_simple_product(false);
69
+		$this->products[0]->set_category_ids(array($parent['term_id']));
70 70
 		$this->products[0]->save();
71 71
 
72
-		$this->products[1] = ProductHelper::create_simple_product( false );
73
-		$this->products[1]->set_category_ids( array( $single['term_id'] ) );
72
+		$this->products[1] = ProductHelper::create_simple_product(false);
73
+		$this->products[1]->set_category_ids(array($single['term_id']));
74 74
 		$this->products[1]->save();
75 75
 
76
-		$this->products[2] = ProductHelper::create_simple_product( false );
77
-		$this->products[2]->set_category_ids( array( $child['term_id'], $single['term_id'] ) );
76
+		$this->products[2] = ProductHelper::create_simple_product(false);
77
+		$this->products[2]->set_category_ids(array($child['term_id'], $single['term_id']));
78 78
 		$this->products[2]->save();
79 79
 
80
-		$this->products[3] = ProductHelper::create_simple_product( false );
81
-		$this->products[3]->set_category_ids( array( $parent['term_id'], $single['term_id'] ) );
80
+		$this->products[3] = ProductHelper::create_simple_product(false);
81
+		$this->products[3]->set_category_ids(array($parent['term_id'], $single['term_id']));
82 82
 		$this->products[3]->save();
83 83
 	}
84 84
 
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 	public function test_register_routes() {
91 91
 		$routes = $this->server->get_routes();
92 92
 
93
-		$this->assertArrayHasKey( '/wc-blocks/v1/products', $routes );
94
-		$this->assertArrayHasKey( '/wc-blocks/v1/products/(?P<id>[\d]+)', $routes );
93
+		$this->assertArrayHasKey('/wc-blocks/v1/products', $routes);
94
+		$this->assertArrayHasKey('/wc-blocks/v1/products/(?P<id>[\d]+)', $routes);
95 95
 	}
96 96
 
97 97
 	/**
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
 	 * @since 3.6.0
101 101
 	 */
102 102
 	public function test_get_products() {
103
-		wp_set_current_user( $this->user );
103
+		wp_set_current_user($this->user);
104 104
 		ProductHelper::create_external_product();
105
-		sleep( 1 ); // So both products have different timestamps.
105
+		sleep(1); // So both products have different timestamps.
106 106
 		$product  = ProductHelper::create_simple_product();
107
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc-blocks/v1/products' ) );
107
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc-blocks/v1/products'));
108 108
 		$products = $response->get_data();
109 109
 
110
-		$this->assertEquals( 200, $response->get_status() );
110
+		$this->assertEquals(200, $response->get_status());
111 111
 
112
-		$this->assertEquals( 6, count( $products ) );
112
+		$this->assertEquals(6, count($products));
113 113
 	}
114 114
 
115 115
 	/**
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
 	 * @since 3.6.0
119 119
 	 */
120 120
 	public function test_get_products_as_contributor() {
121
-		wp_set_current_user( $this->contributor );
121
+		wp_set_current_user($this->contributor);
122 122
 		ProductHelper::create_simple_product();
123
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc-blocks/v1/products' ) );
124
-		$this->assertEquals( 200, $response->get_status() );
123
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc-blocks/v1/products'));
124
+		$this->assertEquals(200, $response->get_status());
125 125
 	}
126 126
 
127 127
 	/**
@@ -130,10 +130,10 @@  discard block
 block discarded – undo
130 130
 	 * @since 3.6.0
131 131
 	 */
132 132
 	public function test_get_products_as_subscriber() {
133
-		wp_set_current_user( $this->subscriber );
133
+		wp_set_current_user($this->subscriber);
134 134
 		ProductHelper::create_simple_product();
135
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc-blocks/v1/products' ) );
136
-		$this->assertEquals( 403, $response->get_status() );
135
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc-blocks/v1/products'));
136
+		$this->assertEquals(403, $response->get_status());
137 137
 	}
138 138
 
139 139
 	/**
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
 	 * @since 3.6.0
143 143
 	 */
144 144
 	public function test_get_products_order_by_price() {
145
-		wp_set_current_user( $this->user );
145
+		wp_set_current_user($this->user);
146 146
 		ProductHelper::create_external_product();
147
-		sleep( 1 ); // So both products have different timestamps.
148
-		$product = ProductHelper::create_simple_product( false ); // Prevent saving, since we save here.
147
+		sleep(1); // So both products have different timestamps.
148
+		$product = ProductHelper::create_simple_product(false); // Prevent saving, since we save here.
149 149
 		// Customize the price, otherwise both are 10.
150 150
 		$product->set_props(
151 151
 			array(
@@ -155,17 +155,17 @@  discard block
 block discarded – undo
155 155
 		);
156 156
 		$product->save();
157 157
 
158
-		$request = new WP_REST_Request( 'GET', '/wc-blocks/v1/products' );
159
-		$request->set_param( 'orderby', 'price' );
160
-		$request->set_param( 'order', 'asc' );
161
-		$response = $this->server->dispatch( $request );
158
+		$request = new WP_REST_Request('GET', '/wc-blocks/v1/products');
159
+		$request->set_param('orderby', 'price');
160
+		$request->set_param('order', 'asc');
161
+		$response = $this->server->dispatch($request);
162 162
 		$products = $response->get_data();
163 163
 
164
-		$this->assertEquals( 200, $response->get_status() );
165
-		$this->assertEquals( 6, count( $products ) );
164
+		$this->assertEquals(200, $response->get_status());
165
+		$this->assertEquals(6, count($products));
166 166
 
167
-		$this->assertEquals( 'Dummy Product', $products[1]['name'] );
168
-		$this->assertEquals( '10', $products[1]['price'] );
167
+		$this->assertEquals('Dummy Product', $products[1]['name']);
168
+		$this->assertEquals('10', $products[1]['price']);
169 169
 	}
170 170
 
171 171
 	/**
@@ -174,78 +174,78 @@  discard block
 block discarded – undo
174 174
 	 * @since 3.6.0
175 175
 	 */
176 176
 	public function test_product_visibility() {
177
-		wp_set_current_user( $this->user );
177
+		wp_set_current_user($this->user);
178 178
 		$visible_product = ProductHelper::create_simple_product();
179
-		$visible_product->set_name( 'Visible Product' );
180
-		$visible_product->set_catalog_visibility( 'visible' );
179
+		$visible_product->set_name('Visible Product');
180
+		$visible_product->set_catalog_visibility('visible');
181 181
 		$visible_product->save();
182 182
 
183 183
 		$catalog_product = ProductHelper::create_simple_product();
184
-		$catalog_product->set_name( 'Catalog Product' );
185
-		$catalog_product->set_catalog_visibility( 'catalog' );
184
+		$catalog_product->set_name('Catalog Product');
185
+		$catalog_product->set_catalog_visibility('catalog');
186 186
 		$catalog_product->save();
187 187
 
188 188
 		$search_product = ProductHelper::create_simple_product();
189
-		$search_product->set_name( 'Search Product' );
190
-		$search_product->set_catalog_visibility( 'search' );
189
+		$search_product->set_name('Search Product');
190
+		$search_product->set_catalog_visibility('search');
191 191
 		$search_product->save();
192 192
 
193 193
 		$hidden_product = ProductHelper::create_simple_product();
194
-		$hidden_product->set_name( 'Hidden Product' );
195
-		$hidden_product->set_catalog_visibility( 'hidden' );
194
+		$hidden_product->set_name('Hidden Product');
195
+		$hidden_product->set_catalog_visibility('hidden');
196 196
 		$hidden_product->save();
197 197
 
198 198
 		$query_params = array(
199 199
 			'catalog_visibility' => 'visible',
200 200
 		);
201
-		$request      = new WP_REST_REQUEST( 'GET', '/wc-blocks/v1/products' );
202
-		$request->set_query_params( $query_params );
203
-		$response = $this->server->dispatch( $request );
201
+		$request      = new WP_REST_REQUEST('GET', '/wc-blocks/v1/products');
202
+		$request->set_query_params($query_params);
203
+		$response = $this->server->dispatch($request);
204 204
 		$products = $response->get_data();
205 205
 
206
-		$this->assertEquals( 200, $response->get_status() );
207
-		$this->assertEquals( 5, count( $products ) );
208
-		$this->assertEquals( 'Visible Product', $products[0]['name'] );
206
+		$this->assertEquals(200, $response->get_status());
207
+		$this->assertEquals(5, count($products));
208
+		$this->assertEquals('Visible Product', $products[0]['name']);
209 209
 
210 210
 		$query_params = array(
211 211
 			'catalog_visibility' => 'catalog',
212 212
 			'orderby'            => 'id',
213 213
 			'order'              => 'asc',
214 214
 		);
215
-		$request      = new WP_REST_REQUEST( 'GET', '/wc-blocks/v1/products' );
216
-		$request->set_query_params( $query_params );
217
-		$response = $this->server->dispatch( $request );
215
+		$request = new WP_REST_REQUEST('GET', '/wc-blocks/v1/products');
216
+		$request->set_query_params($query_params);
217
+		$response = $this->server->dispatch($request);
218 218
 		$products = $response->get_data();
219 219
 
220
-		$this->assertEquals( 200, $response->get_status() );
221
-		$this->assertEquals( 6, count( $products ) );
222
-		$this->assertEquals( 'Dummy Product', $products[0]['name'] );
220
+		$this->assertEquals(200, $response->get_status());
221
+		$this->assertEquals(6, count($products));
222
+		$this->assertEquals('Dummy Product', $products[0]['name']);
223 223
 
224 224
 		$query_params = array(
225 225
 			'catalog_visibility' => 'search',
226 226
 			'orderby'            => 'id',
227 227
 			'order'              => 'asc',
228 228
 		);
229
-		$request      = new WP_REST_REQUEST( 'GET', '/wc-blocks/v1/products' );
230
-		$request->set_query_params( $query_params );
231
-		$response = $this->server->dispatch( $request );
229
+		$request = new WP_REST_REQUEST('GET', '/wc-blocks/v1/products');
230
+		$request->set_query_params($query_params);
231
+		$response = $this->server->dispatch($request);
232 232
 		$products = $response->get_data();
233 233
 
234
-		$this->assertEquals( 200, $response->get_status() );
235
-		$this->assertEquals( 6, count( $products ) );
236
-		$this->assertEquals( 'Dummy Product', $products[0]['name'] );
234
+		$this->assertEquals(200, $response->get_status());
235
+		$this->assertEquals(6, count($products));
236
+		$this->assertEquals('Dummy Product', $products[0]['name']);
237 237
 
238 238
 		$query_params = array(
239 239
 			'catalog_visibility' => 'hidden',
240 240
 		);
241
-		$request      = new WP_REST_REQUEST( 'GET', '/wc-blocks/v1/products' );
242
-		$request->set_query_params( $query_params );
243
-		$response = $this->server->dispatch( $request );
241
+		$request      = new WP_REST_REQUEST('GET', '/wc-blocks/v1/products');
242
+		$request->set_query_params($query_params);
243
+		$response = $this->server->dispatch($request);
244 244
 		$products = $response->get_data();
245 245
 
246
-		$this->assertEquals( 200, $response->get_status() );
247
-		$this->assertEquals( 1, count( $products ) );
248
-		$this->assertEquals( 'Hidden Product', $products[0]['name'] );
246
+		$this->assertEquals(200, $response->get_status());
247
+		$this->assertEquals(1, count($products));
248
+		$this->assertEquals('Hidden Product', $products[0]['name']);
249 249
 	}
250 250
 
251 251
 	/**
@@ -254,19 +254,19 @@  discard block
 block discarded – undo
254 254
 	 * @since 3.6.0
255 255
 	 */
256 256
 	public function test_get_products_in_any_categories_child() {
257
-		wp_set_current_user( $this->user );
257
+		wp_set_current_user($this->user);
258 258
 
259 259
 		$cats = $this->categories['child']['term_id'] . ',' . $this->categories['single']['term_id'];
260 260
 
261
-		$request = new WP_REST_Request( 'GET', '/wc-blocks/v1/products' );
262
-		$request->set_param( 'category', $cats );
263
-		$request->set_param( 'category_operator', 'in' );
261
+		$request = new WP_REST_Request('GET', '/wc-blocks/v1/products');
262
+		$request->set_param('category', $cats);
263
+		$request->set_param('category_operator', 'in');
264 264
 
265
-		$response          = $this->server->dispatch( $request );
265
+		$response          = $this->server->dispatch($request);
266 266
 		$response_products = $response->get_data();
267 267
 
268
-		$this->assertEquals( 200, $response->get_status() );
269
-		$this->assertEquals( 3, count( $response_products ) );
268
+		$this->assertEquals(200, $response->get_status());
269
+		$this->assertEquals(3, count($response_products));
270 270
 	}
271 271
 
272 272
 	/**
@@ -275,19 +275,19 @@  discard block
 block discarded – undo
275 275
 	 * @since 3.6.0
276 276
 	 */
277 277
 	public function test_get_products_in_all_categories_child() {
278
-		wp_set_current_user( $this->user );
278
+		wp_set_current_user($this->user);
279 279
 
280 280
 		$cats = $this->categories['child']['term_id'] . ',' . $this->categories['single']['term_id'];
281 281
 
282
-		$request = new WP_REST_Request( 'GET', '/wc-blocks/v1/products' );
283
-		$request->set_param( 'category', $cats );
284
-		$request->set_param( 'category_operator', 'and' );
282
+		$request = new WP_REST_Request('GET', '/wc-blocks/v1/products');
283
+		$request->set_param('category', $cats);
284
+		$request->set_param('category_operator', 'and');
285 285
 
286
-		$response          = $this->server->dispatch( $request );
286
+		$response          = $this->server->dispatch($request);
287 287
 		$response_products = $response->get_data();
288 288
 
289
-		$this->assertEquals( 200, $response->get_status() );
290
-		$this->assertEquals( 1, count( $response_products ) );
289
+		$this->assertEquals(200, $response->get_status());
290
+		$this->assertEquals(1, count($response_products));
291 291
 	}
292 292
 
293 293
 	/**
@@ -296,18 +296,18 @@  discard block
 block discarded – undo
296 296
 	 * @since 3.6.0
297 297
 	 */
298 298
 	public function test_get_products_in_all_categories_parent() {
299
-		wp_set_current_user( $this->user );
299
+		wp_set_current_user($this->user);
300 300
 
301 301
 		$cats = $this->categories['parent']['term_id'] . ',' . $this->categories['single']['term_id'];
302 302
 
303
-		$request = new WP_REST_Request( 'GET', '/wc-blocks/v1/products' );
304
-		$request->set_param( 'category', $cats );
305
-		$request->set_param( 'category_operator', 'and' );
303
+		$request = new WP_REST_Request('GET', '/wc-blocks/v1/products');
304
+		$request->set_param('category', $cats);
305
+		$request->set_param('category_operator', 'and');
306 306
 
307
-		$response          = $this->server->dispatch( $request );
307
+		$response          = $this->server->dispatch($request);
308 308
 		$response_products = $response->get_data();
309 309
 
310
-		$this->assertEquals( 200, $response->get_status() );
311
-		$this->assertEquals( 1, count( $response_products ) );
310
+		$this->assertEquals(200, $response->get_status());
311
+		$this->assertEquals(1, count($response_products));
312 312
 	}
313 313
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version2/shipping-zones.php 1 patch
Spacing   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 				'role' => 'administrator',
27 27
 			)
28 28
 		);
29
-		$this->zones    = array();
29
+		$this->zones = array();
30 30
 	}
31 31
 
32 32
 	/**
@@ -36,11 +36,11 @@  discard block
 block discarded – undo
36 36
 	 * @param int    $order Optional. Zone sort order.
37 37
 	 * @return WC_Shipping_Zone
38 38
 	 */
39
-	protected function create_shipping_zone( $name, $order = 0, $locations = array() ) {
40
-		$zone = new WC_Shipping_Zone( null );
41
-		$zone->set_zone_name( $name );
42
-		$zone->set_zone_order( $order );
43
-		$zone->set_locations( $locations );
39
+	protected function create_shipping_zone($name, $order = 0, $locations = array()) {
40
+		$zone = new WC_Shipping_Zone(null);
41
+		$zone->set_zone_name($name);
42
+		$zone->set_zone_order($order);
43
+		$zone->set_locations($locations);
44 44
 		$zone->save();
45 45
 
46 46
 		$this->zones[] = $zone;
@@ -54,11 +54,11 @@  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/v2/shipping/zones', $routes );
58
-		$this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P<id>[\d-]+)', $routes );
59
-		$this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P<id>[\d]+)/locations', $routes );
60
-		$this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P<zone_id>[\d]+)/methods', $routes );
61
-		$this->assertArrayHasKey( '/wc/v2/shipping/zones/(?P<zone_id>[\d]+)/methods/(?P<instance_id>[\d]+)', $routes );
57
+		$this->assertArrayHasKey('/wc/v2/shipping/zones', $routes);
58
+		$this->assertArrayHasKey('/wc/v2/shipping/zones/(?P<id>[\d-]+)', $routes);
59
+		$this->assertArrayHasKey('/wc/v2/shipping/zones/(?P<id>[\d]+)/locations', $routes);
60
+		$this->assertArrayHasKey('/wc/v2/shipping/zones/(?P<zone_id>[\d]+)/methods', $routes);
61
+		$this->assertArrayHasKey('/wc/v2/shipping/zones/(?P<zone_id>[\d]+)/methods/(?P<instance_id>[\d]+)', $routes);
62 62
 	}
63 63
 
64 64
 	/**
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
 	 * @since 3.0.0
67 67
 	 */
68 68
 	public function test_get_zones() {
69
-		wp_set_current_user( $this->user );
69
+		wp_set_current_user($this->user);
70 70
 
71 71
 		// "Rest of the World" zone exists by default
72
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones' ) );
72
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping/zones'));
73 73
 		$data     = $response->get_data();
74 74
 
75
-		$this->assertEquals( 200, $response->get_status() );
76
-		$this->assertEquals( count( $data ), 1 );
75
+		$this->assertEquals(200, $response->get_status());
76
+		$this->assertEquals(count($data), 1);
77 77
 		$this->assertContains(
78 78
 			array(
79 79
 				'id'     => $data[0]['id'],
@@ -82,17 +82,17 @@  discard block
 block discarded – undo
82 82
 				'_links' => array(
83 83
 					'self'        => array(
84 84
 						array(
85
-							'href' => rest_url( '/wc/v2/shipping/zones/' . $data[0]['id'] ),
85
+							'href' => rest_url('/wc/v2/shipping/zones/' . $data[0]['id']),
86 86
 						),
87 87
 					),
88 88
 					'collection'  => array(
89 89
 						array(
90
-							'href' => rest_url( '/wc/v2/shipping/zones' ),
90
+							'href' => rest_url('/wc/v2/shipping/zones'),
91 91
 						),
92 92
 					),
93 93
 					'describedby' => array(
94 94
 						array(
95
-							'href' => rest_url( '/wc/v2/shipping/zones/' . $data[0]['id'] . '/locations' ),
95
+							'href' => rest_url('/wc/v2/shipping/zones/' . $data[0]['id'] . '/locations'),
96 96
 						),
97 97
 					),
98 98
 				),
@@ -101,13 +101,13 @@  discard block
 block discarded – undo
101 101
 		);
102 102
 
103 103
 		// Create a zone and make sure it's in the response
104
-		$this->create_shipping_zone( 'Zone 1' );
104
+		$this->create_shipping_zone('Zone 1');
105 105
 
106
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones' ) );
106
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping/zones'));
107 107
 		$data     = $response->get_data();
108 108
 
109
-		$this->assertEquals( 200, $response->get_status() );
110
-		$this->assertEquals( count( $data ), 2 );
109
+		$this->assertEquals(200, $response->get_status());
110
+		$this->assertEquals(count($data), 2);
111 111
 		$this->assertContains(
112 112
 			array(
113 113
 				'id'     => $data[1]['id'],
@@ -116,17 +116,17 @@  discard block
 block discarded – undo
116 116
 				'_links' => array(
117 117
 					'self'        => array(
118 118
 						array(
119
-							'href' => rest_url( '/wc/v2/shipping/zones/' . $data[1]['id'] ),
119
+							'href' => rest_url('/wc/v2/shipping/zones/' . $data[1]['id']),
120 120
 						),
121 121
 					),
122 122
 					'collection'  => array(
123 123
 						array(
124
-							'href' => rest_url( '/wc/v2/shipping/zones' ),
124
+							'href' => rest_url('/wc/v2/shipping/zones'),
125 125
 						),
126 126
 					),
127 127
 					'describedby' => array(
128 128
 						array(
129
-							'href' => rest_url( '/wc/v2/shipping/zones/' . $data[1]['id'] . '/locations' ),
129
+							'href' => rest_url('/wc/v2/shipping/zones/' . $data[1]['id'] . '/locations'),
130 130
 						),
131 131
 					),
132 132
 				),
@@ -140,10 +140,10 @@  discard block
 block discarded – undo
140 140
 	 * @since 3.0.0
141 141
 	 */
142 142
 	public function test_get_shipping_zones_without_permission() {
143
-		wp_set_current_user( 0 );
143
+		wp_set_current_user(0);
144 144
 
145
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones' ) );
146
-		$this->assertEquals( 401, $response->get_status() );
145
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping/zones'));
146
+		$this->assertEquals(401, $response->get_status());
147 147
 	}
148 148
 
149 149
 	/**
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
 	 * @since 3.0.0
152 152
 	 */
153 153
 	public function test_get_shipping_zones_disabled_shipping() {
154
-		wp_set_current_user( $this->user );
154
+		wp_set_current_user($this->user);
155 155
 
156
-		add_filter( 'wc_shipping_enabled', '__return_false' );
156
+		add_filter('wc_shipping_enabled', '__return_false');
157 157
 
158
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones' ) );
159
-		$this->assertEquals( 404, $response->get_status() );
158
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping/zones'));
159
+		$this->assertEquals(404, $response->get_status());
160 160
 
161
-		remove_filter( 'wc_shipping_enabled', '__return_false' );
161
+		remove_filter('wc_shipping_enabled', '__return_false');
162 162
 	}
163 163
 
164 164
 	/**
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
 	 * @since 3.0.0
167 167
 	 */
168 168
 	public function test_get_shipping_zone_schema() {
169
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v2/shipping/zones' );
170
-		$response   = $this->server->dispatch( $request );
169
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v2/shipping/zones');
170
+		$response   = $this->server->dispatch($request);
171 171
 		$data       = $response->get_data();
172 172
 		$properties = $data['schema']['properties'];
173
-		$this->assertEquals( 3, count( $properties ) );
174
-		$this->assertArrayHasKey( 'id', $properties );
175
-		$this->assertTrue( $properties['id']['readonly'] );
176
-		$this->assertArrayHasKey( 'name', $properties );
177
-		$this->assertArrayHasKey( 'order', $properties );
173
+		$this->assertEquals(3, count($properties));
174
+		$this->assertArrayHasKey('id', $properties);
175
+		$this->assertTrue($properties['id']['readonly']);
176
+		$this->assertArrayHasKey('name', $properties);
177
+		$this->assertArrayHasKey('order', $properties);
178 178
 	}
179 179
 
180 180
 	/**
@@ -182,19 +182,19 @@  discard block
 block discarded – undo
182 182
 	 * @since 3.0.0
183 183
 	 */
184 184
 	public function test_create_shipping_zone() {
185
-		wp_set_current_user( $this->user );
185
+		wp_set_current_user($this->user);
186 186
 
187
-		$request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones' );
187
+		$request = new WP_REST_Request('POST', '/wc/v2/shipping/zones');
188 188
 		$request->set_body_params(
189 189
 			array(
190 190
 				'name'  => 'Test Zone',
191 191
 				'order' => 1,
192 192
 			)
193 193
 		);
194
-		$response = $this->server->dispatch( $request );
194
+		$response = $this->server->dispatch($request);
195 195
 		$data     = $response->get_data();
196 196
 
197
-		$this->assertEquals( 201, $response->get_status() );
197
+		$this->assertEquals(201, $response->get_status());
198 198
 		$this->assertEquals(
199 199
 			array(
200 200
 				'id'     => $data['id'],
@@ -203,17 +203,17 @@  discard block
 block discarded – undo
203 203
 				'_links' => array(
204 204
 					'self'        => array(
205 205
 						array(
206
-							'href' => rest_url( '/wc/v2/shipping/zones/' . $data['id'] ),
206
+							'href' => rest_url('/wc/v2/shipping/zones/' . $data['id']),
207 207
 						),
208 208
 					),
209 209
 					'collection'  => array(
210 210
 						array(
211
-							'href' => rest_url( '/wc/v2/shipping/zones' ),
211
+							'href' => rest_url('/wc/v2/shipping/zones'),
212 212
 						),
213 213
 					),
214 214
 					'describedby' => array(
215 215
 						array(
216
-							'href' => rest_url( '/wc/v2/shipping/zones/' . $data['id'] . '/locations' ),
216
+							'href' => rest_url('/wc/v2/shipping/zones/' . $data['id'] . '/locations'),
217 217
 						),
218 218
 					),
219 219
 				),
@@ -227,17 +227,17 @@  discard block
 block discarded – undo
227 227
 	 * @since 3.0.0
228 228
 	 */
229 229
 	public function test_create_shipping_zone_without_permission() {
230
-		wp_set_current_user( 0 );
230
+		wp_set_current_user(0);
231 231
 
232
-		$request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones' );
232
+		$request = new WP_REST_Request('POST', '/wc/v2/shipping/zones');
233 233
 		$request->set_body_params(
234 234
 			array(
235 235
 				'name'  => 'Test Zone',
236 236
 				'order' => 1,
237 237
 			)
238 238
 		);
239
-		$response = $this->server->dispatch( $request );
240
-		$this->assertEquals( 401, $response->get_status() );
239
+		$response = $this->server->dispatch($request);
240
+		$this->assertEquals(401, $response->get_status());
241 241
 	}
242 242
 
243 243
 	/**
@@ -245,21 +245,21 @@  discard block
 block discarded – undo
245 245
 	 * @since 3.0.0
246 246
 	 */
247 247
 	public function test_update_shipping_zone() {
248
-		wp_set_current_user( $this->user );
248
+		wp_set_current_user($this->user);
249 249
 
250
-		$zone = $this->create_shipping_zone( 'Test Zone' );
250
+		$zone = $this->create_shipping_zone('Test Zone');
251 251
 
252
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/shipping/zones/' . $zone->get_id() );
252
+		$request = new WP_REST_Request('PUT', '/wc/v2/shipping/zones/' . $zone->get_id());
253 253
 		$request->set_body_params(
254 254
 			array(
255 255
 				'name'  => 'Zone Test',
256 256
 				'order' => 2,
257 257
 			)
258 258
 		);
259
-		$response = $this->server->dispatch( $request );
259
+		$response = $this->server->dispatch($request);
260 260
 		$data     = $response->get_data();
261 261
 
262
-		$this->assertEquals( 200, $response->get_status() );
262
+		$this->assertEquals(200, $response->get_status());
263 263
 		$this->assertEquals(
264 264
 			array(
265 265
 				'id'     => $zone->get_id(),
@@ -268,17 +268,17 @@  discard block
 block discarded – undo
268 268
 				'_links' => array(
269 269
 					'self'        => array(
270 270
 						array(
271
-							'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ),
271
+							'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id()),
272 272
 						),
273 273
 					),
274 274
 					'collection'  => array(
275 275
 						array(
276
-							'href' => rest_url( '/wc/v2/shipping/zones' ),
276
+							'href' => rest_url('/wc/v2/shipping/zones'),
277 277
 						),
278 278
 					),
279 279
 					'describedby' => array(
280 280
 						array(
281
-							'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ),
281
+							'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id() . '/locations'),
282 282
 						),
283 283
 					),
284 284
 				),
@@ -292,18 +292,18 @@  discard block
 block discarded – undo
292 292
 	 * @since 3.0.0
293 293
 	 */
294 294
 	public function test_update_shipping_zone_invalid_id() {
295
-		wp_set_current_user( $this->user );
295
+		wp_set_current_user($this->user);
296 296
 
297
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/shipping/zones/555555' );
297
+		$request = new WP_REST_Request('PUT', '/wc/v2/shipping/zones/555555');
298 298
 		$request->set_body_params(
299 299
 			array(
300 300
 				'name'  => 'Zone Test',
301 301
 				'order' => 2,
302 302
 			)
303 303
 		);
304
-		$response = $this->server->dispatch( $request );
304
+		$response = $this->server->dispatch($request);
305 305
 
306
-		$this->assertEquals( 404, $response->get_status() );
306
+		$this->assertEquals(404, $response->get_status());
307 307
 	}
308 308
 
309 309
 	/**
@@ -311,15 +311,15 @@  discard block
 block discarded – undo
311 311
 	 * @since 3.0.0
312 312
 	 */
313 313
 	public function test_delete_shipping_zone() {
314
-		wp_set_current_user( $this->user );
315
-		$zone = $this->create_shipping_zone( 'Zone 1' );
314
+		wp_set_current_user($this->user);
315
+		$zone = $this->create_shipping_zone('Zone 1');
316 316
 
317
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/shipping/zones/' . $zone->get_id() );
318
-		$request->set_param( 'force', true );
319
-		$response = $this->server->dispatch( $request );
317
+		$request = new WP_REST_Request('DELETE', '/wc/v2/shipping/zones/' . $zone->get_id());
318
+		$request->set_param('force', true);
319
+		$response = $this->server->dispatch($request);
320 320
 		$data     = $response->get_data();
321 321
 
322
-		$this->assertEquals( 200, $response->get_status() );
322
+		$this->assertEquals(200, $response->get_status());
323 323
 	}
324 324
 
325 325
 	/**
@@ -327,13 +327,13 @@  discard block
 block discarded – undo
327 327
 	 * @since 3.0.0
328 328
 	 */
329 329
 	public function test_delete_shipping_zone_without_permission() {
330
-		wp_set_current_user( 0 );
331
-		$zone = $this->create_shipping_zone( 'Zone 1' );
330
+		wp_set_current_user(0);
331
+		$zone = $this->create_shipping_zone('Zone 1');
332 332
 
333
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/shipping/zones/' . $zone->get_id() );
334
-		$request->set_param( 'force', true );
335
-		$response = $this->server->dispatch( $request );
336
-		$this->assertEquals( 401, $response->get_status() );
333
+		$request = new WP_REST_Request('DELETE', '/wc/v2/shipping/zones/' . $zone->get_id());
334
+		$request->set_param('force', true);
335
+		$response = $this->server->dispatch($request);
336
+		$this->assertEquals(401, $response->get_status());
337 337
 	}
338 338
 
339 339
 	/**
@@ -341,10 +341,10 @@  discard block
 block discarded – undo
341 341
 	 * @since 3.0.0
342 342
 	 */
343 343
 	public function test_delete_shipping_zone_invalid_id() {
344
-		wp_set_current_user( $this->user );
345
-		$request  = new WP_REST_Request( 'DELETE', '/wc/v2/shipping/zones/555555' );
346
-		$response = $this->server->dispatch( $request );
347
-		$this->assertEquals( 404, $response->get_status() );
344
+		wp_set_current_user($this->user);
345
+		$request  = new WP_REST_Request('DELETE', '/wc/v2/shipping/zones/555555');
346
+		$response = $this->server->dispatch($request);
347
+		$this->assertEquals(404, $response->get_status());
348 348
 	}
349 349
 
350 350
 	/**
@@ -352,13 +352,13 @@  discard block
 block discarded – undo
352 352
 	 * @since 3.0.0
353 353
 	 */
354 354
 	public function test_get_single_shipping_zone() {
355
-		wp_set_current_user( $this->user );
355
+		wp_set_current_user($this->user);
356 356
 
357
-		$zone     = $this->create_shipping_zone( 'Test Zone' );
358
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/' . $zone->get_id() ) );
357
+		$zone     = $this->create_shipping_zone('Test Zone');
358
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping/zones/' . $zone->get_id()));
359 359
 		$data     = $response->get_data();
360 360
 
361
-		$this->assertEquals( 200, $response->get_status() );
361
+		$this->assertEquals(200, $response->get_status());
362 362
 		$this->assertEquals(
363 363
 			array(
364 364
 				'id'     => $zone->get_id(),
@@ -367,17 +367,17 @@  discard block
 block discarded – undo
367 367
 				'_links' => array(
368 368
 					'self'        => array(
369 369
 						array(
370
-							'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ),
370
+							'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id()),
371 371
 						),
372 372
 					),
373 373
 					'collection'  => array(
374 374
 						array(
375
-							'href' => rest_url( '/wc/v2/shipping/zones' ),
375
+							'href' => rest_url('/wc/v2/shipping/zones'),
376 376
 						),
377 377
 					),
378 378
 					'describedby' => array(
379 379
 						array(
380
-							'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ),
380
+							'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id() . '/locations'),
381 381
 						),
382 382
 					),
383 383
 				),
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
 	 * @since 3.0.0
392 392
 	 */
393 393
 	public function test_get_single_shipping_zone_invalid_id() {
394
-		wp_set_current_user( $this->user );
394
+		wp_set_current_user($this->user);
395 395
 
396
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/1' ) );
396
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping/zones/1'));
397 397
 
398
-		$this->assertEquals( 404, $response->get_status() );
398
+		$this->assertEquals(404, $response->get_status());
399 399
 	}
400 400
 
401 401
 	/**
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 	 * @since 3.0.0
404 404
 	 */
405 405
 	public function test_get_locations() {
406
-		wp_set_current_user( $this->user );
406
+		wp_set_current_user($this->user);
407 407
 
408 408
 		// Create a zone
409 409
 		$zone = $this->create_shipping_zone(
@@ -417,11 +417,11 @@  discard block
 block discarded – undo
417 417
 			)
418 418
 		);
419 419
 
420
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ) );
420
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations'));
421 421
 		$data     = $response->get_data();
422 422
 
423
-		$this->assertEquals( 200, $response->get_status() );
424
-		$this->assertEquals( count( $data ), 1 );
423
+		$this->assertEquals(200, $response->get_status());
424
+		$this->assertEquals(count($data), 1);
425 425
 		$this->assertEquals(
426 426
 			array(
427 427
 				array(
@@ -430,12 +430,12 @@  discard block
 block discarded – undo
430 430
 					'_links' => array(
431 431
 						'collection' => array(
432 432
 							array(
433
-								'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ),
433
+								'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id() . '/locations'),
434 434
 							),
435 435
 						),
436 436
 						'describes'  => array(
437 437
 							array(
438
-								'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ),
438
+								'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id()),
439 439
 							),
440 440
 						),
441 441
 					),
@@ -450,11 +450,11 @@  discard block
 block discarded – undo
450 450
 	 * @since 3.0.0
451 451
 	 */
452 452
 	public function test_get_locations_invalid_id() {
453
-		wp_set_current_user( $this->user );
453
+		wp_set_current_user($this->user);
454 454
 
455
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/1/locations' ) );
455
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping/zones/1/locations'));
456 456
 
457
-		$this->assertEquals( 404, $response->get_status() );
457
+		$this->assertEquals(404, $response->get_status());
458 458
 	}
459 459
 
460 460
 	/**
@@ -462,12 +462,12 @@  discard block
 block discarded – undo
462 462
 	 * @since 3.0.0
463 463
 	 */
464 464
 	public function test_update_locations() {
465
-		wp_set_current_user( $this->user );
465
+		wp_set_current_user($this->user);
466 466
 
467
-		$zone = $this->create_shipping_zone( 'Test Zone' );
467
+		$zone = $this->create_shipping_zone('Test Zone');
468 468
 
469
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' );
470
-		$request->add_header( 'Content-Type', 'application/json' );
469
+		$request = new WP_REST_Request('PUT', '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations');
470
+		$request->add_header('Content-Type', 'application/json');
471 471
 		$request->set_body(
472 472
 			json_encode(
473 473
 				array(
@@ -488,10 +488,10 @@  discard block
 block discarded – undo
488 488
 				)
489 489
 			)
490 490
 		);
491
-		$response = $this->server->dispatch( $request );
491
+		$response = $this->server->dispatch($request);
492 492
 		$data     = $response->get_data();
493 493
 
494
-		$this->assertEquals( 3, count( $data ) );
494
+		$this->assertEquals(3, count($data));
495 495
 		$this->assertEquals(
496 496
 			array(
497 497
 				array(
@@ -500,12 +500,12 @@  discard block
 block discarded – undo
500 500
 					'_links' => array(
501 501
 						'collection' => array(
502 502
 							array(
503
-								'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ),
503
+								'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id() . '/locations'),
504 504
 							),
505 505
 						),
506 506
 						'describes'  => array(
507 507
 							array(
508
-								'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ),
508
+								'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id()),
509 509
 							),
510 510
 						),
511 511
 					),
@@ -516,12 +516,12 @@  discard block
 block discarded – undo
516 516
 					'_links' => array(
517 517
 						'collection' => array(
518 518
 							array(
519
-								'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ),
519
+								'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id() . '/locations'),
520 520
 							),
521 521
 						),
522 522
 						'describes'  => array(
523 523
 							array(
524
-								'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ),
524
+								'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id()),
525 525
 							),
526 526
 						),
527 527
 					),
@@ -532,12 +532,12 @@  discard block
 block discarded – undo
532 532
 					'_links' => array(
533 533
 						'collection' => array(
534 534
 							array(
535
-								'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/locations' ),
535
+								'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id() . '/locations'),
536 536
 							),
537 537
 						),
538 538
 						'describes'  => array(
539 539
 							array(
540
-								'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ),
540
+								'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id()),
541 541
 							),
542 542
 						),
543 543
 					),
@@ -552,11 +552,11 @@  discard block
 block discarded – undo
552 552
 	 * @since 3.0.0
553 553
 	 */
554 554
 	public function test_update_locations_invalid_id() {
555
-		wp_set_current_user( $this->user );
555
+		wp_set_current_user($this->user);
556 556
 
557
-		$response = $this->server->dispatch( new WP_REST_Request( 'PUT', '/wc/v2/shipping/zones/1/locations' ) );
557
+		$response = $this->server->dispatch(new WP_REST_Request('PUT', '/wc/v2/shipping/zones/1/locations'));
558 558
 
559
-		$this->assertEquals( 404, $response->get_status() );
559
+		$this->assertEquals(404, $response->get_status());
560 560
 	}
561 561
 
562 562
 	/**
@@ -564,41 +564,41 @@  discard block
 block discarded – undo
564 564
 	 * @since 3.0.0
565 565
 	 */
566 566
 	public function test_get_methods() {
567
-		wp_set_current_user( $this->user );
567
+		wp_set_current_user($this->user);
568 568
 
569 569
 		// Create a shipping method and make sure it's in the response
570
-		$zone        = $this->create_shipping_zone( 'Zone 1' );
571
-		$instance_id = $zone->add_shipping_method( 'flat_rate' );
570
+		$zone        = $this->create_shipping_zone('Zone 1');
571
+		$instance_id = $zone->add_shipping_method('flat_rate');
572 572
 		$methods     = $zone->get_shipping_methods();
573
-		$method      = $methods[ $instance_id ];
573
+		$method      = $methods[$instance_id];
574 574
 
575 575
 		$settings = array();
576 576
 		$method->init_instance_settings();
577
-		foreach ( $method->get_instance_form_fields() as $id => $field ) {
577
+		foreach ($method->get_instance_form_fields() as $id => $field) {
578 578
 			$data = array(
579 579
 				'id'          => $id,
580 580
 				'label'       => $field['title'],
581
-				'description' => ( empty( $field['description'] ) ? '' : $field['description'] ),
581
+				'description' => (empty($field['description']) ? '' : $field['description']),
582 582
 				'type'        => $field['type'],
583
-				'value'       => $method->instance_settings[ $id ],
584
-				'default'     => ( empty( $field['default'] ) ? '' : $field['default'] ),
585
-				'tip'         => ( empty( $field['description'] ) ? '' : $field['description'] ),
586
-				'placeholder' => ( empty( $field['placeholder'] ) ? '' : $field['placeholder'] ),
583
+				'value'       => $method->instance_settings[$id],
584
+				'default'     => (empty($field['default']) ? '' : $field['default']),
585
+				'tip'         => (empty($field['description']) ? '' : $field['description']),
586
+				'placeholder' => (empty($field['placeholder']) ? '' : $field['placeholder']),
587 587
 			);
588
-			if ( ! empty( $field['options'] ) ) {
588
+			if ( ! empty($field['options'])) {
589 589
 				$data['options'] = $field['options'];
590 590
 			}
591
-			$settings[ $id ] = $data;
591
+			$settings[$id] = $data;
592 592
 		}
593 593
 
594
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods' ) );
594
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods'));
595 595
 		$data     = $response->get_data();
596 596
 		$expected = array(
597 597
 			'id'                 => $instance_id,
598 598
 			'instance_id'        => $instance_id,
599 599
 			'title'              => $method->instance_settings['title'],
600 600
 			'order'              => $method->method_order,
601
-			'enabled'            => ( 'yes' === $method->enabled ),
601
+			'enabled'            => ('yes' === $method->enabled),
602 602
 			'method_id'          => $method->id,
603 603
 			'method_title'       => $method->method_title,
604 604
 			'method_description' => $method->method_description,
@@ -606,31 +606,31 @@  discard block
 block discarded – undo
606 606
 			'_links'             => array(
607 607
 				'self'       => array(
608 608
 					array(
609
-						'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ),
609
+						'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id),
610 610
 					),
611 611
 				),
612 612
 				'collection' => array(
613 613
 					array(
614
-						'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods' ),
614
+						'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id() . '/methods'),
615 615
 					),
616 616
 				),
617 617
 				'describes'  => array(
618 618
 					array(
619
-						'href' => rest_url( '/wc/v2/shipping/zones/' . $zone->get_id() ),
619
+						'href' => rest_url('/wc/v2/shipping/zones/' . $zone->get_id()),
620 620
 					),
621 621
 				),
622 622
 			),
623 623
 		);
624 624
 
625
-		$this->assertEquals( 200, $response->get_status() );
626
-		$this->assertEquals( count( $data ), 1 );
627
-		$this->assertContains( $expected, $data );
625
+		$this->assertEquals(200, $response->get_status());
626
+		$this->assertEquals(count($data), 1);
627
+		$this->assertContains($expected, $data);
628 628
 
629
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ) );
629
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id));
630 630
 		$data     = $response->get_data();
631 631
 
632
-		$this->assertEquals( 200, $response->get_status() );
633
-		$this->assertEquals( $expected, $data );
632
+		$this->assertEquals(200, $response->get_status());
633
+		$this->assertEquals($expected, $data);
634 634
 	}
635 635
 
636 636
 	/**
@@ -638,15 +638,15 @@  discard block
 block discarded – undo
638 638
 	 * @since 3.0.0
639 639
 	 */
640 640
 	public function test_get_methods_invalid_zone_id() {
641
-		wp_set_current_user( $this->user );
641
+		wp_set_current_user($this->user);
642 642
 
643
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/1/methods' ) );
643
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping/zones/1/methods'));
644 644
 
645
-		$this->assertEquals( 404, $response->get_status() );
645
+		$this->assertEquals(404, $response->get_status());
646 646
 
647
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/1/methods/1' ) );
647
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping/zones/1/methods/1'));
648 648
 
649
-		$this->assertEquals( 404, $response->get_status() );
649
+		$this->assertEquals(404, $response->get_status());
650 650
 	}
651 651
 
652 652
 	/**
@@ -654,12 +654,12 @@  discard block
 block discarded – undo
654 654
 	 * @since 3.0.0
655 655
 	 */
656 656
 	public function test_get_methods_invalid_method_id() {
657
-		wp_set_current_user( $this->user );
657
+		wp_set_current_user($this->user);
658 658
 
659
-		$zone     = $this->create_shipping_zone( 'Zone 1' );
660
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/1' ) );
659
+		$zone     = $this->create_shipping_zone('Zone 1');
660
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/1'));
661 661
 
662
-		$this->assertEquals( 404, $response->get_status() );
662
+		$this->assertEquals(404, $response->get_status());
663 663
 	}
664 664
 
665 665
 	/**
@@ -667,27 +667,27 @@  discard block
 block discarded – undo
667 667
 	 * @since 3.0.0
668 668
 	 */
669 669
 	public function test_update_methods() {
670
-		wp_set_current_user( $this->user );
670
+		wp_set_current_user($this->user);
671 671
 
672
-		$zone        = $this->create_shipping_zone( 'Zone 1' );
673
-		$instance_id = $zone->add_shipping_method( 'flat_rate' );
672
+		$zone        = $this->create_shipping_zone('Zone 1');
673
+		$instance_id = $zone->add_shipping_method('flat_rate');
674 674
 		$methods     = $zone->get_shipping_methods();
675
-		$method      = $methods[ $instance_id ];
675
+		$method      = $methods[$instance_id];
676 676
 
677 677
 		// Test defaults
678
-		$request  = new WP_REST_Request( 'GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
679
-		$response = $this->server->dispatch( $request );
678
+		$request  = new WP_REST_Request('GET', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id);
679
+		$response = $this->server->dispatch($request);
680 680
 		$data     = $response->get_data();
681 681
 
682
-		$this->assertArrayHasKey( 'title', $data['settings'] );
683
-		$this->assertEquals( 'Flat rate', $data['settings']['title']['value'] );
684
-		$this->assertArrayHasKey( 'tax_status', $data['settings'] );
685
-		$this->assertEquals( 'taxable', $data['settings']['tax_status']['value'] );
686
-		$this->assertArrayHasKey( 'cost', $data['settings'] );
687
-		$this->assertEquals( '0', $data['settings']['cost']['value'] );
682
+		$this->assertArrayHasKey('title', $data['settings']);
683
+		$this->assertEquals('Flat rate', $data['settings']['title']['value']);
684
+		$this->assertArrayHasKey('tax_status', $data['settings']);
685
+		$this->assertEquals('taxable', $data['settings']['tax_status']['value']);
686
+		$this->assertArrayHasKey('cost', $data['settings']);
687
+		$this->assertEquals('0', $data['settings']['cost']['value']);
688 688
 
689 689
 		// Update a single value
690
-		$request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
690
+		$request = new WP_REST_Request('POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id);
691 691
 		$request->set_body_params(
692 692
 			array(
693 693
 				'settings' => array(
@@ -695,18 +695,18 @@  discard block
 block discarded – undo
695 695
 				),
696 696
 			)
697 697
 		);
698
-		$response = $this->server->dispatch( $request );
698
+		$response = $this->server->dispatch($request);
699 699
 		$data     = $response->get_data();
700 700
 
701
-		$this->assertArrayHasKey( 'title', $data['settings'] );
702
-		$this->assertEquals( 'Flat rate', $data['settings']['title']['value'] );
703
-		$this->assertArrayHasKey( 'tax_status', $data['settings'] );
704
-		$this->assertEquals( 'taxable', $data['settings']['tax_status']['value'] );
705
-		$this->assertArrayHasKey( 'cost', $data['settings'] );
706
-		$this->assertEquals( '5', $data['settings']['cost']['value'] );
701
+		$this->assertArrayHasKey('title', $data['settings']);
702
+		$this->assertEquals('Flat rate', $data['settings']['title']['value']);
703
+		$this->assertArrayHasKey('tax_status', $data['settings']);
704
+		$this->assertEquals('taxable', $data['settings']['tax_status']['value']);
705
+		$this->assertArrayHasKey('cost', $data['settings']);
706
+		$this->assertEquals('5', $data['settings']['cost']['value']);
707 707
 
708 708
 		// Test multiple settings
709
-		$request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
709
+		$request = new WP_REST_Request('POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id);
710 710
 		$request->set_body_params(
711 711
 			array(
712 712
 				'settings' => array(
@@ -715,18 +715,18 @@  discard block
 block discarded – undo
715 715
 				),
716 716
 			)
717 717
 		);
718
-		$response = $this->server->dispatch( $request );
718
+		$response = $this->server->dispatch($request);
719 719
 		$data     = $response->get_data();
720 720
 
721
-		$this->assertArrayHasKey( 'title', $data['settings'] );
722
-		$this->assertEquals( 'Flat rate', $data['settings']['title']['value'] );
723
-		$this->assertArrayHasKey( 'tax_status', $data['settings'] );
724
-		$this->assertEquals( 'none', $data['settings']['tax_status']['value'] );
725
-		$this->assertArrayHasKey( 'cost', $data['settings'] );
726
-		$this->assertEquals( '10', $data['settings']['cost']['value'] );
721
+		$this->assertArrayHasKey('title', $data['settings']);
722
+		$this->assertEquals('Flat rate', $data['settings']['title']['value']);
723
+		$this->assertArrayHasKey('tax_status', $data['settings']);
724
+		$this->assertEquals('none', $data['settings']['tax_status']['value']);
725
+		$this->assertArrayHasKey('cost', $data['settings']);
726
+		$this->assertEquals('10', $data['settings']['cost']['value']);
727 727
 
728 728
 		// Test bogus
729
-		$request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
729
+		$request = new WP_REST_Request('POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id);
730 730
 		$request->set_body_params(
731 731
 			array(
732 732
 				'settings' => array(
@@ -735,27 +735,27 @@  discard block
 block discarded – undo
735 735
 				),
736 736
 			)
737 737
 		);
738
-		$response = $this->server->dispatch( $request );
739
-		$this->assertEquals( 400, $response->get_status() );
738
+		$response = $this->server->dispatch($request);
739
+		$this->assertEquals(400, $response->get_status());
740 740
 
741 741
 		// Test other parameters
742
-		$this->assertTrue( $data['enabled'] );
743
-		$this->assertEquals( 1, $data['order'] );
742
+		$this->assertTrue($data['enabled']);
743
+		$this->assertEquals(1, $data['order']);
744 744
 
745
-		$request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
745
+		$request = new WP_REST_Request('POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id);
746 746
 		$request->set_body_params(
747 747
 			array(
748 748
 				'enabled' => false,
749 749
 				'order'   => 2,
750 750
 			)
751 751
 		);
752
-		$response = $this->server->dispatch( $request );
752
+		$response = $this->server->dispatch($request);
753 753
 		$data     = $response->get_data();
754 754
 
755
-		$this->assertFalse( $data['enabled'] );
756
-		$this->assertEquals( 2, $data['order'] );
757
-		$this->assertArrayHasKey( 'cost', $data['settings'] );
758
-		$this->assertEquals( '10', $data['settings']['cost']['value'] );
755
+		$this->assertFalse($data['enabled']);
756
+		$this->assertEquals(2, $data['order']);
757
+		$this->assertArrayHasKey('cost', $data['settings']);
758
+		$this->assertEquals('10', $data['settings']['cost']['value']);
759 759
 	}
760 760
 
761 761
 	/**
@@ -763,9 +763,9 @@  discard block
 block discarded – undo
763 763
 	 * @since 3.0.0
764 764
 	 */
765 765
 	public function test_create_method() {
766
-		wp_set_current_user( $this->user );
767
-		$zone    = $this->create_shipping_zone( 'Zone 1' );
768
-		$request = new WP_REST_Request( 'POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods' );
766
+		wp_set_current_user($this->user);
767
+		$zone    = $this->create_shipping_zone('Zone 1');
768
+		$request = new WP_REST_Request('POST', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods');
769 769
 		$request->set_body_params(
770 770
 			array(
771 771
 				'method_id' => 'flat_rate',
@@ -773,13 +773,13 @@  discard block
 block discarded – undo
773 773
 				'order'     => 2,
774 774
 			)
775 775
 		);
776
-		$response = $this->server->dispatch( $request );
776
+		$response = $this->server->dispatch($request);
777 777
 		$data     = $response->get_data();
778 778
 
779
-		$this->assertFalse( $data['enabled'] );
780
-		$this->assertEquals( 2, $data['order'] );
781
-		$this->assertArrayHasKey( 'cost', $data['settings'] );
782
-		$this->assertEquals( '0', $data['settings']['cost']['value'] );
779
+		$this->assertFalse($data['enabled']);
780
+		$this->assertEquals(2, $data['order']);
781
+		$this->assertArrayHasKey('cost', $data['settings']);
782
+		$this->assertEquals('0', $data['settings']['cost']['value']);
783 783
 	}
784 784
 
785 785
 	/**
@@ -787,14 +787,14 @@  discard block
 block discarded – undo
787 787
 	 * @since 3.0.0
788 788
 	 */
789 789
 	public function test_delete_method() {
790
-		wp_set_current_user( $this->user );
791
-		$zone        = $this->create_shipping_zone( 'Zone 1' );
792
-		$instance_id = $zone->add_shipping_method( 'flat_rate' );
790
+		wp_set_current_user($this->user);
791
+		$zone        = $this->create_shipping_zone('Zone 1');
792
+		$instance_id = $zone->add_shipping_method('flat_rate');
793 793
 		$methods     = $zone->get_shipping_methods();
794
-		$method      = $methods[ $instance_id ];
795
-		$request     = new WP_REST_Request( 'DELETE', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
796
-		$request->set_param( 'force', true );
797
-		$response = $this->server->dispatch( $request );
798
-		$this->assertEquals( 200, $response->get_status() );
794
+		$method      = $methods[$instance_id];
795
+		$request     = new WP_REST_Request('DELETE', '/wc/v2/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id);
796
+		$request->set_param('force', true);
797
+		$response = $this->server->dispatch($request);
798
+		$this->assertEquals(200, $response->get_status());
799 799
 	}
800 800
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version2/settings.php 1 patch
Spacing   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
29 29
 	 */
30 30
 	public function test_register_routes() {
31 31
 		$routes = $this->server->get_routes();
32
-		$this->assertArrayHasKey( '/wc/v2/settings', $routes );
33
-		$this->assertArrayHasKey( '/wc/v2/settings/(?P<group_id>[\w-]+)', $routes );
34
-		$this->assertArrayHasKey( '/wc/v2/settings/(?P<group_id>[\w-]+)/(?P<id>[\w-]+)', $routes );
32
+		$this->assertArrayHasKey('/wc/v2/settings', $routes);
33
+		$this->assertArrayHasKey('/wc/v2/settings/(?P<group_id>[\w-]+)', $routes);
34
+		$this->assertArrayHasKey('/wc/v2/settings/(?P<group_id>[\w-]+)/(?P<id>[\w-]+)', $routes);
35 35
 	}
36 36
 
37 37
 	/**
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
 	 * @since 3.0.0
41 41
 	 */
42 42
 	public function test_get_groups() {
43
-		wp_set_current_user( $this->user );
43
+		wp_set_current_user($this->user);
44 44
 
45
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings' ) );
45
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings'));
46 46
 		$data     = $response->get_data();
47 47
 
48
-		$this->assertEquals( 200, $response->get_status() );
48
+		$this->assertEquals(200, $response->get_status());
49 49
 
50 50
 		$this->assertContains(
51 51
 			array(
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
 				'label'       => 'Test extension',
54 54
 				'parent_id'   => '',
55 55
 				'description' => 'My awesome test settings.',
56
-				'sub_groups'  => array( 'sub-test' ),
56
+				'sub_groups'  => array('sub-test'),
57 57
 				'_links'      => array(
58 58
 					'options' => array(
59 59
 						array(
60
-							'href' => rest_url( '/wc/v2/settings/test' ),
60
+							'href' => rest_url('/wc/v2/settings/test'),
61 61
 						),
62 62
 					),
63 63
 				),
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 				'_links'      => array(
76 76
 					'options' => array(
77 77
 						array(
78
-							'href' => rest_url( '/wc/v2/settings/sub-test' ),
78
+							'href' => rest_url('/wc/v2/settings/sub-test'),
79 79
 						),
80 80
 					),
81 81
 				),
@@ -90,10 +90,10 @@  discard block
 block discarded – undo
90 90
 	 * @since 3.0.0
91 91
 	 */
92 92
 	public function test_get_groups_without_permission() {
93
-		wp_set_current_user( 0 );
93
+		wp_set_current_user(0);
94 94
 
95
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings' ) );
96
-		$this->assertEquals( 401, $response->get_status() );
95
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings'));
96
+		$this->assertEquals(401, $response->get_status());
97 97
 	}
98 98
 
99 99
 	/**
@@ -103,12 +103,12 @@  discard block
 block discarded – undo
103 103
 	 * @covers WC_Rest_Settings_Controller::get_items
104 104
 	 */
105 105
 	public function test_get_groups_none_registered() {
106
-		wp_set_current_user( $this->user );
106
+		wp_set_current_user($this->user);
107 107
 
108
-		remove_all_filters( 'woocommerce_settings_groups' );
108
+		remove_all_filters('woocommerce_settings_groups');
109 109
 
110
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings' ) );
111
-		$this->assertEquals( 500, $response->get_status() );
110
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings'));
111
+		$this->assertEquals(500, $response->get_status());
112 112
 
113 113
 		\WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register();
114 114
 	}
@@ -119,16 +119,16 @@  discard block
 block discarded – undo
119 119
 	 * @since 3.0.0
120 120
 	 */
121 121
 	public function test_get_group_schema() {
122
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v2/settings' );
123
-		$response   = $this->server->dispatch( $request );
122
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v2/settings');
123
+		$response   = $this->server->dispatch($request);
124 124
 		$data       = $response->get_data();
125 125
 		$properties = $data['schema']['properties'];
126
-		$this->assertEquals( 5, count( $properties ) );
127
-		$this->assertArrayHasKey( 'id', $properties );
128
-		$this->assertArrayHasKey( 'parent_id', $properties );
129
-		$this->assertArrayHasKey( 'label', $properties );
130
-		$this->assertArrayHasKey( 'description', $properties );
131
-		$this->assertArrayHasKey( 'sub_groups', $properties );
126
+		$this->assertEquals(5, count($properties));
127
+		$this->assertArrayHasKey('id', $properties);
128
+		$this->assertArrayHasKey('parent_id', $properties);
129
+		$this->assertArrayHasKey('label', $properties);
130
+		$this->assertArrayHasKey('description', $properties);
131
+		$this->assertArrayHasKey('sub_groups', $properties);
132 132
 	}
133 133
 
134 134
 	/**
@@ -137,20 +137,20 @@  discard block
 block discarded – undo
137 137
 	 * @since 3.0.0
138 138
 	 */
139 139
 	public function test_get_setting_schema() {
140
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v2/settings/test/woocommerce_shop_page_display' );
141
-		$response   = $this->server->dispatch( $request );
140
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v2/settings/test/woocommerce_shop_page_display');
141
+		$response   = $this->server->dispatch($request);
142 142
 		$data       = $response->get_data();
143 143
 		$properties = $data['schema']['properties'];
144
-		$this->assertEquals( 9, count( $properties ) );
145
-		$this->assertArrayHasKey( 'id', $properties );
146
-		$this->assertArrayHasKey( 'label', $properties );
147
-		$this->assertArrayHasKey( 'description', $properties );
148
-		$this->assertArrayHasKey( 'value', $properties );
149
-		$this->assertArrayHasKey( 'default', $properties );
150
-		$this->assertArrayHasKey( 'tip', $properties );
151
-		$this->assertArrayHasKey( 'placeholder', $properties );
152
-		$this->assertArrayHasKey( 'type', $properties );
153
-		$this->assertArrayHasKey( 'options', $properties );
144
+		$this->assertEquals(9, count($properties));
145
+		$this->assertArrayHasKey('id', $properties);
146
+		$this->assertArrayHasKey('label', $properties);
147
+		$this->assertArrayHasKey('description', $properties);
148
+		$this->assertArrayHasKey('value', $properties);
149
+		$this->assertArrayHasKey('default', $properties);
150
+		$this->assertArrayHasKey('tip', $properties);
151
+		$this->assertArrayHasKey('placeholder', $properties);
152
+		$this->assertArrayHasKey('type', $properties);
153
+		$this->assertArrayHasKey('options', $properties);
154 154
 	}
155 155
 
156 156
 	/**
@@ -159,26 +159,26 @@  discard block
 block discarded – undo
159 159
 	 * @since 3.0.0
160 160
 	 */
161 161
 	public function test_get_group() {
162
-		wp_set_current_user( $this->user );
162
+		wp_set_current_user($this->user);
163 163
 
164 164
 		// test route callback receiving an empty group id
165
-		$result = $this->endpoint->get_group_settings( '' );
166
-		$this->assertIsWPError( $result );
165
+		$result = $this->endpoint->get_group_settings('');
166
+		$this->assertIsWPError($result);
167 167
 
168 168
 		// test getting a group that does not exist
169
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/not-real' ) );
170
-		$this->assertEquals( 404, $response->get_status() );
169
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/not-real'));
170
+		$this->assertEquals(404, $response->get_status());
171 171
 
172 172
 		// test getting the 'invalid' group
173
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/invalid' ) );
174
-		$this->assertEquals( 404, $response->get_status() );
173
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/invalid'));
174
+		$this->assertEquals(404, $response->get_status());
175 175
 
176 176
 		// test getting a valid group with settings attached to it
177
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test' ) );
177
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/test'));
178 178
 		$data     = $response->get_data();
179
-		$this->assertEquals( 1, count( $data ) );
180
-		$this->assertEquals( 'woocommerce_shop_page_display', $data[0]['id'] );
181
-		$this->assertEmpty( $data[0]['value'] );
179
+		$this->assertEquals(1, count($data));
180
+		$this->assertEquals('woocommerce_shop_page_display', $data[0]['id']);
181
+		$this->assertEmpty($data[0]['value']);
182 182
 	}
183 183
 
184 184
 	/**
@@ -187,10 +187,10 @@  discard block
 block discarded – undo
187 187
 	 * @since 3.0.0
188 188
 	 */
189 189
 	public function test_get_group_without_permission() {
190
-		wp_set_current_user( 0 );
190
+		wp_set_current_user(0);
191 191
 
192
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/coupon-data' ) );
193
-		$this->assertEquals( 401, $response->get_status() );
192
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/coupon-data'));
193
+		$this->assertEquals(401, $response->get_status());
194 194
 	}
195 195
 
196 196
 	/**
@@ -199,49 +199,49 @@  discard block
 block discarded – undo
199 199
 	 * @since 3.0.0
200 200
 	 */
201 201
 	public function test_update_setting() {
202
-		wp_set_current_user( $this->user );
202
+		wp_set_current_user($this->user);
203 203
 
204 204
 		// test defaults first
205
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test/woocommerce_shop_page_display' ) );
205
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/test/woocommerce_shop_page_display'));
206 206
 		$data     = $response->get_data();
207
-		$this->assertEquals( '', $data['value'] );
207
+		$this->assertEquals('', $data['value']);
208 208
 
209 209
 		// test updating shop display setting
210
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) );
210
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display'));
211 211
 		$request->set_body_params(
212 212
 			array(
213 213
 				'value' => 'both',
214 214
 			)
215 215
 		);
216
-		$response = $this->server->dispatch( $request );
216
+		$response = $this->server->dispatch($request);
217 217
 		$data     = $response->get_data();
218 218
 
219
-		$this->assertEquals( 'both', $data['value'] );
220
-		$this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) );
219
+		$this->assertEquals('both', $data['value']);
220
+		$this->assertEquals('both', get_option('woocommerce_shop_page_display'));
221 221
 
222
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) );
222
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display'));
223 223
 		$request->set_body_params(
224 224
 			array(
225 225
 				'value' => 'subcategories',
226 226
 			)
227 227
 		);
228
-		$response = $this->server->dispatch( $request );
228
+		$response = $this->server->dispatch($request);
229 229
 		$data     = $response->get_data();
230 230
 
231
-		$this->assertEquals( 'subcategories', $data['value'] );
232
-		$this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) );
231
+		$this->assertEquals('subcategories', $data['value']);
232
+		$this->assertEquals('subcategories', get_option('woocommerce_shop_page_display'));
233 233
 
234
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) );
234
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display'));
235 235
 		$request->set_body_params(
236 236
 			array(
237 237
 				'value' => '',
238 238
 			)
239 239
 		);
240
-		$response = $this->server->dispatch( $request );
240
+		$response = $this->server->dispatch($request);
241 241
 		$data     = $response->get_data();
242 242
 
243
-		$this->assertEquals( '', $data['value'] );
244
-		$this->assertEquals( '', get_option( 'woocommerce_shop_page_display' ) );
243
+		$this->assertEquals('', $data['value']);
244
+		$this->assertEquals('', get_option('woocommerce_shop_page_display'));
245 245
 	}
246 246
 
247 247
 	/**
@@ -250,15 +250,15 @@  discard block
 block discarded – undo
250 250
 	 * @since 3.0.0
251 251
 	 */
252 252
 	public function test_update_settings() {
253
-		wp_set_current_user( $this->user );
253
+		wp_set_current_user($this->user);
254 254
 
255 255
 		// test defaults first
256
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test' ) );
256
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/test'));
257 257
 		$data     = $response->get_data();
258
-		$this->assertEquals( '', $data[0]['value'] );
258
+		$this->assertEquals('', $data[0]['value']);
259 259
 
260 260
 		// test setting both at once
261
-		$request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' );
261
+		$request = new WP_REST_Request('POST', '/wc/v2/settings/test/batch');
262 262
 		$request->set_body_params(
263 263
 			array(
264 264
 				'update' => array(
@@ -269,14 +269,14 @@  discard block
 block discarded – undo
269 269
 				),
270 270
 			)
271 271
 		);
272
-		$response = $this->server->dispatch( $request );
272
+		$response = $this->server->dispatch($request);
273 273
 		$data     = $response->get_data();
274 274
 
275
-		$this->assertEquals( 'both', $data['update'][0]['value'] );
276
-		$this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) );
275
+		$this->assertEquals('both', $data['update'][0]['value']);
276
+		$this->assertEquals('both', get_option('woocommerce_shop_page_display'));
277 277
 
278 278
 		// test updating one, but making sure the other value stays the same
279
-		$request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' );
279
+		$request = new WP_REST_Request('POST', '/wc/v2/settings/test/batch');
280 280
 		$request->set_body_params(
281 281
 			array(
282 282
 				'update' => array(
@@ -287,10 +287,10 @@  discard block
 block discarded – undo
287 287
 				),
288 288
 			)
289 289
 		);
290
-		$response = $this->server->dispatch( $request );
290
+		$response = $this->server->dispatch($request);
291 291
 		$data     = $response->get_data();
292
-		$this->assertEquals( 'subcategories', $data['update'][0]['value'] );
293
-		$this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) );
292
+		$this->assertEquals('subcategories', $data['update'][0]['value']);
293
+		$this->assertEquals('subcategories', get_option('woocommerce_shop_page_display'));
294 294
 	}
295 295
 
296 296
 	/**
@@ -299,29 +299,29 @@  discard block
 block discarded – undo
299 299
 	 * @since 3.0.0
300 300
 	 */
301 301
 	public function test_get_setting() {
302
-		wp_set_current_user( $this->user );
302
+		wp_set_current_user($this->user);
303 303
 
304 304
 		// test getting an invalid setting from a group that does not exist
305
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/not-real/woocommerce_shop_page_display' ) );
305
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/not-real/woocommerce_shop_page_display'));
306 306
 		$data     = $response->get_data();
307
-		$this->assertEquals( 404, $response->get_status() );
307
+		$this->assertEquals(404, $response->get_status());
308 308
 
309 309
 		// test getting an invalid setting from a group that does exist
310
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/invalid/invalid' ) );
310
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/invalid/invalid'));
311 311
 		$data     = $response->get_data();
312
-		$this->assertEquals( 404, $response->get_status() );
312
+		$this->assertEquals(404, $response->get_status());
313 313
 
314 314
 		// test getting a valid setting
315
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test/woocommerce_shop_page_display' ) );
315
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/test/woocommerce_shop_page_display'));
316 316
 		$data     = $response->get_data();
317 317
 
318
-		$this->assertEquals( 200, $response->get_status() );
318
+		$this->assertEquals(200, $response->get_status());
319 319
 
320
-		$this->assertEquals( 'woocommerce_shop_page_display', $data['id'] );
321
-		$this->assertEquals( 'Shop page display', $data['label'] );
322
-		$this->assertEquals( '', $data['default'] );
323
-		$this->assertEquals( 'select', $data['type'] );
324
-		$this->assertEquals( '', $data['value'] );
320
+		$this->assertEquals('woocommerce_shop_page_display', $data['id']);
321
+		$this->assertEquals('Shop page display', $data['label']);
322
+		$this->assertEquals('', $data['default']);
323
+		$this->assertEquals('select', $data['type']);
324
+		$this->assertEquals('', $data['value']);
325 325
 	}
326 326
 
327 327
 	/**
@@ -330,10 +330,10 @@  discard block
 block discarded – undo
330 330
 	 * @since 3.0.0
331 331
 	 */
332 332
 	public function test_get_setting_without_permission() {
333
-		wp_set_current_user( 0 );
333
+		wp_set_current_user(0);
334 334
 
335
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test/woocommerce_shop_page_display' ) );
336
-		$this->assertEquals( 401, $response->get_status() );
335
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/test/woocommerce_shop_page_display'));
336
+		$this->assertEquals(401, $response->get_status());
337 337
 	}
338 338
 
339 339
 	/**
@@ -342,9 +342,9 @@  discard block
 block discarded – undo
342 342
 	 * @since 3.0.0
343 343
 	 */
344 344
 	public function test_get_setting_empty_setting_id() {
345
-		$result = $this->endpoint->get_setting( 'test', '' );
345
+		$result = $this->endpoint->get_setting('test', '');
346 346
 
347
-		$this->assertIsWPError( $result );
347
+		$this->assertIsWPError($result);
348 348
 	}
349 349
 
350 350
 	/**
@@ -353,9 +353,9 @@  discard block
 block discarded – undo
353 353
 	 * @since 3.0.0
354 354
 	 */
355 355
 	public function test_get_setting_invalid_setting_id() {
356
-		$result = $this->endpoint->get_setting( 'test', 'invalid' );
356
+		$result = $this->endpoint->get_setting('test', 'invalid');
357 357
 
358
-		$this->assertIsWPError( $result );
358
+		$this->assertIsWPError($result);
359 359
 	}
360 360
 
361 361
 	/**
@@ -365,21 +365,21 @@  discard block
 block discarded – undo
365 365
 	 */
366 366
 	public function test_get_setting_invalid_setting_type() {
367 367
 		// $controller = $this->getMock( 'WC_Rest_Setting_Options_Controller', array( 'get_group_settings', 'is_setting_type_valid' ) );
368
-		$controller = $this->getMockBuilder( 'WC_Rest_Setting_Options_Controller' )->setMethods( array( 'get_group_settings', 'is_setting_type_valid' ) )->getMock();
368
+		$controller = $this->getMockBuilder('WC_Rest_Setting_Options_Controller')->setMethods(array('get_group_settings', 'is_setting_type_valid'))->getMock();
369 369
 
370 370
 		$controller
371
-			->expects( $this->any() )
372
-			->method( 'get_group_settings' )
373
-			->will( $this->returnValue( \WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register_test_settings( array() ) ) );
371
+			->expects($this->any())
372
+			->method('get_group_settings')
373
+			->will($this->returnValue(\WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register_test_settings(array())));
374 374
 
375 375
 		$controller
376
-			->expects( $this->any() )
377
-			->method( 'is_setting_type_valid' )
378
-			->will( $this->returnValue( false ) );
376
+			->expects($this->any())
377
+			->method('is_setting_type_valid')
378
+			->will($this->returnValue(false));
379 379
 
380
-		$result = $controller->get_setting( 'test', 'woocommerce_shop_page_display' );
380
+		$result = $controller->get_setting('test', 'woocommerce_shop_page_display');
381 381
 
382
-		$this->assertIsWPError( $result );
382
+		$this->assertIsWPError($result);
383 383
 	}
384 384
 
385 385
 	/**
@@ -388,16 +388,16 @@  discard block
 block discarded – undo
388 388
 	 * @since 3.0.0
389 389
 	 */
390 390
 	public function test_update_setting_without_permission() {
391
-		wp_set_current_user( 0 );
391
+		wp_set_current_user(0);
392 392
 
393
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) );
393
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'test', 'woocommerce_shop_page_display'));
394 394
 		$request->set_body_params(
395 395
 			array(
396 396
 				'value' => 'subcategories',
397 397
 			)
398 398
 		);
399
-		$response = $this->server->dispatch( $request );
400
-		$this->assertEquals( 401, $response->get_status() );
399
+		$response = $this->server->dispatch($request);
400
+		$this->assertEquals(401, $response->get_status());
401 401
 	}
402 402
 
403 403
 
@@ -407,9 +407,9 @@  discard block
 block discarded – undo
407 407
 	 * @since 3.0.0
408 408
 	 */
409 409
 	public function test_update_settings_without_permission() {
410
-		wp_set_current_user( 0 );
410
+		wp_set_current_user(0);
411 411
 
412
-		$request = new WP_REST_Request( 'POST', '/wc/v2/settings/test/batch' );
412
+		$request = new WP_REST_Request('POST', '/wc/v2/settings/test/batch');
413 413
 		$request->set_body_params(
414 414
 			array(
415 415
 				'update' => array(
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
 				),
421 421
 			)
422 422
 		);
423
-		$response = $this->server->dispatch( $request );
424
-		$this->assertEquals( 401, $response->get_status() );
423
+		$response = $this->server->dispatch($request);
424
+		$this->assertEquals(401, $response->get_status());
425 425
 	}
426 426
 
427 427
 	/**
@@ -431,16 +431,16 @@  discard block
 block discarded – undo
431 431
 	 * @covers WC_Rest_Setting_Options_Controller::update_item
432 432
 	 */
433 433
 	public function test_update_setting_bad_setting_id() {
434
-		wp_set_current_user( $this->user );
434
+		wp_set_current_user($this->user);
435 435
 
436
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/test/invalid' );
436
+		$request = new WP_REST_Request('PUT', '/wc/v2/settings/test/invalid');
437 437
 		$request->set_body_params(
438 438
 			array(
439 439
 				'value' => 'test',
440 440
 			)
441 441
 		);
442
-		$response = $this->server->dispatch( $request );
443
-		$this->assertEquals( 404, $response->get_status() );
442
+		$response = $this->server->dispatch($request);
443
+		$this->assertEquals(404, $response->get_status());
444 444
 	}
445 445
 
446 446
 	/**
@@ -449,12 +449,12 @@  discard block
 block discarded – undo
449 449
 	 * @since 3.0.0
450 450
 	 */
451 451
 	public function test_classic_settings() {
452
-		wp_set_current_user( $this->user );
452
+		wp_set_current_user($this->user);
453 453
 
454 454
 		// Make sure the group is properly registered
455
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/products' ) );
455
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/products'));
456 456
 		$data     = $response->get_data();
457
-		$this->assertTrue( is_array( $data ) );
457
+		$this->assertTrue(is_array($data));
458 458
 		$this->assertContains(
459 459
 			array(
460 460
 				'id'          => 'woocommerce_downloads_require_login',
@@ -467,12 +467,12 @@  discard block
 block discarded – undo
467 467
 				'_links'      => array(
468 468
 					'self'       => array(
469 469
 						array(
470
-							'href' => rest_url( '/wc/v2/settings/products/woocommerce_downloads_require_login' ),
470
+							'href' => rest_url('/wc/v2/settings/products/woocommerce_downloads_require_login'),
471 471
 						),
472 472
 					),
473 473
 					'collection' => array(
474 474
 						array(
475
-							'href' => rest_url( '/wc/v2/settings/products' ),
475
+							'href' => rest_url('/wc/v2/settings/products'),
476 476
 						),
477 477
 					),
478 478
 				),
@@ -481,23 +481,23 @@  discard block
 block discarded – undo
481 481
 		);
482 482
 
483 483
 		// test get single
484
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/products/woocommerce_dimension_unit' ) );
484
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/products/woocommerce_dimension_unit'));
485 485
 		$data     = $response->get_data();
486 486
 
487
-		$this->assertEquals( 'cm', $data['default'] );
487
+		$this->assertEquals('cm', $data['default']);
488 488
 
489 489
 		// test update
490
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_dimension_unit' ) );
490
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'products', 'woocommerce_dimension_unit'));
491 491
 		$request->set_body_params(
492 492
 			array(
493 493
 				'value' => 'yd',
494 494
 			)
495 495
 		);
496
-		$response = $this->server->dispatch( $request );
496
+		$response = $this->server->dispatch($request);
497 497
 		$data     = $response->get_data();
498 498
 
499
-		$this->assertEquals( 'yd', $data['value'] );
500
-		$this->assertEquals( 'yd', get_option( 'woocommerce_dimension_unit' ) );
499
+		$this->assertEquals('yd', $data['value']);
500
+		$this->assertEquals('yd', get_option('woocommerce_dimension_unit'));
501 501
 	}
502 502
 
503 503
 	/**
@@ -506,12 +506,12 @@  discard block
 block discarded – undo
506 506
 	 * @since 3.0.0
507 507
 	 */
508 508
 	public function test_email_settings() {
509
-		wp_set_current_user( $this->user );
509
+		wp_set_current_user($this->user);
510 510
 
511
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/email_new_order' ) );
511
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/email_new_order'));
512 512
 		$settings = $response->get_data();
513 513
 
514
-		$this->assertEquals( 200, $response->get_status() );
514
+		$this->assertEquals(200, $response->get_status());
515 515
 
516 516
 		$this->assertContains(
517 517
 			array(
@@ -525,12 +525,12 @@  discard block
 block discarded – undo
525 525
 				'_links'      => array(
526 526
 					'self'       => array(
527 527
 						array(
528
-							'href' => rest_url( '/wc/v2/settings/email_new_order/recipient' ),
528
+							'href' => rest_url('/wc/v2/settings/email_new_order/recipient'),
529 529
 						),
530 530
 					),
531 531
 					'collection' => array(
532 532
 						array(
533
-							'href' => rest_url( '/wc/v2/settings/email_new_order' ),
533
+							'href' => rest_url('/wc/v2/settings/email_new_order'),
534 534
 						),
535 535
 					),
536 536
 				),
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 		);
540 540
 
541 541
 		// test get single
542
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/email_new_order/subject' ) );
542
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/email_new_order/subject'));
543 543
 		$setting  = $response->get_data();
544 544
 
545 545
 		$this->assertEquals(
@@ -556,13 +556,13 @@  discard block
 block discarded – undo
556 556
 		);
557 557
 
558 558
 		// test update
559
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_new_order', 'subject' ) );
559
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'email_new_order', 'subject'));
560 560
 		$request->set_body_params(
561 561
 			array(
562 562
 				'value' => 'This is my subject',
563 563
 			)
564 564
 		);
565
-		$response = $this->server->dispatch( $request );
565
+		$response = $this->server->dispatch($request);
566 566
 		$setting  = $response->get_data();
567 567
 
568 568
 		$this->assertEquals(
@@ -579,29 +579,29 @@  discard block
 block discarded – undo
579 579
 		);
580 580
 
581 581
 		// test updating another subject and making sure it works with a "similar" id
582
-		$request  = new WP_REST_Request( 'GET', sprintf( '/wc/v2/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
583
-		$response = $this->server->dispatch( $request );
582
+		$request  = new WP_REST_Request('GET', sprintf('/wc/v2/settings/%s/%s', 'email_customer_new_account', 'subject'));
583
+		$response = $this->server->dispatch($request);
584 584
 		$setting  = $response->get_data();
585 585
 
586
-		$this->assertEmpty( $setting['value'] );
586
+		$this->assertEmpty($setting['value']);
587 587
 
588 588
 		// test update
589
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_customer_new_account', 'subject' ) );
589
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'email_customer_new_account', 'subject'));
590 590
 		$request->set_body_params(
591 591
 			array(
592 592
 				'value' => 'This is my new subject',
593 593
 			)
594 594
 		);
595
-		$response = $this->server->dispatch( $request );
595
+		$response = $this->server->dispatch($request);
596 596
 		$setting  = $response->get_data();
597 597
 
598
-		$this->assertEquals( 'This is my new subject', $setting['value'] );
598
+		$this->assertEquals('This is my new subject', $setting['value']);
599 599
 
600 600
 		// make sure the other is what we left it
601
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/email_new_order/subject' ) );
601
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/email_new_order/subject'));
602 602
 		$setting  = $response->get_data();
603 603
 
604
-		$this->assertEquals( 'This is my subject', $setting['value'] );
604
+		$this->assertEquals('This is my subject', $setting['value']);
605 605
 	}
606 606
 
607 607
 	/**
@@ -610,37 +610,37 @@  discard block
 block discarded – undo
610 610
 	 * @since 3.0.0
611 611
 	 */
612 612
 	public function test_validation_checkbox() {
613
-		wp_set_current_user( $this->user );
613
+		wp_set_current_user($this->user);
614 614
 
615 615
 		// test bogus value
616
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
616
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled'));
617 617
 		$request->set_body_params(
618 618
 			array(
619 619
 				'value' => 'not_yes_or_no',
620 620
 			)
621 621
 		);
622
-		$response = $this->server->dispatch( $request );
623
-		$this->assertEquals( 400, $response->get_status() );
622
+		$response = $this->server->dispatch($request);
623
+		$this->assertEquals(400, $response->get_status());
624 624
 
625 625
 		// test yes
626
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
626
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled'));
627 627
 		$request->set_body_params(
628 628
 			array(
629 629
 				'value' => 'yes',
630 630
 			)
631 631
 		);
632
-		$response = $this->server->dispatch( $request );
633
-		$this->assertEquals( 200, $response->get_status() );
632
+		$response = $this->server->dispatch($request);
633
+		$this->assertEquals(200, $response->get_status());
634 634
 
635 635
 		// test no
636
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled' ) );
636
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'email_cancelled_order', 'enabled'));
637 637
 		$request->set_body_params(
638 638
 			array(
639 639
 				'value' => 'no',
640 640
 			)
641 641
 		);
642
-		$response = $this->server->dispatch( $request );
643
-		$this->assertEquals( 200, $response->get_status() );
642
+		$response = $this->server->dispatch($request);
643
+		$this->assertEquals(200, $response->get_status());
644 644
 	}
645 645
 
646 646
 	/**
@@ -649,27 +649,27 @@  discard block
 block discarded – undo
649 649
 	 * @since 3.0.0
650 650
 	 */
651 651
 	public function test_validation_radio() {
652
-		wp_set_current_user( $this->user );
652
+		wp_set_current_user($this->user);
653 653
 
654 654
 		// not a valid option
655
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
655
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination'));
656 656
 		$request->set_body_params(
657 657
 			array(
658 658
 				'value' => 'billing2',
659 659
 			)
660 660
 		);
661
-		$response = $this->server->dispatch( $request );
662
-		$this->assertEquals( 400, $response->get_status() );
661
+		$response = $this->server->dispatch($request);
662
+		$this->assertEquals(400, $response->get_status());
663 663
 
664 664
 		// valid
665
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) );
665
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination'));
666 666
 		$request->set_body_params(
667 667
 			array(
668 668
 				'value' => 'billing',
669 669
 			)
670 670
 		);
671
-		$response = $this->server->dispatch( $request );
672
-		$this->assertEquals( 200, $response->get_status() );
671
+		$response = $this->server->dispatch($request);
672
+		$this->assertEquals(200, $response->get_status());
673 673
 	}
674 674
 
675 675
 	/**
@@ -678,21 +678,21 @@  discard block
 block discarded – undo
678 678
 	 * @since 3.0.0
679 679
 	 */
680 680
 	public function test_validation_multiselect() {
681
-		wp_set_current_user( $this->user );
681
+		wp_set_current_user($this->user);
682 682
 
683
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', sprintf( '/wc/v2/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) ) );
683
+		$response = $this->server->dispatch(new WP_REST_Request('GET', sprintf('/wc/v2/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries')));
684 684
 		$setting  = $response->get_data();
685
-		$this->assertEmpty( $setting['value'] );
685
+		$this->assertEmpty($setting['value']);
686 686
 
687
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) );
687
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries'));
688 688
 		$request->set_body_params(
689 689
 			array(
690
-				'value' => array( 'AX', 'DZ', 'MMM' ),
690
+				'value' => array('AX', 'DZ', 'MMM'),
691 691
 			)
692 692
 		);
693
-		$response = $this->server->dispatch( $request );
693
+		$response = $this->server->dispatch($request);
694 694
 		$setting  = $response->get_data();
695
-		$this->assertEquals( array( 'AX', 'DZ' ), $setting['value'] );
695
+		$this->assertEquals(array('AX', 'DZ'), $setting['value']);
696 696
 	}
697 697
 
698 698
 	/**
@@ -701,32 +701,32 @@  discard block
 block discarded – undo
701 701
 	 * @since 3.0.0
702 702
 	 */
703 703
 	public function test_validation_select() {
704
-		wp_set_current_user( $this->user );
704
+		wp_set_current_user($this->user);
705 705
 
706
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) ) );
706
+		$response = $this->server->dispatch(new WP_REST_Request('GET', sprintf('/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit')));
707 707
 		$setting  = $response->get_data();
708
-		$this->assertEquals( 'kg', $setting['value'] );
708
+		$this->assertEquals('kg', $setting['value']);
709 709
 
710 710
 		// invalid
711
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
711
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit'));
712 712
 		$request->set_body_params(
713 713
 			array(
714 714
 				'value' => 'pounds', // invalid, should be lbs
715 715
 			)
716 716
 		);
717
-		$response = $this->server->dispatch( $request );
718
-		$this->assertEquals( 400, $response->get_status() );
717
+		$response = $this->server->dispatch($request);
718
+		$this->assertEquals(400, $response->get_status());
719 719
 
720 720
 		// valid
721
-		$request = new WP_REST_Request( 'PUT', sprintf( '/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) );
721
+		$request = new WP_REST_Request('PUT', sprintf('/wc/v2/settings/%s/%s', 'products', 'woocommerce_weight_unit'));
722 722
 		$request->set_body_params(
723 723
 			array(
724 724
 				'value' => 'lbs', // invalid, should be lbs
725 725
 			)
726 726
 		);
727
-		$response = $this->server->dispatch( $request );
727
+		$response = $this->server->dispatch($request);
728 728
 		$setting  = $response->get_data();
729
-		$this->assertEquals( 'lbs', $setting['value'] );
729
+		$this->assertEquals('lbs', $setting['value']);
730 730
 	}
731 731
 
732 732
 	/**
@@ -737,13 +737,13 @@  discard block
 block discarded – undo
737 737
 	 * @since 3.0.7
738 738
 	 */
739 739
 	public function test_woocommerce_default_country() {
740
-		wp_set_current_user( $this->user );
741
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_default_country' ) );
740
+		wp_set_current_user($this->user);
741
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/general/woocommerce_default_country'));
742 742
 		$setting  = $response->get_data();
743 743
 
744
-		$this->assertEquals( 'select', $setting['type'] );
745
-		$this->assertArrayHasKey( 'GB', $setting['options'] );
746
-		$this->assertArrayHasKey( 'US:OR', $setting['options'] );
744
+		$this->assertEquals('select', $setting['type']);
745
+		$this->assertArrayHasKey('GB', $setting['options']);
746
+		$this->assertArrayHasKey('US:OR', $setting['options']);
747 747
 	}
748 748
 
749 749
 	/**
@@ -752,34 +752,34 @@  discard block
 block discarded – undo
752 752
 	 * @since 3.1.1
753 753
 	 */
754 754
 	public function test_woocommerce_store_address() {
755
-		wp_set_current_user( $this->user );
756
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_store_address' ) );
755
+		wp_set_current_user($this->user);
756
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/general/woocommerce_store_address'));
757 757
 		$setting  = $response->get_data();
758
-		$this->assertEquals( 'text', $setting['type'] );
758
+		$this->assertEquals('text', $setting['type']);
759 759
 
760 760
 		// Repalce the old value with something uniquely new
761 761
 		$old_value = $setting['value'];
762
-		$new_value = $old_value . ' ' . rand( 1000, 9999 );
763
-		$request   = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address' );
762
+		$new_value = $old_value . ' ' . rand(1000, 9999);
763
+		$request   = new WP_REST_Request('PUT', '/wc/v2/settings/general/woocommerce_store_address');
764 764
 		$request->set_body_params(
765 765
 			array(
766 766
 				'value' => $new_value,
767 767
 			)
768 768
 		);
769
-		$response = $this->server->dispatch( $request );
769
+		$response = $this->server->dispatch($request);
770 770
 		$setting  = $response->get_data();
771
-		$this->assertEquals( $new_value, $setting['value'] );
771
+		$this->assertEquals($new_value, $setting['value']);
772 772
 
773 773
 		// Put the original value back
774
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address' );
774
+		$request = new WP_REST_Request('PUT', '/wc/v2/settings/general/woocommerce_store_address');
775 775
 		$request->set_body_params(
776 776
 			array(
777 777
 				'value' => $old_value,
778 778
 			)
779 779
 		);
780
-		$response = $this->server->dispatch( $request );
780
+		$response = $this->server->dispatch($request);
781 781
 		$setting  = $response->get_data();
782
-		$this->assertEquals( $old_value, $setting['value'] );
782
+		$this->assertEquals($old_value, $setting['value']);
783 783
 	}
784 784
 
785 785
 	/**
@@ -788,34 +788,34 @@  discard block
 block discarded – undo
788 788
 	 * @since 3.1.1
789 789
 	 */
790 790
 	public function test_woocommerce_store_address_2() {
791
-		wp_set_current_user( $this->user );
792
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_store_address_2' ) );
791
+		wp_set_current_user($this->user);
792
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/general/woocommerce_store_address_2'));
793 793
 		$setting  = $response->get_data();
794
-		$this->assertEquals( 'text', $setting['type'] );
794
+		$this->assertEquals('text', $setting['type']);
795 795
 
796 796
 		// Repalce the old value with something uniquely new
797 797
 		$old_value = $setting['value'];
798
-		$new_value = $old_value . ' ' . rand( 1000, 9999 );
799
-		$request   = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address_2' );
798
+		$new_value = $old_value . ' ' . rand(1000, 9999);
799
+		$request   = new WP_REST_Request('PUT', '/wc/v2/settings/general/woocommerce_store_address_2');
800 800
 		$request->set_body_params(
801 801
 			array(
802 802
 				'value' => $new_value,
803 803
 			)
804 804
 		);
805
-		$response = $this->server->dispatch( $request );
805
+		$response = $this->server->dispatch($request);
806 806
 		$setting  = $response->get_data();
807
-		$this->assertEquals( $new_value, $setting['value'] );
807
+		$this->assertEquals($new_value, $setting['value']);
808 808
 
809 809
 		// Put the original value back
810
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_address_2' );
810
+		$request = new WP_REST_Request('PUT', '/wc/v2/settings/general/woocommerce_store_address_2');
811 811
 		$request->set_body_params(
812 812
 			array(
813 813
 				'value' => $old_value,
814 814
 			)
815 815
 		);
816
-		$response = $this->server->dispatch( $request );
816
+		$response = $this->server->dispatch($request);
817 817
 		$setting  = $response->get_data();
818
-		$this->assertEquals( $old_value, $setting['value'] );
818
+		$this->assertEquals($old_value, $setting['value']);
819 819
 	}
820 820
 
821 821
 	/**
@@ -824,34 +824,34 @@  discard block
 block discarded – undo
824 824
 	 * @since 3.1.1
825 825
 	 */
826 826
 	public function test_woocommerce_store_city() {
827
-		wp_set_current_user( $this->user );
828
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_store_city' ) );
827
+		wp_set_current_user($this->user);
828
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/general/woocommerce_store_city'));
829 829
 		$setting  = $response->get_data();
830
-		$this->assertEquals( 'text', $setting['type'] );
830
+		$this->assertEquals('text', $setting['type']);
831 831
 
832 832
 		// Repalce the old value with something uniquely new
833 833
 		$old_value = $setting['value'];
834
-		$new_value = $old_value . ' ' . rand( 1000, 9999 );
835
-		$request   = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_city' );
834
+		$new_value = $old_value . ' ' . rand(1000, 9999);
835
+		$request   = new WP_REST_Request('PUT', '/wc/v2/settings/general/woocommerce_store_city');
836 836
 		$request->set_body_params(
837 837
 			array(
838 838
 				'value' => $new_value,
839 839
 			)
840 840
 		);
841
-		$response = $this->server->dispatch( $request );
841
+		$response = $this->server->dispatch($request);
842 842
 		$setting  = $response->get_data();
843
-		$this->assertEquals( $new_value, $setting['value'] );
843
+		$this->assertEquals($new_value, $setting['value']);
844 844
 
845 845
 		// Put the original value back
846
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_city' );
846
+		$request = new WP_REST_Request('PUT', '/wc/v2/settings/general/woocommerce_store_city');
847 847
 		$request->set_body_params(
848 848
 			array(
849 849
 				'value' => $old_value,
850 850
 			)
851 851
 		);
852
-		$response = $this->server->dispatch( $request );
852
+		$response = $this->server->dispatch($request);
853 853
 		$setting  = $response->get_data();
854
-		$this->assertEquals( $old_value, $setting['value'] );
854
+		$this->assertEquals($old_value, $setting['value']);
855 855
 	}
856 856
 
857 857
 	/**
@@ -860,33 +860,33 @@  discard block
 block discarded – undo
860 860
 	 * @since 3.1.1
861 861
 	 */
862 862
 	public function test_woocommerce_store_postcode() {
863
-		wp_set_current_user( $this->user );
864
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general/woocommerce_store_postcode' ) );
863
+		wp_set_current_user($this->user);
864
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/settings/general/woocommerce_store_postcode'));
865 865
 		$setting  = $response->get_data();
866
-		$this->assertEquals( 'text', $setting['type'] );
866
+		$this->assertEquals('text', $setting['type']);
867 867
 
868 868
 		// Repalce the old value with something uniquely new
869 869
 		$old_value = $setting['value'];
870
-		$new_value = $old_value . ' ' . rand( 1000, 9999 );
871
-		$request   = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_postcode' );
870
+		$new_value = $old_value . ' ' . rand(1000, 9999);
871
+		$request   = new WP_REST_Request('PUT', '/wc/v2/settings/general/woocommerce_store_postcode');
872 872
 		$request->set_body_params(
873 873
 			array(
874 874
 				'value' => $new_value,
875 875
 			)
876 876
 		);
877
-		$response = $this->server->dispatch( $request );
877
+		$response = $this->server->dispatch($request);
878 878
 		$setting  = $response->get_data();
879
-		$this->assertEquals( $new_value, $setting['value'] );
879
+		$this->assertEquals($new_value, $setting['value']);
880 880
 
881 881
 		// Put the original value back
882
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/settings/general/woocommerce_store_postcode' );
882
+		$request = new WP_REST_Request('PUT', '/wc/v2/settings/general/woocommerce_store_postcode');
883 883
 		$request->set_body_params(
884 884
 			array(
885 885
 				'value' => $old_value,
886 886
 			)
887 887
 		);
888
-		$response = $this->server->dispatch( $request );
888
+		$response = $this->server->dispatch($request);
889 889
 		$setting  = $response->get_data();
890
-		$this->assertEquals( $old_value, $setting['value'] );
890
+		$this->assertEquals($old_value, $setting['value']);
891 891
 	}
892 892
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version2/product-variations.php 1 patch
Spacing   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
 	 */
29 29
 	public function test_register_routes() {
30 30
 		$routes = $this->server->get_routes();
31
-		$this->assertArrayHasKey( '/wc/v2/products/(?P<product_id>[\d]+)/variations', $routes );
32
-		$this->assertArrayHasKey( '/wc/v2/products/(?P<product_id>[\d]+)/variations/(?P<id>[\d]+)', $routes );
33
-		$this->assertArrayHasKey( '/wc/v2/products/(?P<product_id>[\d]+)/variations/batch', $routes );
31
+		$this->assertArrayHasKey('/wc/v2/products/(?P<product_id>[\d]+)/variations', $routes);
32
+		$this->assertArrayHasKey('/wc/v2/products/(?P<product_id>[\d]+)/variations/(?P<id>[\d]+)', $routes);
33
+		$this->assertArrayHasKey('/wc/v2/products/(?P<product_id>[\d]+)/variations/batch', $routes);
34 34
 	}
35 35
 
36 36
 	/**
@@ -39,14 +39,14 @@  discard block
 block discarded – undo
39 39
 	 * @since 3.0.0
40 40
 	 */
41 41
 	public function test_get_variations() {
42
-		wp_set_current_user( $this->user );
42
+		wp_set_current_user($this->user);
43 43
 		$product    = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
44
-		$response   = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations' ) );
44
+		$response   = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products/' . $product->get_id() . '/variations'));
45 45
 		$variations = $response->get_data();
46
-		$this->assertEquals( 200, $response->get_status() );
47
-		$this->assertEquals( 2, count( $variations ) );
48
-		$this->assertEquals( 'DUMMY SKU VARIABLE LARGE', $variations[0]['sku'] );
49
-		$this->assertEquals( 'size', $variations[0]['attributes'][0]['name'] );
46
+		$this->assertEquals(200, $response->get_status());
47
+		$this->assertEquals(2, count($variations));
48
+		$this->assertEquals('DUMMY SKU VARIABLE LARGE', $variations[0]['sku']);
49
+		$this->assertEquals('size', $variations[0]['attributes'][0]['name']);
50 50
 	}
51 51
 
52 52
 	/**
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
 	 * @since 3.0.0
56 56
 	 */
57 57
 	public function test_get_variations_without_permission() {
58
-		wp_set_current_user( 0 );
58
+		wp_set_current_user(0);
59 59
 		$product  = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
60
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations' ) );
61
-		$this->assertEquals( 401, $response->get_status() );
60
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products/' . $product->get_id() . '/variations'));
61
+		$this->assertEquals(401, $response->get_status());
62 62
 	}
63 63
 
64 64
 	/**
@@ -67,17 +67,17 @@  discard block
 block discarded – undo
67 67
 	 * @since 3.0.0
68 68
 	 */
69 69
 	public function test_get_variation() {
70
-		wp_set_current_user( $this->user );
70
+		wp_set_current_user($this->user);
71 71
 		$product      = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
72 72
 		$children     = $product->get_children();
73 73
 		$variation_id = $children[0];
74 74
 
75
-		$response  = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id ) );
75
+		$response  = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id));
76 76
 		$variation = $response->get_data();
77 77
 
78
-		$this->assertEquals( 200, $response->get_status() );
79
-		$this->assertEquals( $variation_id, $variation['id'] );
80
-		$this->assertEquals( 'size', $variation['attributes'][0]['name'] );
78
+		$this->assertEquals(200, $response->get_status());
79
+		$this->assertEquals($variation_id, $variation['id']);
80
+		$this->assertEquals('size', $variation['attributes'][0]['name']);
81 81
 	}
82 82
 
83 83
 	/**
@@ -86,12 +86,12 @@  discard block
 block discarded – undo
86 86
 	 * @since 3.0.0
87 87
 	 */
88 88
 	public function test_get_variation_without_permission() {
89
-		wp_set_current_user( 0 );
89
+		wp_set_current_user(0);
90 90
 		$product      = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
91 91
 		$children     = $product->get_children();
92 92
 		$variation_id = $children[0];
93
-		$response     = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id ) );
94
-		$this->assertEquals( 401, $response->get_status() );
93
+		$response     = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id));
94
+		$this->assertEquals(401, $response->get_status());
95 95
 	}
96 96
 
97 97
 	/**
@@ -100,19 +100,19 @@  discard block
 block discarded – undo
100 100
 	 * @since 3.0.0
101 101
 	 */
102 102
 	public function test_delete_variation() {
103
-		wp_set_current_user( $this->user );
103
+		wp_set_current_user($this->user);
104 104
 		$product      = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
105 105
 		$children     = $product->get_children();
106 106
 		$variation_id = $children[0];
107 107
 
108
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id );
109
-		$request->set_param( 'force', true );
110
-		$response = $this->server->dispatch( $request );
111
-		$this->assertEquals( 200, $response->get_status() );
108
+		$request = new WP_REST_Request('DELETE', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id);
109
+		$request->set_param('force', true);
110
+		$response = $this->server->dispatch($request);
111
+		$this->assertEquals(200, $response->get_status());
112 112
 
113
-		$response   = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations' ) );
113
+		$response   = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products/' . $product->get_id() . '/variations'));
114 114
 		$variations = $response->get_data();
115
-		$this->assertEquals( 1, count( $variations ) );
115
+		$this->assertEquals(1, count($variations));
116 116
 	}
117 117
 
118 118
 	/**
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
 	 * @since 3.0.0
122 122
 	 */
123 123
 	public function test_delete_variation_without_permission() {
124
-		wp_set_current_user( 0 );
124
+		wp_set_current_user(0);
125 125
 		$product      = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
126 126
 		$children     = $product->get_children();
127 127
 		$variation_id = $children[0];
128 128
 
129
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id );
130
-		$request->set_param( 'force', true );
131
-		$response = $this->server->dispatch( $request );
132
-		$this->assertEquals( 401, $response->get_status() );
129
+		$request = new WP_REST_Request('DELETE', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id);
130
+		$request->set_param('force', true);
131
+		$response = $this->server->dispatch($request);
132
+		$this->assertEquals(401, $response->get_status());
133 133
 	}
134 134
 
135 135
 	/**
@@ -138,12 +138,12 @@  discard block
 block discarded – undo
138 138
 	 * @since 3.0.0
139 139
 	 */
140 140
 	public function test_delete_variation_with_invalid_id() {
141
-		wp_set_current_user( 0 );
141
+		wp_set_current_user(0);
142 142
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
143
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/products/' . $product->get_id() . '/variations/0' );
144
-		$request->set_param( 'force', true );
145
-		$response = $this->server->dispatch( $request );
146
-		$this->assertEquals( 404, $response->get_status() );
143
+		$request = new WP_REST_Request('DELETE', '/wc/v2/products/' . $product->get_id() . '/variations/0');
144
+		$request->set_param('force', true);
145
+		$response = $this->server->dispatch($request);
146
+		$this->assertEquals(404, $response->get_status());
147 147
 	}
148 148
 
149 149
 	/**
@@ -152,20 +152,20 @@  discard block
 block discarded – undo
152 152
 	 * @since 3.0.0
153 153
 	 */
154 154
 	public function test_update_variation() {
155
-		wp_set_current_user( $this->user );
155
+		wp_set_current_user($this->user);
156 156
 		$product      = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
157 157
 		$children     = $product->get_children();
158 158
 		$variation_id = $children[0];
159 159
 
160
-		$response  = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id ) );
160
+		$response  = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id));
161 161
 		$variation = $response->get_data();
162 162
 
163
-		$this->assertEquals( 'DUMMY SKU VARIABLE SMALL', $variation['sku'] );
164
-		$this->assertEquals( 10, $variation['regular_price'] );
165
-		$this->assertEmpty( $variation['sale_price'] );
166
-		$this->assertEquals( 'small', $variation['attributes'][0]['option'] );
163
+		$this->assertEquals('DUMMY SKU VARIABLE SMALL', $variation['sku']);
164
+		$this->assertEquals(10, $variation['regular_price']);
165
+		$this->assertEmpty($variation['sale_price']);
166
+		$this->assertEquals('small', $variation['attributes'][0]['option']);
167 167
 
168
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id );
168
+		$request = new WP_REST_Request('PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id);
169 169
 		$request->set_body_params(
170 170
 			array(
171 171
 				'sku'         => 'FIXED-SKU',
@@ -184,18 +184,18 @@  discard block
 block discarded – undo
184 184
 				),
185 185
 			)
186 186
 		);
187
-		$response  = $this->server->dispatch( $request );
187
+		$response  = $this->server->dispatch($request);
188 188
 		$variation = $response->get_data();
189 189
 
190
-		$this->assertTrue( isset( $variation['description'] ), print_r( $variation, true ) );
191
-		$this->assertContains( 'O_O', $variation['description'], print_r( $variation, true ) );
192
-		$this->assertEquals( '8', $variation['price'], print_r( $variation, true ) );
193
-		$this->assertEquals( '8', $variation['sale_price'], print_r( $variation, true ) );
194
-		$this->assertEquals( '10', $variation['regular_price'], print_r( $variation, true ) );
195
-		$this->assertEquals( 'FIXED-SKU', $variation['sku'], print_r( $variation, true ) );
196
-		$this->assertEquals( 'medium', $variation['attributes'][0]['option'], print_r( $variation, true ) );
197
-		$this->assertContains( 'Dr1Bczxq4q', $variation['image']['src'], print_r( $variation, true ) );
198
-		$this->assertContains( 'test upload image', $variation['image']['alt'], print_r( $variation, true ) );
190
+		$this->assertTrue(isset($variation['description']), print_r($variation, true));
191
+		$this->assertContains('O_O', $variation['description'], print_r($variation, true));
192
+		$this->assertEquals('8', $variation['price'], print_r($variation, true));
193
+		$this->assertEquals('8', $variation['sale_price'], print_r($variation, true));
194
+		$this->assertEquals('10', $variation['regular_price'], print_r($variation, true));
195
+		$this->assertEquals('FIXED-SKU', $variation['sku'], print_r($variation, true));
196
+		$this->assertEquals('medium', $variation['attributes'][0]['option'], print_r($variation, true));
197
+		$this->assertContains('Dr1Bczxq4q', $variation['image']['src'], print_r($variation, true));
198
+		$this->assertContains('test upload image', $variation['image']['alt'], print_r($variation, true));
199 199
 	}
200 200
 
201 201
 	/**
@@ -204,19 +204,19 @@  discard block
 block discarded – undo
204 204
 	 * @since 3.0.0
205 205
 	 */
206 206
 	public function test_update_variation_without_permission() {
207
-		wp_set_current_user( 0 );
207
+		wp_set_current_user(0);
208 208
 		$product      = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
209 209
 		$children     = $product->get_children();
210 210
 		$variation_id = $children[0];
211 211
 
212
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id );
212
+		$request = new WP_REST_Request('PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id);
213 213
 		$request->set_body_params(
214 214
 			array(
215 215
 				'sku' => 'FIXED-SKU-NO-PERMISSION',
216 216
 			)
217 217
 		);
218
-		$response = $this->server->dispatch( $request );
219
-		$this->assertEquals( 401, $response->get_status() );
218
+		$response = $this->server->dispatch($request);
219
+		$this->assertEquals(401, $response->get_status());
220 220
 	}
221 221
 
222 222
 	/**
@@ -225,16 +225,16 @@  discard block
 block discarded – undo
225 225
 	 * @since 3.0.0
226 226
 	 */
227 227
 	public function test_update_variation_with_invalid_id() {
228
-		wp_set_current_user( $this->user );
228
+		wp_set_current_user($this->user);
229 229
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
230
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() . '/variations/0' );
230
+		$request = new WP_REST_Request('PUT', '/wc/v2/products/' . $product->get_id() . '/variations/0');
231 231
 		$request->set_body_params(
232 232
 			array(
233 233
 				'sku' => 'FIXED-SKU-NO-PERMISSION',
234 234
 			)
235 235
 		);
236
-		$response = $this->server->dispatch( $request );
237
-		$this->assertEquals( 400, $response->get_status() );
236
+		$response = $this->server->dispatch($request);
237
+		$this->assertEquals(400, $response->get_status());
238 238
 	}
239 239
 
240 240
 	/**
@@ -243,14 +243,14 @@  discard block
 block discarded – undo
243 243
 	 * @since 3.0.0
244 244
 	 */
245 245
 	public function test_create_variation() {
246
-		wp_set_current_user( $this->user );
246
+		wp_set_current_user($this->user);
247 247
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
248 248
 
249
-		$response   = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations' ) );
249
+		$response   = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products/' . $product->get_id() . '/variations'));
250 250
 		$variations = $response->get_data();
251
-		$this->assertEquals( 2, count( $variations ) );
251
+		$this->assertEquals(2, count($variations));
252 252
 
253
-		$request = new WP_REST_Request( 'POST', '/wc/v2/products/' . $product->get_id() . '/variations' );
253
+		$request = new WP_REST_Request('POST', '/wc/v2/products/' . $product->get_id() . '/variations');
254 254
 		$request->set_body_params(
255 255
 			array(
256 256
 				'sku'           => 'DUMMY SKU VARIABLE MEDIUM',
@@ -264,19 +264,19 @@  discard block
 block discarded – undo
264 264
 				),
265 265
 			)
266 266
 		);
267
-		$response  = $this->server->dispatch( $request );
267
+		$response  = $this->server->dispatch($request);
268 268
 		$variation = $response->get_data();
269 269
 
270
-		$this->assertContains( 'A medium size.', $variation['description'] );
271
-		$this->assertEquals( '12', $variation['price'] );
272
-		$this->assertEquals( '12', $variation['regular_price'] );
273
-		$this->assertTrue( $variation['purchasable'] );
274
-		$this->assertEquals( 'DUMMY SKU VARIABLE MEDIUM', $variation['sku'] );
275
-		$this->assertEquals( 'medium', $variation['attributes'][0]['option'] );
270
+		$this->assertContains('A medium size.', $variation['description']);
271
+		$this->assertEquals('12', $variation['price']);
272
+		$this->assertEquals('12', $variation['regular_price']);
273
+		$this->assertTrue($variation['purchasable']);
274
+		$this->assertEquals('DUMMY SKU VARIABLE MEDIUM', $variation['sku']);
275
+		$this->assertEquals('medium', $variation['attributes'][0]['option']);
276 276
 
277
-		$response   = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations' ) );
277
+		$response   = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products/' . $product->get_id() . '/variations'));
278 278
 		$variations = $response->get_data();
279
-		$this->assertEquals( 3, count( $variations ) );
279
+		$this->assertEquals(3, count($variations));
280 280
 	}
281 281
 
282 282
 	/**
@@ -285,10 +285,10 @@  discard block
 block discarded – undo
285 285
 	 * @since 3.0.0
286 286
 	 */
287 287
 	public function test_create_variation_without_permission() {
288
-		wp_set_current_user( 0 );
288
+		wp_set_current_user(0);
289 289
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
290 290
 
291
-		$request = new WP_REST_Request( 'POST', '/wc/v2/products/' . $product->get_id() . '/variations' );
291
+		$request = new WP_REST_Request('POST', '/wc/v2/products/' . $product->get_id() . '/variations');
292 292
 		$request->set_body_params(
293 293
 			array(
294 294
 				'sku'           => 'DUMMY SKU VARIABLE MEDIUM',
@@ -302,18 +302,18 @@  discard block
 block discarded – undo
302 302
 				),
303 303
 			)
304 304
 		);
305
-		$response = $this->server->dispatch( $request );
306
-		$this->assertEquals( 401, $response->get_status() );
305
+		$response = $this->server->dispatch($request);
306
+		$this->assertEquals(401, $response->get_status());
307 307
 	}
308 308
 
309 309
 	/**
310 310
 	 * Test batch managing product variations.
311 311
 	 */
312 312
 	public function test_product_variations_batch() {
313
-		wp_set_current_user( $this->user );
313
+		wp_set_current_user($this->user);
314 314
 		$product  = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
315 315
 		$children = $product->get_children();
316
-		$request  = new WP_REST_Request( 'POST', '/wc/v2/products/' . $product->get_id() . '/variations/batch' );
316
+		$request  = new WP_REST_Request('POST', '/wc/v2/products/' . $product->get_id() . '/variations/batch');
317 317
 		$request->set_body_params(
318 318
 			array(
319 319
 				'update' => array(
@@ -345,19 +345,19 @@  discard block
 block discarded – undo
345 345
 				),
346 346
 			)
347 347
 		);
348
-		$response = $this->server->dispatch( $request );
348
+		$response = $this->server->dispatch($request);
349 349
 		$data     = $response->get_data();
350 350
 
351
-		$this->assertContains( 'Updated description.', $data['update'][0]['description'] );
352
-		$this->assertEquals( 'DUMMY SKU VARIABLE MEDIUM', $data['create'][0]['sku'] );
353
-		$this->assertEquals( 'medium', $data['create'][0]['attributes'][0]['option'] );
354
-		$this->assertEquals( $children[1], $data['delete'][0]['id'] );
351
+		$this->assertContains('Updated description.', $data['update'][0]['description']);
352
+		$this->assertEquals('DUMMY SKU VARIABLE MEDIUM', $data['create'][0]['sku']);
353
+		$this->assertEquals('medium', $data['create'][0]['attributes'][0]['option']);
354
+		$this->assertEquals($children[1], $data['delete'][0]['id']);
355 355
 
356
-		$request  = new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() . '/variations' );
357
-		$response = $this->server->dispatch( $request );
356
+		$request  = new WP_REST_Request('GET', '/wc/v2/products/' . $product->get_id() . '/variations');
357
+		$response = $this->server->dispatch($request);
358 358
 		$data     = $response->get_data();
359 359
 
360
-		$this->assertEquals( 2, count( $data ) );
360
+		$this->assertEquals(2, count($data));
361 361
 	}
362 362
 
363 363
 	/**
@@ -366,49 +366,49 @@  discard block
 block discarded – undo
366 366
 	 * @since 3.0.0
367 367
 	 */
368 368
 	public function test_variation_schema() {
369
-		wp_set_current_user( $this->user );
369
+		wp_set_current_user($this->user);
370 370
 		$product    = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
371
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v2/products/' . $product->get_id() . '/variations' );
372
-		$response   = $this->server->dispatch( $request );
371
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v2/products/' . $product->get_id() . '/variations');
372
+		$response   = $this->server->dispatch($request);
373 373
 		$data       = $response->get_data();
374 374
 		$properties = $data['schema']['properties'];
375 375
 
376
-		$this->assertEquals( 37, count( $properties ) );
377
-		$this->assertArrayHasKey( 'id', $properties );
378
-		$this->assertArrayHasKey( 'date_created', $properties );
379
-		$this->assertArrayHasKey( 'date_modified', $properties );
380
-		$this->assertArrayHasKey( 'description', $properties );
381
-		$this->assertArrayHasKey( 'permalink', $properties );
382
-		$this->assertArrayHasKey( 'sku', $properties );
383
-		$this->assertArrayHasKey( 'price', $properties );
384
-		$this->assertArrayHasKey( 'regular_price', $properties );
385
-		$this->assertArrayHasKey( 'sale_price', $properties );
386
-		$this->assertArrayHasKey( 'date_on_sale_from', $properties );
387
-		$this->assertArrayHasKey( 'date_on_sale_to', $properties );
388
-		$this->assertArrayHasKey( 'on_sale', $properties );
389
-		$this->assertArrayHasKey( 'visible', $properties );
390
-		$this->assertArrayHasKey( 'purchasable', $properties );
391
-		$this->assertArrayHasKey( 'virtual', $properties );
392
-		$this->assertArrayHasKey( 'downloadable', $properties );
393
-		$this->assertArrayHasKey( 'downloads', $properties );
394
-		$this->assertArrayHasKey( 'download_limit', $properties );
395
-		$this->assertArrayHasKey( 'download_expiry', $properties );
396
-		$this->assertArrayHasKey( 'tax_status', $properties );
397
-		$this->assertArrayHasKey( 'tax_class', $properties );
398
-		$this->assertArrayHasKey( 'manage_stock', $properties );
399
-		$this->assertArrayHasKey( 'stock_quantity', $properties );
400
-		$this->assertArrayHasKey( 'in_stock', $properties );
401
-		$this->assertArrayHasKey( 'backorders', $properties );
402
-		$this->assertArrayHasKey( 'backorders_allowed', $properties );
403
-		$this->assertArrayHasKey( 'backordered', $properties );
404
-		$this->assertArrayHasKey( 'weight', $properties );
405
-		$this->assertArrayHasKey( 'dimensions', $properties );
406
-		$this->assertArrayHasKey( 'shipping_class', $properties );
407
-		$this->assertArrayHasKey( 'shipping_class_id', $properties );
408
-		$this->assertArrayHasKey( 'image', $properties );
409
-		$this->assertArrayHasKey( 'attributes', $properties );
410
-		$this->assertArrayHasKey( 'menu_order', $properties );
411
-		$this->assertArrayHasKey( 'meta_data', $properties );
376
+		$this->assertEquals(37, count($properties));
377
+		$this->assertArrayHasKey('id', $properties);
378
+		$this->assertArrayHasKey('date_created', $properties);
379
+		$this->assertArrayHasKey('date_modified', $properties);
380
+		$this->assertArrayHasKey('description', $properties);
381
+		$this->assertArrayHasKey('permalink', $properties);
382
+		$this->assertArrayHasKey('sku', $properties);
383
+		$this->assertArrayHasKey('price', $properties);
384
+		$this->assertArrayHasKey('regular_price', $properties);
385
+		$this->assertArrayHasKey('sale_price', $properties);
386
+		$this->assertArrayHasKey('date_on_sale_from', $properties);
387
+		$this->assertArrayHasKey('date_on_sale_to', $properties);
388
+		$this->assertArrayHasKey('on_sale', $properties);
389
+		$this->assertArrayHasKey('visible', $properties);
390
+		$this->assertArrayHasKey('purchasable', $properties);
391
+		$this->assertArrayHasKey('virtual', $properties);
392
+		$this->assertArrayHasKey('downloadable', $properties);
393
+		$this->assertArrayHasKey('downloads', $properties);
394
+		$this->assertArrayHasKey('download_limit', $properties);
395
+		$this->assertArrayHasKey('download_expiry', $properties);
396
+		$this->assertArrayHasKey('tax_status', $properties);
397
+		$this->assertArrayHasKey('tax_class', $properties);
398
+		$this->assertArrayHasKey('manage_stock', $properties);
399
+		$this->assertArrayHasKey('stock_quantity', $properties);
400
+		$this->assertArrayHasKey('in_stock', $properties);
401
+		$this->assertArrayHasKey('backorders', $properties);
402
+		$this->assertArrayHasKey('backorders_allowed', $properties);
403
+		$this->assertArrayHasKey('backordered', $properties);
404
+		$this->assertArrayHasKey('weight', $properties);
405
+		$this->assertArrayHasKey('dimensions', $properties);
406
+		$this->assertArrayHasKey('shipping_class', $properties);
407
+		$this->assertArrayHasKey('shipping_class_id', $properties);
408
+		$this->assertArrayHasKey('image', $properties);
409
+		$this->assertArrayHasKey('attributes', $properties);
410
+		$this->assertArrayHasKey('menu_order', $properties);
411
+		$this->assertArrayHasKey('meta_data', $properties);
412 412
 	}
413 413
 
414 414
 	/**
@@ -417,57 +417,57 @@  discard block
 block discarded – undo
417 417
 	 * @since 3.0.0
418 418
 	 */
419 419
 	public function test_update_variation_manage_stock() {
420
-		wp_set_current_user( $this->user );
420
+		wp_set_current_user($this->user);
421 421
 
422 422
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
423
-		$product->set_manage_stock( false );
423
+		$product->set_manage_stock(false);
424 424
 		$product->save();
425 425
 
426 426
 		$children     = $product->get_children();
427 427
 		$variation_id = $children[0];
428 428
 
429 429
 		// Set stock to true.
430
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id );
430
+		$request = new WP_REST_Request('PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id);
431 431
 		$request->set_body_params(
432 432
 			array(
433 433
 				'manage_stock' => true,
434 434
 			)
435 435
 		);
436 436
 
437
-		$response  = $this->server->dispatch( $request );
437
+		$response  = $this->server->dispatch($request);
438 438
 		$variation = $response->get_data();
439 439
 
440
-		$this->assertEquals( 200, $response->get_status() );
441
-		$this->assertEquals( true, $variation['manage_stock'] );
440
+		$this->assertEquals(200, $response->get_status());
441
+		$this->assertEquals(true, $variation['manage_stock']);
442 442
 
443 443
 		// Set stock to false.
444
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id );
444
+		$request = new WP_REST_Request('PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id);
445 445
 		$request->set_body_params(
446 446
 			array(
447 447
 				'manage_stock' => false,
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( false, $variation['manage_stock'] );
454
+		$this->assertEquals(200, $response->get_status());
455
+		$this->assertEquals(false, $variation['manage_stock']);
456 456
 
457 457
 		// Set stock to false but parent is managing stock.
458
-		$product->set_manage_stock( true );
458
+		$product->set_manage_stock(true);
459 459
 		$product->save();
460
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id );
460
+		$request = new WP_REST_Request('PUT', '/wc/v2/products/' . $product->get_id() . '/variations/' . $variation_id);
461 461
 		$request->set_body_params(
462 462
 			array(
463 463
 				'manage_stock' => false,
464 464
 			)
465 465
 		);
466 466
 
467
-		$response  = $this->server->dispatch( $request );
467
+		$response  = $this->server->dispatch($request);
468 468
 		$variation = $response->get_data();
469 469
 
470
-		$this->assertEquals( 200, $response->get_status() );
471
-		$this->assertEquals( 'parent', $variation['manage_stock'] );
470
+		$this->assertEquals(200, $response->get_status());
471
+		$this->assertEquals('parent', $variation['manage_stock']);
472 472
 	}
473 473
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version2/coupons.php 1 patch
Spacing   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
 	 */
29 29
 	public function test_register_routes() {
30 30
 		$routes = $this->server->get_routes();
31
-		$this->assertArrayHasKey( '/wc/v2/coupons', $routes );
32
-		$this->assertArrayHasKey( '/wc/v2/coupons/(?P<id>[\d]+)', $routes );
33
-		$this->assertArrayHasKey( '/wc/v2/coupons/batch', $routes );
31
+		$this->assertArrayHasKey('/wc/v2/coupons', $routes);
32
+		$this->assertArrayHasKey('/wc/v2/coupons/(?P<id>[\d]+)', $routes);
33
+		$this->assertArrayHasKey('/wc/v2/coupons/batch', $routes);
34 34
 	}
35 35
 
36 36
 	/**
@@ -38,26 +38,26 @@  discard block
 block discarded – undo
38 38
 	 * @since 3.0.0
39 39
 	 */
40 40
 	public function test_get_coupons() {
41
-		wp_set_current_user( $this->user );
41
+		wp_set_current_user($this->user);
42 42
 
43
-		$coupon_1 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' );
44
-		$post_1   = get_post( $coupon_1->get_id() );
45
-		$coupon_2 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-2' );
43
+		$coupon_1 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1');
44
+		$post_1   = get_post($coupon_1->get_id());
45
+		$coupon_2 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-2');
46 46
 
47
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons' ) );
47
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/coupons'));
48 48
 		$coupons  = $response->get_data();
49 49
 
50
-		$this->assertEquals( 200, $response->get_status() );
51
-		$this->assertEquals( 2, count( $coupons ) );
50
+		$this->assertEquals(200, $response->get_status());
51
+		$this->assertEquals(2, count($coupons));
52 52
 		$this->assertContains(
53 53
 			array(
54 54
 				'id'                          => $coupon_1->get_id(),
55 55
 				'code'                        => 'dummycoupon-1',
56 56
 				'amount'                      => '1.00',
57
-				'date_created'                => wc_rest_prepare_date_response( $post_1->post_date_gmt, false ),
58
-				'date_created_gmt'            => wc_rest_prepare_date_response( $post_1->post_date_gmt ),
59
-				'date_modified'               => wc_rest_prepare_date_response( $post_1->post_modified_gmt, false ),
60
-				'date_modified_gmt'           => wc_rest_prepare_date_response( $post_1->post_modified_gmt ),
57
+				'date_created'                => wc_rest_prepare_date_response($post_1->post_date_gmt, false),
58
+				'date_created_gmt'            => wc_rest_prepare_date_response($post_1->post_date_gmt),
59
+				'date_modified'               => wc_rest_prepare_date_response($post_1->post_modified_gmt, false),
60
+				'date_modified_gmt'           => wc_rest_prepare_date_response($post_1->post_modified_gmt),
61 61
 				'discount_type'               => 'fixed_cart',
62 62
 				'description'                 => 'This is a dummy coupon',
63 63
 				'date_expires'                => '',
@@ -81,12 +81,12 @@  discard block
 block discarded – undo
81 81
 				'_links'                      => array(
82 82
 					'self'       => array(
83 83
 						array(
84
-							'href' => rest_url( '/wc/v2/coupons/' . $coupon_1->get_id() ),
84
+							'href' => rest_url('/wc/v2/coupons/' . $coupon_1->get_id()),
85 85
 						),
86 86
 					),
87 87
 					'collection' => array(
88 88
 						array(
89
-							'href' => rest_url( '/wc/v2/coupons' ),
89
+							'href' => rest_url('/wc/v2/coupons'),
90 90
 						),
91 91
 					),
92 92
 				),
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
 	 * @since 3.0.0
101 101
 	 */
102 102
 	public function test_get_coupons_without_permission() {
103
-		wp_set_current_user( 0 );
104
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons' ) );
105
-		$this->assertEquals( 401, $response->get_status() );
103
+		wp_set_current_user(0);
104
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/coupons'));
105
+		$this->assertEquals(401, $response->get_status());
106 106
 	}
107 107
 
108 108
 	/**
@@ -110,22 +110,22 @@  discard block
 block discarded – undo
110 110
 	 * @since 3.0.0
111 111
 	 */
112 112
 	public function test_get_coupon() {
113
-		wp_set_current_user( $this->user );
114
-		$coupon   = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' );
115
-		$post     = get_post( $coupon->get_id() );
116
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons/' . $coupon->get_id() ) );
113
+		wp_set_current_user($this->user);
114
+		$coupon   = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1');
115
+		$post     = get_post($coupon->get_id());
116
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/coupons/' . $coupon->get_id()));
117 117
 		$data     = $response->get_data();
118 118
 
119
-		$this->assertEquals( 200, $response->get_status() );
119
+		$this->assertEquals(200, $response->get_status());
120 120
 		$this->assertEquals(
121 121
 			array(
122 122
 				'id'                          => $coupon->get_id(),
123 123
 				'code'                        => 'dummycoupon-1',
124 124
 				'amount'                      => '1.00',
125
-				'date_created'                => wc_rest_prepare_date_response( $post->post_date_gmt, false ),
126
-				'date_created_gmt'            => wc_rest_prepare_date_response( $post->post_date_gmt ),
127
-				'date_modified'               => wc_rest_prepare_date_response( $post->post_modified_gmt, false ),
128
-				'date_modified_gmt'           => wc_rest_prepare_date_response( $post->post_modified_gmt ),
125
+				'date_created'                => wc_rest_prepare_date_response($post->post_date_gmt, false),
126
+				'date_created_gmt'            => wc_rest_prepare_date_response($post->post_date_gmt),
127
+				'date_modified'               => wc_rest_prepare_date_response($post->post_modified_gmt, false),
128
+				'date_modified_gmt'           => wc_rest_prepare_date_response($post->post_modified_gmt),
129 129
 				'discount_type'               => 'fixed_cart',
130 130
 				'description'                 => 'This is a dummy coupon',
131 131
 				'date_expires'                => null,
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 	 * @since 3.0.0
157 157
 	 */
158 158
 	public function test_get_coupon_invalid_id() {
159
-		wp_set_current_user( $this->user );
160
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons/0' ) );
161
-		$this->assertEquals( 404, $response->get_status() );
159
+		wp_set_current_user($this->user);
160
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/coupons/0'));
161
+		$this->assertEquals(404, $response->get_status());
162 162
 	}
163 163
 
164 164
 	/**
@@ -166,10 +166,10 @@  discard block
 block discarded – undo
166 166
 	 * @since 3.0.0
167 167
 	 */
168 168
 	public function test_get_coupon_without_permission() {
169
-		wp_set_current_user( 0 );
170
-		$coupon   = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' );
171
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons/' . $coupon->get_id() ) );
172
-		$this->assertEquals( 401, $response->get_status() );
169
+		wp_set_current_user(0);
170
+		$coupon   = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1');
171
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/coupons/' . $coupon->get_id()));
172
+		$this->assertEquals(401, $response->get_status());
173 173
 	}
174 174
 
175 175
 	/**
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
 	 * @since 3.0.0
178 178
 	 */
179 179
 	public function test_create_coupon() {
180
-		wp_set_current_user( $this->user );
181
-		$request = new WP_REST_Request( 'POST', '/wc/v2/coupons' );
180
+		wp_set_current_user($this->user);
181
+		$request = new WP_REST_Request('POST', '/wc/v2/coupons');
182 182
 		$request->set_body_params(
183 183
 			array(
184 184
 				'code'          => 'test',
@@ -188,10 +188,10 @@  discard block
 block discarded – undo
188 188
 				'usage_limit'   => 10,
189 189
 			)
190 190
 		);
191
-		$response = $this->server->dispatch( $request );
191
+		$response = $this->server->dispatch($request);
192 192
 		$data     = $response->get_data();
193 193
 
194
-		$this->assertEquals( 201, $response->get_status() );
194
+		$this->assertEquals(201, $response->get_status());
195 195
 		$this->assertEquals(
196 196
 			array(
197 197
 				'id'                          => $data['id'],
@@ -231,20 +231,20 @@  discard block
 block discarded – undo
231 231
 	 * @since 3.0.0
232 232
 	 */
233 233
 	public function test_create_coupon_invalid_fields() {
234
-		wp_set_current_user( $this->user );
234
+		wp_set_current_user($this->user);
235 235
 
236 236
 		// test no code...
237
-		$request = new WP_REST_Request( 'POST', '/wc/v2/coupons' );
237
+		$request = new WP_REST_Request('POST', '/wc/v2/coupons');
238 238
 		$request->set_body_params(
239 239
 			array(
240 240
 				'amount'        => '5.00',
241 241
 				'discount_type' => 'fixed_product',
242 242
 			)
243 243
 		);
244
-		$response = $this->server->dispatch( $request );
244
+		$response = $this->server->dispatch($request);
245 245
 		$data     = $response->get_data();
246 246
 
247
-		$this->assertEquals( 400, $response->get_status() );
247
+		$this->assertEquals(400, $response->get_status());
248 248
 	}
249 249
 
250 250
 	/**
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
 	 * @since 3.0.0
253 253
 	 */
254 254
 	public function test_create_coupon_without_permission() {
255
-		wp_set_current_user( 0 );
255
+		wp_set_current_user(0);
256 256
 
257 257
 		// test no code...
258
-		$request = new WP_REST_Request( 'POST', '/wc/v2/coupons' );
258
+		$request = new WP_REST_Request('POST', '/wc/v2/coupons');
259 259
 		$request->set_body_params(
260 260
 			array(
261 261
 				'code'          => 'fail',
@@ -263,10 +263,10 @@  discard block
 block discarded – undo
263 263
 				'discount_type' => 'fixed_product',
264 264
 			)
265 265
 		);
266
-		$response = $this->server->dispatch( $request );
266
+		$response = $this->server->dispatch($request);
267 267
 		$data     = $response->get_data();
268 268
 
269
-		$this->assertEquals( 401, $response->get_status() );
269
+		$this->assertEquals(401, $response->get_status());
270 270
 	}
271 271
 
272 272
 	/**
@@ -274,29 +274,29 @@  discard block
 block discarded – undo
274 274
 	 * @since 3.0.0
275 275
 	 */
276 276
 	public function test_update_coupon() {
277
-		wp_set_current_user( $this->user );
278
-		$coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' );
279
-		$post   = get_post( $coupon->get_id() );
277
+		wp_set_current_user($this->user);
278
+		$coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1');
279
+		$post   = get_post($coupon->get_id());
280 280
 
281
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/coupons/' . $coupon->get_id() ) );
281
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/coupons/' . $coupon->get_id()));
282 282
 		$data     = $response->get_data();
283
-		$this->assertEquals( 'This is a dummy coupon', $data['description'] );
284
-		$this->assertEquals( 'fixed_cart', $data['discount_type'] );
285
-		$this->assertEquals( '1.00', $data['amount'] );
283
+		$this->assertEquals('This is a dummy coupon', $data['description']);
284
+		$this->assertEquals('fixed_cart', $data['discount_type']);
285
+		$this->assertEquals('1.00', $data['amount']);
286 286
 
287
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/' . $coupon->get_id() );
287
+		$request = new WP_REST_Request('PUT', '/wc/v2/coupons/' . $coupon->get_id());
288 288
 		$request->set_body_params(
289 289
 			array(
290 290
 				'amount'      => '10.00',
291 291
 				'description' => 'New description',
292 292
 			)
293 293
 		);
294
-		$response = $this->server->dispatch( $request );
294
+		$response = $this->server->dispatch($request);
295 295
 		$data     = $response->get_data();
296 296
 
297
-		$this->assertEquals( '10.00', $data['amount'] );
298
-		$this->assertEquals( 'New description', $data['description'] );
299
-		$this->assertEquals( 'fixed_cart', $data['discount_type'] );
297
+		$this->assertEquals('10.00', $data['amount']);
298
+		$this->assertEquals('New description', $data['description']);
299
+		$this->assertEquals('fixed_cart', $data['discount_type']);
300 300
 	}
301 301
 
302 302
 	/**
@@ -304,9 +304,9 @@  discard block
 block discarded – undo
304 304
 	 * @since 3.0.0
305 305
 	 */
306 306
 	public function test_update_coupon_invalid_id() {
307
-		wp_set_current_user( $this->user );
307
+		wp_set_current_user($this->user);
308 308
 
309
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/0' );
309
+		$request = new WP_REST_Request('PUT', '/wc/v2/coupons/0');
310 310
 		$request->set_body_params(
311 311
 			array(
312 312
 				'code'        => 'tester',
@@ -314,10 +314,10 @@  discard block
 block discarded – undo
314 314
 				'description' => 'New description',
315 315
 			)
316 316
 		);
317
-		$response = $this->server->dispatch( $request );
317
+		$response = $this->server->dispatch($request);
318 318
 		$data     = $response->get_data();
319 319
 
320
-		$this->assertEquals( 400, $response->get_status() );
320
+		$this->assertEquals(400, $response->get_status());
321 321
 	}
322 322
 
323 323
 	/**
@@ -325,20 +325,20 @@  discard block
 block discarded – undo
325 325
 	 * @since 3.0.0
326 326
 	 */
327 327
 	public function test_update_coupon_without_permission() {
328
-		wp_set_current_user( 0 );
329
-		$coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' );
330
-		$post   = get_post( $coupon->get_id() );
328
+		wp_set_current_user(0);
329
+		$coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1');
330
+		$post   = get_post($coupon->get_id());
331 331
 
332
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/coupons/' . $coupon->get_id() );
332
+		$request = new WP_REST_Request('PUT', '/wc/v2/coupons/' . $coupon->get_id());
333 333
 		$request->set_body_params(
334 334
 			array(
335 335
 				'amount'      => '10.00',
336 336
 				'description' => 'New description',
337 337
 			)
338 338
 		);
339
-		$response = $this->server->dispatch( $request );
339
+		$response = $this->server->dispatch($request);
340 340
 
341
-		$this->assertEquals( 401, $response->get_status() );
341
+		$this->assertEquals(401, $response->get_status());
342 342
 	}
343 343
 
344 344
 	/**
@@ -346,12 +346,12 @@  discard block
 block discarded – undo
346 346
 	 * @since 3.0.0
347 347
 	 */
348 348
 	public function test_delete_coupon() {
349
-		wp_set_current_user( $this->user );
350
-		$coupon  = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' );
351
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/coupons/' . $coupon->get_id() );
352
-		$request->set_param( 'force', true );
353
-		$response = $this->server->dispatch( $request );
354
-		$this->assertEquals( 200, $response->get_status() );
349
+		wp_set_current_user($this->user);
350
+		$coupon  = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1');
351
+		$request = new WP_REST_Request('DELETE', '/wc/v2/coupons/' . $coupon->get_id());
352
+		$request->set_param('force', true);
353
+		$response = $this->server->dispatch($request);
354
+		$this->assertEquals(200, $response->get_status());
355 355
 	}
356 356
 
357 357
 	/**
@@ -359,12 +359,12 @@  discard block
 block discarded – undo
359 359
 	 * @since 3.0.0
360 360
 	 */
361 361
 	public function test_delete_coupon_invalid_id() {
362
-		wp_set_current_user( $this->user );
363
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/coupons/0' );
364
-		$request->set_param( 'force', true );
365
-		$response = $this->server->dispatch( $request );
362
+		wp_set_current_user($this->user);
363
+		$request = new WP_REST_Request('DELETE', '/wc/v2/coupons/0');
364
+		$request->set_param('force', true);
365
+		$response = $this->server->dispatch($request);
366 366
 
367
-		$this->assertEquals( 404, $response->get_status() );
367
+		$this->assertEquals(404, $response->get_status());
368 368
 	}
369 369
 
370 370
 	/**
@@ -372,12 +372,12 @@  discard block
 block discarded – undo
372 372
 	 * @since 3.0.0
373 373
 	 */
374 374
 	public function test_delete_coupon_without_permission() {
375
-		wp_set_current_user( 0 );
376
-		$coupon   = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' );
377
-		$request  = new WP_REST_Request( 'DELETE', '/wc/v2/coupons/' . $coupon->get_id() );
378
-		$response = $this->server->dispatch( $request );
375
+		wp_set_current_user(0);
376
+		$coupon   = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1');
377
+		$request  = new WP_REST_Request('DELETE', '/wc/v2/coupons/' . $coupon->get_id());
378
+		$response = $this->server->dispatch($request);
379 379
 
380
-		$this->assertEquals( 401, $response->get_status() );
380
+		$this->assertEquals(401, $response->get_status());
381 381
 	}
382 382
 
383 383
 	/**
@@ -385,14 +385,14 @@  discard block
 block discarded – undo
385 385
 	 * @since 3.0.0
386 386
 	 */
387 387
 	public function test_batch_coupon() {
388
-		wp_set_current_user( $this->user );
388
+		wp_set_current_user($this->user);
389 389
 
390
-		$coupon_1 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' );
391
-		$coupon_2 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-2' );
392
-		$coupon_3 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-3' );
393
-		$coupon_4 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-4' );
390
+		$coupon_1 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1');
391
+		$coupon_2 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-2');
392
+		$coupon_3 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-3');
393
+		$coupon_4 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-4');
394 394
 
395
-		$request = new WP_REST_Request( 'POST', '/wc/v2/coupons/batch' );
395
+		$request = new WP_REST_Request('POST', '/wc/v2/coupons/batch');
396 396
 		$request->set_body_params(
397 397
 			array(
398 398
 				'update' => array(
@@ -413,20 +413,20 @@  discard block
 block discarded – undo
413 413
 				),
414 414
 			)
415 415
 		);
416
-		$response = $this->server->dispatch( $request );
416
+		$response = $this->server->dispatch($request);
417 417
 		$data     = $response->get_data();
418 418
 
419
-		$this->assertEquals( '5.15', $data['update'][0]['amount'] );
420
-		$this->assertEquals( '11.00', $data['create'][0]['amount'] );
421
-		$this->assertEquals( 'new-coupon', $data['create'][0]['code'] );
422
-		$this->assertEquals( $coupon_2->get_id(), $data['delete'][0]['id'] );
423
-		$this->assertEquals( $coupon_3->get_id(), $data['delete'][1]['id'] );
419
+		$this->assertEquals('5.15', $data['update'][0]['amount']);
420
+		$this->assertEquals('11.00', $data['create'][0]['amount']);
421
+		$this->assertEquals('new-coupon', $data['create'][0]['code']);
422
+		$this->assertEquals($coupon_2->get_id(), $data['delete'][0]['id']);
423
+		$this->assertEquals($coupon_3->get_id(), $data['delete'][1]['id']);
424 424
 
425
-		$request  = new WP_REST_Request( 'GET', '/wc/v2/coupons' );
426
-		$response = $this->server->dispatch( $request );
425
+		$request  = new WP_REST_Request('GET', '/wc/v2/coupons');
426
+		$response = $this->server->dispatch($request);
427 427
 		$data     = $response->get_data();
428 428
 
429
-		$this->assertEquals( 3, count( $data ) );
429
+		$this->assertEquals(3, count($data));
430 430
 	}
431 431
 
432 432
 	/**
@@ -434,38 +434,38 @@  discard block
 block discarded – undo
434 434
 	 * @since 3.0.0
435 435
 	 */
436 436
 	public function test_coupon_schema() {
437
-		wp_set_current_user( $this->user );
438
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v2/coupons' );
439
-		$response   = $this->server->dispatch( $request );
437
+		wp_set_current_user($this->user);
438
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v2/coupons');
439
+		$response   = $this->server->dispatch($request);
440 440
 		$data       = $response->get_data();
441 441
 		$properties = $data['schema']['properties'];
442 442
 
443
-		$this->assertEquals( 27, count( $properties ) );
444
-		$this->assertArrayHasKey( 'id', $properties );
445
-		$this->assertArrayHasKey( 'code', $properties );
446
-		$this->assertArrayHasKey( 'date_created', $properties );
447
-		$this->assertArrayHasKey( 'date_created_gmt', $properties );
448
-		$this->assertArrayHasKey( 'date_modified', $properties );
449
-		$this->assertArrayHasKey( 'date_modified_gmt', $properties );
450
-		$this->assertArrayHasKey( 'description', $properties );
451
-		$this->assertArrayHasKey( 'discount_type', $properties );
452
-		$this->assertArrayHasKey( 'amount', $properties );
453
-		$this->assertArrayHasKey( 'date_expires', $properties );
454
-		$this->assertArrayHasKey( 'date_expires_gmt', $properties );
455
-		$this->assertArrayHasKey( 'usage_count', $properties );
456
-		$this->assertArrayHasKey( 'individual_use', $properties );
457
-		$this->assertArrayHasKey( 'product_ids', $properties );
458
-		$this->assertArrayHasKey( 'excluded_product_ids', $properties );
459
-		$this->assertArrayHasKey( 'usage_limit', $properties );
460
-		$this->assertArrayHasKey( 'usage_limit_per_user', $properties );
461
-		$this->assertArrayHasKey( 'limit_usage_to_x_items', $properties );
462
-		$this->assertArrayHasKey( 'free_shipping', $properties );
463
-		$this->assertArrayHasKey( 'product_categories', $properties );
464
-		$this->assertArrayHasKey( 'excluded_product_categories', $properties );
465
-		$this->assertArrayHasKey( 'exclude_sale_items', $properties );
466
-		$this->assertArrayHasKey( 'minimum_amount', $properties );
467
-		$this->assertArrayHasKey( 'maximum_amount', $properties );
468
-		$this->assertArrayHasKey( 'email_restrictions', $properties );
469
-		$this->assertArrayHasKey( 'used_by', $properties );
443
+		$this->assertEquals(27, count($properties));
444
+		$this->assertArrayHasKey('id', $properties);
445
+		$this->assertArrayHasKey('code', $properties);
446
+		$this->assertArrayHasKey('date_created', $properties);
447
+		$this->assertArrayHasKey('date_created_gmt', $properties);
448
+		$this->assertArrayHasKey('date_modified', $properties);
449
+		$this->assertArrayHasKey('date_modified_gmt', $properties);
450
+		$this->assertArrayHasKey('description', $properties);
451
+		$this->assertArrayHasKey('discount_type', $properties);
452
+		$this->assertArrayHasKey('amount', $properties);
453
+		$this->assertArrayHasKey('date_expires', $properties);
454
+		$this->assertArrayHasKey('date_expires_gmt', $properties);
455
+		$this->assertArrayHasKey('usage_count', $properties);
456
+		$this->assertArrayHasKey('individual_use', $properties);
457
+		$this->assertArrayHasKey('product_ids', $properties);
458
+		$this->assertArrayHasKey('excluded_product_ids', $properties);
459
+		$this->assertArrayHasKey('usage_limit', $properties);
460
+		$this->assertArrayHasKey('usage_limit_per_user', $properties);
461
+		$this->assertArrayHasKey('limit_usage_to_x_items', $properties);
462
+		$this->assertArrayHasKey('free_shipping', $properties);
463
+		$this->assertArrayHasKey('product_categories', $properties);
464
+		$this->assertArrayHasKey('excluded_product_categories', $properties);
465
+		$this->assertArrayHasKey('exclude_sale_items', $properties);
466
+		$this->assertArrayHasKey('minimum_amount', $properties);
467
+		$this->assertArrayHasKey('maximum_amount', $properties);
468
+		$this->assertArrayHasKey('email_restrictions', $properties);
469
+		$this->assertArrayHasKey('used_by', $properties);
470 470
 	}
471 471
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version2/orders.php 1 patch
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 	 */
33 33
 	public function test_register_routes() {
34 34
 		$routes = $this->server->get_routes();
35
-		$this->assertArrayHasKey( '/wc/v2/orders', $routes );
36
-		$this->assertArrayHasKey( '/wc/v2/orders/batch', $routes );
37
-		$this->assertArrayHasKey( '/wc/v2/orders/(?P<id>[\d]+)', $routes );
35
+		$this->assertArrayHasKey('/wc/v2/orders', $routes);
36
+		$this->assertArrayHasKey('/wc/v2/orders/batch', $routes);
37
+		$this->assertArrayHasKey('/wc/v2/orders/(?P<id>[\d]+)', $routes);
38 38
 	}
39 39
 
40 40
 	/**
@@ -42,18 +42,18 @@  discard block
 block discarded – undo
42 42
 	 * @since 3.0.0
43 43
 	 */
44 44
 	public function test_get_items() {
45
-		wp_set_current_user( $this->user );
45
+		wp_set_current_user($this->user);
46 46
 
47 47
 		// Create 10 orders.
48
-		for ( $i = 0; $i < 10; $i++ ) {
49
-			$this->orders[] = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order( $this->user );
48
+		for ($i = 0; $i < 10; $i++) {
49
+			$this->orders[] = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order($this->user);
50 50
 		}
51 51
 
52
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders' ) );
52
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/orders'));
53 53
 		$orders   = $response->get_data();
54 54
 
55
-		$this->assertEquals( 200, $response->get_status() );
56
-		$this->assertEquals( 10, count( $orders ) );
55
+		$this->assertEquals(200, $response->get_status());
56
+		$this->assertEquals(10, count($orders));
57 57
 	}
58 58
 
59 59
 	/**
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
 	 * @since 3.0.0
63 63
 	 */
64 64
 	public function test_get_items_without_permission() {
65
-		wp_set_current_user( 0 );
65
+		wp_set_current_user(0);
66 66
 		$this->orders[] = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
67
-		$response       = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders' ) );
68
-		$this->assertEquals( 401, $response->get_status() );
67
+		$response       = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/orders'));
68
+		$this->assertEquals(401, $response->get_status());
69 69
 	}
70 70
 
71 71
 	/**
@@ -73,23 +73,23 @@  discard block
 block discarded – undo
73 73
 	 * @since 3.0.0
74 74
 	 */
75 75
 	public function test_get_item() {
76
-		wp_set_current_user( $this->user );
76
+		wp_set_current_user($this->user);
77 77
 		$order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
78
-		$order->add_meta_data( 'key', 'value' );
79
-		$order->add_meta_data( 'key2', 'value2' );
78
+		$order->add_meta_data('key', 'value');
79
+		$order->add_meta_data('key2', 'value2');
80 80
 		$order->save();
81 81
 		$this->orders[] = $order;
82
-		$response       = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders/' . $order->get_id() ) );
82
+		$response       = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/orders/' . $order->get_id()));
83 83
 		$data           = $response->get_data();
84 84
 
85
-		$this->assertEquals( 200, $response->get_status() );
86
-		$this->assertEquals( $order->get_id(), $data['id'] );
85
+		$this->assertEquals(200, $response->get_status());
86
+		$this->assertEquals($order->get_id(), $data['id']);
87 87
 
88 88
 		// Test meta data is set.
89
-		$this->assertEquals( 'key', $data['meta_data'][0]->key );
90
-		$this->assertEquals( 'value', $data['meta_data'][0]->value );
91
-		$this->assertEquals( 'key2', $data['meta_data'][1]->key );
92
-		$this->assertEquals( 'value2', $data['meta_data'][1]->value );
89
+		$this->assertEquals('key', $data['meta_data'][0]->key);
90
+		$this->assertEquals('value', $data['meta_data'][0]->value);
91
+		$this->assertEquals('key2', $data['meta_data'][1]->key);
92
+		$this->assertEquals('value2', $data['meta_data'][1]->value);
93 93
 	}
94 94
 
95 95
 	/**
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	 * @since 3.0.0
98 98
 	 */
99 99
 	public function test_get_item_without_permission() {
100
-		wp_set_current_user( 0 );
100
+		wp_set_current_user(0);
101 101
 		$order          = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
102 102
 		$this->orders[] = $order;
103
-		$response       = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders/' . $order->get_id() ) );
104
-		$this->assertEquals( 401, $response->get_status() );
103
+		$response       = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/orders/' . $order->get_id()));
104
+		$this->assertEquals(401, $response->get_status());
105 105
 	}
106 106
 
107 107
 	/**
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
 	 * @since 3.0.0
110 110
 	 */
111 111
 	public function test_get_item_invalid_id() {
112
-		wp_set_current_user( $this->user );
113
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders/99999999' ) );
114
-		$this->assertEquals( 404, $response->get_status() );
112
+		wp_set_current_user($this->user);
113
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/orders/99999999'));
114
+		$this->assertEquals(404, $response->get_status());
115 115
 	}
116 116
 
117 117
 	/**
@@ -119,15 +119,15 @@  discard block
 block discarded – undo
119 119
 	 * @since 3.5.0
120 120
 	 */
121 121
 	public function test_get_item_refund_id() {
122
-		wp_set_current_user( $this->user );
122
+		wp_set_current_user($this->user);
123 123
 		$order    = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
124 124
 		$refund   = wc_create_refund(
125 125
 			array(
126 126
 				'order_id' => $order->get_id(),
127 127
 			)
128 128
 		);
129
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders/' . $refund->get_id() ) );
130
-		$this->assertEquals( 404, $response->get_status() );
129
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/orders/' . $refund->get_id()));
130
+		$this->assertEquals(404, $response->get_status());
131 131
 	}
132 132
 
133 133
 	/**
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
 	 * @since 3.0.0
136 136
 	 */
137 137
 	public function test_create_order() {
138
-		wp_set_current_user( $this->user );
138
+		wp_set_current_user($this->user);
139 139
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
140
-		$request = new WP_REST_Request( 'POST', '/wc/v2/orders' );
140
+		$request = new WP_REST_Request('POST', '/wc/v2/orders');
141 141
 		$request->set_body_params(
142 142
 			array(
143 143
 				'payment_method'       => 'bacs',
@@ -180,34 +180,34 @@  discard block
 block discarded – undo
180 180
 				),
181 181
 			)
182 182
 		);
183
-		$response = $this->server->dispatch( $request );
183
+		$response = $this->server->dispatch($request);
184 184
 		$data     = $response->get_data();
185
-		$order    = wc_get_order( $data['id'] );
186
-		$this->assertEquals( 201, $response->get_status() );
187
-		$this->assertEquals( $order->get_payment_method(), $data['payment_method'] );
188
-		$this->assertEquals( $order->get_payment_method_title(), $data['payment_method_title'] );
189
-		$this->assertEquals( $order->get_billing_first_name(), $data['billing']['first_name'] );
190
-		$this->assertEquals( $order->get_billing_last_name(), $data['billing']['last_name'] );
191
-		$this->assertEquals( '', $data['billing']['company'] );
192
-		$this->assertEquals( $order->get_billing_address_1(), $data['billing']['address_1'] );
193
-		$this->assertEquals( $order->get_billing_address_2(), $data['billing']['address_2'] );
194
-		$this->assertEquals( $order->get_billing_city(), $data['billing']['city'] );
195
-		$this->assertEquals( $order->get_billing_state(), $data['billing']['state'] );
196
-		$this->assertEquals( $order->get_billing_postcode(), $data['billing']['postcode'] );
197
-		$this->assertEquals( $order->get_billing_country(), $data['billing']['country'] );
198
-		$this->assertEquals( $order->get_billing_email(), $data['billing']['email'] );
199
-		$this->assertEquals( $order->get_billing_phone(), $data['billing']['phone'] );
200
-		$this->assertEquals( $order->get_shipping_first_name(), $data['shipping']['first_name'] );
201
-		$this->assertEquals( $order->get_shipping_last_name(), $data['shipping']['last_name'] );
202
-		$this->assertEquals( '', $data['shipping']['company'] );
203
-		$this->assertEquals( $order->get_shipping_address_1(), $data['shipping']['address_1'] );
204
-		$this->assertEquals( $order->get_shipping_address_2(), $data['shipping']['address_2'] );
205
-		$this->assertEquals( $order->get_shipping_city(), $data['shipping']['city'] );
206
-		$this->assertEquals( $order->get_shipping_state(), $data['shipping']['state'] );
207
-		$this->assertEquals( $order->get_shipping_postcode(), $data['shipping']['postcode'] );
208
-		$this->assertEquals( $order->get_shipping_country(), $data['shipping']['country'] );
209
-		$this->assertEquals( 1, count( $data['line_items'] ) );
210
-		$this->assertEquals( 1, count( $data['shipping_lines'] ) );
185
+		$order    = wc_get_order($data['id']);
186
+		$this->assertEquals(201, $response->get_status());
187
+		$this->assertEquals($order->get_payment_method(), $data['payment_method']);
188
+		$this->assertEquals($order->get_payment_method_title(), $data['payment_method_title']);
189
+		$this->assertEquals($order->get_billing_first_name(), $data['billing']['first_name']);
190
+		$this->assertEquals($order->get_billing_last_name(), $data['billing']['last_name']);
191
+		$this->assertEquals('', $data['billing']['company']);
192
+		$this->assertEquals($order->get_billing_address_1(), $data['billing']['address_1']);
193
+		$this->assertEquals($order->get_billing_address_2(), $data['billing']['address_2']);
194
+		$this->assertEquals($order->get_billing_city(), $data['billing']['city']);
195
+		$this->assertEquals($order->get_billing_state(), $data['billing']['state']);
196
+		$this->assertEquals($order->get_billing_postcode(), $data['billing']['postcode']);
197
+		$this->assertEquals($order->get_billing_country(), $data['billing']['country']);
198
+		$this->assertEquals($order->get_billing_email(), $data['billing']['email']);
199
+		$this->assertEquals($order->get_billing_phone(), $data['billing']['phone']);
200
+		$this->assertEquals($order->get_shipping_first_name(), $data['shipping']['first_name']);
201
+		$this->assertEquals($order->get_shipping_last_name(), $data['shipping']['last_name']);
202
+		$this->assertEquals('', $data['shipping']['company']);
203
+		$this->assertEquals($order->get_shipping_address_1(), $data['shipping']['address_1']);
204
+		$this->assertEquals($order->get_shipping_address_2(), $data['shipping']['address_2']);
205
+		$this->assertEquals($order->get_shipping_city(), $data['shipping']['city']);
206
+		$this->assertEquals($order->get_shipping_state(), $data['shipping']['state']);
207
+		$this->assertEquals($order->get_shipping_postcode(), $data['shipping']['postcode']);
208
+		$this->assertEquals($order->get_shipping_country(), $data['shipping']['country']);
209
+		$this->assertEquals(1, count($data['line_items']));
210
+		$this->assertEquals(1, count($data['shipping_lines']));
211 211
 	}
212 212
 
213 213
 	/**
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
 	 * @since 3.5.2
217 217
 	 */
218 218
 	public function test_create_update_order_payment_method_title_sanitize() {
219
-		wp_set_current_user( $this->user );
219
+		wp_set_current_user($this->user);
220 220
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
221 221
 
222 222
 		// Test when creating order.
223
-		$request = new WP_REST_Request( 'POST', '/wc/v3/orders' );
223
+		$request = new WP_REST_Request('POST', '/wc/v3/orders');
224 224
 		$request->set_body_params(
225 225
 			array(
226 226
 				'payment_method'       => 'bacs',
@@ -263,27 +263,27 @@  discard block
 block discarded – undo
263 263
 				),
264 264
 			)
265 265
 		);
266
-		$response = $this->server->dispatch( $request );
266
+		$response = $this->server->dispatch($request);
267 267
 		$data     = $response->get_data();
268
-		$order    = wc_get_order( $data['id'] );
269
-		$this->assertEquals( 201, $response->get_status() );
270
-		$this->assertEquals( $order->get_payment_method(), $data['payment_method'] );
271
-		$this->assertEquals( $order->get_payment_method_title(), 'Sanitize this' );
268
+		$order    = wc_get_order($data['id']);
269
+		$this->assertEquals(201, $response->get_status());
270
+		$this->assertEquals($order->get_payment_method(), $data['payment_method']);
271
+		$this->assertEquals($order->get_payment_method_title(), 'Sanitize this');
272 272
 
273 273
 		// Test when updating order.
274
-		$request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $data['id'] );
274
+		$request = new WP_REST_Request('PUT', '/wc/v3/orders/' . $data['id']);
275 275
 		$request->set_body_params(
276 276
 			array(
277 277
 				'payment_method'       => 'bacs',
278 278
 				'payment_method_title' => '<h1>Sanitize this too <script>alert(1);</script></h1>',
279 279
 			)
280 280
 		);
281
-		$response = $this->server->dispatch( $request );
281
+		$response = $this->server->dispatch($request);
282 282
 		$data     = $response->get_data();
283
-		$order    = wc_get_order( $data['id'] );
284
-		$this->assertEquals( 200, $response->get_status() );
285
-		$this->assertEquals( $order->get_payment_method(), $data['payment_method'] );
286
-		$this->assertEquals( $order->get_payment_method_title(), 'Sanitize this too' );
283
+		$order    = wc_get_order($data['id']);
284
+		$this->assertEquals(200, $response->get_status());
285
+		$this->assertEquals($order->get_payment_method(), $data['payment_method']);
286
+		$this->assertEquals($order->get_payment_method_title(), 'Sanitize this too');
287 287
 	}
288 288
 
289 289
 	/**
@@ -291,11 +291,11 @@  discard block
 block discarded – undo
291 291
 	 * @since 3.0.0
292 292
 	 */
293 293
 	public function test_create_order_invalid_fields() {
294
-		wp_set_current_user( $this->user );
294
+		wp_set_current_user($this->user);
295 295
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
296 296
 
297 297
 		// non-existent customer
298
-		$request = new WP_REST_Request( 'POST', '/wc/v2/orders' );
298
+		$request = new WP_REST_Request('POST', '/wc/v2/orders');
299 299
 		$request->set_body_params(
300 300
 			array(
301 301
 				'payment_method'       => 'bacs',
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
 				),
340 340
 			)
341 341
 		);
342
-		$response = $this->server->dispatch( $request );
342
+		$response = $this->server->dispatch($request);
343 343
 		$data     = $response->get_data();
344
-		$this->assertEquals( 400, $response->get_status() );
344
+		$this->assertEquals(400, $response->get_status());
345 345
 	}
346 346
 
347 347
 	/**
@@ -350,9 +350,9 @@  discard block
 block discarded – undo
350 350
 	 * @since 3.0.0
351 351
 	 */
352 352
 	public function test_update_order() {
353
-		wp_set_current_user( $this->user );
353
+		wp_set_current_user($this->user);
354 354
 		$order   = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
355
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/orders/' . $order->get_id() );
355
+		$request = new WP_REST_Request('PUT', '/wc/v2/orders/' . $order->get_id());
356 356
 		$request->set_body_params(
357 357
 			array(
358 358
 				'payment_method' => 'test-update',
@@ -362,13 +362,13 @@  discard block
 block discarded – undo
362 362
 				),
363 363
 			)
364 364
 		);
365
-		$response = $this->server->dispatch( $request );
365
+		$response = $this->server->dispatch($request);
366 366
 		$data     = $response->get_data();
367 367
 
368
-		$this->assertEquals( 200, $response->get_status() );
369
-		$this->assertEquals( 'test-update', $data['payment_method'] );
370
-		$this->assertEquals( 'Fish', $data['billing']['first_name'] );
371
-		$this->assertEquals( 'Face', $data['billing']['last_name'] );
368
+		$this->assertEquals(200, $response->get_status());
369
+		$this->assertEquals('test-update', $data['payment_method']);
370
+		$this->assertEquals('Fish', $data['billing']['first_name']);
371
+		$this->assertEquals('Face', $data['billing']['last_name']);
372 372
 	}
373 373
 
374 374
 	/**
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 	 * @since 3.0.0
378 378
 	 */
379 379
 	public function test_update_order_remove_items() {
380
-		wp_set_current_user( $this->user );
380
+		wp_set_current_user($this->user);
381 381
 		$order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
382 382
 		$fee   = new WC_Order_Item_Fee();
383 383
 		$fee->set_props(
@@ -388,11 +388,11 @@  discard block
 block discarded – undo
388 388
 				'tax_class'  => '',
389 389
 			)
390 390
 		);
391
-		$order->add_item( $fee );
391
+		$order->add_item($fee);
392 392
 		$order->save();
393 393
 
394
-		$request  = new WP_REST_Request( 'PUT', '/wc/v2/orders/' . $order->get_id() );
395
-		$fee_data = current( $order->get_items( 'fee' ) );
394
+		$request  = new WP_REST_Request('PUT', '/wc/v2/orders/' . $order->get_id());
395
+		$fee_data = current($order->get_items('fee'));
396 396
 
397 397
 		$request->set_body_params(
398 398
 			array(
@@ -404,11 +404,11 @@  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( 200, $response->get_status() );
411
-		$this->assertTrue( empty( $data['fee_lines'] ) );
410
+		$this->assertEquals(200, $response->get_status());
411
+		$this->assertTrue(empty($data['fee_lines']));
412 412
 	}
413 413
 
414 414
 	/**
@@ -417,13 +417,13 @@  discard block
 block discarded – undo
417 417
 	 * @since 3.3.0
418 418
 	 */
419 419
 	public function test_update_order_add_coupons() {
420
-		wp_set_current_user( $this->user );
420
+		wp_set_current_user($this->user);
421 421
 		$order      = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
422
-		$order_item = current( $order->get_items() );
423
-		$coupon     = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'fake-coupon' );
424
-		$coupon->set_amount( 5 );
422
+		$order_item = current($order->get_items());
423
+		$coupon     = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('fake-coupon');
424
+		$coupon->set_amount(5);
425 425
 		$coupon->save();
426
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/orders/' . $order->get_id() );
426
+		$request = new WP_REST_Request('PUT', '/wc/v2/orders/' . $order->get_id());
427 427
 		$request->set_body_params(
428 428
 			array(
429 429
 				'coupon_lines' => array(
@@ -442,12 +442,12 @@  discard block
 block discarded – undo
442 442
 				),
443 443
 			)
444 444
 		);
445
-		$response = $this->server->dispatch( $request );
445
+		$response = $this->server->dispatch($request);
446 446
 		$data     = $response->get_data();
447 447
 
448
-		$this->assertEquals( 200, $response->get_status() );
449
-		$this->assertCount( 1, $data['coupon_lines'] );
450
-		$this->assertEquals( '45.00', $data['total'] );
448
+		$this->assertEquals(200, $response->get_status());
449
+		$this->assertCount(1, $data['coupon_lines']);
450
+		$this->assertEquals('45.00', $data['total']);
451 451
 	}
452 452
 
453 453
 	/**
@@ -456,21 +456,21 @@  discard block
 block discarded – undo
456 456
 	 * @since 3.3.0
457 457
 	 */
458 458
 	public function test_update_order_remove_coupons() {
459
-		wp_set_current_user( $this->user );
459
+		wp_set_current_user($this->user);
460 460
 		$order      = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
461
-		$order_item = current( $order->get_items() );
462
-		$coupon     = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'fake-coupon' );
463
-		$coupon->set_amount( 5 );
461
+		$order_item = current($order->get_items());
462
+		$coupon     = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('fake-coupon');
463
+		$coupon->set_amount(5);
464 464
 		$coupon->save();
465 465
 
466
-		$order->apply_coupon( $coupon );
466
+		$order->apply_coupon($coupon);
467 467
 		$order->save();
468 468
 
469 469
 		// Check that the coupon is applied.
470
-		$this->assertEquals( '45.00', $order->get_total() );
470
+		$this->assertEquals('45.00', $order->get_total());
471 471
 
472
-		$request     = new WP_REST_Request( 'PUT', '/wc/v2/orders/' . $order->get_id() );
473
-		$coupon_data = current( $order->get_items( 'coupon' ) );
472
+		$request     = new WP_REST_Request('PUT', '/wc/v2/orders/' . $order->get_id());
473
+		$coupon_data = current($order->get_items('coupon'));
474 474
 
475 475
 		$request->set_body_params(
476 476
 			array(
@@ -489,12 +489,12 @@  discard block
 block discarded – undo
489 489
 				),
490 490
 			)
491 491
 		);
492
-		$response = $this->server->dispatch( $request );
492
+		$response = $this->server->dispatch($request);
493 493
 		$data     = $response->get_data();
494 494
 
495
-		$this->assertEquals( 200, $response->get_status() );
496
-		$this->assertTrue( empty( $data['coupon_lines'] ) );
497
-		$this->assertEquals( '50.00', $data['total'] );
495
+		$this->assertEquals(200, $response->get_status());
496
+		$this->assertTrue(empty($data['coupon_lines']));
497
+		$this->assertEquals('50.00', $data['total']);
498 498
 	}
499 499
 
500 500
 	/**
@@ -503,9 +503,9 @@  discard block
 block discarded – undo
503 503
 	 * @since 3.0.0
504 504
 	 */
505 505
 	public function test_update_order_without_permission() {
506
-		wp_set_current_user( 0 );
506
+		wp_set_current_user(0);
507 507
 		$order   = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
508
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/orders/' . $order->get_id() );
508
+		$request = new WP_REST_Request('PUT', '/wc/v2/orders/' . $order->get_id());
509 509
 		$request->set_body_params(
510 510
 			array(
511 511
 				'payment_method' => 'test-update',
@@ -515,8 +515,8 @@  discard block
 block discarded – undo
515 515
 				),
516 516
 			)
517 517
 		);
518
-		$response = $this->server->dispatch( $request );
519
-		$this->assertEquals( 401, $response->get_status() );
518
+		$response = $this->server->dispatch($request);
519
+		$this->assertEquals(401, $response->get_status());
520 520
 	}
521 521
 
522 522
 	/**
@@ -524,8 +524,8 @@  discard block
 block discarded – undo
524 524
 	 * @since 3.0.0
525 525
 	 */
526 526
 	public function test_update_order_invalid_id() {
527
-		wp_set_current_user( $this->user );
528
-		$request = new WP_REST_Request( 'POST', '/wc/v2/orders/999999' );
527
+		wp_set_current_user($this->user);
528
+		$request = new WP_REST_Request('POST', '/wc/v2/orders/999999');
529 529
 		$request->set_body_params(
530 530
 			array(
531 531
 				'payment_method' => 'test-update',
@@ -535,8 +535,8 @@  discard block
 block discarded – undo
535 535
 				),
536 536
 			)
537 537
 		);
538
-		$response = $this->server->dispatch( $request );
539
-		$this->assertEquals( 400, $response->get_status() );
538
+		$response = $this->server->dispatch($request);
539
+		$this->assertEquals(400, $response->get_status());
540 540
 	}
541 541
 
542 542
 	/**
@@ -544,13 +544,13 @@  discard block
 block discarded – undo
544 544
 	 * @since 3.0.0
545 545
 	 */
546 546
 	public function test_delete_order() {
547
-		wp_set_current_user( $this->user );
547
+		wp_set_current_user($this->user);
548 548
 		$order   = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
549
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/orders/' . $order->get_id() );
550
-		$request->set_param( 'force', true );
551
-		$response = $this->server->dispatch( $request );
552
-		$this->assertEquals( 200, $response->get_status() );
553
-		$this->assertEquals( null, get_post( $order->get_id() ) );
549
+		$request = new WP_REST_Request('DELETE', '/wc/v2/orders/' . $order->get_id());
550
+		$request->set_param('force', true);
551
+		$response = $this->server->dispatch($request);
552
+		$this->assertEquals(200, $response->get_status());
553
+		$this->assertEquals(null, get_post($order->get_id()));
554 554
 	}
555 555
 
556 556
 	/**
@@ -558,12 +558,12 @@  discard block
 block discarded – undo
558 558
 	 * @since 3.0.0
559 559
 	 */
560 560
 	public function test_delete_order_without_permission() {
561
-		wp_set_current_user( 0 );
561
+		wp_set_current_user(0);
562 562
 		$order   = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
563
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/orders/' . $order->get_id() );
564
-		$request->set_param( 'force', true );
565
-		$response = $this->server->dispatch( $request );
566
-		$this->assertEquals( 401, $response->get_status() );
563
+		$request = new WP_REST_Request('DELETE', '/wc/v2/orders/' . $order->get_id());
564
+		$request->set_param('force', true);
565
+		$response = $this->server->dispatch($request);
566
+		$this->assertEquals(401, $response->get_status());
567 567
 	}
568 568
 
569 569
 	/**
@@ -572,24 +572,24 @@  discard block
 block discarded – undo
572 572
 	 * @since 3.0.0
573 573
 	 */
574 574
 	public function test_delete_order_invalid_id() {
575
-		wp_set_current_user( $this->user );
576
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/orders/9999999' );
577
-		$request->set_param( 'force', true );
578
-		$response = $this->server->dispatch( $request );
579
-		$this->assertEquals( 404, $response->get_status() );
575
+		wp_set_current_user($this->user);
576
+		$request = new WP_REST_Request('DELETE', '/wc/v2/orders/9999999');
577
+		$request->set_param('force', true);
578
+		$response = $this->server->dispatch($request);
579
+		$this->assertEquals(404, $response->get_status());
580 580
 	}
581 581
 
582 582
 	/**
583 583
 	 * Test batch managing product reviews.
584 584
 	 */
585 585
 	public function test_orders_batch() {
586
-		wp_set_current_user( $this->user );
586
+		wp_set_current_user($this->user);
587 587
 
588 588
 		$order1 = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
589 589
 		$order2 = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
590 590
 		$order3 = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
591 591
 
592
-		$request = new WP_REST_Request( 'POST', '/wc/v2/orders/batch' );
592
+		$request = new WP_REST_Request('POST', '/wc/v2/orders/batch');
593 593
 		$request->set_body_params(
594 594
 			array(
595 595
 				'update' => array(
@@ -604,17 +604,17 @@  discard block
 block discarded – undo
604 604
 				),
605 605
 			)
606 606
 		);
607
-		$response = $this->server->dispatch( $request );
607
+		$response = $this->server->dispatch($request);
608 608
 		$data     = $response->get_data();
609 609
 
610
-		$this->assertEquals( 'updated', $data['update'][0]['payment_method'] );
611
-		$this->assertEquals( $order2->get_id(), $data['delete'][0]['id'] );
612
-		$this->assertEquals( $order3->get_id(), $data['delete'][1]['id'] );
610
+		$this->assertEquals('updated', $data['update'][0]['payment_method']);
611
+		$this->assertEquals($order2->get_id(), $data['delete'][0]['id']);
612
+		$this->assertEquals($order3->get_id(), $data['delete'][1]['id']);
613 613
 
614
-		$request  = new WP_REST_Request( 'GET', '/wc/v2/orders' );
615
-		$response = $this->server->dispatch( $request );
614
+		$request  = new WP_REST_Request('GET', '/wc/v2/orders');
615
+		$response = $this->server->dispatch($request);
616 616
 		$data     = $response->get_data();
617
-		$this->assertEquals( 1, count( $data ) );
617
+		$this->assertEquals(1, count($data));
618 618
 	}
619 619
 
620 620
 	/**
@@ -622,14 +622,14 @@  discard block
 block discarded – undo
622 622
 	 * @since 3.0.0
623 623
 	 */
624 624
 	public function test_order_schema() {
625
-		wp_set_current_user( $this->user );
625
+		wp_set_current_user($this->user);
626 626
 		$order      = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
627
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v2/orders/' . $order->get_id() );
628
-		$response   = $this->server->dispatch( $request );
627
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v2/orders/' . $order->get_id());
628
+		$response   = $this->server->dispatch($request);
629 629
 		$data       = $response->get_data();
630 630
 		$properties = $data['schema']['properties'];
631 631
 
632
-		$this->assertEquals( 42, count( $properties ) );
633
-		$this->assertArrayHasKey( 'id', $properties );
632
+		$this->assertEquals(42, count($properties));
633
+		$this->assertArrayHasKey('id', $properties);
634 634
 	}
635 635
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version2/product-reviews.php 1 patch
Spacing   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public function test_register_routes() {
29 29
 		$routes = $this->server->get_routes();
30
-		$this->assertArrayHasKey( '/wc/v3/products/reviews', $routes );
31
-		$this->assertArrayHasKey( '/wc/v3/products/reviews/(?P<id>[\d]+)', $routes );
32
-		$this->assertArrayHasKey( '/wc/v3/products/reviews/batch', $routes );
30
+		$this->assertArrayHasKey('/wc/v3/products/reviews', $routes);
31
+		$this->assertArrayHasKey('/wc/v3/products/reviews/(?P<id>[\d]+)', $routes);
32
+		$this->assertArrayHasKey('/wc/v3/products/reviews/batch', $routes);
33 33
 	}
34 34
 
35 35
 	/**
@@ -38,18 +38,18 @@  discard block
 block discarded – undo
38 38
 	 * @since 3.0.0
39 39
 	 */
40 40
 	public function test_get_product_reviews() {
41
-		wp_set_current_user( $this->user );
41
+		wp_set_current_user($this->user);
42 42
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
43 43
 		// Create 10 products reviews for the product
44
-		for ( $i = 0; $i < 10; $i++ ) {
45
-			$review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() );
44
+		for ($i = 0; $i < 10; $i++) {
45
+			$review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id());
46 46
 		}
47 47
 
48
-		$response        = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ) );
48
+		$response        = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/reviews'));
49 49
 		$product_reviews = $response->get_data();
50 50
 
51
-		$this->assertEquals( 200, $response->get_status() );
52
-		$this->assertEquals( 10, count( $product_reviews ) );
51
+		$this->assertEquals(200, $response->get_status());
52
+		$this->assertEquals(10, count($product_reviews));
53 53
 		$this->assertContains(
54 54
 			array(
55 55
 				'id'                   => $review_id,
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
 				'_links'               => array(
67 67
 					'self'       => array(
68 68
 						array(
69
-							'href' => rest_url( '/wc/v3/products/reviews/' . $review_id ),
69
+							'href' => rest_url('/wc/v3/products/reviews/' . $review_id),
70 70
 						),
71 71
 					),
72 72
 					'collection' => array(
73 73
 						array(
74
-							'href' => rest_url( '/wc/v3/products/reviews' ),
74
+							'href' => rest_url('/wc/v3/products/reviews'),
75 75
 						),
76 76
 					),
77 77
 					'up'         => array(
78 78
 						array(
79
-							'href' => rest_url( '/wc/v3/products/' . $product->get_id() ),
79
+							'href' => rest_url('/wc/v3/products/' . $product->get_id()),
80 80
 						),
81 81
 					),
82 82
 				),
@@ -91,10 +91,10 @@  discard block
 block discarded – undo
91 91
 	 * @since 3.0.0
92 92
 	 */
93 93
 	public function test_get_product_reviews_without_permission() {
94
-		wp_set_current_user( 0 );
94
+		wp_set_current_user(0);
95 95
 		$product  = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
96
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ) );
97
-		$this->assertEquals( 401, $response->get_status() );
96
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/reviews'));
97
+		$this->assertEquals(401, $response->get_status());
98 98
 	}
99 99
 
100 100
 	/**
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
 	 * @since 3.0.0
104 104
 	 */
105 105
 	public function test_get_product_reviews_invalid_product() {
106
-		wp_set_current_user( $this->user );
107
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/0/reviews' ) );
108
-		$this->assertEquals( 404, $response->get_status() );
106
+		wp_set_current_user($this->user);
107
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/0/reviews'));
108
+		$this->assertEquals(404, $response->get_status());
109 109
 	}
110 110
 
111 111
 	/**
@@ -114,14 +114,14 @@  discard block
 block discarded – undo
114 114
 	 * @since 3.0.0
115 115
 	 */
116 116
 	public function test_get_product_review() {
117
-		wp_set_current_user( $this->user );
117
+		wp_set_current_user($this->user);
118 118
 		$product           = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
119
-		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() );
119
+		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id());
120 120
 
121
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) );
121
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/reviews/' . $product_review_id));
122 122
 		$data     = $response->get_data();
123 123
 
124
-		$this->assertEquals( 200, $response->get_status() );
124
+		$this->assertEquals(200, $response->get_status());
125 125
 		$this->assertEquals(
126 126
 			array(
127 127
 				'id'                   => $product_review_id,
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
 	 * @since 3.0.0
147 147
 	 */
148 148
 	public function test_get_product_review_without_permission() {
149
-		wp_set_current_user( 0 );
149
+		wp_set_current_user(0);
150 150
 		$product           = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
151
-		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() );
152
-		$response          = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) );
153
-		$this->assertEquals( 401, $response->get_status() );
151
+		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id());
152
+		$response          = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/reviews/' . $product_review_id));
153
+		$this->assertEquals(401, $response->get_status());
154 154
 	}
155 155
 
156 156
 	/**
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
 	 * @since 3.0.0
160 160
 	 */
161 161
 	public function test_get_product_review_invalid_id() {
162
-		wp_set_current_user( $this->user );
162
+		wp_set_current_user($this->user);
163 163
 		$product  = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
164
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/0' ) );
165
-		$this->assertEquals( 404, $response->get_status() );
164
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/reviews/0'));
165
+		$this->assertEquals(404, $response->get_status());
166 166
 	}
167 167
 
168 168
 	/**
@@ -171,9 +171,9 @@  discard block
 block discarded – undo
171 171
 	 * @since 3.0.0
172 172
 	 */
173 173
 	public function test_create_product_review() {
174
-		wp_set_current_user( $this->user );
174
+		wp_set_current_user($this->user);
175 175
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
176
-		$request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' );
176
+		$request = new WP_REST_Request('POST', '/wc/v3/products/reviews');
177 177
 		$request->set_body_params(
178 178
 			array(
179 179
 				'review'         => 'Hello world.',
@@ -183,10 +183,10 @@  discard block
 block discarded – undo
183 183
 				'product_id'     => $product->get_id(),
184 184
 			)
185 185
 		);
186
-		$response = $this->server->dispatch( $request );
186
+		$response = $this->server->dispatch($request);
187 187
 		$data     = $response->get_data();
188 188
 
189
-		$this->assertEquals( 201, $response->get_status() );
189
+		$this->assertEquals(201, $response->get_status());
190 190
 		$this->assertEquals(
191 191
 			array(
192 192
 				'id'                   => $data['id'],
@@ -211,47 +211,47 @@  discard block
 block discarded – undo
211 211
 	 * @since 3.0.0
212 212
 	 */
213 213
 	public function test_create_product_review_invalid_fields() {
214
-		wp_set_current_user( $this->user );
214
+		wp_set_current_user($this->user);
215 215
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
216 216
 
217 217
 		// missing review
218
-		$request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' );
218
+		$request = new WP_REST_Request('POST', '/wc/v3/products/reviews');
219 219
 		$request->set_body_params(
220 220
 			array(
221 221
 				'reviewer'       => 'Admin',
222 222
 				'reviewer_email' => '[email protected]',
223 223
 			)
224 224
 		);
225
-		$response = $this->server->dispatch( $request );
225
+		$response = $this->server->dispatch($request);
226 226
 		$data     = $response->get_data();
227 227
 
228
-		$this->assertEquals( 400, $response->get_status() );
228
+		$this->assertEquals(400, $response->get_status());
229 229
 
230 230
 		// Missing reviewer.
231
-		$request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' );
231
+		$request = new WP_REST_Request('POST', '/wc/v3/products/reviews');
232 232
 		$request->set_body_params(
233 233
 			array(
234 234
 				'review'         => 'Hello world.',
235 235
 				'reviewer_email' => '[email protected]',
236 236
 			)
237 237
 		);
238
-		$response = $this->server->dispatch( $request );
238
+		$response = $this->server->dispatch($request);
239 239
 		$data     = $response->get_data();
240 240
 
241
-		$this->assertEquals( 400, $response->get_status() );
241
+		$this->assertEquals(400, $response->get_status());
242 242
 
243 243
 		// missing reviewer_email
244
-		$request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' );
244
+		$request = new WP_REST_Request('POST', '/wc/v3/products/reviews');
245 245
 		$request->set_body_params(
246 246
 			array(
247 247
 				'review'   => 'Hello world.',
248 248
 				'reviewer' => 'Admin',
249 249
 			)
250 250
 		);
251
-		$response = $this->server->dispatch( $request );
251
+		$response = $this->server->dispatch($request);
252 252
 		$data     = $response->get_data();
253 253
 
254
-		$this->assertEquals( 400, $response->get_status() );
254
+		$this->assertEquals(400, $response->get_status());
255 255
 	}
256 256
 
257 257
 	/**
@@ -260,18 +260,18 @@  discard block
 block discarded – undo
260 260
 	 * @since 3.0.0
261 261
 	 */
262 262
 	public function test_update_product_review() {
263
-		wp_set_current_user( $this->user );
263
+		wp_set_current_user($this->user);
264 264
 		$product           = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
265
-		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() );
265
+		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id());
266 266
 
267
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) );
267
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/reviews/' . $product_review_id));
268 268
 		$data     = $response->get_data();
269
-		$this->assertEquals( "<p>Review content here</p>\n", $data['review'] );
270
-		$this->assertEquals( 'admin', $data['reviewer'] );
271
-		$this->assertEquals( '[email protected]', $data['reviewer_email'] );
272
-		$this->assertEquals( 0, $data['rating'] );
269
+		$this->assertEquals("<p>Review content here</p>\n", $data['review']);
270
+		$this->assertEquals('admin', $data['reviewer']);
271
+		$this->assertEquals('[email protected]', $data['reviewer_email']);
272
+		$this->assertEquals(0, $data['rating']);
273 273
 
274
-		$request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/' . $product_review_id );
274
+		$request = new WP_REST_Request('PUT', '/wc/v3/products/reviews/' . $product_review_id);
275 275
 		$request->set_body_params(
276 276
 			array(
277 277
 				'review'         => 'Hello world - updated.',
@@ -280,12 +280,12 @@  discard block
 block discarded – undo
280 280
 				'rating'         => 3,
281 281
 			)
282 282
 		);
283
-		$response = $this->server->dispatch( $request );
283
+		$response = $this->server->dispatch($request);
284 284
 		$data     = $response->get_data();
285
-		$this->assertEquals( 'Hello world - updated.', $data['review'] );
286
-		$this->assertEquals( 'Justin', $data['reviewer'] );
287
-		$this->assertEquals( '[email protected]', $data['reviewer_email'] );
288
-		$this->assertEquals( 3, $data['rating'] );
285
+		$this->assertEquals('Hello world - updated.', $data['review']);
286
+		$this->assertEquals('Justin', $data['reviewer']);
287
+		$this->assertEquals('[email protected]', $data['reviewer_email']);
288
+		$this->assertEquals(3, $data['rating']);
289 289
 	}
290 290
 
291 291
 	/**
@@ -294,11 +294,11 @@  discard block
 block discarded – undo
294 294
 	 * @since 3.0.0
295 295
 	 */
296 296
 	public function test_update_product_review_without_permission() {
297
-		wp_set_current_user( 0 );
297
+		wp_set_current_user(0);
298 298
 		$product           = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
299
-		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() );
299
+		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id());
300 300
 
301
-		$request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/' . $product_review_id );
301
+		$request = new WP_REST_Request('PUT', '/wc/v3/products/reviews/' . $product_review_id);
302 302
 		$request->set_body_params(
303 303
 			array(
304 304
 				'review'         => 'Hello world.',
@@ -306,10 +306,10 @@  discard block
 block discarded – undo
306 306
 				'reviewer_email' => '[email protected]',
307 307
 			)
308 308
 		);
309
-		$response = $this->server->dispatch( $request );
309
+		$response = $this->server->dispatch($request);
310 310
 		$data     = $response->get_data();
311 311
 
312
-		$this->assertEquals( 401, $response->get_status() );
312
+		$this->assertEquals(401, $response->get_status());
313 313
 	}
314 314
 
315 315
 	/**
@@ -318,10 +318,10 @@  discard block
 block discarded – undo
318 318
 	 * @since 3.0.0
319 319
 	 */
320 320
 	public function test_update_product_review_invalid_id() {
321
-		wp_set_current_user( $this->user );
321
+		wp_set_current_user($this->user);
322 322
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
323 323
 
324
-		$request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/0' );
324
+		$request = new WP_REST_Request('PUT', '/wc/v3/products/reviews/0');
325 325
 		$request->set_body_params(
326 326
 			array(
327 327
 				'review'         => 'Hello world.',
@@ -329,10 +329,10 @@  discard block
 block discarded – undo
329 329
 				'reviewer_email' => '[email protected]',
330 330
 			)
331 331
 		);
332
-		$response = $this->server->dispatch( $request );
332
+		$response = $this->server->dispatch($request);
333 333
 		$data     = $response->get_data();
334 334
 
335
-		$this->assertEquals( 404, $response->get_status() );
335
+		$this->assertEquals(404, $response->get_status());
336 336
 	}
337 337
 
338 338
 	/**
@@ -341,14 +341,14 @@  discard block
 block discarded – undo
341 341
 	 * @since 3.0.0
342 342
 	 */
343 343
 	public function test_delete_product_review() {
344
-		wp_set_current_user( $this->user );
344
+		wp_set_current_user($this->user);
345 345
 		$product           = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
346
-		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() );
346
+		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id());
347 347
 
348
-		$request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/' . $product_review_id );
349
-		$request->set_param( 'force', true );
350
-		$response = $this->server->dispatch( $request );
351
-		$this->assertEquals( 200, $response->get_status() );
348
+		$request = new WP_REST_Request('DELETE', '/wc/v3/products/reviews/' . $product_review_id);
349
+		$request->set_param('force', true);
350
+		$response = $this->server->dispatch($request);
351
+		$this->assertEquals(200, $response->get_status());
352 352
 	}
353 353
 
354 354
 	/**
@@ -357,14 +357,14 @@  discard block
 block discarded – undo
357 357
 	 * @since 3.0.0
358 358
 	 */
359 359
 	public function test_delete_product_without_permission() {
360
-		wp_set_current_user( 0 );
360
+		wp_set_current_user(0);
361 361
 		$product           = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
362
-		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() );
362
+		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id());
363 363
 
364
-		$request  = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/' . $product_review_id );
365
-		$response = $this->server->dispatch( $request );
364
+		$request  = new WP_REST_Request('DELETE', '/wc/v3/products/reviews/' . $product_review_id);
365
+		$response = $this->server->dispatch($request);
366 366
 
367
-		$this->assertEquals( 401, $response->get_status() );
367
+		$this->assertEquals(401, $response->get_status());
368 368
 	}
369 369
 
370 370
 	/**
@@ -373,30 +373,30 @@  discard block
 block discarded – undo
373 373
 	 * @since 3.0.0
374 374
 	 */
375 375
 	public function test_delete_product_review_invalid_id() {
376
-		wp_set_current_user( $this->user );
376
+		wp_set_current_user($this->user);
377 377
 		$product           = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
378
-		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() );
378
+		$product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id());
379 379
 
380
-		$request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/0' );
381
-		$request->set_param( 'force', true );
382
-		$response = $this->server->dispatch( $request );
380
+		$request = new WP_REST_Request('DELETE', '/wc/v3/products/reviews/0');
381
+		$request->set_param('force', true);
382
+		$response = $this->server->dispatch($request);
383 383
 
384
-		$this->assertEquals( 404, $response->get_status() );
384
+		$this->assertEquals(404, $response->get_status());
385 385
 	}
386 386
 
387 387
 	/**
388 388
 	 * Test batch managing product reviews.
389 389
 	 */
390 390
 	public function test_product_reviews_batch() {
391
-		wp_set_current_user( $this->user );
391
+		wp_set_current_user($this->user);
392 392
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
393 393
 
394
-		$review_1_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() );
395
-		$review_2_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() );
396
-		$review_3_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() );
397
-		$review_4_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() );
394
+		$review_1_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id());
395
+		$review_2_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id());
396
+		$review_3_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id());
397
+		$review_4_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id());
398 398
 
399
-		$request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews/batch' );
399
+		$request = new WP_REST_Request('POST', '/wc/v3/products/reviews/batch');
400 400
 		$request->set_body_params(
401 401
 			array(
402 402
 				'update' => array(
@@ -419,21 +419,21 @@  discard block
 block discarded – undo
419 419
 				),
420 420
 			)
421 421
 		);
422
-		$response = $this->server->dispatch( $request );
422
+		$response = $this->server->dispatch($request);
423 423
 		$data     = $response->get_data();
424 424
 
425
-		$this->assertEquals( 'Updated review.', $data['update'][0]['review'] );
426
-		$this->assertEquals( 'New review.', $data['create'][0]['review'] );
427
-		$this->assertEquals( $review_2_id, $data['delete'][0]['previous']['id'] );
428
-		$this->assertEquals( $review_3_id, $data['delete'][1]['previous']['id'] );
425
+		$this->assertEquals('Updated review.', $data['update'][0]['review']);
426
+		$this->assertEquals('New review.', $data['create'][0]['review']);
427
+		$this->assertEquals($review_2_id, $data['delete'][0]['previous']['id']);
428
+		$this->assertEquals($review_3_id, $data['delete'][1]['previous']['id']);
429 429
 
430
-		$request = new WP_REST_Request( 'GET', '/wc/v3/products/reviews' );
431
-		$request->set_param( 'product', $product->get_id() );
430
+		$request = new WP_REST_Request('GET', '/wc/v3/products/reviews');
431
+		$request->set_param('product', $product->get_id());
432 432
 
433
-		$response = $this->server->dispatch( $request );
433
+		$response = $this->server->dispatch($request);
434 434
 		$data     = $response->get_data();
435 435
 
436
-		$this->assertEquals( 3, count( $data ) );
436
+		$this->assertEquals(3, count($data));
437 437
 	}
438 438
 
439 439
 	/**
@@ -442,27 +442,27 @@  discard block
 block discarded – undo
442 442
 	 * @since 3.0.0
443 443
 	 */
444 444
 	public function test_product_review_schema() {
445
-		wp_set_current_user( $this->user );
445
+		wp_set_current_user($this->user);
446 446
 		$product    = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
447
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v3/products/reviews' );
448
-		$response   = $this->server->dispatch( $request );
447
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v3/products/reviews');
448
+		$response   = $this->server->dispatch($request);
449 449
 		$data       = $response->get_data();
450 450
 		$properties = $data['schema']['properties'];
451 451
 
452
-		$this->assertEquals( 11, count( $properties ) );
453
-		$this->assertArrayHasKey( 'id', $properties );
454
-		$this->assertArrayHasKey( 'date_created', $properties );
455
-		$this->assertArrayHasKey( 'date_created_gmt', $properties );
456
-		$this->assertArrayHasKey( 'product_id', $properties );
457
-		$this->assertArrayHasKey( 'status', $properties );
458
-		$this->assertArrayHasKey( 'reviewer', $properties );
459
-		$this->assertArrayHasKey( 'reviewer_email', $properties );
460
-		$this->assertArrayHasKey( 'review', $properties );
461
-		$this->assertArrayHasKey( 'rating', $properties );
462
-		$this->assertArrayHasKey( 'verified', $properties );
463
-
464
-		if ( get_option( 'show_avatars' ) ) {
465
-			$this->assertArrayHasKey( 'reviewer_avatar_urls', $properties );
452
+		$this->assertEquals(11, count($properties));
453
+		$this->assertArrayHasKey('id', $properties);
454
+		$this->assertArrayHasKey('date_created', $properties);
455
+		$this->assertArrayHasKey('date_created_gmt', $properties);
456
+		$this->assertArrayHasKey('product_id', $properties);
457
+		$this->assertArrayHasKey('status', $properties);
458
+		$this->assertArrayHasKey('reviewer', $properties);
459
+		$this->assertArrayHasKey('reviewer_email', $properties);
460
+		$this->assertArrayHasKey('review', $properties);
461
+		$this->assertArrayHasKey('rating', $properties);
462
+		$this->assertArrayHasKey('verified', $properties);
463
+
464
+		if (get_option('show_avatars')) {
465
+			$this->assertArrayHasKey('reviewer_avatar_urls', $properties);
466 466
 		}
467 467
 	}
468 468
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version2/customers.php 1 patch
Spacing   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
 	public function test_register_routes() {
25 25
 		$routes = $this->server->get_routes();
26 26
 
27
-		$this->assertArrayHasKey( '/wc/v2/customers', $routes );
28
-		$this->assertArrayHasKey( '/wc/v2/customers/(?P<id>[\d]+)', $routes );
29
-		$this->assertArrayHasKey( '/wc/v2/customers/batch', $routes );
27
+		$this->assertArrayHasKey('/wc/v2/customers', $routes);
28
+		$this->assertArrayHasKey('/wc/v2/customers/(?P<id>[\d]+)', $routes);
29
+		$this->assertArrayHasKey('/wc/v2/customers/batch', $routes);
30 30
 	}
31 31
 
32 32
 	/**
@@ -35,30 +35,30 @@  discard block
 block discarded – undo
35 35
 	 * @since 3.0.0
36 36
 	 */
37 37
 	public function test_get_customers() {
38
-		wp_set_current_user( 1 );
38
+		wp_set_current_user(1);
39 39
 
40 40
 		$customer_1 = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer();
41
-		\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test2', 'test2', '[email protected]' );
41
+		\WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer('test2', 'test2', '[email protected]');
42 42
 
43
-		$request = new WP_REST_Request( 'GET', '/wc/v2/customers' );
43
+		$request = new WP_REST_Request('GET', '/wc/v2/customers');
44 44
 		$request->set_query_params(
45 45
 			array(
46 46
 				'orderby' => 'id',
47 47
 			)
48 48
 		);
49
-		$response  = $this->server->dispatch( $request );
49
+		$response  = $this->server->dispatch($request);
50 50
 		$customers = $response->get_data();
51 51
 
52
-		$this->assertEquals( 200, $response->get_status() );
53
-		$this->assertEquals( 2, count( $customers ) );
52
+		$this->assertEquals(200, $response->get_status());
53
+		$this->assertEquals(2, count($customers));
54 54
 
55 55
 		$this->assertContains(
56 56
 			array(
57 57
 				'id'                 => $customer_1->get_id(),
58
-				'date_created'       => wc_rest_prepare_date_response( $customer_1->get_date_created(), false ),
59
-				'date_created_gmt'   => wc_rest_prepare_date_response( $customer_1->get_date_created() ),
60
-				'date_modified'      => wc_rest_prepare_date_response( $customer_1->get_date_modified(), false ),
61
-				'date_modified_gmt'  => wc_rest_prepare_date_response( $customer_1->get_date_modified() ),
58
+				'date_created'       => wc_rest_prepare_date_response($customer_1->get_date_created(), false),
59
+				'date_created_gmt'   => wc_rest_prepare_date_response($customer_1->get_date_created()),
60
+				'date_modified'      => wc_rest_prepare_date_response($customer_1->get_date_modified(), false),
61
+				'date_modified_gmt'  => wc_rest_prepare_date_response($customer_1->get_date_modified()),
62 62
 				'email'              => '[email protected]',
63 63
 				'first_name'         => 'Justin',
64 64
 				'last_name'          => '',
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
 				'_links'             => array(
97 97
 					'self'       => array(
98 98
 						array(
99
-							'href' => rest_url( '/wc/v2/customers/' . $customer_1->get_id() . '' ),
99
+							'href' => rest_url('/wc/v2/customers/' . $customer_1->get_id() . ''),
100 100
 						),
101 101
 					),
102 102
 					'collection' => array(
103 103
 						array(
104
-							'href' => rest_url( '/wc/v2/customers' ),
104
+							'href' => rest_url('/wc/v2/customers'),
105 105
 						),
106 106
 					),
107 107
 				),
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 	 * @since 3.0.0
117 117
 	 */
118 118
 	public function test_get_customers_without_permission() {
119
-		wp_set_current_user( 0 );
120
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers' ) );
121
-		$this->assertEquals( 401, $response->get_status() );
119
+		wp_set_current_user(0);
120
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/customers'));
121
+		$this->assertEquals(401, $response->get_status());
122 122
 	}
123 123
 
124 124
 	/**
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
 	 * @since 3.0.0
128 128
 	 */
129 129
 	public function test_create_customer() {
130
-		wp_set_current_user( 1 );
130
+		wp_set_current_user(1);
131 131
 
132 132
 		// Test just the basics first..
133
-		$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
133
+		$request = new WP_REST_Request('POST', '/wc/v2/customers');
134 134
 		$request->set_body_params(
135 135
 			array(
136 136
 				'username' => 'create_customer_test',
@@ -138,10 +138,10 @@  discard block
 block discarded – undo
138 138
 				'email'    => '[email protected]',
139 139
 			)
140 140
 		);
141
-		$response = $this->server->dispatch( $request );
141
+		$response = $this->server->dispatch($request);
142 142
 		$data     = $response->get_data();
143 143
 
144
-		$this->assertEquals( 201, $response->get_status() );
144
+		$this->assertEquals(201, $response->get_status());
145 145
 		$this->assertEquals(
146 146
 			array(
147 147
 				'id'                 => $data['id'],
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 		);
189 189
 
190 190
 		// Test extra data
191
-		$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
191
+		$request = new WP_REST_Request('POST', '/wc/v2/customers');
192 192
 		$request->set_body_params(
193 193
 			array(
194 194
 				'username'   => 'create_customer_test2',
@@ -206,10 +206,10 @@  discard block
 block discarded – undo
206 206
 				),
207 207
 			)
208 208
 		);
209
-		$response = $this->server->dispatch( $request );
209
+		$response = $this->server->dispatch($request);
210 210
 		$data     = $response->get_data();
211 211
 
212
-		$this->assertEquals( 201, $response->get_status() );
212
+		$this->assertEquals(201, $response->get_status());
213 213
 		$this->assertEquals(
214 214
 			array(
215 215
 				'id'                 => $data['id'],
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 		);
257 257
 
258 258
 		// Test without required field
259
-		$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
259
+		$request = new WP_REST_Request('POST', '/wc/v2/customers');
260 260
 		$request->set_body_params(
261 261
 			array(
262 262
 				'username'   => 'create_customer_test3',
@@ -264,10 +264,10 @@  discard block
 block discarded – undo
264 264
 				'last_name'  => 'McTestFace',
265 265
 			)
266 266
 		);
267
-		$response = $this->server->dispatch( $request );
267
+		$response = $this->server->dispatch($request);
268 268
 		$data     = $response->get_data();
269 269
 
270
-		$this->assertEquals( 400, $response->get_status() );
270
+		$this->assertEquals(400, $response->get_status());
271 271
 	}
272 272
 
273 273
 	/**
@@ -276,8 +276,8 @@  discard block
 block discarded – undo
276 276
 	 * @since 3.0.0
277 277
 	 */
278 278
 	public function test_create_customer_without_permission() {
279
-		wp_set_current_user( 0 );
280
-		$request = new WP_REST_Request( 'POST', '/wc/v2/customers' );
279
+		wp_set_current_user(0);
280
+		$request = new WP_REST_Request('POST', '/wc/v2/customers');
281 281
 		$request->set_body_params(
282 282
 			array(
283 283
 				'username' => 'create_customer_test_without_permission',
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 				'email'    => '[email protected]',
286 286
 			)
287 287
 		);
288
-		$response = $this->server->dispatch( $request );
289
-		$this->assertEquals( 401, $response->get_status() );
288
+		$response = $this->server->dispatch($request);
289
+		$this->assertEquals(401, $response->get_status());
290 290
 	}
291 291
 
292 292
 	/**
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
 	 * @since 3.0.0
296 296
 	 */
297 297
 	public function test_get_customer() {
298
-		wp_set_current_user( 1 );
299
-		$customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'get_customer_test', 'test123', '[email protected]' );
300
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/' . $customer->get_id() ) );
298
+		wp_set_current_user(1);
299
+		$customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer('get_customer_test', 'test123', '[email protected]');
300
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/customers/' . $customer->get_id()));
301 301
 		$data     = $response->get_data();
302 302
 
303 303
 		$this->assertEquals(
@@ -352,10 +352,10 @@  discard block
 block discarded – undo
352 352
 	 * @since 3.0.0
353 353
 	 */
354 354
 	public function test_get_customer_without_permission() {
355
-		wp_set_current_user( 0 );
356
-		$customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'get_customer_test_without_permission', 'test123', '[email protected]' );
357
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/' . $customer->get_id() ) );
358
-		$this->assertEquals( 401, $response->get_status() );
355
+		wp_set_current_user(0);
356
+		$customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer('get_customer_test_without_permission', 'test123', '[email protected]');
357
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/customers/' . $customer->get_id()));
358
+		$this->assertEquals(401, $response->get_status());
359 359
 	}
360 360
 
361 361
 	/**
@@ -364,9 +364,9 @@  discard block
 block discarded – undo
364 364
 	 * @since 3.0.0
365 365
 	 */
366 366
 	public function test_get_customer_invalid_id() {
367
-		wp_set_current_user( 1 );
368
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/0' ) );
369
-		$this->assertEquals( 404, $response->get_status() );
367
+		wp_set_current_user(1);
368
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/customers/0'));
369
+		$this->assertEquals(404, $response->get_status());
370 370
 	}
371 371
 
372 372
 	/**
@@ -375,26 +375,26 @@  discard block
 block discarded – undo
375 375
 	 * @since 3.0.0
376 376
 	 */
377 377
 	public function test_update_customer() {
378
-		wp_set_current_user( 1 );
379
-		$customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'update_customer_test', 'test123', '[email protected]' );
378
+		wp_set_current_user(1);
379
+		$customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer('update_customer_test', 'test123', '[email protected]');
380 380
 
381
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/' . $customer->get_id() ) );
381
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/customers/' . $customer->get_id()));
382 382
 		$data     = $response->get_data();
383
-		$this->assertEquals( 'update_customer_test', $data['username'] );
384
-		$this->assertEquals( '[email protected]', $data['email'] );
383
+		$this->assertEquals('update_customer_test', $data['username']);
384
+		$this->assertEquals('[email protected]', $data['email']);
385 385
 
386
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/customers/' . $customer->get_id() );
386
+		$request = new WP_REST_Request('PUT', '/wc/v2/customers/' . $customer->get_id());
387 387
 		$request->set_body_params(
388 388
 			array(
389 389
 				'email'      => '[email protected]',
390 390
 				'first_name' => 'UpdatedTest',
391 391
 			)
392 392
 		);
393
-		$response = $this->server->dispatch( $request );
393
+		$response = $this->server->dispatch($request);
394 394
 		$data     = $response->get_data();
395 395
 
396
-		$this->assertEquals( '[email protected]', $data['email'] );
397
-		$this->assertEquals( 'UpdatedTest', $data['first_name'] );
396
+		$this->assertEquals('[email protected]', $data['email']);
397
+		$this->assertEquals('UpdatedTest', $data['first_name']);
398 398
 	}
399 399
 
400 400
 	/**
@@ -403,10 +403,10 @@  discard block
 block discarded – undo
403 403
 	 * @since 3.0.0
404 404
 	 */
405 405
 	public function test_update_customer_without_permission() {
406
-		wp_set_current_user( 0 );
407
-		$customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'update_customer_test_without_permission', 'test123', '[email protected]' );
408
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/' . $customer->get_id() ) );
409
-		$this->assertEquals( 401, $response->get_status() );
406
+		wp_set_current_user(0);
407
+		$customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer('update_customer_test_without_permission', 'test123', '[email protected]');
408
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/customers/' . $customer->get_id()));
409
+		$this->assertEquals(401, $response->get_status());
410 410
 	}
411 411
 
412 412
 	/**
@@ -415,9 +415,9 @@  discard block
 block discarded – undo
415 415
 	 * @since 3.0.0
416 416
 	 */
417 417
 	public function test_update_customer_invalid_id() {
418
-		wp_set_current_user( 1 );
419
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/customers/0' ) );
420
-		$this->assertEquals( 404, $response->get_status() );
418
+		wp_set_current_user(1);
419
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/customers/0'));
420
+		$this->assertEquals(404, $response->get_status());
421 421
 	}
422 422
 
423 423
 
@@ -427,12 +427,12 @@  discard block
 block discarded – undo
427 427
 	 * @since 3.0.0
428 428
 	 */
429 429
 	public function test_delete_customer() {
430
-		wp_set_current_user( 1 );
431
-		$customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'delete_customer_test', 'test123', '[email protected]' );
432
-		$request  = new WP_REST_Request( 'DELETE', '/wc/v2/customers/' . $customer->get_id() );
433
-		$request->set_param( 'force', true );
434
-		$response = $this->server->dispatch( $request );
435
-		$this->assertEquals( 200, $response->get_status() );
430
+		wp_set_current_user(1);
431
+		$customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer('delete_customer_test', 'test123', '[email protected]');
432
+		$request  = new WP_REST_Request('DELETE', '/wc/v2/customers/' . $customer->get_id());
433
+		$request->set_param('force', true);
434
+		$response = $this->server->dispatch($request);
435
+		$this->assertEquals(200, $response->get_status());
436 436
 	}
437 437
 
438 438
 	/**
@@ -441,11 +441,11 @@  discard block
 block discarded – undo
441 441
 	 * @since 3.0.0
442 442
 	 */
443 443
 	public function test_delete_customer_invalid_id() {
444
-		wp_set_current_user( 1 );
445
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/customers/0' );
446
-		$request->set_param( 'force', true );
447
-		$response = $this->server->dispatch( $request );
448
-		$this->assertEquals( 400, $response->get_status() );
444
+		wp_set_current_user(1);
445
+		$request = new WP_REST_Request('DELETE', '/wc/v2/customers/0');
446
+		$request->set_param('force', true);
447
+		$response = $this->server->dispatch($request);
448
+		$this->assertEquals(400, $response->get_status());
449 449
 	}
450 450
 
451 451
 	/**
@@ -454,12 +454,12 @@  discard block
 block discarded – undo
454 454
 	 * @since 3.0.0
455 455
 	 */
456 456
 	public function test_delete_customer_without_permission() {
457
-		wp_set_current_user( 0 );
458
-		$customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'delete_customer_test_without_permission', 'test123', '[email protected]' );
459
-		$request  = new WP_REST_Request( 'DELETE', '/wc/v2/customers/' . $customer->get_id() );
460
-		$request->set_param( 'force', true );
461
-		$response = $this->server->dispatch( $request );
462
-		$this->assertEquals( 401, $response->get_status() );
457
+		wp_set_current_user(0);
458
+		$customer = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer('delete_customer_test_without_permission', 'test123', '[email protected]');
459
+		$request  = new WP_REST_Request('DELETE', '/wc/v2/customers/' . $customer->get_id());
460
+		$request->set_param('force', true);
461
+		$response = $this->server->dispatch($request);
462
+		$this->assertEquals(401, $response->get_status());
463 463
 	}
464 464
 
465 465
 	/**
@@ -468,14 +468,14 @@  discard block
 block discarded – undo
468 468
 	 * @since 3.0.0
469 469
 	 */
470 470
 	public function test_batch_customer() {
471
-		wp_set_current_user( 1 );
471
+		wp_set_current_user(1);
472 472
 
473
-		$customer_1 = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test_batch_customer', 'test123', '[email protected]' );
474
-		$customer_2 = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test_batch_customer2', 'test123', '[email protected]' );
475
-		$customer_3 = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test_batch_customer3', 'test123', '[email protected]' );
476
-		$customer_4 = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer( 'test_batch_customer4', 'test123', '[email protected]' );
473
+		$customer_1 = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer('test_batch_customer', 'test123', '[email protected]');
474
+		$customer_2 = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer('test_batch_customer2', 'test123', '[email protected]');
475
+		$customer_3 = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer('test_batch_customer3', 'test123', '[email protected]');
476
+		$customer_4 = \WooCommerce\RestApi\UnitTests\Helpers\CustomerHelper::create_customer('test_batch_customer4', 'test123', '[email protected]');
477 477
 
478
-		$request = new WP_REST_Request( 'POST', '/wc/v2/customers/batch' );
478
+		$request = new WP_REST_Request('POST', '/wc/v2/customers/batch');
479 479
 		$request->set_body_params(
480 480
 			array(
481 481
 				'update' => array(
@@ -497,20 +497,20 @@  discard block
 block discarded – undo
497 497
 				),
498 498
 			)
499 499
 		);
500
-		$response = $this->server->dispatch( $request );
500
+		$response = $this->server->dispatch($request);
501 501
 		$data     = $response->get_data();
502 502
 
503
-		$this->assertEquals( 'McTest', $data['update'][0]['last_name'] );
504
-		$this->assertEquals( 'newuser', $data['create'][0]['username'] );
505
-		$this->assertEmpty( $data['create'][0]['last_name'] );
506
-		$this->assertEquals( $customer_2->get_id(), $data['delete'][0]['id'] );
507
-		$this->assertEquals( $customer_3->get_id(), $data['delete'][1]['id'] );
503
+		$this->assertEquals('McTest', $data['update'][0]['last_name']);
504
+		$this->assertEquals('newuser', $data['create'][0]['username']);
505
+		$this->assertEmpty($data['create'][0]['last_name']);
506
+		$this->assertEquals($customer_2->get_id(), $data['delete'][0]['id']);
507
+		$this->assertEquals($customer_3->get_id(), $data['delete'][1]['id']);
508 508
 
509
-		$request  = new WP_REST_Request( 'GET', '/wc/v2/customers' );
510
-		$response = $this->server->dispatch( $request );
509
+		$request  = new WP_REST_Request('GET', '/wc/v2/customers');
510
+		$response = $this->server->dispatch($request);
511 511
 		$data     = $response->get_data();
512 512
 
513
-		$this->assertEquals( 3, count( $data ) );
513
+		$this->assertEquals(3, count($data));
514 514
 	}
515 515
 
516 516
 	/**
@@ -519,48 +519,48 @@  discard block
 block discarded – undo
519 519
 	 * @since 3.0.0
520 520
 	 */
521 521
 	public function test_customer_schema() {
522
-		wp_set_current_user( 1 );
523
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v2/customers' );
524
-		$response   = $this->server->dispatch( $request );
522
+		wp_set_current_user(1);
523
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v2/customers');
524
+		$response   = $this->server->dispatch($request);
525 525
 		$data       = $response->get_data();
526 526
 		$properties = $data['schema']['properties'];
527 527
 
528
-		$this->assertEquals( 18, count( $properties ) );
529
-		$this->assertArrayHasKey( 'id', $properties );
530
-		$this->assertArrayHasKey( 'date_created', $properties );
531
-		$this->assertArrayHasKey( 'date_created_gmt', $properties );
532
-		$this->assertArrayHasKey( 'date_modified', $properties );
533
-		$this->assertArrayHasKey( 'date_modified_gmt', $properties );
534
-		$this->assertArrayHasKey( 'email', $properties );
535
-		$this->assertArrayHasKey( 'first_name', $properties );
536
-		$this->assertArrayHasKey( 'last_name', $properties );
537
-		$this->assertArrayHasKey( 'role', $properties );
538
-		$this->assertArrayHasKey( 'username', $properties );
539
-		$this->assertArrayHasKey( 'password', $properties );
540
-		$this->assertArrayHasKey( 'orders_count', $properties );
541
-		$this->assertArrayHasKey( 'total_spent', $properties );
542
-		$this->assertArrayHasKey( 'avatar_url', $properties );
543
-		$this->assertArrayHasKey( 'billing', $properties );
544
-		$this->assertArrayHasKey( 'first_name', $properties['billing']['properties'] );
545
-		$this->assertArrayHasKey( 'last_name', $properties['billing']['properties'] );
546
-		$this->assertArrayHasKey( 'company', $properties['billing']['properties'] );
547
-		$this->assertArrayHasKey( 'address_1', $properties['billing']['properties'] );
548
-		$this->assertArrayHasKey( 'address_2', $properties['billing']['properties'] );
549
-		$this->assertArrayHasKey( 'city', $properties['billing']['properties'] );
550
-		$this->assertArrayHasKey( 'state', $properties['billing']['properties'] );
551
-		$this->assertArrayHasKey( 'postcode', $properties['billing']['properties'] );
552
-		$this->assertArrayHasKey( 'country', $properties['billing']['properties'] );
553
-		$this->assertArrayHasKey( 'email', $properties['billing']['properties'] );
554
-		$this->assertArrayHasKey( 'phone', $properties['billing']['properties'] );
555
-		$this->assertArrayHasKey( 'shipping', $properties );
556
-		$this->assertArrayHasKey( 'first_name', $properties['shipping']['properties'] );
557
-		$this->assertArrayHasKey( 'last_name', $properties['shipping']['properties'] );
558
-		$this->assertArrayHasKey( 'company', $properties['shipping']['properties'] );
559
-		$this->assertArrayHasKey( 'address_1', $properties['shipping']['properties'] );
560
-		$this->assertArrayHasKey( 'address_2', $properties['shipping']['properties'] );
561
-		$this->assertArrayHasKey( 'city', $properties['shipping']['properties'] );
562
-		$this->assertArrayHasKey( 'state', $properties['shipping']['properties'] );
563
-		$this->assertArrayHasKey( 'postcode', $properties['shipping']['properties'] );
564
-		$this->assertArrayHasKey( 'country', $properties['shipping']['properties'] );
528
+		$this->assertEquals(18, count($properties));
529
+		$this->assertArrayHasKey('id', $properties);
530
+		$this->assertArrayHasKey('date_created', $properties);
531
+		$this->assertArrayHasKey('date_created_gmt', $properties);
532
+		$this->assertArrayHasKey('date_modified', $properties);
533
+		$this->assertArrayHasKey('date_modified_gmt', $properties);
534
+		$this->assertArrayHasKey('email', $properties);
535
+		$this->assertArrayHasKey('first_name', $properties);
536
+		$this->assertArrayHasKey('last_name', $properties);
537
+		$this->assertArrayHasKey('role', $properties);
538
+		$this->assertArrayHasKey('username', $properties);
539
+		$this->assertArrayHasKey('password', $properties);
540
+		$this->assertArrayHasKey('orders_count', $properties);
541
+		$this->assertArrayHasKey('total_spent', $properties);
542
+		$this->assertArrayHasKey('avatar_url', $properties);
543
+		$this->assertArrayHasKey('billing', $properties);
544
+		$this->assertArrayHasKey('first_name', $properties['billing']['properties']);
545
+		$this->assertArrayHasKey('last_name', $properties['billing']['properties']);
546
+		$this->assertArrayHasKey('company', $properties['billing']['properties']);
547
+		$this->assertArrayHasKey('address_1', $properties['billing']['properties']);
548
+		$this->assertArrayHasKey('address_2', $properties['billing']['properties']);
549
+		$this->assertArrayHasKey('city', $properties['billing']['properties']);
550
+		$this->assertArrayHasKey('state', $properties['billing']['properties']);
551
+		$this->assertArrayHasKey('postcode', $properties['billing']['properties']);
552
+		$this->assertArrayHasKey('country', $properties['billing']['properties']);
553
+		$this->assertArrayHasKey('email', $properties['billing']['properties']);
554
+		$this->assertArrayHasKey('phone', $properties['billing']['properties']);
555
+		$this->assertArrayHasKey('shipping', $properties);
556
+		$this->assertArrayHasKey('first_name', $properties['shipping']['properties']);
557
+		$this->assertArrayHasKey('last_name', $properties['shipping']['properties']);
558
+		$this->assertArrayHasKey('company', $properties['shipping']['properties']);
559
+		$this->assertArrayHasKey('address_1', $properties['shipping']['properties']);
560
+		$this->assertArrayHasKey('address_2', $properties['shipping']['properties']);
561
+		$this->assertArrayHasKey('city', $properties['shipping']['properties']);
562
+		$this->assertArrayHasKey('state', $properties['shipping']['properties']);
563
+		$this->assertArrayHasKey('postcode', $properties['shipping']['properties']);
564
+		$this->assertArrayHasKey('country', $properties['shipping']['properties']);
565 565
 	}
566 566
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version2/products.php 1 patch
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	public function test_register_routes() {
33 33
 		$routes = $this->server->get_routes();
34
-		$this->assertArrayHasKey( '/wc/v2/products', $routes );
35
-		$this->assertArrayHasKey( '/wc/v2/products/(?P<id>[\d]+)', $routes );
36
-		$this->assertArrayHasKey( '/wc/v2/products/batch', $routes );
34
+		$this->assertArrayHasKey('/wc/v2/products', $routes);
35
+		$this->assertArrayHasKey('/wc/v2/products/(?P<id>[\d]+)', $routes);
36
+		$this->assertArrayHasKey('/wc/v2/products/batch', $routes);
37 37
 	}
38 38
 
39 39
 	/**
@@ -42,20 +42,20 @@  discard block
 block discarded – undo
42 42
 	 * @since 3.0.0
43 43
 	 */
44 44
 	public function test_get_products() {
45
-		wp_set_current_user( $this->user );
45
+		wp_set_current_user($this->user);
46 46
 		\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product();
47
-		sleep( 1 ); // So both products have different timestamps.
47
+		sleep(1); // So both products have different timestamps.
48 48
 		\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
49
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products' ) );
49
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products'));
50 50
 		$products = $response->get_data();
51 51
 
52
-		$this->assertEquals( 200, $response->get_status() );
52
+		$this->assertEquals(200, $response->get_status());
53 53
 
54
-		$this->assertEquals( 2, count( $products ) );
55
-		$this->assertEquals( 'Dummy Product', $products[0]['name'] );
56
-		$this->assertEquals( 'DUMMY SKU', $products[0]['sku'] );
57
-		$this->assertEquals( 'Dummy External Product', $products[1]['name'] );
58
-		$this->assertEquals( 'DUMMY EXTERNAL SKU', $products[1]['sku'] );
54
+		$this->assertEquals(2, count($products));
55
+		$this->assertEquals('Dummy Product', $products[0]['name']);
56
+		$this->assertEquals('DUMMY SKU', $products[0]['sku']);
57
+		$this->assertEquals('Dummy External Product', $products[1]['name']);
58
+		$this->assertEquals('DUMMY EXTERNAL SKU', $products[1]['sku']);
59 59
 	}
60 60
 
61 61
 	/**
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
 	 * @since 3.0.0
65 65
 	 */
66 66
 	public function test_get_products_without_permission() {
67
-		wp_set_current_user( 0 );
67
+		wp_set_current_user(0);
68 68
 		\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
69
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products' ) );
70
-		$this->assertEquals( 401, $response->get_status() );
69
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products'));
70
+		$this->assertEquals(401, $response->get_status());
71 71
 	}
72 72
 
73 73
 	/**
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
 	 * @since 3.0.0
77 77
 	 */
78 78
 	public function test_get_product() {
79
-		wp_set_current_user( $this->user );
79
+		wp_set_current_user($this->user);
80 80
 		$simple   = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product();
81
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $simple->get_id() ) );
81
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products/' . $simple->get_id()));
82 82
 		$product  = $response->get_data();
83 83
 
84
-		$this->assertEquals( 200, $response->get_status() );
84
+		$this->assertEquals(200, $response->get_status());
85 85
 		$this->assertContains(
86 86
 			array(
87 87
 				'id'            => $simple->get_id(),
@@ -101,10 +101,10 @@  discard block
 block discarded – undo
101 101
 	 * @since 3.0.0
102 102
 	 */
103 103
 	public function test_get_product_without_permission() {
104
-		wp_set_current_user( 0 );
104
+		wp_set_current_user(0);
105 105
 		$product  = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
106
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() ) );
107
-		$this->assertEquals( 401, $response->get_status() );
106
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products/' . $product->get_id()));
107
+		$this->assertEquals(401, $response->get_status());
108 108
 	}
109 109
 
110 110
 	/**
@@ -113,17 +113,17 @@  discard block
 block discarded – undo
113 113
 	 * @since 3.0.0
114 114
 	 */
115 115
 	public function test_delete_product() {
116
-		wp_set_current_user( $this->user );
116
+		wp_set_current_user($this->user);
117 117
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
118 118
 
119
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/products/' . $product->get_id() );
120
-		$request->set_param( 'force', true );
121
-		$response = $this->server->dispatch( $request );
122
-		$this->assertEquals( 200, $response->get_status() );
119
+		$request = new WP_REST_Request('DELETE', '/wc/v2/products/' . $product->get_id());
120
+		$request->set_param('force', true);
121
+		$response = $this->server->dispatch($request);
122
+		$this->assertEquals(200, $response->get_status());
123 123
 
124
-		$response   = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products' ) );
124
+		$response   = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products'));
125 125
 		$variations = $response->get_data();
126
-		$this->assertEquals( 0, count( $variations ) );
126
+		$this->assertEquals(0, count($variations));
127 127
 	}
128 128
 
129 129
 	/**
@@ -132,12 +132,12 @@  discard block
 block discarded – undo
132 132
 	 * @since 3.0.0
133 133
 	 */
134 134
 	public function test_delete_product_without_permission() {
135
-		wp_set_current_user( 0 );
135
+		wp_set_current_user(0);
136 136
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
137
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/products/' . $product->get_id() );
138
-		$request->set_param( 'force', true );
139
-		$response = $this->server->dispatch( $request );
140
-		$this->assertEquals( 401, $response->get_status() );
137
+		$request = new WP_REST_Request('DELETE', '/wc/v2/products/' . $product->get_id());
138
+		$request->set_param('force', true);
139
+		$response = $this->server->dispatch($request);
140
+		$this->assertEquals(401, $response->get_status());
141 141
 	}
142 142
 
143 143
 	/**
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
 	 * @since 3.0.0
147 147
 	 */
148 148
 	public function test_delete_product_with_invalid_id() {
149
-		wp_set_current_user( 0 );
150
-		$request = new WP_REST_Request( 'DELETE', '/wc/v2/products/0' );
151
-		$request->set_param( 'force', true );
152
-		$response = $this->server->dispatch( $request );
153
-		$this->assertEquals( 404, $response->get_status() );
149
+		wp_set_current_user(0);
150
+		$request = new WP_REST_Request('DELETE', '/wc/v2/products/0');
151
+		$request->set_param('force', true);
152
+		$response = $this->server->dispatch($request);
153
+		$this->assertEquals(404, $response->get_status());
154 154
 	}
155 155
 
156 156
 	/**
@@ -159,18 +159,18 @@  discard block
 block discarded – undo
159 159
 	 * @since 3.0.0
160 160
 	 */
161 161
 	public function test_update_product() {
162
-		wp_set_current_user( $this->user );
162
+		wp_set_current_user($this->user);
163 163
 
164 164
 		// test simple products.
165 165
 		$product  = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
166
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() ) );
166
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products/' . $product->get_id()));
167 167
 		$data     = $response->get_data();
168 168
 
169
-		$this->assertEquals( 'DUMMY SKU', $data['sku'] );
170
-		$this->assertEquals( 10, $data['regular_price'] );
171
-		$this->assertEmpty( $data['sale_price'] );
169
+		$this->assertEquals('DUMMY SKU', $data['sku']);
170
+		$this->assertEquals(10, $data['regular_price']);
171
+		$this->assertEmpty($data['sale_price']);
172 172
 
173
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() );
173
+		$request = new WP_REST_Request('PUT', '/wc/v2/products/' . $product->get_id());
174 174
 		$request->set_body_params(
175 175
 			array(
176 176
 				'sku'         => 'FIXED-SKU',
@@ -185,28 +185,28 @@  discard block
 block discarded – undo
185 185
 				),
186 186
 			)
187 187
 		);
188
-		$response = $this->server->dispatch( $request );
188
+		$response = $this->server->dispatch($request);
189 189
 		$data     = $response->get_data();
190 190
 
191
-		$this->assertContains( 'Testing', $data['description'] );
192
-		$this->assertEquals( '8', $data['price'] );
193
-		$this->assertEquals( '8', $data['sale_price'] );
194
-		$this->assertEquals( '10', $data['regular_price'] );
195
-		$this->assertEquals( 'FIXED-SKU', $data['sku'] );
196
-		$this->assertContains( 'Dr1Bczxq4q', $data['images'][0]['src'] );
197
-		$this->assertContains( 'test upload image', $data['images'][0]['alt'] );
198
-		$product->delete( true );
191
+		$this->assertContains('Testing', $data['description']);
192
+		$this->assertEquals('8', $data['price']);
193
+		$this->assertEquals('8', $data['sale_price']);
194
+		$this->assertEquals('10', $data['regular_price']);
195
+		$this->assertEquals('FIXED-SKU', $data['sku']);
196
+		$this->assertContains('Dr1Bczxq4q', $data['images'][0]['src']);
197
+		$this->assertContains('test upload image', $data['images'][0]['alt']);
198
+		$product->delete(true);
199 199
 
200 200
 		// test variable product (variations are tested in product-variations.php).
201 201
 		$product  = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
202
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() ) );
202
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products/' . $product->get_id()));
203 203
 		$data     = $response->get_data();
204 204
 
205
-		foreach ( array( 'small', 'large' ) as $term_name ) {
206
-			$this->assertContains( $term_name, $data['attributes'][0]['options'] );
205
+		foreach (array('small', 'large') as $term_name) {
206
+			$this->assertContains($term_name, $data['attributes'][0]['options']);
207 207
 		}
208 208
 
209
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() );
209
+		$request = new WP_REST_Request('PUT', '/wc/v2/products/' . $product->get_id());
210 210
 		$request->set_body_params(
211 211
 			array(
212 212
 				'attributes' => array(
@@ -232,33 +232,33 @@  discard block
 block discarded – undo
232 232
 				),
233 233
 			)
234 234
 		);
235
-		$response = $this->server->dispatch( $request );
235
+		$response = $this->server->dispatch($request);
236 236
 		$data     = $response->get_data();
237 237
 
238
-		$this->assertEquals( array( 'small' ), $data['attributes'][0]['options'] );
239
-		$this->assertEquals( array( 'red', 'yellow' ), $data['attributes'][1]['options'] );
240
-		$product->delete( true );
238
+		$this->assertEquals(array('small'), $data['attributes'][0]['options']);
239
+		$this->assertEquals(array('red', 'yellow'), $data['attributes'][1]['options']);
240
+		$product->delete(true);
241 241
 
242 242
 		// test external product.
243 243
 		$product  = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product();
244
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products/' . $product->get_id() ) );
244
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products/' . $product->get_id()));
245 245
 		$data     = $response->get_data();
246 246
 
247
-		$this->assertEquals( 'Buy external product', $data['button_text'] );
248
-		$this->assertEquals( 'http://woocommerce.com', $data['external_url'] );
247
+		$this->assertEquals('Buy external product', $data['button_text']);
248
+		$this->assertEquals('http://woocommerce.com', $data['external_url']);
249 249
 
250
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() );
250
+		$request = new WP_REST_Request('PUT', '/wc/v2/products/' . $product->get_id());
251 251
 		$request->set_body_params(
252 252
 			array(
253 253
 				'button_text'  => 'Test API Update',
254 254
 				'external_url' => 'http://automattic.com',
255 255
 			)
256 256
 		);
257
-		$response = $this->server->dispatch( $request );
257
+		$response = $this->server->dispatch($request);
258 258
 		$data     = $response->get_data();
259 259
 
260
-		$this->assertEquals( 'Test API Update', $data['button_text'] );
261
-		$this->assertEquals( 'http://automattic.com', $data['external_url'] );
260
+		$this->assertEquals('Test API Update', $data['button_text']);
261
+		$this->assertEquals('http://automattic.com', $data['external_url']);
262 262
 	}
263 263
 
264 264
 	/**
@@ -267,16 +267,16 @@  discard block
 block discarded – undo
267 267
 	 * @since 3.0.0
268 268
 	 */
269 269
 	public function test_update_product_without_permission() {
270
-		wp_set_current_user( 0 );
270
+		wp_set_current_user(0);
271 271
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
272
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/products/' . $product->get_id() );
272
+		$request = new WP_REST_Request('PUT', '/wc/v2/products/' . $product->get_id());
273 273
 		$request->set_body_params(
274 274
 			array(
275 275
 				'sku' => 'FIXED-SKU-NO-PERMISSION',
276 276
 			)
277 277
 		);
278
-		$response = $this->server->dispatch( $request );
279
-		$this->assertEquals( 401, $response->get_status() );
278
+		$response = $this->server->dispatch($request);
279
+		$this->assertEquals(401, $response->get_status());
280 280
 	}
281 281
 
282 282
 	/**
@@ -285,16 +285,16 @@  discard block
 block discarded – undo
285 285
 	 * @since 3.0.0
286 286
 	 */
287 287
 	public function test_update_product_with_invalid_id() {
288
-		wp_set_current_user( $this->user );
288
+		wp_set_current_user($this->user);
289 289
 		$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
290
-		$request = new WP_REST_Request( 'PUT', '/wc/v2/products/0' );
290
+		$request = new WP_REST_Request('PUT', '/wc/v2/products/0');
291 291
 		$request->set_body_params(
292 292
 			array(
293 293
 				'sku' => 'FIXED-SKU-INVALID-ID',
294 294
 			)
295 295
 		);
296
-		$response = $this->server->dispatch( $request );
297
-		$this->assertEquals( 400, $response->get_status() );
296
+		$response = $this->server->dispatch($request);
297
+		$this->assertEquals(400, $response->get_status());
298 298
 	}
299 299
 
300 300
 	/**
@@ -303,20 +303,20 @@  discard block
 block discarded – undo
303 303
 	 * @since 3.0.0
304 304
 	 */
305 305
 	public function test_create_product() {
306
-		wp_set_current_user( $this->user );
306
+		wp_set_current_user($this->user);
307 307
 
308
-		$request = new WP_REST_Request( 'POST', '/wc/v2/products/shipping_classes' );
308
+		$request = new WP_REST_Request('POST', '/wc/v2/products/shipping_classes');
309 309
 		$request->set_body_params(
310 310
 			array(
311 311
 				'name' => 'Test',
312 312
 			)
313 313
 		);
314
-		$response          = $this->server->dispatch( $request );
314
+		$response          = $this->server->dispatch($request);
315 315
 		$data              = $response->get_data();
316 316
 		$shipping_class_id = $data['id'];
317 317
 
318 318
 		// Create simple.
319
-		$request = new WP_REST_Request( 'POST', '/wc/v2/products' );
319
+		$request = new WP_REST_Request('POST', '/wc/v2/products');
320 320
 		$request->set_body_params(
321 321
 			array(
322 322
 				'type'           => 'simple',
@@ -326,19 +326,19 @@  discard block
 block discarded – undo
326 326
 				'shipping_class' => 'test',
327 327
 			)
328 328
 		);
329
-		$response = $this->server->dispatch( $request );
329
+		$response = $this->server->dispatch($request);
330 330
 		$data     = $response->get_data();
331 331
 
332
-		$this->assertEquals( '10', $data['price'] );
333
-		$this->assertEquals( '10', $data['regular_price'] );
334
-		$this->assertTrue( $data['purchasable'] );
335
-		$this->assertEquals( 'DUMMY SKU SIMPLE API', $data['sku'] );
336
-		$this->assertEquals( 'Test Simple Product', $data['name'] );
337
-		$this->assertEquals( 'simple', $data['type'] );
338
-		$this->assertEquals( $shipping_class_id, $data['shipping_class_id'] );
332
+		$this->assertEquals('10', $data['price']);
333
+		$this->assertEquals('10', $data['regular_price']);
334
+		$this->assertTrue($data['purchasable']);
335
+		$this->assertEquals('DUMMY SKU SIMPLE API', $data['sku']);
336
+		$this->assertEquals('Test Simple Product', $data['name']);
337
+		$this->assertEquals('simple', $data['type']);
338
+		$this->assertEquals($shipping_class_id, $data['shipping_class_id']);
339 339
 
340 340
 		// Create external.
341
-		$request = new WP_REST_Request( 'POST', '/wc/v2/products' );
341
+		$request = new WP_REST_Request('POST', '/wc/v2/products');
342 342
 		$request->set_body_params(
343 343
 			array(
344 344
 				'type'          => 'external',
@@ -349,20 +349,20 @@  discard block
 block discarded – undo
349 349
 				'external_url'  => 'https://wordpress.org',
350 350
 			)
351 351
 		);
352
-		$response = $this->server->dispatch( $request );
352
+		$response = $this->server->dispatch($request);
353 353
 		$data     = $response->get_data();
354 354
 
355
-		$this->assertEquals( '10', $data['price'] );
356
-		$this->assertEquals( '10', $data['regular_price'] );
357
-		$this->assertFalse( $data['purchasable'] );
358
-		$this->assertEquals( 'DUMMY SKU EXTERNAL API', $data['sku'] );
359
-		$this->assertEquals( 'Test External Product', $data['name'] );
360
-		$this->assertEquals( 'external', $data['type'] );
361
-		$this->assertEquals( 'Test Button', $data['button_text'] );
362
-		$this->assertEquals( 'https://wordpress.org', $data['external_url'] );
355
+		$this->assertEquals('10', $data['price']);
356
+		$this->assertEquals('10', $data['regular_price']);
357
+		$this->assertFalse($data['purchasable']);
358
+		$this->assertEquals('DUMMY SKU EXTERNAL API', $data['sku']);
359
+		$this->assertEquals('Test External Product', $data['name']);
360
+		$this->assertEquals('external', $data['type']);
361
+		$this->assertEquals('Test Button', $data['button_text']);
362
+		$this->assertEquals('https://wordpress.org', $data['external_url']);
363 363
 
364 364
 		// Create variable.
365
-		$request = new WP_REST_Request( 'POST', '/wc/v2/products' );
365
+		$request = new WP_REST_Request('POST', '/wc/v2/products');
366 366
 		$request->set_body_params(
367 367
 			array(
368 368
 				'type'       => 'variable',
@@ -382,17 +382,17 @@  discard block
 block discarded – undo
382 382
 				),
383 383
 			)
384 384
 		);
385
-		$response = $this->server->dispatch( $request );
385
+		$response = $this->server->dispatch($request);
386 386
 		$data     = $response->get_data();
387 387
 
388
-		$this->assertEquals( 'DUMMY SKU VARIABLE API', $data['sku'] );
389
-		$this->assertEquals( 'Test Variable Product', $data['name'] );
390
-		$this->assertEquals( 'variable', $data['type'] );
391
-		$this->assertEquals( array( 'small', 'medium' ), $data['attributes'][0]['options'] );
388
+		$this->assertEquals('DUMMY SKU VARIABLE API', $data['sku']);
389
+		$this->assertEquals('Test Variable Product', $data['name']);
390
+		$this->assertEquals('variable', $data['type']);
391
+		$this->assertEquals(array('small', 'medium'), $data['attributes'][0]['options']);
392 392
 
393
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/products' ) );
393
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/products'));
394 394
 		$products = $response->get_data();
395
-		$this->assertEquals( 3, count( $products ) );
395
+		$this->assertEquals(3, count($products));
396 396
 	}
397 397
 
398 398
 	/**
@@ -401,27 +401,27 @@  discard block
 block discarded – undo
401 401
 	 * @since 3.0.0
402 402
 	 */
403 403
 	public function test_create_product_without_permission() {
404
-		wp_set_current_user( 0 );
404
+		wp_set_current_user(0);
405 405
 
406
-		$request = new WP_REST_Request( 'POST', '/wc/v2/products' );
406
+		$request = new WP_REST_Request('POST', '/wc/v2/products');
407 407
 		$request->set_body_params(
408 408
 			array(
409 409
 				'name'          => 'Test Product',
410 410
 				'regular_price' => '12',
411 411
 			)
412 412
 		);
413
-		$response = $this->server->dispatch( $request );
414
-		$this->assertEquals( 401, $response->get_status() );
413
+		$response = $this->server->dispatch($request);
414
+		$this->assertEquals(401, $response->get_status());
415 415
 	}
416 416
 
417 417
 	/**
418 418
 	 * Test batch managing products.
419 419
 	 */
420 420
 	public function test_products_batch() {
421
-		wp_set_current_user( $this->user );
421
+		wp_set_current_user($this->user);
422 422
 		$product   = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
423 423
 		$product_2 = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
424
-		$request   = new WP_REST_Request( 'POST', '/wc/v2/products/batch' );
424
+		$request   = new WP_REST_Request('POST', '/wc/v2/products/batch');
425 425
 		$request->set_body_params(
426 426
 			array(
427 427
 				'update' => array(
@@ -450,22 +450,22 @@  discard block
 block discarded – undo
450 450
 				),
451 451
 			)
452 452
 		);
453
-		$response = $this->server->dispatch( $request );
453
+		$response = $this->server->dispatch($request);
454 454
 		$data     = $response->get_data();
455 455
 
456
-		$this->assertContains( 'Updated description.', $data['update'][0]['description'] );
457
-		$this->assertEquals( 'DUMMY SKU BATCH TEST 1', $data['create'][0]['sku'] );
458
-		$this->assertEquals( 'DUMMY SKU BATCH TEST 2', $data['create'][1]['sku'] );
459
-		$this->assertEquals( 'Test Button', $data['create'][0]['button_text'] );
460
-		$this->assertEquals( 'external', $data['create'][0]['type'] );
461
-		$this->assertEquals( 'simple', $data['create'][1]['type'] );
462
-		$this->assertEquals( $product_2->get_id(), $data['delete'][0]['id'] );
456
+		$this->assertContains('Updated description.', $data['update'][0]['description']);
457
+		$this->assertEquals('DUMMY SKU BATCH TEST 1', $data['create'][0]['sku']);
458
+		$this->assertEquals('DUMMY SKU BATCH TEST 2', $data['create'][1]['sku']);
459
+		$this->assertEquals('Test Button', $data['create'][0]['button_text']);
460
+		$this->assertEquals('external', $data['create'][0]['type']);
461
+		$this->assertEquals('simple', $data['create'][1]['type']);
462
+		$this->assertEquals($product_2->get_id(), $data['delete'][0]['id']);
463 463
 
464
-		$request  = new WP_REST_Request( 'GET', '/wc/v2/products' );
465
-		$response = $this->server->dispatch( $request );
464
+		$request  = new WP_REST_Request('GET', '/wc/v2/products');
465
+		$response = $this->server->dispatch($request);
466 466
 		$data     = $response->get_data();
467 467
 
468
-		$this->assertEquals( 3, count( $data ) );
468
+		$this->assertEquals(3, count($data));
469 469
 	}
470 470
 
471 471
 	/**
@@ -475,10 +475,10 @@  discard block
 block discarded – undo
475 475
 	 * @since 3.0.0
476 476
 	 */
477 477
 	public function test_products_filter_post_status() {
478
-		wp_set_current_user( $this->user );
479
-		for ( $i = 0; $i < 8; $i++ ) {
478
+		wp_set_current_user($this->user);
479
+		for ($i = 0; $i < 8; $i++) {
480 480
 			$product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
481
-			if ( 0 === $i % 2 ) {
481
+			if (0 === $i % 2) {
482 482
 				wp_update_post(
483 483
 					array(
484 484
 						'ID'          => $product->get_id(),
@@ -489,33 +489,33 @@  discard block
 block discarded – undo
489 489
 		}
490 490
 
491 491
 		// Test filtering with status=publish.
492
-		$request = new WP_REST_Request( 'GET', '/wc/v2/products' );
493
-		$request->set_param( 'status', 'publish' );
494
-		$response = $this->server->dispatch( $request );
492
+		$request = new WP_REST_Request('GET', '/wc/v2/products');
493
+		$request->set_param('status', 'publish');
494
+		$response = $this->server->dispatch($request);
495 495
 		$products = $response->get_data();
496 496
 
497
-		$this->assertEquals( 4, count( $products ) );
498
-		foreach ( $products as $product ) {
499
-			$this->assertEquals( 'publish', $product['status'] );
497
+		$this->assertEquals(4, count($products));
498
+		foreach ($products as $product) {
499
+			$this->assertEquals('publish', $product['status']);
500 500
 		}
501 501
 
502 502
 		// Test filtering with status=draft.
503
-		$request = new WP_REST_Request( 'GET', '/wc/v2/products' );
504
-		$request->set_param( 'status', 'draft' );
505
-		$response = $this->server->dispatch( $request );
503
+		$request = new WP_REST_Request('GET', '/wc/v2/products');
504
+		$request->set_param('status', 'draft');
505
+		$response = $this->server->dispatch($request);
506 506
 		$products = $response->get_data();
507 507
 
508
-		$this->assertEquals( 4, count( $products ) );
509
-		foreach ( $products as $product ) {
510
-			$this->assertEquals( 'draft', $product['status'] );
508
+		$this->assertEquals(4, count($products));
509
+		foreach ($products as $product) {
510
+			$this->assertEquals('draft', $product['status']);
511 511
 		}
512 512
 
513 513
 		// Test filtering with no filters - which should return 'any' (all 8).
514
-		$request  = new WP_REST_Request( 'GET', '/wc/v2/products' );
515
-		$response = $this->server->dispatch( $request );
514
+		$request  = new WP_REST_Request('GET', '/wc/v2/products');
515
+		$response = $this->server->dispatch($request);
516 516
 		$products = $response->get_data();
517 517
 
518
-		$this->assertEquals( 8, count( $products ) );
518
+		$this->assertEquals(8, count($products));
519 519
 	}
520 520
 
521 521
 	/**
@@ -524,12 +524,12 @@  discard block
 block discarded – undo
524 524
 	 * @since 3.0.0
525 525
 	 */
526 526
 	public function test_product_schema() {
527
-		wp_set_current_user( $this->user );
527
+		wp_set_current_user($this->user);
528 528
 		$product    = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product();
529
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v2/products/' . $product->get_id() );
530
-		$response   = $this->server->dispatch( $request );
529
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v2/products/' . $product->get_id());
530
+		$response   = $this->server->dispatch($request);
531 531
 		$data       = $response->get_data();
532 532
 		$properties = $data['schema']['properties'];
533
-		$this->assertEquals( 65, count( $properties ) );
533
+		$this->assertEquals(65, count($properties));
534 534
 	}
535 535
 }
Please login to merge, or discard this patch.