Test Failed
Push — master ( 44764d...6dc399 )
by Mike
04:21
created
unit-tests/Tests/Version2/shipping-methods.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -28,8 +28,8 @@  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/shipping_methods', $routes );
32
-		$this->assertArrayHasKey( '/wc/v2/shipping_methods/(?P<id>[\w-]+)', $routes );
31
+		$this->assertArrayHasKey('/wc/v2/shipping_methods', $routes);
32
+		$this->assertArrayHasKey('/wc/v2/shipping_methods/(?P<id>[\w-]+)', $routes);
33 33
 	}
34 34
 
35 35
 	/**
@@ -38,12 +38,12 @@  discard block
 block discarded – undo
38 38
 	 * @since 3.0.0
39 39
 	 */
40 40
 	public function test_get_shipping_methods() {
41
-		wp_set_current_user( $this->user );
41
+		wp_set_current_user($this->user);
42 42
 
43
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping_methods' ) );
43
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping_methods'));
44 44
 		$methods  = $response->get_data();
45 45
 
46
-		$this->assertEquals( 200, $response->get_status() );
46
+		$this->assertEquals(200, $response->get_status());
47 47
 		$this->assertContains(
48 48
 			array(
49 49
 				'id'          => 'free_shipping',
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
 				'_links'      => array(
53 53
 					'self'       => array(
54 54
 						array(
55
-							'href' => rest_url( '/wc/v2/shipping_methods/free_shipping' ),
55
+							'href' => rest_url('/wc/v2/shipping_methods/free_shipping'),
56 56
 						),
57 57
 					),
58 58
 					'collection' => array(
59 59
 						array(
60
-							'href' => rest_url( '/wc/v2/shipping_methods' ),
60
+							'href' => rest_url('/wc/v2/shipping_methods'),
61 61
 						),
62 62
 					),
63 63
 				),
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
 	 * @since 3.0.0
73 73
 	 */
74 74
 	public function test_get_shipping_methods_without_permission() {
75
-		wp_set_current_user( 0 );
76
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping_methods' ) );
77
-		$this->assertEquals( 401, $response->get_status() );
75
+		wp_set_current_user(0);
76
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping_methods'));
77
+		$this->assertEquals(401, $response->get_status());
78 78
 	}
79 79
 
80 80
 	/**
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
 	 * @since 3.0.0
84 84
 	 */
85 85
 	public function test_get_shipping_method() {
86
-		wp_set_current_user( $this->user );
86
+		wp_set_current_user($this->user);
87 87
 
88
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping_methods/local_pickup' ) );
88
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping_methods/local_pickup'));
89 89
 		$method   = $response->get_data();
90 90
 
91
-		$this->assertEquals( 200, $response->get_status() );
91
+		$this->assertEquals(200, $response->get_status());
92 92
 		$this->assertEquals(
93 93
 			array(
94 94
 				'id'          => 'local_pickup',
@@ -105,10 +105,10 @@  discard block
 block discarded – undo
105 105
 	 * @since 3.0.0
106 106
 	 */
107 107
 	public function test_get_shipping_method_without_permission() {
108
-		wp_set_current_user( 0 );
108
+		wp_set_current_user(0);
109 109
 
110
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping_methods/local_pickup' ) );
111
-		$this->assertEquals( 401, $response->get_status() );
110
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping_methods/local_pickup'));
111
+		$this->assertEquals(401, $response->get_status());
112 112
 	}
113 113
 
114 114
 	/**
@@ -117,9 +117,9 @@  discard block
 block discarded – undo
117 117
 	 * @since 3.0.0
118 118
 	 */
119 119
 	public function test_get_shipping_method_invalid_id() {
120
-		wp_set_current_user( $this->user );
121
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/shipping_methods/fake_method' ) );
122
-		$this->assertEquals( 404, $response->get_status() );
120
+		wp_set_current_user($this->user);
121
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/shipping_methods/fake_method'));
122
+		$this->assertEquals(404, $response->get_status());
123 123
 	}
124 124
 
125 125
 	/**
@@ -128,16 +128,16 @@  discard block
 block discarded – undo
128 128
 	 * @since 3.0.0
129 129
 	 */
130 130
 	public function test_shipping_method_schema() {
131
-		wp_set_current_user( $this->user );
131
+		wp_set_current_user($this->user);
132 132
 
133
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v2/shipping_methods' );
134
-		$response   = $this->server->dispatch( $request );
133
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v2/shipping_methods');
134
+		$response   = $this->server->dispatch($request);
135 135
 		$data       = $response->get_data();
136 136
 		$properties = $data['schema']['properties'];
137 137
 
138
-		$this->assertEquals( 3, count( $properties ) );
139
-		$this->assertArrayHasKey( 'id', $properties );
140
-		$this->assertArrayHasKey( 'title', $properties );
141
-		$this->assertArrayHasKey( 'description', $properties );
138
+		$this->assertEquals(3, count($properties));
139
+		$this->assertArrayHasKey('id', $properties);
140
+		$this->assertArrayHasKey('title', $properties);
141
+		$this->assertArrayHasKey('description', $properties);
142 142
 	}
143 143
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version2/system-status.php 1 patch
Spacing   +106 added lines, -106 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/system_status', $routes );
35
-		$this->assertArrayHasKey( '/wc/v2/system_status/tools', $routes );
36
-		$this->assertArrayHasKey( '/wc/v2/system_status/tools/(?P<id>[\w-]+)', $routes );
34
+		$this->assertArrayHasKey('/wc/v2/system_status', $routes);
35
+		$this->assertArrayHasKey('/wc/v2/system_status/tools', $routes);
36
+		$this->assertArrayHasKey('/wc/v2/system_status/tools/(?P<id>[\w-]+)', $routes);
37 37
 	}
38 38
 
39 39
 	/**
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 	 * @since 3.0.0
43 43
 	 */
44 44
 	public function test_get_system_status_info_without_permission() {
45
-		wp_set_current_user( 0 );
46
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) );
47
-		$this->assertEquals( 401, $response->get_status() );
45
+		wp_set_current_user(0);
46
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/system_status'));
47
+		$this->assertEquals(401, $response->get_status());
48 48
 	}
49 49
 
50 50
 	/**
@@ -54,17 +54,17 @@  discard block
 block discarded – undo
54 54
 	 * @since 3.0.0
55 55
 	 */
56 56
 	public function test_get_system_status_info_returns_root_properties() {
57
-		wp_set_current_user( $this->user );
58
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) );
57
+		wp_set_current_user($this->user);
58
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/system_status'));
59 59
 		$data     = $response->get_data();
60 60
 
61
-		$this->assertArrayHasKey( 'environment', $data );
62
-		$this->assertArrayHasKey( 'database', $data );
63
-		$this->assertArrayHasKey( 'active_plugins', $data );
64
-		$this->assertArrayHasKey( 'theme', $data );
65
-		$this->assertArrayHasKey( 'settings', $data );
66
-		$this->assertArrayHasKey( 'security', $data );
67
-		$this->assertArrayHasKey( 'pages', $data );
61
+		$this->assertArrayHasKey('environment', $data);
62
+		$this->assertArrayHasKey('database', $data);
63
+		$this->assertArrayHasKey('active_plugins', $data);
64
+		$this->assertArrayHasKey('theme', $data);
65
+		$this->assertArrayHasKey('settings', $data);
66
+		$this->assertArrayHasKey('security', $data);
67
+		$this->assertArrayHasKey('pages', $data);
68 68
 	}
69 69
 
70 70
 	/**
@@ -73,18 +73,18 @@  discard block
 block discarded – undo
73 73
 	 * @since 3.0.0
74 74
 	 */
75 75
 	public function test_get_system_status_info_environment() {
76
-		wp_set_current_user( $this->user );
77
-		$response    = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) );
76
+		wp_set_current_user($this->user);
77
+		$response    = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/system_status'));
78 78
 		$data        = $response->get_data();
79 79
 		$environment = (array) $data['environment'];
80 80
 
81 81
 		// Make sure all expected data is present.
82
-		$this->assertEquals( 32, count( $environment ) );
82
+		$this->assertEquals(32, count($environment));
83 83
 
84 84
 		// Test some responses to make sure they match up.
85
-		$this->assertEquals( get_option( 'home' ), $environment['home_url'] );
86
-		$this->assertEquals( get_option( 'siteurl' ), $environment['site_url'] );
87
-		$this->assertEquals( WC()->version, $environment['version'] );
85
+		$this->assertEquals(get_option('home'), $environment['home_url']);
86
+		$this->assertEquals(get_option('siteurl'), $environment['site_url']);
87
+		$this->assertEquals(WC()->version, $environment['version']);
88 88
 	}
89 89
 
90 90
 	/**
@@ -94,16 +94,16 @@  discard block
 block discarded – undo
94 94
 	 */
95 95
 	public function test_get_system_status_info_database() {
96 96
 		global $wpdb;
97
-		wp_set_current_user( $this->user );
98
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) );
97
+		wp_set_current_user($this->user);
98
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/system_status'));
99 99
 		$data     = $response->get_data();
100 100
 		$database = (array) $data['database'];
101 101
 
102
-		$this->assertEquals( get_option( 'woocommerce_db_version' ), $database['wc_database_version'] );
103
-		$this->assertEquals( $wpdb->prefix, $database['database_prefix'] );
104
-		$this->assertEquals( WC_Geolocation::get_local_database_path(), $database['maxmind_geoip_database'] );
105
-		$this->assertArrayHasKey( 'woocommerce', $database['database_tables'], print_r( $database, true ) );
106
-		$this->assertArrayHasKey( $wpdb->prefix . 'woocommerce_payment_tokens', $database['database_tables']['woocommerce'], print_r( $database, true ) );
102
+		$this->assertEquals(get_option('woocommerce_db_version'), $database['wc_database_version']);
103
+		$this->assertEquals($wpdb->prefix, $database['database_prefix']);
104
+		$this->assertEquals(WC_Geolocation::get_local_database_path(), $database['maxmind_geoip_database']);
105
+		$this->assertArrayHasKey('woocommerce', $database['database_tables'], print_r($database, true));
106
+		$this->assertArrayHasKey($wpdb->prefix . 'woocommerce_payment_tokens', $database['database_tables']['woocommerce'], print_r($database, true));
107 107
 	}
108 108
 
109 109
 	/**
@@ -112,18 +112,18 @@  discard block
 block discarded – undo
112 112
 	 * @since 3.0.0
113 113
 	 */
114 114
 	public function test_get_system_status_info_active_plugins() {
115
-		wp_set_current_user( $this->user );
115
+		wp_set_current_user($this->user);
116 116
 
117
-		$actual_plugins = array( 'hello.php' );
118
-		update_option( 'active_plugins', $actual_plugins );
119
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) );
120
-		update_option( 'active_plugins', array() );
117
+		$actual_plugins = array('hello.php');
118
+		update_option('active_plugins', $actual_plugins);
119
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/system_status'));
120
+		update_option('active_plugins', array());
121 121
 
122 122
 		$data    = $response->get_data();
123 123
 		$plugins = (array) $data['active_plugins'];
124 124
 
125
-		$this->assertEquals( 1, count( $plugins ) );
126
-		$this->assertEquals( 'Hello Dolly', $plugins[0]['name'] );
125
+		$this->assertEquals(1, count($plugins));
126
+		$this->assertEquals('Hello Dolly', $plugins[0]['name']);
127 127
 	}
128 128
 
129 129
 	/**
@@ -132,15 +132,15 @@  discard block
 block discarded – undo
132 132
 	 * @since 3.0.0
133 133
 	 */
134 134
 	public function test_get_system_status_info_theme() {
135
-		wp_set_current_user( $this->user );
135
+		wp_set_current_user($this->user);
136 136
 		$active_theme = wp_get_theme();
137 137
 
138
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) );
138
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/system_status'));
139 139
 		$data     = $response->get_data();
140 140
 		$theme    = (array) $data['theme'];
141 141
 
142
-		$this->assertEquals( 13, count( $theme ) );
143
-		$this->assertEquals( $active_theme->Name, $theme['name'] ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
142
+		$this->assertEquals(13, count($theme));
143
+		$this->assertEquals($active_theme->Name, $theme['name']); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
144 144
 	}
145 145
 
146 146
 	/**
@@ -149,22 +149,22 @@  discard block
 block discarded – undo
149 149
 	 * @since 3.0.0
150 150
 	 */
151 151
 	public function test_get_system_status_info_settings() {
152
-		wp_set_current_user( $this->user );
152
+		wp_set_current_user($this->user);
153 153
 
154 154
 		$term_response = array();
155
-		$terms         = get_terms( 'product_type', array( 'hide_empty' => 0 ) );
156
-		foreach ( $terms as $term ) {
157
-			$term_response[ $term->slug ] = strtolower( $term->name );
155
+		$terms         = get_terms('product_type', array('hide_empty' => 0));
156
+		foreach ($terms as $term) {
157
+			$term_response[$term->slug] = strtolower($term->name);
158 158
 		}
159 159
 
160
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) );
160
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/system_status'));
161 161
 		$data     = $response->get_data();
162 162
 		$settings = (array) $data['settings'];
163 163
 
164
-		$this->assertEquals( 12, count( $settings ) );
165
-		$this->assertEquals( ( 'yes' === get_option( 'woocommerce_api_enabled' ) ), $settings['api_enabled'] );
166
-		$this->assertEquals( get_woocommerce_currency(), $settings['currency'] );
167
-		$this->assertEquals( $term_response, $settings['taxonomies'] );
164
+		$this->assertEquals(12, count($settings));
165
+		$this->assertEquals(('yes' === get_option('woocommerce_api_enabled')), $settings['api_enabled']);
166
+		$this->assertEquals(get_woocommerce_currency(), $settings['currency']);
167
+		$this->assertEquals($term_response, $settings['taxonomies']);
168 168
 	}
169 169
 
170 170
 	/**
@@ -173,15 +173,15 @@  discard block
 block discarded – undo
173 173
 	 * @since 3.0.0
174 174
 	 */
175 175
 	public function test_get_system_status_info_security() {
176
-		wp_set_current_user( $this->user );
176
+		wp_set_current_user($this->user);
177 177
 
178
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) );
178
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/system_status'));
179 179
 		$data     = $response->get_data();
180 180
 		$settings = (array) $data['security'];
181 181
 
182
-		$this->assertEquals( 2, count( $settings ) );
183
-		$this->assertEquals( 'https' === substr( wc_get_page_permalink( 'shop' ), 0, 5 ), $settings['secure_connection'] );
184
-		$this->assertEquals( ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ), $settings['hide_errors'] );
182
+		$this->assertEquals(2, count($settings));
183
+		$this->assertEquals('https' === substr(wc_get_page_permalink('shop'), 0, 5), $settings['secure_connection']);
184
+		$this->assertEquals( ! (defined('WP_DEBUG') && defined('WP_DEBUG_DISPLAY') && WP_DEBUG && WP_DEBUG_DISPLAY) || 0 === intval(ini_get('display_errors')), $settings['hide_errors']);
185 185
 	}
186 186
 
187 187
 	/**
@@ -190,11 +190,11 @@  discard block
 block discarded – undo
190 190
 	 * @since 3.0.0
191 191
 	 */
192 192
 	public function test_get_system_status_info_pages() {
193
-		wp_set_current_user( $this->user );
194
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status' ) );
193
+		wp_set_current_user($this->user);
194
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/system_status'));
195 195
 		$data     = $response->get_data();
196 196
 		$pages    = $data['pages'];
197
-		$this->assertEquals( 5, count( $pages ) );
197
+		$this->assertEquals(5, count($pages));
198 198
 	}
199 199
 
200 200
 	/**
@@ -203,18 +203,18 @@  discard block
 block discarded – undo
203 203
 	 * @since 3.0.0
204 204
 	 */
205 205
 	public function test_system_status_schema() {
206
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v2/system_status' );
207
-		$response   = $this->server->dispatch( $request );
206
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v2/system_status');
207
+		$response   = $this->server->dispatch($request);
208 208
 		$data       = $response->get_data();
209 209
 		$properties = $data['schema']['properties'];
210
-		$this->assertEquals( 9, count( $properties ) );
211
-		$this->assertArrayHasKey( 'environment', $properties );
212
-		$this->assertArrayHasKey( 'database', $properties );
213
-		$this->assertArrayHasKey( 'active_plugins', $properties );
214
-		$this->assertArrayHasKey( 'theme', $properties );
215
-		$this->assertArrayHasKey( 'settings', $properties );
216
-		$this->assertArrayHasKey( 'security', $properties );
217
-		$this->assertArrayHasKey( 'pages', $properties );
210
+		$this->assertEquals(9, count($properties));
211
+		$this->assertArrayHasKey('environment', $properties);
212
+		$this->assertArrayHasKey('database', $properties);
213
+		$this->assertArrayHasKey('active_plugins', $properties);
214
+		$this->assertArrayHasKey('theme', $properties);
215
+		$this->assertArrayHasKey('settings', $properties);
216
+		$this->assertArrayHasKey('security', $properties);
217
+		$this->assertArrayHasKey('pages', $properties);
218 218
 	}
219 219
 
220 220
 	/**
@@ -223,16 +223,16 @@  discard block
 block discarded – undo
223 223
 	 * @since 3.0.0
224 224
 	 */
225 225
 	public function test_get_system_tools() {
226
-		wp_set_current_user( $this->user );
226
+		wp_set_current_user($this->user);
227 227
 
228 228
 		$tools_controller = new WC_REST_System_Status_Tools_Controller();
229 229
 		$raw_tools        = $tools_controller->get_tools();
230 230
 
231
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status/tools' ) );
231
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/system_status/tools'));
232 232
 		$data     = $response->get_data();
233 233
 
234
-		$this->assertEquals( 200, $response->get_status() );
235
-		$this->assertEquals( count( $raw_tools ), count( $data ) );
234
+		$this->assertEquals(200, $response->get_status());
235
+		$this->assertEquals(count($raw_tools), count($data));
236 236
 		$this->assertContains(
237 237
 			array(
238 238
 				'id'          => 'regenerate_thumbnails',
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 				'_links'      => array(
243 243
 					'item' => array(
244 244
 						array(
245
-							'href'       => rest_url( '/wc/v2/system_status/tools/regenerate_thumbnails' ),
245
+							'href'       => rest_url('/wc/v2/system_status/tools/regenerate_thumbnails'),
246 246
 							'embeddable' => true,
247 247
 						),
248 248
 					),
@@ -258,9 +258,9 @@  discard block
 block discarded – undo
258 258
 	 * @since 3.0.0
259 259
 	 */
260 260
 	public function test_get_system_status_tools_without_permission() {
261
-		wp_set_current_user( 0 );
262
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status/tools' ) );
263
-		$this->assertEquals( 401, $response->get_status() );
261
+		wp_set_current_user(0);
262
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/system_status/tools'));
263
+		$this->assertEquals(401, $response->get_status());
264 264
 	}
265 265
 
266 266
 	/**
@@ -269,21 +269,21 @@  discard block
 block discarded – undo
269 269
 	 * @since 3.0.0
270 270
 	 */
271 271
 	public function test_get_system_tool() {
272
-		wp_set_current_user( $this->user );
272
+		wp_set_current_user($this->user);
273 273
 
274 274
 		$tools_controller = new WC_REST_System_Status_Tools_Controller();
275 275
 		$raw_tools        = $tools_controller->get_tools();
276 276
 		$raw_tool         = $raw_tools['recount_terms'];
277 277
 
278
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status/tools/recount_terms' ) );
278
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/system_status/tools/recount_terms'));
279 279
 		$data     = $response->get_data();
280 280
 
281
-		$this->assertEquals( 200, $response->get_status() );
281
+		$this->assertEquals(200, $response->get_status());
282 282
 
283
-		$this->assertEquals( 'recount_terms', $data['id'] );
284
-		$this->assertEquals( 'Term counts', $data['name'] );
285
-		$this->assertEquals( 'Recount terms', $data['action'] );
286
-		$this->assertEquals( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description'] );
283
+		$this->assertEquals('recount_terms', $data['id']);
284
+		$this->assertEquals('Term counts', $data['name']);
285
+		$this->assertEquals('Recount terms', $data['action']);
286
+		$this->assertEquals('This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description']);
287 287
 	}
288 288
 
289 289
 	/**
@@ -292,9 +292,9 @@  discard block
 block discarded – undo
292 292
 	 * @since 3.0.0
293 293
 	 */
294 294
 	public function test_get_system_status_tool_without_permission() {
295
-		wp_set_current_user( 0 );
296
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/system_status/tools/recount_terms' ) );
297
-		$this->assertEquals( 401, $response->get_status() );
295
+		wp_set_current_user(0);
296
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v2/system_status/tools/recount_terms'));
297
+		$this->assertEquals(401, $response->get_status());
298 298
 	}
299 299
 
300 300
 	/**
@@ -303,24 +303,24 @@  discard block
 block discarded – undo
303 303
 	 * @since 3.0.0
304 304
 	 */
305 305
 	public function test_execute_system_tool() {
306
-		wp_set_current_user( $this->user );
306
+		wp_set_current_user($this->user);
307 307
 
308 308
 		$tools_controller = new WC_REST_System_Status_Tools_Controller();
309 309
 		$raw_tools        = $tools_controller->get_tools();
310 310
 		$raw_tool         = $raw_tools['recount_terms'];
311 311
 
312
-		$response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v2/system_status/tools/recount_terms' ) );
312
+		$response = $this->server->dispatch(new WP_REST_Request('POST', '/wc/v2/system_status/tools/recount_terms'));
313 313
 		$data     = $response->get_data();
314 314
 
315
-		$this->assertEquals( 'recount_terms', $data['id'] );
316
-		$this->assertEquals( 'Term counts', $data['name'] );
317
-		$this->assertEquals( 'Recount terms', $data['action'] );
318
-		$this->assertEquals( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description'] );
319
-		$this->assertTrue( $data['success'] );
320
-		$this->assertEquals( 1, did_action( 'woocommerce_rest_insert_system_status_tool' ) );
315
+		$this->assertEquals('recount_terms', $data['id']);
316
+		$this->assertEquals('Term counts', $data['name']);
317
+		$this->assertEquals('Recount terms', $data['action']);
318
+		$this->assertEquals('This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description']);
319
+		$this->assertTrue($data['success']);
320
+		$this->assertEquals(1, did_action('woocommerce_rest_insert_system_status_tool'));
321 321
 
322
-		$response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v2/system_status/tools/not_a_real_tool' ) );
323
-		$this->assertEquals( 404, $response->get_status() );
322
+		$response = $this->server->dispatch(new WP_REST_Request('POST', '/wc/v2/system_status/tools/not_a_real_tool'));
323
+		$this->assertEquals(404, $response->get_status());
324 324
 	}
325 325
 
326 326
 	/**
@@ -329,9 +329,9 @@  discard block
 block discarded – undo
329 329
 	 * @since 3.0.0
330 330
 	 */
331 331
 	public function test_execute_system_status_tool_without_permission() {
332
-		wp_set_current_user( 0 );
333
-		$response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v2/system_status/tools/recount_terms' ) );
334
-		$this->assertEquals( 401, $response->get_status() );
332
+		wp_set_current_user(0);
333
+		$response = $this->server->dispatch(new WP_REST_Request('POST', '/wc/v2/system_status/tools/recount_terms'));
334
+		$this->assertEquals(401, $response->get_status());
335 335
 	}
336 336
 
337 337
 	/**
@@ -340,17 +340,17 @@  discard block
 block discarded – undo
340 340
 	 * @since 3.0.0
341 341
 	 */
342 342
 	public function test_system_status_tool_schema() {
343
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v2/system_status/tools' );
344
-		$response   = $this->server->dispatch( $request );
343
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v2/system_status/tools');
344
+		$response   = $this->server->dispatch($request);
345 345
 		$data       = $response->get_data();
346 346
 		$properties = $data['schema']['properties'];
347 347
 
348
-		$this->assertEquals( 6, count( $properties ) );
349
-		$this->assertArrayHasKey( 'id', $properties );
350
-		$this->assertArrayHasKey( 'name', $properties );
351
-		$this->assertArrayHasKey( 'action', $properties );
352
-		$this->assertArrayHasKey( 'description', $properties );
353
-		$this->assertArrayHasKey( 'success', $properties );
354
-		$this->assertArrayHasKey( 'message', $properties );
348
+		$this->assertEquals(6, count($properties));
349
+		$this->assertArrayHasKey('id', $properties);
350
+		$this->assertArrayHasKey('name', $properties);
351
+		$this->assertArrayHasKey('action', $properties);
352
+		$this->assertArrayHasKey('description', $properties);
353
+		$this->assertArrayHasKey('success', $properties);
354
+		$this->assertArrayHasKey('message', $properties);
355 355
 	}
356 356
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/AdminNotes.php 1 patch
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use \WooCommerce\RestApi\UnitTests\Helpers\AdminNotesHelper;
13 13
 use \WC_REST_Unit_Test_Case;
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @param object $factory Factory object.
39 39
 	 */
40
-	public static function wpSetUpBeforeClass( $factory ) {
40
+	public static function wpSetUpBeforeClass($factory) {
41 41
 		self::$user = $factory->user->create(
42 42
 			array(
43 43
 				'role' => 'administrator',
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
 	 * @since 3.5.0
52 52
 	 */
53 53
 	public function setUp() {
54
-		if ( ! class_exists( '\WC_Admin_Note' ) ) {
55
-			$this->markTestSkipped( 'Skipping admin notes tests - WC_Admin_Note class not found.' );
54
+		if ( ! class_exists('\WC_Admin_Note')) {
55
+			$this->markTestSkipped('Skipping admin notes tests - WC_Admin_Note class not found.');
56 56
 			return;
57 57
 		}
58 58
 
59 59
 		parent::setUp();
60
-		wp_set_current_user( self::$user );
60
+		wp_set_current_user(self::$user);
61 61
 		AdminNotesHelper::reset_notes_dbs();
62 62
 		AdminNotesHelper::add_notes_for_tests();
63 63
 	}
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	public function test_register_routes() {
71 71
 		$routes = $this->server->get_routes();
72 72
 
73
-		$this->assertArrayHasKey( $this->endpoint, $routes );
73
+		$this->assertArrayHasKey($this->endpoint, $routes);
74 74
 	}
75 75
 
76 76
 	/**
@@ -79,32 +79,32 @@  discard block
 block discarded – undo
79 79
 	 * @since 3.5.0
80 80
 	 */
81 81
 	public function test_get_note() {
82
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint . '/1' ) );
82
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint . '/1'));
83 83
 		$note     = $response->get_data();
84 84
 
85
-		$this->assertEquals( 200, $response->get_status() );
86
-
87
-		$this->assertEquals( 1, $note['id'] );
88
-		$this->assertEquals( 'PHPUNIT_TEST_NOTE_NAME', $note['name'] );
89
-		$this->assertEquals( \WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL, $note['type'] );
90
-		$this->assertArrayHasKey( 'locale', $note );
91
-		$this->assertEquals( 'PHPUNIT_TEST_NOTE_1_TITLE', $note['title'] );
92
-
93
-		$this->assertEquals( 'PHPUNIT_TEST_NOTE_1_CONTENT', $note['content'] );
94
-		$this->assertEquals( 'info', $note['icon'] );
95
-		$this->assertArrayHasKey( 'content_data', $note );
96
-		$this->assertEquals( 1.23, $note['content_data']->amount );
97
-		$this->assertEquals( \WC_Admin_Note::E_WC_ADMIN_NOTE_UNACTIONED, $note['status'] );
98
-		$this->assertEquals( 'PHPUNIT_TEST', $note['source'] );
99
-
100
-		$this->assertArrayHasKey( 'date_created', $note );
101
-		$this->assertArrayHasKey( 'date_created_gmt', $note );
102
-		$this->assertArrayHasKey( 'date_reminder', $note );
103
-		$this->assertArrayHasKey( 'date_reminder_gmt', $note );
104
-		$this->assertArrayHasKey( 'actions', $note );
105
-
106
-		$this->assertEquals( 'PHPUNIT_TEST_NOTE_1_ACTION_1_SLUG', $note['actions'][0]->name );
107
-		$this->assertEquals( 'http://example.org/wp-admin/admin.php?s=PHPUNIT_TEST_NOTE_1_ACTION_1_URL', $note['actions'][0]->url );
85
+		$this->assertEquals(200, $response->get_status());
86
+
87
+		$this->assertEquals(1, $note['id']);
88
+		$this->assertEquals('PHPUNIT_TEST_NOTE_NAME', $note['name']);
89
+		$this->assertEquals(\WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL, $note['type']);
90
+		$this->assertArrayHasKey('locale', $note);
91
+		$this->assertEquals('PHPUNIT_TEST_NOTE_1_TITLE', $note['title']);
92
+
93
+		$this->assertEquals('PHPUNIT_TEST_NOTE_1_CONTENT', $note['content']);
94
+		$this->assertEquals('info', $note['icon']);
95
+		$this->assertArrayHasKey('content_data', $note);
96
+		$this->assertEquals(1.23, $note['content_data']->amount);
97
+		$this->assertEquals(\WC_Admin_Note::E_WC_ADMIN_NOTE_UNACTIONED, $note['status']);
98
+		$this->assertEquals('PHPUNIT_TEST', $note['source']);
99
+
100
+		$this->assertArrayHasKey('date_created', $note);
101
+		$this->assertArrayHasKey('date_created_gmt', $note);
102
+		$this->assertArrayHasKey('date_reminder', $note);
103
+		$this->assertArrayHasKey('date_reminder_gmt', $note);
104
+		$this->assertArrayHasKey('actions', $note);
105
+
106
+		$this->assertEquals('PHPUNIT_TEST_NOTE_1_ACTION_1_SLUG', $note['actions'][0]->name);
107
+		$this->assertEquals('http://example.org/wp-admin/admin.php?s=PHPUNIT_TEST_NOTE_1_ACTION_1_URL', $note['actions'][0]->url);
108 108
 	}
109 109
 
110 110
 	/**
@@ -113,10 +113,10 @@  discard block
 block discarded – undo
113 113
 	 * @since 3.5.0
114 114
 	 */
115 115
 	public function test_get_invalid_note() {
116
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint . '/999' ) );
116
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint . '/999'));
117 117
 		$note     = $response->get_data();
118 118
 
119
-		$this->assertEquals( 404, $response->get_status() );
119
+		$this->assertEquals(404, $response->get_status());
120 120
 	}
121 121
 
122 122
 	/**
@@ -125,47 +125,47 @@  discard block
 block discarded – undo
125 125
 	 * @since 3.5.0
126 126
 	 */
127 127
 	public function test_get_note_without_permission() {
128
-		wp_set_current_user( 0 );
129
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint . '/1' ) );
130
-		$this->assertEquals( 401, $response->get_status() );
128
+		wp_set_current_user(0);
129
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint . '/1'));
130
+		$this->assertEquals(401, $response->get_status());
131 131
 	}
132 132
 
133 133
 	/**
134 134
 	 * Test updating a single note.
135 135
 	 */
136 136
 	public function test_update_note() {
137
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint . '/1' ) );
137
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint . '/1'));
138 138
 		$note     = $response->get_data();
139 139
 
140
-		$this->assertEquals( 200, $response->get_status() );
141
-		$this->assertEquals( 'unactioned', $note['status'] );
140
+		$this->assertEquals(200, $response->get_status());
141
+		$this->assertEquals('unactioned', $note['status']);
142 142
 
143
-		$request = new WP_REST_Request( 'PUT', $this->endpoint . '/1' );
143
+		$request = new WP_REST_Request('PUT', $this->endpoint . '/1');
144 144
 		$request->set_body_params(
145 145
 			array(
146 146
 				'status' => 'actioned',
147 147
 			)
148 148
 		);
149 149
 
150
-		$response = $this->server->dispatch( $request );
150
+		$response = $this->server->dispatch($request);
151 151
 		$note     = $response->get_data();
152
-		$this->assertEquals( 200, $response->get_status() );
153
-		$this->assertEquals( 'actioned', $note['status'] );
152
+		$this->assertEquals(200, $response->get_status());
153
+		$this->assertEquals('actioned', $note['status']);
154 154
 	}
155 155
 
156 156
 	/**
157 157
 	 * Test updating a single note without permission. It should fail.
158 158
 	 */
159 159
 	public function test_update_note_without_permission() {
160
-		wp_set_current_user( 0 );
161
-		$request = new WP_REST_Request( 'PUT', $this->endpoint . '/1' );
160
+		wp_set_current_user(0);
161
+		$request = new WP_REST_Request('PUT', $this->endpoint . '/1');
162 162
 		$request->set_body_params(
163 163
 			array(
164 164
 				'status' => 'actioned',
165 165
 			)
166 166
 		);
167
-		$response = $this->server->dispatch( $request );
168
-		$this->assertEquals( 401, $response->get_status() );
167
+		$response = $this->server->dispatch($request);
168
+		$this->assertEquals(401, $response->get_status());
169 169
 	}
170 170
 
171 171
 	/**
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
 	 * @since 3.5.0
175 175
 	 */
176 176
 	public function test_get_notes() {
177
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
177
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
178 178
 		$notes    = $response->get_data();
179 179
 
180
-		$this->assertEquals( 200, $response->get_status() );
181
-		$this->assertEquals( 3, count( $notes ) );
180
+		$this->assertEquals(200, $response->get_status());
181
+		$this->assertEquals(3, count($notes));
182 182
 	}
183 183
 
184 184
 	/**
@@ -187,14 +187,14 @@  discard block
 block discarded – undo
187 187
 	 * @since 3.5.0
188 188
 	 */
189 189
 	public function test_get_warning_notes() {
190
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
191
-		$request->set_query_params( array( 'type' => 'warning' ) );
192
-		$response = $this->server->dispatch( $request );
190
+		$request = new WP_REST_Request('GET', $this->endpoint);
191
+		$request->set_query_params(array('type' => 'warning'));
192
+		$response = $this->server->dispatch($request);
193 193
 		$notes    = $response->get_data();
194 194
 
195
-		$this->assertEquals( 200, $response->get_status() );
196
-		$this->assertEquals( 1, count( $notes ) );
197
-		$this->assertEquals( $notes[0]['title'], 'PHPUNIT_TEST_NOTE_2_TITLE' );
195
+		$this->assertEquals(200, $response->get_status());
196
+		$this->assertEquals(1, count($notes));
197
+		$this->assertEquals($notes[0]['title'], 'PHPUNIT_TEST_NOTE_2_TITLE');
198 198
 	}
199 199
 
200 200
 
@@ -202,81 +202,81 @@  discard block
 block discarded – undo
202 202
 	 * Test getting notes of a certain status.
203 203
 	 */
204 204
 	public function test_get_actioned_notes() {
205
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
206
-		$request->set_query_params( array( 'status' => 'actioned' ) );
207
-		$response = $this->server->dispatch( $request );
205
+		$request = new WP_REST_Request('GET', $this->endpoint);
206
+		$request->set_query_params(array('status' => 'actioned'));
207
+		$response = $this->server->dispatch($request);
208 208
 		$notes    = $response->get_data();
209 209
 
210
-		$this->assertEquals( 200, $response->get_status() );
211
-		$this->assertEquals( 1, count( $notes ) );
212
-		$this->assertEquals( $notes[0]['title'], 'PHPUNIT_TEST_NOTE_2_TITLE' );
210
+		$this->assertEquals(200, $response->get_status());
211
+		$this->assertEquals(1, count($notes));
212
+		$this->assertEquals($notes[0]['title'], 'PHPUNIT_TEST_NOTE_2_TITLE');
213 213
 
214
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
215
-		$request->set_query_params( array( 'status' => 'invalid' ) );
216
-		$response = $this->server->dispatch( $request );
214
+		$request = new WP_REST_Request('GET', $this->endpoint);
215
+		$request->set_query_params(array('status' => 'invalid'));
216
+		$response = $this->server->dispatch($request);
217 217
 		$notes    = $response->get_data();
218 218
 
219 219
 		// get_notes returns all results since 'status' is not one of actioned or unactioned.
220
-		$this->assertEquals( 3, count( $notes ) );
220
+		$this->assertEquals(3, count($notes));
221 221
 	}
222 222
 
223 223
 	/**
224 224
 	 * Test note "unsnoozing".
225 225
 	 */
226 226
 	public function test_note_unsnoozing() {
227
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
228
-		$request->set_query_params( array( 'status' => 'snoozed' ) );
229
-		$response = $this->server->dispatch( $request );
227
+		$request = new WP_REST_Request('GET', $this->endpoint);
228
+		$request->set_query_params(array('status' => 'snoozed'));
229
+		$response = $this->server->dispatch($request);
230 230
 		$notes    = $response->get_data();
231 231
 
232
-		$this->assertEquals( 200, $response->get_status() );
233
-		$this->assertEquals( 1, count( $notes ) );
234
-		$this->assertEquals( $notes[0]['title'], 'PHPUNIT_TEST_NOTE_3_TITLE' );
232
+		$this->assertEquals(200, $response->get_status());
233
+		$this->assertEquals(1, count($notes));
234
+		$this->assertEquals($notes[0]['title'], 'PHPUNIT_TEST_NOTE_3_TITLE');
235 235
 
236 236
 		// The test snoozed note's reminder date is an hour ago.
237 237
 		\WC_Admin_Notes::unsnooze_notes();
238 238
 
239
-		$response = $this->server->dispatch( $request );
239
+		$response = $this->server->dispatch($request);
240 240
 		$notes    = $response->get_data();
241 241
 
242
-		$this->assertEquals( 200, $response->get_status() );
243
-		$this->assertEmpty( $notes );
242
+		$this->assertEquals(200, $response->get_status());
243
+		$this->assertEmpty($notes);
244 244
 	}
245 245
 
246 246
 	/**
247 247
 	 * Test ordering of notes.
248 248
 	 */
249 249
 	public function test_order_notes() {
250
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
250
+		$request = new WP_REST_Request('GET', $this->endpoint);
251 251
 		$request->set_query_params(
252 252
 			array(
253 253
 				'orderby' => 'title',
254 254
 				'order'   => 'asc',
255 255
 			)
256 256
 		);
257
-		$response = $this->server->dispatch( $request );
257
+		$response = $this->server->dispatch($request);
258 258
 		$notes    = $response->get_data();
259 259
 
260
-		$this->assertEquals( 200, $response->get_status() );
261
-		$this->assertEquals( 3, count( $notes ) );
262
-		$this->assertEquals( $notes[0]['title'], 'PHPUNIT_TEST_NOTE_1_TITLE' );
263
-		$this->assertEquals( $notes[1]['title'], 'PHPUNIT_TEST_NOTE_2_TITLE' );
264
-		$this->assertEquals( $notes[2]['title'], 'PHPUNIT_TEST_NOTE_3_TITLE' );
260
+		$this->assertEquals(200, $response->get_status());
261
+		$this->assertEquals(3, count($notes));
262
+		$this->assertEquals($notes[0]['title'], 'PHPUNIT_TEST_NOTE_1_TITLE');
263
+		$this->assertEquals($notes[1]['title'], 'PHPUNIT_TEST_NOTE_2_TITLE');
264
+		$this->assertEquals($notes[2]['title'], 'PHPUNIT_TEST_NOTE_3_TITLE');
265 265
 
266
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
266
+		$request = new WP_REST_Request('GET', $this->endpoint);
267 267
 		$request->set_query_params(
268 268
 			array(
269 269
 				'orderby' => 'status',
270 270
 				'order'   => 'desc',
271 271
 			)
272 272
 		);
273
-		$response = $this->server->dispatch( $request );
273
+		$response = $this->server->dispatch($request);
274 274
 		$notes    = $response->get_data();
275 275
 
276
-		$this->assertEquals( 3, count( $notes ) );
277
-		$this->assertEquals( $notes[0]['status'], \WC_Admin_Note::E_WC_ADMIN_NOTE_UNACTIONED );
278
-		$this->assertEquals( $notes[1]['status'], \WC_Admin_Note::E_WC_ADMIN_NOTE_SNOOZED );
279
-		$this->assertEquals( $notes[2]['status'], \WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED );
276
+		$this->assertEquals(3, count($notes));
277
+		$this->assertEquals($notes[0]['status'], \WC_Admin_Note::E_WC_ADMIN_NOTE_UNACTIONED);
278
+		$this->assertEquals($notes[1]['status'], \WC_Admin_Note::E_WC_ADMIN_NOTE_SNOOZED);
279
+		$this->assertEquals($notes[2]['status'], \WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED);
280 280
 	}
281 281
 
282 282
 	/**
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
 	 * @since 3.5.0
286 286
 	 */
287 287
 	public function test_get_notes_without_permission() {
288
-		wp_set_current_user( 0 );
289
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
290
-		$this->assertEquals( 401, $response->get_status() );
288
+		wp_set_current_user(0);
289
+		$response = $this->server->dispatch(new WP_REST_Request('GET', $this->endpoint));
290
+		$this->assertEquals(401, $response->get_status());
291 291
 	}
292 292
 
293 293
 	/**
@@ -296,30 +296,30 @@  discard block
 block discarded – undo
296 296
 	 * @since 3.5.0
297 297
 	 */
298 298
 	public function test_get_notes_schema() {
299
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
300
-		$response   = $this->server->dispatch( $request );
299
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
300
+		$response   = $this->server->dispatch($request);
301 301
 		$data       = $response->get_data();
302 302
 		$properties = $data['schema']['properties'];
303 303
 
304
-		$this->assertEquals( 16, count( $properties ) );
305
-
306
-		$this->assertArrayHasKey( 'id', $properties );
307
-		$this->assertArrayHasKey( 'name', $properties );
308
-		$this->assertArrayHasKey( 'type', $properties );
309
-		$this->assertArrayHasKey( 'locale', $properties );
310
-		$this->assertArrayHasKey( 'title', $properties );
311
-
312
-		$this->assertArrayHasKey( 'content', $properties );
313
-		$this->assertArrayHasKey( 'icon', $properties );
314
-		$this->assertArrayHasKey( 'content_data', $properties );
315
-		$this->assertArrayHasKey( 'status', $properties );
316
-		$this->assertArrayHasKey( 'source', $properties );
317
-
318
-		$this->assertArrayHasKey( 'date_created', $properties );
319
-		$this->assertArrayHasKey( 'date_created_gmt', $properties );
320
-		$this->assertArrayHasKey( 'date_reminder', $properties );
321
-		$this->assertArrayHasKey( 'date_reminder_gmt', $properties );
322
-		$this->assertArrayHasKey( 'actions', $properties );
323
-		$this->assertArrayHasKey( 'is_snoozable', $properties );
304
+		$this->assertEquals(16, count($properties));
305
+
306
+		$this->assertArrayHasKey('id', $properties);
307
+		$this->assertArrayHasKey('name', $properties);
308
+		$this->assertArrayHasKey('type', $properties);
309
+		$this->assertArrayHasKey('locale', $properties);
310
+		$this->assertArrayHasKey('title', $properties);
311
+
312
+		$this->assertArrayHasKey('content', $properties);
313
+		$this->assertArrayHasKey('icon', $properties);
314
+		$this->assertArrayHasKey('content_data', $properties);
315
+		$this->assertArrayHasKey('status', $properties);
316
+		$this->assertArrayHasKey('source', $properties);
317
+
318
+		$this->assertArrayHasKey('date_created', $properties);
319
+		$this->assertArrayHasKey('date_created_gmt', $properties);
320
+		$this->assertArrayHasKey('date_reminder', $properties);
321
+		$this->assertArrayHasKey('date_reminder_gmt', $properties);
322
+		$this->assertArrayHasKey('actions', $properties);
323
+		$this->assertArrayHasKey('is_snoozable', $properties);
324 324
 	}
325 325
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/SystemStatus.php 1 patch
Spacing   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use \WP_REST_Request;
13 13
 use \WC_REST_Unit_Test_Case;
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @param object $factory Factory object.
34 34
 	 */
35
-	public static function wpSetUpBeforeClass( $factory ) {
35
+	public static function wpSetUpBeforeClass($factory) {
36 36
 		self::$user = $factory->user->create(
37 37
 			array(
38 38
 				'role' => 'administrator',
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
 	 */
46 46
 	public function setUp() {
47 47
 		parent::setUp();
48
-		wp_set_current_user( self::$user );
48
+		wp_set_current_user(self::$user);
49 49
 
50 50
 		// Callback used by WP_HTTP_TestCase to decide whether to perform HTTP requests or to provide a mocked response.
51
-		$this->http_responder = array( $this, 'mock_http_responses' );
51
+		$this->http_responder = array($this, 'mock_http_responses');
52 52
 	}
53 53
 
54 54
 	/**
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	public function test_register_routes() {
58 58
 		$routes = $this->server->get_routes();
59
-		$this->assertArrayHasKey( '/wc/v4/system_status', $routes );
60
-		$this->assertArrayHasKey( '/wc/v4/system_status/tools', $routes );
61
-		$this->assertArrayHasKey( '/wc/v4/system_status/tools/(?P<id>[\w-]+)', $routes );
59
+		$this->assertArrayHasKey('/wc/v4/system_status', $routes);
60
+		$this->assertArrayHasKey('/wc/v4/system_status/tools', $routes);
61
+		$this->assertArrayHasKey('/wc/v4/system_status/tools/(?P<id>[\w-]+)', $routes);
62 62
 	}
63 63
 
64 64
 	/**
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
 	 * @since 3.5.0
68 68
 	 */
69 69
 	public function test_get_system_status_info_without_permission() {
70
-		wp_set_current_user( 0 );
71
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/system_status' ) );
72
-		$this->assertEquals( 401, $response->get_status() );
70
+		wp_set_current_user(0);
71
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/system_status'));
72
+		$this->assertEquals(401, $response->get_status());
73 73
 	}
74 74
 
75 75
 	/**
@@ -79,16 +79,16 @@  discard block
 block discarded – undo
79 79
 	 * @since 3.5.0
80 80
 	 */
81 81
 	public function test_get_system_status_info_returns_root_properties() {
82
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/system_status' ) );
82
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/system_status'));
83 83
 		$data     = $response->get_data();
84 84
 
85
-		$this->assertArrayHasKey( 'environment', $data );
86
-		$this->assertArrayHasKey( 'database', $data );
87
-		$this->assertArrayHasKey( 'active_plugins', $data );
88
-		$this->assertArrayHasKey( 'theme', $data );
89
-		$this->assertArrayHasKey( 'settings', $data );
90
-		$this->assertArrayHasKey( 'security', $data );
91
-		$this->assertArrayHasKey( 'pages', $data );
85
+		$this->assertArrayHasKey('environment', $data);
86
+		$this->assertArrayHasKey('database', $data);
87
+		$this->assertArrayHasKey('active_plugins', $data);
88
+		$this->assertArrayHasKey('theme', $data);
89
+		$this->assertArrayHasKey('settings', $data);
90
+		$this->assertArrayHasKey('security', $data);
91
+		$this->assertArrayHasKey('pages', $data);
92 92
 	}
93 93
 
94 94
 	/**
@@ -97,17 +97,17 @@  discard block
 block discarded – undo
97 97
 	 * @since 3.5.0
98 98
 	 */
99 99
 	public function test_get_system_status_info_environment() {
100
-		$response    = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/system_status' ) );
100
+		$response    = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/system_status'));
101 101
 		$data        = $response->get_data();
102 102
 		$environment = (array) $data['environment'];
103 103
 
104 104
 		// Make sure all expected data is present.
105
-		$this->assertEquals( 32, count( $environment ) );
105
+		$this->assertEquals(32, count($environment));
106 106
 
107 107
 		// Test some responses to make sure they match up.
108
-		$this->assertEquals( get_option( 'home' ), $environment['home_url'] );
109
-		$this->assertEquals( get_option( 'siteurl' ), $environment['site_url'] );
110
-		$this->assertEquals( WC()->version, $environment['version'] );
108
+		$this->assertEquals(get_option('home'), $environment['home_url']);
109
+		$this->assertEquals(get_option('siteurl'), $environment['site_url']);
110
+		$this->assertEquals(WC()->version, $environment['version']);
111 111
 	}
112 112
 
113 113
 	/**
@@ -117,15 +117,15 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	public function test_get_system_status_info_database() {
119 119
 		global $wpdb;
120
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/system_status' ) );
120
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/system_status'));
121 121
 		$data     = $response->get_data();
122 122
 		$database = (array) $data['database'];
123 123
 
124
-		$this->assertEquals( get_option( 'woocommerce_db_version' ), $database['wc_database_version'] );
125
-		$this->assertEquals( $wpdb->prefix, $database['database_prefix'] );
126
-		$this->assertEquals( \WC_Geolocation::get_local_database_path(), $database['maxmind_geoip_database'] );
127
-		$this->assertArrayHasKey( 'woocommerce', $database['database_tables'], wc_print_r( $database, true ) );
128
-		$this->assertArrayHasKey( $wpdb->prefix . 'woocommerce_payment_tokens', $database['database_tables']['woocommerce'], wc_print_r( $database, true ) );
124
+		$this->assertEquals(get_option('woocommerce_db_version'), $database['wc_database_version']);
125
+		$this->assertEquals($wpdb->prefix, $database['database_prefix']);
126
+		$this->assertEquals(\WC_Geolocation::get_local_database_path(), $database['maxmind_geoip_database']);
127
+		$this->assertArrayHasKey('woocommerce', $database['database_tables'], wc_print_r($database, true));
128
+		$this->assertArrayHasKey($wpdb->prefix . 'woocommerce_payment_tokens', $database['database_tables']['woocommerce'], wc_print_r($database, true));
129 129
 	}
130 130
 
131 131
 	/**
@@ -134,16 +134,16 @@  discard block
 block discarded – undo
134 134
 	 * @since 3.5.0
135 135
 	 */
136 136
 	public function test_get_system_status_info_active_plugins() {
137
-		$actual_plugins = array( 'hello.php' );
138
-		update_option( 'active_plugins', $actual_plugins );
139
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/system_status' ) );
140
-		update_option( 'active_plugins', array() );
137
+		$actual_plugins = array('hello.php');
138
+		update_option('active_plugins', $actual_plugins);
139
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/system_status'));
140
+		update_option('active_plugins', array());
141 141
 
142 142
 		$data    = $response->get_data();
143 143
 		$plugins = (array) $data['active_plugins'];
144 144
 
145
-		$this->assertEquals( 1, count( $plugins ) );
146
-		$this->assertEquals( 'Hello Dolly', $plugins[0]['name'] );
145
+		$this->assertEquals(1, count($plugins));
146
+		$this->assertEquals('Hello Dolly', $plugins[0]['name']);
147 147
 	}
148 148
 
149 149
 	/**
@@ -154,12 +154,12 @@  discard block
 block discarded – undo
154 154
 	public function test_get_system_status_info_theme() {
155 155
 		$active_theme = wp_get_theme();
156 156
 
157
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/system_status' ) );
157
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/system_status'));
158 158
 		$data     = $response->get_data();
159 159
 		$theme    = (array) $data['theme'];
160 160
 
161
-		$this->assertEquals( 13, count( $theme ) );
162
-		$this->assertEquals( $active_theme->Name, $theme['name'] ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
161
+		$this->assertEquals(13, count($theme));
162
+		$this->assertEquals($active_theme->Name, $theme['name']); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
163 163
 	}
164 164
 
165 165
 	/**
@@ -169,19 +169,19 @@  discard block
 block discarded – undo
169 169
 	 */
170 170
 	public function test_get_system_status_info_settings() {
171 171
 		$term_response = array();
172
-		$terms         = get_terms( 'product_type', array( 'hide_empty' => 0 ) );
173
-		foreach ( $terms as $term ) {
174
-			$term_response[ $term->slug ] = strtolower( $term->name );
172
+		$terms         = get_terms('product_type', array('hide_empty' => 0));
173
+		foreach ($terms as $term) {
174
+			$term_response[$term->slug] = strtolower($term->name);
175 175
 		}
176 176
 
177
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/system_status' ) );
177
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/system_status'));
178 178
 		$data     = $response->get_data();
179 179
 		$settings = (array) $data['settings'];
180 180
 
181
-		$this->assertEquals( 12, count( $settings ) );
182
-		$this->assertEquals( ( 'yes' === get_option( 'woocommerce_api_enabled' ) ), $settings['api_enabled'] );
183
-		$this->assertEquals( get_woocommerce_currency(), $settings['currency'] );
184
-		$this->assertEquals( $term_response, $settings['taxonomies'] );
181
+		$this->assertEquals(12, count($settings));
182
+		$this->assertEquals(('yes' === get_option('woocommerce_api_enabled')), $settings['api_enabled']);
183
+		$this->assertEquals(get_woocommerce_currency(), $settings['currency']);
184
+		$this->assertEquals($term_response, $settings['taxonomies']);
185 185
 	}
186 186
 
187 187
 	/**
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
 	 * @since 3.5.0
191 191
 	 */
192 192
 	public function test_get_system_status_info_security() {
193
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/system_status' ) );
193
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/system_status'));
194 194
 		$data     = $response->get_data();
195 195
 		$settings = (array) $data['security'];
196 196
 
197
-		$this->assertEquals( 2, count( $settings ) );
198
-		$this->assertEquals( 'https' === substr( wc_get_page_permalink( 'shop' ), 0, 5 ), $settings['secure_connection'] );
199
-		$this->assertEquals( ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ), $settings['hide_errors'] );
197
+		$this->assertEquals(2, count($settings));
198
+		$this->assertEquals('https' === substr(wc_get_page_permalink('shop'), 0, 5), $settings['secure_connection']);
199
+		$this->assertEquals( ! (defined('WP_DEBUG') && defined('WP_DEBUG_DISPLAY') && WP_DEBUG && WP_DEBUG_DISPLAY) || 0 === intval(ini_get('display_errors')), $settings['hide_errors']);
200 200
 	}
201 201
 
202 202
 	/**
@@ -205,10 +205,10 @@  discard block
 block discarded – undo
205 205
 	 * @since 3.5.0
206 206
 	 */
207 207
 	public function test_get_system_status_info_pages() {
208
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/system_status' ) );
208
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/system_status'));
209 209
 		$data     = $response->get_data();
210 210
 		$pages    = $data['pages'];
211
-		$this->assertEquals( 5, count( $pages ) );
211
+		$this->assertEquals(5, count($pages));
212 212
 	}
213 213
 
214 214
 	/**
@@ -217,18 +217,18 @@  discard block
 block discarded – undo
217 217
 	 * @since 3.5.0
218 218
 	 */
219 219
 	public function test_system_status_schema() {
220
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v4/system_status' );
221
-		$response   = $this->server->dispatch( $request );
220
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v4/system_status');
221
+		$response   = $this->server->dispatch($request);
222 222
 		$data       = $response->get_data();
223 223
 		$properties = $data['schema']['properties'];
224
-		$this->assertEquals( 10, count( $properties ) );
225
-		$this->assertArrayHasKey( 'environment', $properties );
226
-		$this->assertArrayHasKey( 'database', $properties );
227
-		$this->assertArrayHasKey( 'active_plugins', $properties );
228
-		$this->assertArrayHasKey( 'theme', $properties );
229
-		$this->assertArrayHasKey( 'settings', $properties );
230
-		$this->assertArrayHasKey( 'security', $properties );
231
-		$this->assertArrayHasKey( 'pages', $properties );
224
+		$this->assertEquals(10, count($properties));
225
+		$this->assertArrayHasKey('environment', $properties);
226
+		$this->assertArrayHasKey('database', $properties);
227
+		$this->assertArrayHasKey('active_plugins', $properties);
228
+		$this->assertArrayHasKey('theme', $properties);
229
+		$this->assertArrayHasKey('settings', $properties);
230
+		$this->assertArrayHasKey('security', $properties);
231
+		$this->assertArrayHasKey('pages', $properties);
232 232
 	}
233 233
 
234 234
 	/**
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
 	 * @since 3.5.0
238 238
 	 */
239 239
 	public function test_get_system_tools() {
240
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/system_status/tools' ) );
240
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/system_status/tools'));
241 241
 		$data     = $response->get_data();
242 242
 
243
-		$this->assertEquals( 200, $response->get_status() );
243
+		$this->assertEquals(200, $response->get_status());
244 244
 		$this->assertContains(
245 245
 			array(
246 246
 				'id'          => 'regenerate_thumbnails',
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 				'_links'      => array(
251 251
 					'item' => array(
252 252
 						array(
253
-							'href'       => rest_url( '/wc/v4/system_status/tools/regenerate_thumbnails' ),
253
+							'href'       => rest_url('/wc/v4/system_status/tools/regenerate_thumbnails'),
254 254
 							'embeddable' => 1,
255 255
 						),
256 256
 					),
@@ -262,12 +262,12 @@  discard block
 block discarded – undo
262 262
 		$query_params = array(
263 263
 			'_fields' => 'id,name,nonexisting',
264 264
 		);
265
-		$request      = new WP_REST_Request( 'GET', '/wc/v4/system_status/tools' );
266
-		$request->set_query_params( $query_params );
267
-		$response = $this->server->dispatch( $request );
265
+		$request      = new WP_REST_Request('GET', '/wc/v4/system_status/tools');
266
+		$request->set_query_params($query_params);
267
+		$response = $this->server->dispatch($request);
268 268
 		$data     = $response->get_data();
269 269
 
270
-		$this->assertEquals( 200, $response->get_status() );
270
+		$this->assertEquals(200, $response->get_status());
271 271
 		$this->assertContains(
272 272
 			array(
273 273
 				'id'   => 'regenerate_thumbnails',
@@ -275,19 +275,19 @@  discard block
 block discarded – undo
275 275
 			),
276 276
 			$data
277 277
 		);
278
-		foreach ( $data as $item ) {
278
+		foreach ($data as $item) {
279 279
 			// Fields that are not requested are not returned in response.
280
-			$this->assertArrayNotHasKey( 'action', $item );
281
-			$this->assertArrayNotHasKey( 'description', $item );
280
+			$this->assertArrayNotHasKey('action', $item);
281
+			$this->assertArrayNotHasKey('description', $item);
282 282
 			// Links are part of data in collections, so excluded if not explicitly requested.
283
-			$this->assertArrayNotHasKey( '_links', $item );
283
+			$this->assertArrayNotHasKey('_links', $item);
284 284
 			// Non existing field is ignored.
285
-			$this->assertArrayNotHasKey( 'nonexisting', $item );
285
+			$this->assertArrayNotHasKey('nonexisting', $item);
286 286
 		}
287 287
 
288 288
 		// Links are part of data, not links in collections.
289 289
 		$links = $response->get_links();
290
-		$this->assertEquals( 0, count( $links ) );
290
+		$this->assertEquals(0, count($links));
291 291
 	}
292 292
 
293 293
 	/**
@@ -296,9 +296,9 @@  discard block
 block discarded – undo
296 296
 	 * @since 3.5.0
297 297
 	 */
298 298
 	public function test_get_system_status_tools_without_permission() {
299
-		wp_set_current_user( 0 );
300
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/system_status/tools' ) );
301
-		$this->assertEquals( 401, $response->get_status() );
299
+		wp_set_current_user(0);
300
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/system_status/tools'));
301
+		$this->assertEquals(401, $response->get_status());
302 302
 	}
303 303
 
304 304
 	/**
@@ -307,37 +307,37 @@  discard block
 block discarded – undo
307 307
 	 * @since 3.5.0
308 308
 	 */
309 309
 	public function test_get_system_tool() {
310
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/system_status/tools/recount_terms' ) );
310
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/system_status/tools/recount_terms'));
311 311
 		$data     = $response->get_data();
312 312
 
313
-		$this->assertEquals( 200, $response->get_status() );
313
+		$this->assertEquals(200, $response->get_status());
314 314
 
315
-		$this->assertEquals( 'recount_terms', $data['id'] );
316
-		$this->assertEquals( 'Term counts', $data['name'] );
317
-		$this->assertEquals( 'Recount terms', $data['action'] );
318
-		$this->assertEquals( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description'] );
315
+		$this->assertEquals('recount_terms', $data['id']);
316
+		$this->assertEquals('Term counts', $data['name']);
317
+		$this->assertEquals('Recount terms', $data['action']);
318
+		$this->assertEquals('This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description']);
319 319
 
320 320
 		// Test for _fields query parameter.
321 321
 		$query_params = array(
322 322
 			'_fields' => 'id,name,nonexisting',
323 323
 		);
324
-		$request      = new WP_REST_Request( 'GET', '/wc/v4/system_status/tools/recount_terms' );
325
-		$request->set_query_params( $query_params );
326
-		$response = $this->server->dispatch( $request );
324
+		$request      = new WP_REST_Request('GET', '/wc/v4/system_status/tools/recount_terms');
325
+		$request->set_query_params($query_params);
326
+		$response = $this->server->dispatch($request);
327 327
 		$data     = $response->get_data();
328 328
 
329
-		$this->assertEquals( 200, $response->get_status() );
329
+		$this->assertEquals(200, $response->get_status());
330 330
 
331
-		$this->assertEquals( 'recount_terms', $data['id'] );
332
-		$this->assertEquals( 'Term counts', $data['name'] );
333
-		$this->assertArrayNotHasKey( 'action', $data );
334
-		$this->assertArrayNotHasKey( 'description', $data );
331
+		$this->assertEquals('recount_terms', $data['id']);
332
+		$this->assertEquals('Term counts', $data['name']);
333
+		$this->assertArrayNotHasKey('action', $data);
334
+		$this->assertArrayNotHasKey('description', $data);
335 335
 		// Links are part of links, not data in single items.
336
-		$this->assertArrayNotHasKey( '_links', $data );
336
+		$this->assertArrayNotHasKey('_links', $data);
337 337
 
338 338
 		// Links are part of links, not data in single item response.
339 339
 		$links = $response->get_links();
340
-		$this->assertEquals( 1, count( $links ) );
340
+		$this->assertEquals(1, count($links));
341 341
 	}
342 342
 
343 343
 	/**
@@ -346,9 +346,9 @@  discard block
 block discarded – undo
346 346
 	 * @since 3.5.0
347 347
 	 */
348 348
 	public function test_get_system_status_tool_without_permission() {
349
-		wp_set_current_user( 0 );
350
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/system_status/tools/recount_terms' ) );
351
-		$this->assertEquals( 401, $response->get_status() );
349
+		wp_set_current_user(0);
350
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/system_status/tools/recount_terms'));
351
+		$this->assertEquals(401, $response->get_status());
352 352
 	}
353 353
 
354 354
 	/**
@@ -357,44 +357,44 @@  discard block
 block discarded – undo
357 357
 	 * @since 3.5.0
358 358
 	 */
359 359
 	public function test_execute_system_tool() {
360
-		$response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v4/system_status/tools/recount_terms' ) );
360
+		$response = $this->server->dispatch(new WP_REST_Request('POST', '/wc/v4/system_status/tools/recount_terms'));
361 361
 		$data     = $response->get_data();
362 362
 
363
-		$this->assertEquals( 'recount_terms', $data['id'] );
364
-		$this->assertEquals( 'Term counts', $data['name'] );
365
-		$this->assertEquals( 'Recount terms', $data['action'] );
366
-		$this->assertEquals( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description'] );
367
-		$this->assertTrue( $data['success'] );
368
-		$this->assertEquals( 1, did_action( 'woocommerce_rest_insert_system_status_tool' ) );
363
+		$this->assertEquals('recount_terms', $data['id']);
364
+		$this->assertEquals('Term counts', $data['name']);
365
+		$this->assertEquals('Recount terms', $data['action']);
366
+		$this->assertEquals('This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description']);
367
+		$this->assertTrue($data['success']);
368
+		$this->assertEquals(1, did_action('woocommerce_rest_insert_system_status_tool'));
369 369
 
370
-		$response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v4/system_status/tools/not_a_real_tool' ) );
371
-		$this->assertEquals( 404, $response->get_status() );
370
+		$response = $this->server->dispatch(new WP_REST_Request('POST', '/wc/v4/system_status/tools/not_a_real_tool'));
371
+		$this->assertEquals(404, $response->get_status());
372 372
 
373 373
 		// Test _fields for execute system tool request.
374 374
 		$query_params = array(
375 375
 			'_fields' => 'id,success,nonexisting',
376 376
 		);
377
-		$request      = new WP_REST_Request( 'PUT', '/wc/v4/system_status/tools/recount_terms' );
378
-		$request->set_query_params( $query_params );
379
-		$response = $this->server->dispatch( $request );
377
+		$request      = new WP_REST_Request('PUT', '/wc/v4/system_status/tools/recount_terms');
378
+		$request->set_query_params($query_params);
379
+		$response = $this->server->dispatch($request);
380 380
 		$data     = $response->get_data();
381 381
 
382
-		$this->assertEquals( 200, $response->get_status() );
383
-		$this->assertEquals( 'recount_terms', $data['id'] );
384
-		$this->assertTrue( $data['success'] );
382
+		$this->assertEquals(200, $response->get_status());
383
+		$this->assertEquals('recount_terms', $data['id']);
384
+		$this->assertTrue($data['success']);
385 385
 
386 386
 		// Fields that are not requested are not returned in response.
387
-		$this->assertArrayNotHasKey( 'action', $data );
388
-		$this->assertArrayNotHasKey( 'name', $data );
389
-		$this->assertArrayNotHasKey( 'description', $data );
387
+		$this->assertArrayNotHasKey('action', $data);
388
+		$this->assertArrayNotHasKey('name', $data);
389
+		$this->assertArrayNotHasKey('description', $data);
390 390
 		// Links are part of links, not data in single item response.
391
-		$this->assertArrayNotHasKey( '_links', $data );
391
+		$this->assertArrayNotHasKey('_links', $data);
392 392
 		// Non existing field is ignored.
393
-		$this->assertArrayNotHasKey( 'nonexisting', $data );
393
+		$this->assertArrayNotHasKey('nonexisting', $data);
394 394
 
395 395
 		// Links are part of links, not data in single item response.
396 396
 		$links = $response->get_links();
397
-		$this->assertEquals( 1, count( $links ) );
397
+		$this->assertEquals(1, count($links));
398 398
 	}
399 399
 
400 400
 	/**
@@ -403,9 +403,9 @@  discard block
 block discarded – undo
403 403
 	 * @since 3.5.0
404 404
 	 */
405 405
 	public function test_execute_system_status_tool_without_permission() {
406
-		wp_set_current_user( 0 );
407
-		$response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v4/system_status/tools/recount_terms' ) );
408
-		$this->assertEquals( 401, $response->get_status() );
406
+		wp_set_current_user(0);
407
+		$response = $this->server->dispatch(new WP_REST_Request('POST', '/wc/v4/system_status/tools/recount_terms'));
408
+		$this->assertEquals(401, $response->get_status());
409 409
 	}
410 410
 
411 411
 	/**
@@ -414,18 +414,18 @@  discard block
 block discarded – undo
414 414
 	 * @since 3.5.0
415 415
 	 */
416 416
 	public function test_system_status_tool_schema() {
417
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v4/system_status/tools' );
418
-		$response   = $this->server->dispatch( $request );
417
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v4/system_status/tools');
418
+		$response   = $this->server->dispatch($request);
419 419
 		$data       = $response->get_data();
420 420
 		$properties = $data['schema']['properties'];
421 421
 
422
-		$this->assertEquals( 6, count( $properties ) );
423
-		$this->assertArrayHasKey( 'id', $properties );
424
-		$this->assertArrayHasKey( 'name', $properties );
425
-		$this->assertArrayHasKey( 'action', $properties );
426
-		$this->assertArrayHasKey( 'description', $properties );
427
-		$this->assertArrayHasKey( 'success', $properties );
428
-		$this->assertArrayHasKey( 'message', $properties );
422
+		$this->assertEquals(6, count($properties));
423
+		$this->assertArrayHasKey('id', $properties);
424
+		$this->assertArrayHasKey('name', $properties);
425
+		$this->assertArrayHasKey('action', $properties);
426
+		$this->assertArrayHasKey('description', $properties);
427
+		$this->assertArrayHasKey('success', $properties);
428
+		$this->assertArrayHasKey('message', $properties);
429 429
 	}
430 430
 
431 431
 	/**
@@ -440,17 +440,17 @@  discard block
 block discarded – undo
440 440
 	 *
441 441
 	 * @return array|false mocked response or false to let WP perform a regular request.
442 442
 	 */
443
-	protected function mock_http_responses( $request, $url ) {
443
+	protected function mock_http_responses($request, $url) {
444 444
 		$mocked_response = false;
445 445
 
446
-		if ( in_array( $url, array( 'https://www.paypal.com/cgi-bin/webscr', 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=0' ), true ) ) {
446
+		if (in_array($url, array('https://www.paypal.com/cgi-bin/webscr', 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=0'), true)) {
447 447
 			$mocked_response = array(
448
-				'response' => array( 'code' => 200 ),
448
+				'response' => array('code' => 200),
449 449
 			);
450
-		} elseif ( 'https://api.wordpress.org/themes/info/1.0/' === $url ) {
450
+		} elseif ('https://api.wordpress.org/themes/info/1.0/' === $url) {
451 451
 			$mocked_response = array(
452 452
 				'body'     => 'O:8:"stdClass":12:{s:4:"name";s:7:"Default";s:4:"slug";s:7:"default";s:7:"version";s:5:"1.7.2";s:11:"preview_url";s:29:"https://wp-themes.com/default";s:6:"author";s:15:"wordpressdotorg";s:14:"screenshot_url";s:61:"//ts.w.org/wp-content/themes/default/screenshot.png?ver=1.7.2";s:6:"rating";d:100;s:11:"num_ratings";s:1:"3";s:10:"downloaded";i:296618;s:12:"last_updated";s:10:"2010-06-14";s:8:"homepage";s:37:"https://wordpress.org/themes/default/";s:13:"download_link";s:55:"https://downloads.wordpress.org/theme/default.1.7.2.zip";}',
453
-				'response' => array( 'code' => 200 ),
453
+				'response' => array('code' => 200),
454 454
 			);
455 455
 		}
456 456
 
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Leaderboards.php 1 patch
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use \WP_REST_Request;
13 13
 use \WC_REST_Unit_Test_Case;
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param object $factory Factory object.
37 37
 	 */
38
-	public static function wpSetUpBeforeClass( $factory ) {
38
+	public static function wpSetUpBeforeClass($factory) {
39 39
 		self::$user = $factory->user->create(
40 40
 			array(
41 41
 				'role' => 'administrator',
@@ -48,43 +48,43 @@  discard block
 block discarded – undo
48 48
 	 */
49 49
 	public function setUp() {
50 50
 		parent::setUp();
51
-		wp_set_current_user( self::$user );
51
+		wp_set_current_user(self::$user);
52 52
 	}
53 53
 
54 54
 	/**
55 55
 	 * Test that leaderboards are returned by the endpoint.
56 56
 	 */
57 57
 	public function test_get_leaderboards() {
58
-		$request  = new WP_REST_Request( 'GET', $this->endpoint );
59
-		$response = $this->server->dispatch( $request );
58
+		$request  = new WP_REST_Request('GET', $this->endpoint);
59
+		$response = $this->server->dispatch($request);
60 60
 		$data     = $response->get_data();
61 61
 
62
-		$this->assertEquals( 200, $response->get_status() );
63
-		$this->assertEquals( 'customers', $data[0]['id'] );
64
-		$this->assertEquals( 'coupons', $data[1]['id'] );
65
-		$this->assertEquals( 'categories', $data[2]['id'] );
66
-		$this->assertEquals( 'products', $data[3]['id'] );
62
+		$this->assertEquals(200, $response->get_status());
63
+		$this->assertEquals('customers', $data[0]['id']);
64
+		$this->assertEquals('coupons', $data[1]['id']);
65
+		$this->assertEquals('categories', $data[2]['id']);
66
+		$this->assertEquals('products', $data[3]['id']);
67 67
 	}
68 68
 
69 69
 	/**
70 70
 	 * Test reports schema.
71 71
 	 */
72 72
 	public function test_schema() {
73
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint );
74
-		$response   = $this->server->dispatch( $request );
73
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint);
74
+		$response   = $this->server->dispatch($request);
75 75
 		$data       = $response->get_data();
76 76
 		$properties = $data['schema']['properties'];
77 77
 
78
-		$this->assertCount( 4, $properties );
79
-		$this->assert_item_schema( $properties );
78
+		$this->assertCount(4, $properties);
79
+		$this->assert_item_schema($properties);
80 80
 
81
-		$request    = new WP_REST_Request( 'OPTIONS', $this->endpoint . '/allowed' );
82
-		$response   = $this->server->dispatch( $request );
81
+		$request    = new WP_REST_Request('OPTIONS', $this->endpoint . '/allowed');
82
+		$response   = $this->server->dispatch($request);
83 83
 		$data       = $response->get_data();
84 84
 		$properties = $data['schema']['properties'];
85 85
 
86
-		$this->assertCount( 3, $properties );
87
-		$this->assert_allowed_item_schema( $properties );
86
+		$this->assertCount(3, $properties);
87
+		$this->assert_allowed_item_schema($properties);
88 88
 	}
89 89
 
90 90
 	/**
@@ -92,20 +92,20 @@  discard block
 block discarded – undo
92 92
 	 *
93 93
 	 * @param array $schema Item to check schema.
94 94
 	 */
95
-	public function assert_item_schema( $schema ) {
96
-		$this->assertArrayHasKey( 'id', $schema );
97
-		$this->assertArrayHasKey( 'label', $schema );
98
-		$this->assertArrayHasKey( 'headers', $schema );
99
-		$this->assertArrayHasKey( 'rows', $schema );
95
+	public function assert_item_schema($schema) {
96
+		$this->assertArrayHasKey('id', $schema);
97
+		$this->assertArrayHasKey('label', $schema);
98
+		$this->assertArrayHasKey('headers', $schema);
99
+		$this->assertArrayHasKey('rows', $schema);
100 100
 
101 101
 		$header_properties = $schema['headers']['items']['properties'];
102
-		$this->assertCount( 1, $header_properties );
103
-		$this->assertArrayHasKey( 'label', $header_properties );
102
+		$this->assertCount(1, $header_properties);
103
+		$this->assertArrayHasKey('label', $header_properties);
104 104
 
105 105
 		$row_properties = $schema['rows']['items']['properties'];
106
-		$this->assertCount( 2, $row_properties );
107
-		$this->assertArrayHasKey( 'display', $row_properties );
108
-		$this->assertArrayHasKey( 'value', $row_properties );
106
+		$this->assertCount(2, $row_properties);
107
+		$this->assertArrayHasKey('display', $row_properties);
108
+		$this->assertArrayHasKey('value', $row_properties);
109 109
 	}
110 110
 
111 111
 	/**
@@ -113,14 +113,14 @@  discard block
 block discarded – undo
113 113
 	 *
114 114
 	 * @param array $schema Item to check schema.
115 115
 	 */
116
-	public function assert_allowed_item_schema( $schema ) {
117
-		$this->assertArrayHasKey( 'id', $schema );
118
-		$this->assertArrayHasKey( 'label', $schema );
119
-		$this->assertArrayHasKey( 'headers', $schema );
116
+	public function assert_allowed_item_schema($schema) {
117
+		$this->assertArrayHasKey('id', $schema);
118
+		$this->assertArrayHasKey('label', $schema);
119
+		$this->assertArrayHasKey('headers', $schema);
120 120
 
121 121
 		$header_properties = $schema['headers']['items']['properties'];
122
-		$this->assertCount( 1, $header_properties );
123
-		$this->assertArrayHasKey( 'label', $header_properties );
122
+		$this->assertCount(1, $header_properties);
123
+		$this->assertArrayHasKey('label', $header_properties);
124 124
 	}
125 125
 
126 126
 	/**
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	public function test_filter_leaderboards() {
130 130
 		add_filter(
131 131
 			'woocommerce_leaderboards',
132
-			function( $leaderboards, $per_page, $after, $before, $persisted_query ) {
132
+			function($leaderboards, $per_page, $after, $before, $persisted_query) {
133 133
 				$leaderboards[] = array(
134 134
 					'id'      => 'top_widgets',
135 135
 					'label'   => 'Top Widgets',
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 					),
141 141
 					'rows'    => array(
142 142
 						array(
143
-							'display' => wc_admin_url( 'test/path', $persisted_query ),
143
+							'display' => wc_admin_url('test/path', $persisted_query),
144 144
 							'value'   => null,
145 145
 						),
146 146
 					),
@@ -150,22 +150,22 @@  discard block
 block discarded – undo
150 150
 			10,
151 151
 			5
152 152
 		);
153
-		$request = new WP_REST_Request( 'GET', $this->endpoint );
154
-		$request->set_query_params( array( 'persisted_query' => '{ "persisted_param": 1 }' ) );
155
-		$response = $this->server->dispatch( $request );
153
+		$request = new WP_REST_Request('GET', $this->endpoint);
154
+		$request->set_query_params(array('persisted_query' => '{ "persisted_param": 1 }'));
155
+		$response = $this->server->dispatch($request);
156 156
 		$data     = $response->get_data();
157 157
 
158
-		$widgets_leaderboard = end( $data );
159
-		$this->assertEquals( 200, $response->get_status() );
160
-		$this->assertEquals( 'top_widgets', $widgets_leaderboard['id'] );
161
-		$this->assertEquals( admin_url( 'admin.php?page=wc-admin#test/path?persisted_param=1' ), $widgets_leaderboard['rows'][0]['display'] );
158
+		$widgets_leaderboard = end($data);
159
+		$this->assertEquals(200, $response->get_status());
160
+		$this->assertEquals('top_widgets', $widgets_leaderboard['id']);
161
+		$this->assertEquals(admin_url('admin.php?page=wc-admin#test/path?persisted_param=1'), $widgets_leaderboard['rows'][0]['display']);
162 162
 
163
-		$request  = new WP_REST_Request( 'GET', $this->endpoint . '/allowed' );
164
-		$response = $this->server->dispatch( $request );
163
+		$request  = new WP_REST_Request('GET', $this->endpoint . '/allowed');
164
+		$response = $this->server->dispatch($request);
165 165
 		$data     = $response->get_data();
166 166
 
167
-		$widgets_leaderboard = end( $data );
168
-		$this->assertEquals( 200, $response->get_status() );
169
-		$this->assertEquals( 'top_widgets', $widgets_leaderboard['id'] );
167
+		$widgets_leaderboard = end($data);
168
+		$this->assertEquals(200, $response->get_status());
169
+		$this->assertEquals('top_widgets', $widgets_leaderboard['id']);
170 170
 	}
171 171
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Coupons.php 1 patch
Spacing   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use \WooCommerce\RestApi\UnitTests\AbstractRestApiTest;
13 13
 use \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper;
@@ -35,33 +35,33 @@  discard block
 block discarded – undo
35 35
 	 * @var array Keys are property names, values are supported context.
36 36
 	 */
37 37
 	protected $properties = [
38
-		'id'                          => array( 'view', 'edit' ),
39
-		'code'                        => array( 'view', 'edit' ),
40
-		'amount'                      => array( 'view', 'edit' ),
41
-		'date_created'                => array( 'view', 'edit' ),
42
-		'date_created_gmt'            => array( 'view', 'edit' ),
43
-		'date_modified'               => array( 'view', 'edit' ),
44
-		'date_modified_gmt'           => array( 'view', 'edit' ),
45
-		'discount_type'               => array( 'view', 'edit' ),
46
-		'description'                 => array( 'view', 'edit' ),
47
-		'date_expires'                => array( 'view', 'edit' ),
48
-		'date_expires_gmt'            => array( 'view', 'edit' ),
49
-		'usage_count'                 => array( 'view', 'edit' ),
50
-		'individual_use'              => array( 'view', 'edit' ),
51
-		'product_ids'                 => array( 'view', 'edit' ),
52
-		'excluded_product_ids'        => array( 'view', 'edit' ),
53
-		'usage_limit'                 => array( 'view', 'edit' ),
54
-		'usage_limit_per_user'        => array( 'view', 'edit' ),
55
-		'limit_usage_to_x_items'      => array( 'view', 'edit' ),
56
-		'free_shipping'               => array( 'view', 'edit' ),
57
-		'product_categories'          => array( 'view', 'edit' ),
58
-		'excluded_product_categories' => array( 'view', 'edit' ),
59
-		'exclude_sale_items'          => array( 'view', 'edit' ),
60
-		'minimum_amount'              => array( 'view', 'edit' ),
61
-		'maximum_amount'              => array( 'view', 'edit' ),
62
-		'email_restrictions'          => array( 'view', 'edit' ),
63
-		'used_by'                     => array( 'view', 'edit' ),
64
-		'meta_data'                   => array( 'view', 'edit' ),
38
+		'id'                          => array('view', 'edit'),
39
+		'code'                        => array('view', 'edit'),
40
+		'amount'                      => array('view', 'edit'),
41
+		'date_created'                => array('view', 'edit'),
42
+		'date_created_gmt'            => array('view', 'edit'),
43
+		'date_modified'               => array('view', 'edit'),
44
+		'date_modified_gmt'           => array('view', 'edit'),
45
+		'discount_type'               => array('view', 'edit'),
46
+		'description'                 => array('view', 'edit'),
47
+		'date_expires'                => array('view', 'edit'),
48
+		'date_expires_gmt'            => array('view', 'edit'),
49
+		'usage_count'                 => array('view', 'edit'),
50
+		'individual_use'              => array('view', 'edit'),
51
+		'product_ids'                 => array('view', 'edit'),
52
+		'excluded_product_ids'        => array('view', 'edit'),
53
+		'usage_limit'                 => array('view', 'edit'),
54
+		'usage_limit_per_user'        => array('view', 'edit'),
55
+		'limit_usage_to_x_items'      => array('view', 'edit'),
56
+		'free_shipping'               => array('view', 'edit'),
57
+		'product_categories'          => array('view', 'edit'),
58
+		'excluded_product_categories' => array('view', 'edit'),
59
+		'exclude_sale_items'          => array('view', 'edit'),
60
+		'minimum_amount'              => array('view', 'edit'),
61
+		'maximum_amount'              => array('view', 'edit'),
62
+		'email_restrictions'          => array('view', 'edit'),
63
+		'used_by'                     => array('view', 'edit'),
64
+		'meta_data'                   => array('view', 'edit'),
65 65
 	];
66 66
 
67 67
 	/**
@@ -73,20 +73,20 @@  discard block
 block discarded – undo
73 73
 			'amount'                      => '5.00',
74 74
 			'discount_type'               => 'fixed_product',
75 75
 			'description'                 => 'Test description.',
76
-			'date_expires'                => date( 'Y-m-d\T00:00:00', strtotime( '+1 day' ) ),
76
+			'date_expires'                => date('Y-m-d\T00:00:00', strtotime('+1 day')),
77 77
 			'individual_use'              => true,
78
-			'product_ids'                 => [ 1, 2, 3 ],
79
-			'excluded_product_ids'        => [ 3, 4, 5 ],
78
+			'product_ids'                 => [1, 2, 3],
79
+			'excluded_product_ids'        => [3, 4, 5],
80 80
 			'usage_limit'                 => 10,
81 81
 			'usage_limit_per_user'        => 10,
82 82
 			'limit_usage_to_x_items'      => 10,
83 83
 			'free_shipping'               => false,
84
-			'product_categories'          => [ 1, 2, 3 ],
85
-			'excluded_product_categories' => [ 3, 4, 5 ],
84
+			'product_categories'          => [1, 2, 3],
85
+			'excluded_product_categories' => [3, 4, 5],
86 86
 			'exclude_sale_items'          => true,
87 87
 			'minimum_amount'              => '100',
88 88
 			'maximum_amount'              => '200',
89
-			'email_restrictions'          => [ '[email protected]' ],
89
+			'email_restrictions'          => ['[email protected]'],
90 90
 			'meta_data'                   => [
91 91
 				[
92 92
 					'key'   => 'test_key',
@@ -94,44 +94,44 @@  discard block
 block discarded – undo
94 94
 				]
95 95
 			]
96 96
 		];
97
-		$response = $this->do_request( '/wc/v4/coupons', 'POST', $valid_data );
98
-		$this->assertExpectedResponse( $response, 201, $valid_data );
97
+		$response = $this->do_request('/wc/v4/coupons', 'POST', $valid_data);
98
+		$this->assertExpectedResponse($response, 201, $valid_data);
99 99
 	}
100 100
 
101 101
 	/**
102 102
 	 * Test read.
103 103
 	 */
104 104
 	public function test_read() {
105
-		$coupon1 = CouponHelper::create_coupon( 'testcoupon-1' );
106
-		$coupon2 = CouponHelper::create_coupon( 'testcoupon-2' );
107
-		$coupon3 = CouponHelper::create_coupon( 'anothertestcoupon-3' );
108
-		$coupon4 = CouponHelper::create_coupon( 'anothertestcoupon-4' );
105
+		$coupon1 = CouponHelper::create_coupon('testcoupon-1');
106
+		$coupon2 = CouponHelper::create_coupon('testcoupon-2');
107
+		$coupon3 = CouponHelper::create_coupon('anothertestcoupon-3');
108
+		$coupon4 = CouponHelper::create_coupon('anothertestcoupon-4');
109 109
 
110 110
 		// Collection.
111
-		$response = $this->do_request( '/wc/v4/coupons', 'GET' );
112
-		$this->assertExpectedResponse( $response, 200 );
113
-		$this->assertEquals( 4, count( $response->data ) );
111
+		$response = $this->do_request('/wc/v4/coupons', 'GET');
112
+		$this->assertExpectedResponse($response, 200);
113
+		$this->assertEquals(4, count($response->data));
114 114
 
115 115
 		// Collection args.
116
-		$response = $this->do_request( '/wc/v4/coupons', 'GET', [ 'code' => 'testcoupon-1' ] );
117
-		$this->assertExpectedResponse( $response, 200 );
118
-		$this->assertEquals( 1, count( $response->data ) );
116
+		$response = $this->do_request('/wc/v4/coupons', 'GET', ['code' => 'testcoupon-1']);
117
+		$this->assertExpectedResponse($response, 200);
118
+		$this->assertEquals(1, count($response->data));
119 119
 
120
-		$response = $this->do_request( '/wc/v4/coupons', 'GET', [ 'search' => 'anothertestcoupon' ] );
121
-		$this->assertExpectedResponse( $response, 200 );
122
-		$this->assertEquals( 2, count( $response->data ) );
120
+		$response = $this->do_request('/wc/v4/coupons', 'GET', ['search' => 'anothertestcoupon']);
121
+		$this->assertExpectedResponse($response, 200);
122
+		$this->assertEquals(2, count($response->data));
123 123
 
124 124
 		// Single.
125
-		$response = $this->do_request( '/wc/v4/coupons/' . $coupon1->get_id(), 'GET' );
126
-		$this->assertExpectedResponse( $response, 200 );
125
+		$response = $this->do_request('/wc/v4/coupons/' . $coupon1->get_id(), 'GET');
126
+		$this->assertExpectedResponse($response, 200);
127 127
 
128
-		foreach ( $this->get_properties( 'view' ) as $property ) {
129
-			$this->assertArrayHasKey( $property, $response->data );
128
+		foreach ($this->get_properties('view') as $property) {
129
+			$this->assertArrayHasKey($property, $response->data);
130 130
 		}
131 131
 
132 132
 		// Invalid.
133
-		$response = $this->do_request( '/wc/v4/coupons/0', 'GET' );
134
-		$this->assertExpectedResponse( $response, 404 );
133
+		$response = $this->do_request('/wc/v4/coupons/0', 'GET');
134
+		$this->assertExpectedResponse($response, 404);
135 135
 	}
136 136
 
137 137
 	/**
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
 	 */
140 140
 	public function test_update() {
141 141
 		// Invalid.
142
-		$response = $this->do_request( '/wc/v4/coupons/0', 'POST', [ 'code' => 'test' ] );
143
-		$this->assertExpectedResponse( $response, 404 );
142
+		$response = $this->do_request('/wc/v4/coupons/0', 'POST', ['code' => 'test']);
143
+		$this->assertExpectedResponse($response, 404);
144 144
 
145 145
 		// Update existing.
146
-		$coupon   = CouponHelper::create_coupon( 'testcoupon-1' );
146
+		$coupon   = CouponHelper::create_coupon('testcoupon-1');
147 147
 		$response = $this->do_request(
148 148
 			'/wc/v4/coupons/' . $coupon->get_id(),
149 149
 			'POST',
@@ -152,15 +152,15 @@  discard block
 block discarded – undo
152 152
 				'description' => 'new description',
153 153
 			]
154 154
 		);
155
-		$this->assertExpectedResponse( $response, 200 );
155
+		$this->assertExpectedResponse($response, 200);
156 156
 
157
-		foreach ( $this->get_properties( 'view' ) as $property ) {
158
-			$this->assertArrayHasKey( $property, $response->data );
157
+		foreach ($this->get_properties('view') as $property) {
158
+			$this->assertArrayHasKey($property, $response->data);
159 159
 		}
160 160
 
161
-		$this->assertEquals( $coupon->get_id(), $response->data['id'] );
162
-		$this->assertEquals( 'new-code', $response->data['code'] );
163
-		$this->assertEquals( 'new description', $response->data['description'] );
161
+		$this->assertEquals($coupon->get_id(), $response->data['id']);
162
+		$this->assertEquals('new-code', $response->data['code']);
163
+		$this->assertEquals('new description', $response->data['description']);
164 164
 	}
165 165
 
166 166
 	/**
@@ -168,48 +168,48 @@  discard block
 block discarded – undo
168 168
 	 */
169 169
 	public function test_delete() {
170 170
 		// Invalid.
171
-		$result = $this->do_request( '/wc/v4/coupons/0', 'DELETE', [ 'force' => false ] );
172
-		$this->assertEquals( 404, $result->status );
171
+		$result = $this->do_request('/wc/v4/coupons/0', 'DELETE', ['force' => false]);
172
+		$this->assertEquals(404, $result->status);
173 173
 
174 174
 		// Trash.
175
-		$coupon = CouponHelper::create_coupon( 'testcoupon-1' );
175
+		$coupon = CouponHelper::create_coupon('testcoupon-1');
176 176
 
177
-		$result = $this->do_request( '/wc/v4/coupons/' . $coupon->get_id(), 'DELETE', [ 'force' => false ] );
178
-		$this->assertEquals( 200, $result->status );
179
-		$this->assertEquals( 'trash', get_post_status( $coupon->get_id() ) );
177
+		$result = $this->do_request('/wc/v4/coupons/' . $coupon->get_id(), 'DELETE', ['force' => false]);
178
+		$this->assertEquals(200, $result->status);
179
+		$this->assertEquals('trash', get_post_status($coupon->get_id()));
180 180
 
181 181
 		// Force.
182
-		$coupon = CouponHelper::create_coupon( 'testcoupon-2' );
182
+		$coupon = CouponHelper::create_coupon('testcoupon-2');
183 183
 
184
-		$result = $this->do_request( '/wc/v4/coupons/' . $coupon->get_id(), 'DELETE', [ 'force' => true ] );
185
-		$this->assertEquals( 200, $result->status );
186
-		$this->assertEquals( false, get_post( $coupon->get_id() ) );
184
+		$result = $this->do_request('/wc/v4/coupons/' . $coupon->get_id(), 'DELETE', ['force' => true]);
185
+		$this->assertEquals(200, $result->status);
186
+		$this->assertEquals(false, get_post($coupon->get_id()));
187 187
 	}
188 188
 
189 189
 	/**
190 190
 	 * Test read.
191 191
 	 */
192 192
 	public function test_guest_create() {
193
-		wp_set_current_user( 0 );
193
+		wp_set_current_user(0);
194 194
 		$valid_data = [
195 195
 			'code'                        => 'test-coupon',
196 196
 			'amount'                      => '5.00',
197 197
 			'discount_type'               => 'fixed_product',
198 198
 			'description'                 => 'Test description.',
199
-			'date_expires'                => date( 'Y-m-d\T00:00:00', strtotime( '+1 day' ) ),
199
+			'date_expires'                => date('Y-m-d\T00:00:00', strtotime('+1 day')),
200 200
 			'individual_use'              => true,
201
-			'product_ids'                 => [ 1, 2, 3 ],
202
-			'excluded_product_ids'        => [ 3, 4, 5 ],
201
+			'product_ids'                 => [1, 2, 3],
202
+			'excluded_product_ids'        => [3, 4, 5],
203 203
 			'usage_limit'                 => 10,
204 204
 			'usage_limit_per_user'        => 10,
205 205
 			'limit_usage_to_x_items'      => 10,
206 206
 			'free_shipping'               => false,
207
-			'product_categories'          => [ 1, 2, 3 ],
208
-			'excluded_product_categories' => [ 3, 4, 5 ],
207
+			'product_categories'          => [1, 2, 3],
208
+			'excluded_product_categories' => [3, 4, 5],
209 209
 			'exclude_sale_items'          => true,
210 210
 			'minimum_amount'              => '100',
211 211
 			'maximum_amount'              => '200',
212
-			'email_restrictions'          => [ '[email protected]' ],
212
+			'email_restrictions'          => ['[email protected]'],
213 213
 			'meta_data'                   => [
214 214
 				[
215 215
 					'key'   => 'test_key',
@@ -217,25 +217,25 @@  discard block
 block discarded – undo
217 217
 				]
218 218
 			]
219 219
 		];
220
-		$response = $this->do_request( '/wc/v4/coupons', 'POST', $valid_data );
221
-		$this->assertExpectedResponse( $response, 401 );
220
+		$response = $this->do_request('/wc/v4/coupons', 'POST', $valid_data);
221
+		$this->assertExpectedResponse($response, 401);
222 222
 	}
223 223
 
224 224
 	/**
225 225
 	 * Test read.
226 226
 	 */
227 227
 	public function test_guest_read() {
228
-		wp_set_current_user( 0 );
229
-		$response = $this->do_request( '/wc/v4/coupons', 'GET' );
230
-		$this->assertExpectedResponse( $response, 401 );
228
+		wp_set_current_user(0);
229
+		$response = $this->do_request('/wc/v4/coupons', 'GET');
230
+		$this->assertExpectedResponse($response, 401);
231 231
 	}
232 232
 
233 233
 	/**
234 234
 	 * Test update.
235 235
 	 */
236 236
 	public function test_guest_update() {
237
-		wp_set_current_user( 0 );
238
-		$coupon   = CouponHelper::create_coupon( 'testcoupon-1' );
237
+		wp_set_current_user(0);
238
+		$coupon   = CouponHelper::create_coupon('testcoupon-1');
239 239
 		$response = $this->do_request(
240 240
 			'/wc/v4/coupons/' . $coupon->get_id(),
241 241
 			'POST',
@@ -244,17 +244,17 @@  discard block
 block discarded – undo
244 244
 				'description' => 'new description',
245 245
 			]
246 246
 		);
247
-		$this->assertExpectedResponse( $response, 401 );
247
+		$this->assertExpectedResponse($response, 401);
248 248
 	}
249 249
 
250 250
 	/**
251 251
 	 * Test delete.
252 252
 	 */
253 253
 	public function test_guest_delete() {
254
-		wp_set_current_user( 0 );
255
-		$coupon = CouponHelper::create_coupon( 'testcoupon-1' );
256
-		$result = $this->do_request( '/wc/v4/coupons/' . $coupon->get_id(), 'DELETE', [ 'force' => false ] );
257
-		$this->assertEquals( 401, $result->status );
254
+		wp_set_current_user(0);
255
+		$coupon = CouponHelper::create_coupon('testcoupon-1');
256
+		$result = $this->do_request('/wc/v4/coupons/' . $coupon->get_id(), 'DELETE', ['force' => false]);
257
+		$this->assertEquals(401, $result->status);
258 258
 	}
259 259
 
260 260
 	/**
@@ -271,18 +271,18 @@  discard block
 block discarded – undo
271 271
 			]
272 272
 		);
273 273
 
274
-		$this->assertEquals( 400, $result->status );
275
-		$this->assertEquals( 'Invalid parameter(s): discount_type', $result->data['message'] );
274
+		$this->assertEquals(400, $result->status);
275
+		$this->assertEquals('Invalid parameter(s): discount_type', $result->data['message']);
276 276
 	}
277 277
 
278 278
 	/**
279 279
 	 * Test a batch update.
280 280
 	 */
281 281
 	public function test_batch() {
282
-		$coupon_1 = CouponHelper::create_coupon( 'batchcoupon-1' );
283
-		$coupon_2 = CouponHelper::create_coupon( 'batchcoupon-2' );
284
-		$coupon_3 = CouponHelper::create_coupon( 'batchcoupon-3' );
285
-		$coupon_4 = CouponHelper::create_coupon( 'batchcoupon-4' );
282
+		$coupon_1 = CouponHelper::create_coupon('batchcoupon-1');
283
+		$coupon_2 = CouponHelper::create_coupon('batchcoupon-2');
284
+		$coupon_3 = CouponHelper::create_coupon('batchcoupon-3');
285
+		$coupon_4 = CouponHelper::create_coupon('batchcoupon-4');
286 286
 
287 287
 		$result = $this->do_request(
288 288
 			'/wc/v4/coupons/batch',
@@ -307,13 +307,13 @@  discard block
 block discarded – undo
307 307
 			)
308 308
 		);
309 309
 
310
-		$this->assertEquals( '5.15', $result->data['update'][0]['amount'] );
311
-		$this->assertEquals( '11.00', $result->data['create'][0]['amount'] );
312
-		$this->assertEquals( 'new-coupon', $result->data['create'][0]['code'] );
313
-		$this->assertEquals( $coupon_2->get_id(), $result->data['delete'][0]['previous']['id'] );
314
-		$this->assertEquals( $coupon_3->get_id(), $result->data['delete'][1]['previous']['id'] );
310
+		$this->assertEquals('5.15', $result->data['update'][0]['amount']);
311
+		$this->assertEquals('11.00', $result->data['create'][0]['amount']);
312
+		$this->assertEquals('new-coupon', $result->data['create'][0]['code']);
313
+		$this->assertEquals($coupon_2->get_id(), $result->data['delete'][0]['previous']['id']);
314
+		$this->assertEquals($coupon_3->get_id(), $result->data['delete'][1]['previous']['id']);
315 315
 
316
-		$result = $this->do_request( '/wc/v4/coupons' );
317
-		$this->assertEquals( 3, count( $result->data ) );
316
+		$result = $this->do_request('/wc/v4/coupons');
317
+		$this->assertEquals(3, count($result->data));
318 318
 	}
319 319
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Orders.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -138,10 +138,10 @@
 block discarded – undo
138 138
 	}
139 139
 
140 140
 		/**
141
-	 * Test the sanitization of the payment_method_title field through the API.
142
-	 *
143
-	 * @since 3.5.2
144
-	 */
141
+		 * Test the sanitization of the payment_method_title field through the API.
142
+		 *
143
+		 * @since 3.5.2
144
+		 */
145 145
 	public function test_create_update_order_payment_method_title_sanitize() {
146 146
 		$product = ProductHelper::create_simple_product();
147 147
 		$data    = [
Please login to merge, or discard this patch.
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 use \WooCommerce\RestApi\UnitTests\AbstractRestApiTest;
13 13
 use \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
@@ -37,49 +37,49 @@  discard block
 block discarded – undo
37 37
 	 * @var array Keys are property names, values are supported context.
38 38
 	 */
39 39
 	protected $properties = [
40
-		'id'                   => array( 'view', 'edit' ),
41
-		'parent_id'            => array( 'view', 'edit' ),
42
-		'number'               => array( 'view', 'edit' ),
43
-		'order_key'            => array( 'view', 'edit' ),
44
-		'created_via'          => array( 'view', 'edit' ),
45
-		'version'              => array( 'view', 'edit' ),
46
-		'status'               => array( 'view', 'edit' ),
47
-		'currency'             => array( 'view', 'edit' ),
48
-		'currency_symbol'      => array( 'view', 'edit' ),
49
-		'date_created'         => array( 'view', 'edit' ),
50
-		'date_created_gmt'     => array( 'view', 'edit' ),
51
-		'date_modified'        => array( 'view', 'edit' ),
52
-		'date_modified_gmt'    => array( 'view', 'edit' ),
53
-		'discount_total'       => array( 'view', 'edit' ),
54
-		'discount_tax'         => array( 'view', 'edit' ),
55
-		'shipping_total'       => array( 'view', 'edit' ),
56
-		'shipping_tax'         => array( 'view', 'edit' ),
57
-		'cart_tax'             => array( 'view', 'edit' ),
58
-		'total'                => array( 'view', 'edit' ),
59
-		'total_tax'            => array( 'view', 'edit' ),
60
-		'prices_include_tax'   => array( 'view', 'edit' ),
61
-		'customer_id'          => array( 'view', 'edit' ),
62
-		'customer_ip_address'  => array( 'view', 'edit' ),
63
-		'customer_user_agent'  => array( 'view', 'edit' ),
64
-		'customer_note'        => array( 'view', 'edit' ),
65
-		'billing'              => array( 'view', 'edit' ),
66
-		'shipping'             => array( 'view', 'edit' ),
67
-		'payment_method'       => array( 'view', 'edit' ),
68
-		'payment_method_title' => array( 'view', 'edit' ),
69
-		'transaction_id'       => array( 'view', 'edit' ),
70
-		'date_paid'            => array( 'view', 'edit' ),
71
-		'date_paid_gmt'        => array( 'view', 'edit' ),
72
-		'date_completed'       => array( 'view', 'edit' ),
73
-		'date_completed_gmt'   => array( 'view', 'edit' ),
74
-		'cart_hash'            => array( 'view', 'edit' ),
75
-		'meta_data'            => array( 'view', 'edit' ),
76
-		'line_items'           => array( 'view', 'edit' ),
77
-		'tax_lines'            => array( 'view', 'edit' ),
78
-		'shipping_lines'       => array( 'view', 'edit' ),
79
-		'fee_lines'            => array( 'view', 'edit' ),
80
-		'coupon_lines'         => array( 'view', 'edit' ),
81
-		'refunds'              => array( 'view', 'edit' ),
82
-		'set_paid'             => array( 'edit' ),
40
+		'id'                   => array('view', 'edit'),
41
+		'parent_id'            => array('view', 'edit'),
42
+		'number'               => array('view', 'edit'),
43
+		'order_key'            => array('view', 'edit'),
44
+		'created_via'          => array('view', 'edit'),
45
+		'version'              => array('view', 'edit'),
46
+		'status'               => array('view', 'edit'),
47
+		'currency'             => array('view', 'edit'),
48
+		'currency_symbol'      => array('view', 'edit'),
49
+		'date_created'         => array('view', 'edit'),
50
+		'date_created_gmt'     => array('view', 'edit'),
51
+		'date_modified'        => array('view', 'edit'),
52
+		'date_modified_gmt'    => array('view', 'edit'),
53
+		'discount_total'       => array('view', 'edit'),
54
+		'discount_tax'         => array('view', 'edit'),
55
+		'shipping_total'       => array('view', 'edit'),
56
+		'shipping_tax'         => array('view', 'edit'),
57
+		'cart_tax'             => array('view', 'edit'),
58
+		'total'                => array('view', 'edit'),
59
+		'total_tax'            => array('view', 'edit'),
60
+		'prices_include_tax'   => array('view', 'edit'),
61
+		'customer_id'          => array('view', 'edit'),
62
+		'customer_ip_address'  => array('view', 'edit'),
63
+		'customer_user_agent'  => array('view', 'edit'),
64
+		'customer_note'        => array('view', 'edit'),
65
+		'billing'              => array('view', 'edit'),
66
+		'shipping'             => array('view', 'edit'),
67
+		'payment_method'       => array('view', 'edit'),
68
+		'payment_method_title' => array('view', 'edit'),
69
+		'transaction_id'       => array('view', 'edit'),
70
+		'date_paid'            => array('view', 'edit'),
71
+		'date_paid_gmt'        => array('view', 'edit'),
72
+		'date_completed'       => array('view', 'edit'),
73
+		'date_completed_gmt'   => array('view', 'edit'),
74
+		'cart_hash'            => array('view', 'edit'),
75
+		'meta_data'            => array('view', 'edit'),
76
+		'line_items'           => array('view', 'edit'),
77
+		'tax_lines'            => array('view', 'edit'),
78
+		'shipping_lines'       => array('view', 'edit'),
79
+		'fee_lines'            => array('view', 'edit'),
80
+		'coupon_lines'         => array('view', 'edit'),
81
+		'refunds'              => array('view', 'edit'),
82
+		'set_paid'             => array('edit'),
83 83
 	];
84 84
 
85 85
 	/**
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
 				),
134 134
 			),
135 135
 		];
136
-		$response = $this->do_request( '/wc/v4/orders', 'POST', $data );
137
-		$this->assertExpectedResponse( $response, 201, $data );
136
+		$response = $this->do_request('/wc/v4/orders', 'POST', $data);
137
+		$this->assertExpectedResponse($response, 201, $data);
138 138
 	}
139 139
 
140 140
 		/**
@@ -184,11 +184,11 @@  discard block
 block discarded – undo
184 184
 				),
185 185
 			),
186 186
 		];
187
-		$response = $this->do_request( '/wc/v4/orders', 'POST', $data );
188
-		$order    = wc_get_order( $response->data['id'] );
189
-		$this->assertExpectedResponse( $response, 201 );
190
-		$this->assertEquals( $order->get_payment_method(), $response->data['payment_method'] );
191
-		$this->assertEquals( $order->get_payment_method_title(), 'Sanitize this' );
187
+		$response = $this->do_request('/wc/v4/orders', 'POST', $data);
188
+		$order    = wc_get_order($response->data['id']);
189
+		$this->assertExpectedResponse($response, 201);
190
+		$this->assertEquals($order->get_payment_method(), $response->data['payment_method']);
191
+		$this->assertEquals($order->get_payment_method_title(), 'Sanitize this');
192 192
 
193 193
 		// Test when updating order.
194 194
 		$response = $this->do_request(
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
 				'payment_method_title' => '<h1>Sanitize this too <script>alert(1);</script></h1>',
199 199
 			]
200 200
 		);
201
-		$order    = wc_get_order( $response->data['id'] );
202
-		$this->assertExpectedResponse( $response, 200 );
203
-		$this->assertEquals( $order->get_payment_method(), $response->data['payment_method'] );
204
-		$this->assertEquals( $order->get_payment_method_title(), 'Sanitize this too' );
201
+		$order = wc_get_order($response->data['id']);
202
+		$this->assertExpectedResponse($response, 200);
203
+		$this->assertEquals($order->get_payment_method(), $response->data['payment_method']);
204
+		$this->assertEquals($order->get_payment_method_title(), 'Sanitize this too');
205 205
 	}
206 206
 
207 207
 	/**
@@ -251,73 +251,73 @@  discard block
 block discarded – undo
251 251
 				),
252 252
 			),
253 253
 		];
254
-		$response = $this->do_request( '/wc/v4/orders', 'POST', $data );
255
-		$this->assertExpectedResponse( $response, 400 );
254
+		$response = $this->do_request('/wc/v4/orders', 'POST', $data);
255
+		$this->assertExpectedResponse($response, 400);
256 256
 	}
257 257
 
258 258
 	/**
259 259
 	 * Test read.
260 260
 	 */
261 261
 	public function test_read() {
262
-		$product  = ProductHelper::create_simple_product();
263
-		$product->set_regular_price( 10.95 );
264
-		$product->set_sale_price( false );
262
+		$product = ProductHelper::create_simple_product();
263
+		$product->set_regular_price(10.95);
264
+		$product->set_sale_price(false);
265 265
 		$product->save();
266 266
 		$customer = CustomerHelper::create_customer();
267 267
 		$orders   = [];
268
-		$orders[] = OrderHelper::create_order( $customer->get_id(), $product );
268
+		$orders[] = OrderHelper::create_order($customer->get_id(), $product);
269 269
 
270 270
 		// Create orders.
271
-		for ( $i = 0; $i < 9; $i++ ) {
272
-			$orders[] = OrderHelper::create_order( $this->user );
271
+		for ($i = 0; $i < 9; $i++) {
272
+			$orders[] = OrderHelper::create_order($this->user);
273 273
 		}
274 274
 
275
-		$orders[5]->set_status( 'on-hold' );
275
+		$orders[5]->set_status('on-hold');
276 276
 		$orders[5]->save();
277
-		$orders[6]->set_status( 'on-hold' );
277
+		$orders[6]->set_status('on-hold');
278 278
 		$orders[6]->save();
279 279
 		$orders[0]->calculate_totals();
280 280
 		$orders[0]->save();
281 281
 
282 282
 		// Collection.
283
-		$response = $this->do_request( '/wc/v4/orders', 'GET' );
284
-		$this->assertExpectedResponse( $response, 200 );
285
-		$this->assertEquals( 10, count( $response->data ) );
283
+		$response = $this->do_request('/wc/v4/orders', 'GET');
284
+		$this->assertExpectedResponse($response, 200);
285
+		$this->assertEquals(10, count($response->data));
286 286
 
287 287
 		// Collection args.
288
-		$response = $this->do_request( '/wc/v4/orders', 'GET', [ 'status' => 'on-hold' ] );
289
-		$this->assertExpectedResponse( $response, 200 );
290
-		$this->assertEquals( 2, count( $response->data ) );
288
+		$response = $this->do_request('/wc/v4/orders', 'GET', ['status' => 'on-hold']);
289
+		$this->assertExpectedResponse($response, 200);
290
+		$this->assertEquals(2, count($response->data));
291 291
 
292
-		$response = $this->do_request( '/wc/v4/orders', 'GET', [ 'number' => (string) $orders[0]->get_id() ] );
293
-		$this->assertExpectedResponse( $response, 200 );
294
-		$this->assertEquals( 1, count( $response->data ) );
292
+		$response = $this->do_request('/wc/v4/orders', 'GET', ['number' => (string) $orders[0]->get_id()]);
293
+		$this->assertExpectedResponse($response, 200);
294
+		$this->assertEquals(1, count($response->data));
295 295
 
296
-		$response = $this->do_request( '/wc/v4/orders', 'GET', [ 'customer' => $customer->get_id() ] );
297
-		$this->assertExpectedResponse( $response, 200 );
298
-		$this->assertEquals( 1, count( $response->data ) );
296
+		$response = $this->do_request('/wc/v4/orders', 'GET', ['customer' => $customer->get_id()]);
297
+		$this->assertExpectedResponse($response, 200);
298
+		$this->assertEquals(1, count($response->data));
299 299
 
300
-		$response = $this->do_request( '/wc/v4/orders', 'GET', [ 'product' => $product->get_id() ] );
301
-		$this->assertExpectedResponse( $response, 200 );
302
-		$this->assertEquals( 1, count( $response->data ) );
300
+		$response = $this->do_request('/wc/v4/orders', 'GET', ['product' => $product->get_id()]);
301
+		$this->assertExpectedResponse($response, 200);
302
+		$this->assertEquals(1, count($response->data));
303 303
 
304 304
 		// Single collection args.
305
-		$response = $this->do_request( '/wc/v4/orders/' . $orders[0]->get_id(), 'GET', [ 'dp' => 0 ] );
306
-		$this->assertEquals( '54', $response->data['total'] );
307
-		$response = $this->do_request( '/wc/v4/orders/' . $orders[0]->get_id(), 'GET', [ 'dp' => 2 ] );
308
-		$this->assertEquals( '53.80', $response->data['total'] );
305
+		$response = $this->do_request('/wc/v4/orders/' . $orders[0]->get_id(), 'GET', ['dp' => 0]);
306
+		$this->assertEquals('54', $response->data['total']);
307
+		$response = $this->do_request('/wc/v4/orders/' . $orders[0]->get_id(), 'GET', ['dp' => 2]);
308
+		$this->assertEquals('53.80', $response->data['total']);
309 309
 
310 310
 		// Single.
311
-		$response = $this->do_request( '/wc/v4/orders/' . $orders[0]->get_id(), 'GET' );
312
-		$this->assertExpectedResponse( $response, 200 );
311
+		$response = $this->do_request('/wc/v4/orders/' . $orders[0]->get_id(), 'GET');
312
+		$this->assertExpectedResponse($response, 200);
313 313
 
314
-		foreach ( $this->get_properties( 'view' ) as $property ) {
315
-			$this->assertArrayHasKey( $property, $response->data );
314
+		foreach ($this->get_properties('view') as $property) {
315
+			$this->assertArrayHasKey($property, $response->data);
316 316
 		}
317 317
 
318 318
 		// Invalid.
319
-		$response = $this->do_request( '/wc/v4/orders/0', 'GET' );
320
-		$this->assertExpectedResponse( $response, 404 );
319
+		$response = $this->do_request('/wc/v4/orders/0', 'GET');
320
+		$this->assertExpectedResponse($response, 404);
321 321
 	}
322 322
 
323 323
 	/**
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 	 */
326 326
 	public function test_update() {
327 327
 		// Invalid.
328
-		$response = $this->do_request( '/wc/v4/orders/0', 'POST', [ 'payment_method' => 'test' ] );
329
-		$this->assertExpectedResponse( $response, 404 );
328
+		$response = $this->do_request('/wc/v4/orders/0', 'POST', ['payment_method' => 'test']);
329
+		$this->assertExpectedResponse($response, 404);
330 330
 
331 331
 		// Update existing.
332 332
 		$order    = OrderHelper::create_order();
@@ -342,10 +342,10 @@  discard block
 block discarded – undo
342 342
 			'POST',
343 343
 			$data
344 344
 		);
345
-		$this->assertExpectedResponse( $response, 200, $data );
345
+		$this->assertExpectedResponse($response, 200, $data);
346 346
 
347
-		foreach ( $this->get_properties( 'view' ) as $property ) {
348
-			$this->assertArrayHasKey( $property, $response->data );
347
+		foreach ($this->get_properties('view') as $property) {
348
+			$this->assertArrayHasKey($property, $response->data);
349 349
 		}
350 350
 	}
351 351
 
@@ -354,27 +354,27 @@  discard block
 block discarded – undo
354 354
 	 */
355 355
 	public function test_delete() {
356 356
 		// Invalid.
357
-		$result = $this->do_request( '/wc/v4/orders/0', 'DELETE', [ 'force' => false ] );
358
-		$this->assertEquals( 404, $result->status );
357
+		$result = $this->do_request('/wc/v4/orders/0', 'DELETE', ['force' => false]);
358
+		$this->assertEquals(404, $result->status);
359 359
 
360 360
 		// Trash.
361 361
 		$order  = OrderHelper::create_order();
362
-		$result = $this->do_request( '/wc/v4/orders/' . $order->get_id(), 'DELETE', [ 'force' => false ] );
363
-		$this->assertEquals( 200, $result->status );
364
-		$this->assertEquals( 'trash', get_post_status( $order->get_id() ) );
362
+		$result = $this->do_request('/wc/v4/orders/' . $order->get_id(), 'DELETE', ['force' => false]);
363
+		$this->assertEquals(200, $result->status);
364
+		$this->assertEquals('trash', get_post_status($order->get_id()));
365 365
 
366 366
 		// Force.
367 367
 		$order  = OrderHelper::create_order();
368
-		$result = $this->do_request( '/wc/v4/orders/' . $order->get_id(), 'DELETE', [ 'force' => true ] );
369
-		$this->assertEquals( 200, $result->status );
370
-		$this->assertEquals( false, get_post( $order->get_id() ) );
368
+		$result = $this->do_request('/wc/v4/orders/' . $order->get_id(), 'DELETE', ['force' => true]);
369
+		$this->assertEquals(200, $result->status);
370
+		$this->assertEquals(false, get_post($order->get_id()));
371 371
 	}
372 372
 
373 373
 	/**
374 374
 	 * Test read.
375 375
 	 */
376 376
 	public function test_guest_create() {
377
-		wp_set_current_user( 0 );
377
+		wp_set_current_user(0);
378 378
 		$product = ProductHelper::create_simple_product();
379 379
 		$data    = [
380 380
 			'currency'             => 'ZAR',
@@ -422,24 +422,24 @@  discard block
 block discarded – undo
422 422
 				),
423 423
 			),
424 424
 		];
425
-		$response = $this->do_request( '/wc/v4/orders', 'POST', $data );
426
-		$this->assertExpectedResponse( $response, 401, $data );
425
+		$response = $this->do_request('/wc/v4/orders', 'POST', $data);
426
+		$this->assertExpectedResponse($response, 401, $data);
427 427
 	}
428 428
 
429 429
 	/**
430 430
 	 * Test read.
431 431
 	 */
432 432
 	public function test_guest_read() {
433
-		wp_set_current_user( 0 );
434
-		$response = $this->do_request( '/wc/v4/orders', 'GET' );
435
-		$this->assertExpectedResponse( $response, 401 );
433
+		wp_set_current_user(0);
434
+		$response = $this->do_request('/wc/v4/orders', 'GET');
435
+		$this->assertExpectedResponse($response, 401);
436 436
 	}
437 437
 
438 438
 	/**
439 439
 	 * Test update.
440 440
 	 */
441 441
 	public function test_guest_update() {
442
-		wp_set_current_user( 0 );
442
+		wp_set_current_user(0);
443 443
 		$order    = OrderHelper::create_order();
444 444
 		$data     = [
445 445
 			'payment_method' => 'test-update',
@@ -453,17 +453,17 @@  discard block
 block discarded – undo
453 453
 			'POST',
454 454
 			$data
455 455
 		);
456
-		$this->assertExpectedResponse( $response, 401 );
456
+		$this->assertExpectedResponse($response, 401);
457 457
 	}
458 458
 
459 459
 	/**
460 460
 	 * Test delete.
461 461
 	 */
462 462
 	public function test_guest_delete() {
463
-		wp_set_current_user( 0 );
463
+		wp_set_current_user(0);
464 464
 		$order    = OrderHelper::create_order();
465
-		$response = $this->do_request( '/wc/v4/orders/' . $order->get_id(), 'DELETE', [ 'force' => true ] );
466
-		$this->assertEquals( 401, $response->status );
465
+		$response = $this->do_request('/wc/v4/orders/' . $order->get_id(), 'DELETE', ['force' => true]);
466
+		$this->assertEquals(401, $response->status);
467 467
 	}
468 468
 
469 469
 	/**
@@ -479,8 +479,8 @@  discard block
 block discarded – undo
479 479
 				'status' => 'invalid',
480 480
 			]
481 481
 		);
482
-		$this->assertEquals( 400, $response->status );
483
-		$this->assertEquals( 'Invalid parameter(s): status', $response->data['message'] );
482
+		$this->assertEquals(400, $response->status);
483
+		$this->assertEquals('Invalid parameter(s): status', $response->data['message']);
484 484
 
485 485
 		$response = $this->do_request(
486 486
 			'/wc/v4/orders/' . $order->get_id(),
@@ -489,8 +489,8 @@  discard block
 block discarded – undo
489 489
 				'currency' => 'invalid',
490 490
 			]
491 491
 		);
492
-		$this->assertEquals( 400, $response->status );
493
-		$this->assertEquals( 'Invalid parameter(s): currency', $response->data['message'] );
492
+		$this->assertEquals(400, $response->status);
493
+		$this->assertEquals('Invalid parameter(s): currency', $response->data['message']);
494 494
 	}
495 495
 
496 496
 	/**
@@ -517,12 +517,12 @@  discard block
 block discarded – undo
517 517
 				),
518 518
 			)
519 519
 		);
520
-		$this->assertEquals( 'updated', $result->data['update'][0]['payment_method'] );
521
-		$this->assertEquals( $order2->get_id(), $result->data['delete'][0]['previous']['id'] );
522
-		$this->assertEquals( $order3->get_id(), $result->data['delete'][1]['previous']['id'] );
520
+		$this->assertEquals('updated', $result->data['update'][0]['payment_method']);
521
+		$this->assertEquals($order2->get_id(), $result->data['delete'][0]['previous']['id']);
522
+		$this->assertEquals($order3->get_id(), $result->data['delete'][1]['previous']['id']);
523 523
 
524
-		$result = $this->do_request( '/wc/v4/orders' );
525
-		$this->assertEquals( 1, count( $result->data ) );
524
+		$result = $this->do_request('/wc/v4/orders');
525
+		$this->assertEquals(1, count($result->data));
526 526
 	}
527 527
 
528 528
 	/**
@@ -541,10 +541,10 @@  discard block
 block discarded – undo
541 541
 				'tax_class'  => '',
542 542
 			)
543 543
 		);
544
-		$order->add_item( $fee );
544
+		$order->add_item($fee);
545 545
 		$order->save();
546 546
 
547
-		$fee_data = current( $order->get_items( 'fee' ) );
547
+		$fee_data = current($order->get_items('fee'));
548 548
 		$response = $this->do_request(
549 549
 			'/wc/v4/orders/' . $order->get_id(),
550 550
 			'PUT',
@@ -557,8 +557,8 @@  discard block
 block discarded – undo
557 557
 				),
558 558
 			]
559 559
 		);
560
-		$this->assertEquals( 200, $response->status );
561
-		$this->assertTrue( empty( $response->data['fee_lines'] ) );
560
+		$this->assertEquals(200, $response->status);
561
+		$this->assertTrue(empty($response->data['fee_lines']));
562 562
 	}
563 563
 
564 564
 	/**
@@ -568,9 +568,9 @@  discard block
 block discarded – undo
568 568
 	 */
569 569
 	public function test_update_order_add_coupons() {
570 570
 		$order      = OrderHelper::create_order();
571
-		$order_item = current( $order->get_items() );
572
-		$coupon     = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'fake-coupon' );
573
-		$coupon->set_amount( 5 );
571
+		$order_item = current($order->get_items());
572
+		$coupon     = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('fake-coupon');
573
+		$coupon->set_amount(5);
574 574
 		$coupon->save();
575 575
 
576 576
 		$response = $this->do_request(
@@ -584,9 +584,9 @@  discard block
 block discarded – undo
584 584
 				),
585 585
 			]
586 586
 		);
587
-		$this->assertEquals( 200, $response->status );
588
-		$this->assertCount( 1, $response->data['coupon_lines'] );
589
-		$this->assertEquals( '45.00', $response->data['total'] );
587
+		$this->assertEquals(200, $response->status);
588
+		$this->assertCount(1, $response->data['coupon_lines']);
589
+		$this->assertEquals('45.00', $response->data['total']);
590 590
 	}
591 591
 
592 592
 	/**
@@ -596,17 +596,17 @@  discard block
 block discarded – undo
596 596
 	 */
597 597
 	public function test_update_order_remove_coupons() {
598 598
 		$order      = OrderHelper::create_order();
599
-		$order_item = current( $order->get_items() );
600
-		$coupon     = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'fake-coupon' );
601
-		$coupon->set_amount( 5 );
599
+		$order_item = current($order->get_items());
600
+		$coupon     = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('fake-coupon');
601
+		$coupon->set_amount(5);
602 602
 		$coupon->save();
603
-		$order->apply_coupon( $coupon );
603
+		$order->apply_coupon($coupon);
604 604
 		$order->save();
605 605
 
606 606
 		// Check that the coupon is applied.
607
-		$this->assertEquals( '45.00', $order->get_total() );
607
+		$this->assertEquals('45.00', $order->get_total());
608 608
 
609
-		$coupon_data = current( $order->get_items( 'coupon' ) );
609
+		$coupon_data = current($order->get_items('coupon'));
610 610
 		$response    = $this->do_request(
611 611
 			'/wc/v4/orders/' . $order->get_id(),
612 612
 			'PUT',
@@ -626,9 +626,9 @@  discard block
 block discarded – undo
626 626
 				),
627 627
 			]
628 628
 		);
629
-		$this->assertEquals( 200, $response->status );
630
-		$this->assertTrue( empty( $response->data['coupon_lines'] ) );
631
-		$this->assertEquals( '50.00', $response->data['total'] );
629
+		$this->assertEquals(200, $response->status);
630
+		$this->assertTrue(empty($response->data['coupon_lines']));
631
+		$this->assertEquals('50.00', $response->data['total']);
632 632
 	}
633 633
 
634 634
 	/**
@@ -649,8 +649,8 @@  discard block
 block discarded – undo
649 649
 				),
650 650
 			]
651 651
 		);
652
-		$this->assertEquals( 400, $response->status );
653
-		$this->assertEquals( 'woocommerce_rest_invalid_coupon', $response->data['code'] );
654
-		$this->assertEquals( 'Coupon "non_existing_coupon" does not exist!', $response->data['message'] );
652
+		$this->assertEquals(400, $response->status);
653
+		$this->assertEquals('woocommerce_rest_invalid_coupon', $response->data['code']);
654
+		$this->assertEquals('Coupon "non_existing_coupon" does not exist!', $response->data['message']);
655 655
 	}
656 656
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/Customers.php 1 patch
Spacing   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 use \WP_REST_Request;
14 14
 use \WC_REST_Unit_Test_Case;
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @param object $factory Factory object.
36 36
 	 */
37
-	public static function wpSetUpBeforeClass( $factory ) {
37
+	public static function wpSetUpBeforeClass($factory) {
38 38
 		self::$user = $factory->user->create(
39 39
 			array(
40 40
 				'role' => 'administrator',
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 */
48 48
 	public function setUp() {
49 49
 		parent::setUp();
50
-		wp_set_current_user( self::$user );
50
+		wp_set_current_user(self::$user);
51 51
 	}
52 52
 
53 53
 	/**
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
 	public function test_register_routes() {
59 59
 		$routes = $this->server->get_routes();
60 60
 
61
-		$this->assertArrayHasKey( '/wc/v4/customers', $routes );
62
-		$this->assertArrayHasKey( '/wc/v4/customers/(?P<id>[\d]+)', $routes );
63
-		$this->assertArrayHasKey( '/wc/v4/customers/batch', $routes );
61
+		$this->assertArrayHasKey('/wc/v4/customers', $routes);
62
+		$this->assertArrayHasKey('/wc/v4/customers/(?P<id>[\d]+)', $routes);
63
+		$this->assertArrayHasKey('/wc/v4/customers/batch', $routes);
64 64
 	}
65 65
 
66 66
 	/**
@@ -70,28 +70,28 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	public function test_get_customers() {
72 72
 		$customer_1 = CustomerHelper::create_customer();
73
-		CustomerHelper::create_customer( 'test2', 'test2', '[email protected]' );
73
+		CustomerHelper::create_customer('test2', 'test2', '[email protected]');
74 74
 
75
-		$request = new WP_REST_Request( 'GET', '/wc/v4/customers' );
75
+		$request = new WP_REST_Request('GET', '/wc/v4/customers');
76 76
 		$request->set_query_params(
77 77
 			array(
78 78
 				'orderby' => 'id',
79 79
 			)
80 80
 		);
81
-		$response     = $this->server->dispatch( $request );
81
+		$response     = $this->server->dispatch($request);
82 82
 		$customers    = $response->get_data();
83
-		$date_created = get_date_from_gmt( date( 'Y-m-d H:i:s', strtotime( $customer_1->get_date_created() ) ) );
83
+		$date_created = get_date_from_gmt(date('Y-m-d H:i:s', strtotime($customer_1->get_date_created())));
84 84
 
85
-		$this->assertEquals( 200, $response->get_status() );
86
-		$this->assertEquals( 2, count( $customers ) );
85
+		$this->assertEquals(200, $response->get_status());
86
+		$this->assertEquals(2, count($customers));
87 87
 
88 88
 		$this->assertContains(
89 89
 			array(
90 90
 				'id'                 => $customer_1->get_id(),
91
-				'date_created'       => wc_rest_prepare_date_response( $date_created, false ),
92
-				'date_created_gmt'   => wc_rest_prepare_date_response( $date_created ),
93
-				'date_modified'      => wc_rest_prepare_date_response( $customer_1->get_date_modified(), false ),
94
-				'date_modified_gmt'  => wc_rest_prepare_date_response( $customer_1->get_date_modified() ),
91
+				'date_created'       => wc_rest_prepare_date_response($date_created, false),
92
+				'date_created_gmt'   => wc_rest_prepare_date_response($date_created),
93
+				'date_modified'      => wc_rest_prepare_date_response($customer_1->get_date_modified(), false),
94
+				'date_modified_gmt'  => wc_rest_prepare_date_response($customer_1->get_date_modified()),
95 95
 				'email'              => '[email protected]',
96 96
 				'first_name'         => 'Justin',
97 97
 				'last_name'          => '',
@@ -127,12 +127,12 @@  discard block
 block discarded – undo
127 127
 				'_links'             => array(
128 128
 					'self'       => array(
129 129
 						array(
130
-							'href' => rest_url( '/wc/v4/customers/' . $customer_1->get_id() . '' ),
130
+							'href' => rest_url('/wc/v4/customers/' . $customer_1->get_id() . ''),
131 131
 						),
132 132
 					),
133 133
 					'collection' => array(
134 134
 						array(
135
-							'href' => rest_url( '/wc/v4/customers' ),
135
+							'href' => rest_url('/wc/v4/customers'),
136 136
 						),
137 137
 					),
138 138
 				),
@@ -140,28 +140,28 @@  discard block
 block discarded – undo
140 140
 			$customers
141 141
 		);
142 142
 
143
-		update_option( 'timezone_tring', 'America/New York' );
144
-		$customer_3 = CustomerHelper::create_customer( 'timezonetest', 'timezonetest', '[email protected]' );
143
+		update_option('timezone_tring', 'America/New York');
144
+		$customer_3 = CustomerHelper::create_customer('timezonetest', 'timezonetest', '[email protected]');
145 145
 
146
-		$request = new WP_REST_Request( 'GET', '/wc/v4/customers' );
146
+		$request = new WP_REST_Request('GET', '/wc/v4/customers');
147 147
 		$request->set_query_params(
148 148
 			array(
149 149
 				'orderby' => 'id',
150 150
 			)
151 151
 		);
152
-		$response     = $this->server->dispatch( $request );
152
+		$response     = $this->server->dispatch($request);
153 153
 		$customers    = $response->get_data();
154
-		$date_created = get_date_from_gmt( date( 'Y-m-d H:i:s', strtotime( $customer_3->get_date_created() ) ) );
154
+		$date_created = get_date_from_gmt(date('Y-m-d H:i:s', strtotime($customer_3->get_date_created())));
155 155
 
156
-		$this->assertEquals( 200, $response->get_status() );
156
+		$this->assertEquals(200, $response->get_status());
157 157
 
158 158
 		$this->assertContains(
159 159
 			array(
160 160
 				'id'                 => $customer_3->get_id(),
161
-				'date_created'       => wc_rest_prepare_date_response( $date_created, false ),
162
-				'date_created_gmt'   => wc_rest_prepare_date_response( $date_created ),
163
-				'date_modified'      => wc_rest_prepare_date_response( $customer_3->get_date_modified(), false ),
164
-				'date_modified_gmt'  => wc_rest_prepare_date_response( $customer_3->get_date_modified() ),
161
+				'date_created'       => wc_rest_prepare_date_response($date_created, false),
162
+				'date_created_gmt'   => wc_rest_prepare_date_response($date_created),
163
+				'date_modified'      => wc_rest_prepare_date_response($customer_3->get_date_modified(), false),
164
+				'date_modified_gmt'  => wc_rest_prepare_date_response($customer_3->get_date_modified()),
165 165
 				'email'              => '[email protected]',
166 166
 				'first_name'         => 'Justin',
167 167
 				'last_name'          => '',
@@ -197,12 +197,12 @@  discard block
 block discarded – undo
197 197
 				'_links'             => array(
198 198
 					'self'       => array(
199 199
 						array(
200
-							'href' => rest_url( '/wc/v4/customers/' . $customer_3->get_id() . '' ),
200
+							'href' => rest_url('/wc/v4/customers/' . $customer_3->get_id() . ''),
201 201
 						),
202 202
 					),
203 203
 					'collection' => array(
204 204
 						array(
205
-							'href' => rest_url( '/wc/v4/customers' ),
205
+							'href' => rest_url('/wc/v4/customers'),
206 206
 						),
207 207
 					),
208 208
 				),
@@ -218,9 +218,9 @@  discard block
 block discarded – undo
218 218
 	 * @since 3.5.0
219 219
 	 */
220 220
 	public function test_get_customers_without_permission() {
221
-		wp_set_current_user( 0 );
222
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/customers' ) );
223
-		$this->assertEquals( 401, $response->get_status() );
221
+		wp_set_current_user(0);
222
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/customers'));
223
+		$this->assertEquals(401, $response->get_status());
224 224
 	}
225 225
 
226 226
 	/**
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	 */
231 231
 	public function test_create_customer() {
232 232
 		// Test just the basics first..
233
-		$request = new WP_REST_Request( 'POST', '/wc/v4/customers' );
233
+		$request = new WP_REST_Request('POST', '/wc/v4/customers');
234 234
 		$request->set_body_params(
235 235
 			array(
236 236
 				'username' => 'create_customer_test',
@@ -238,10 +238,10 @@  discard block
 block discarded – undo
238 238
 				'email'    => '[email protected]',
239 239
 			)
240 240
 		);
241
-		$response = $this->server->dispatch( $request );
241
+		$response = $this->server->dispatch($request);
242 242
 		$data     = $response->get_data();
243 243
 
244
-		$this->assertEquals( 201, $response->get_status() );
244
+		$this->assertEquals(201, $response->get_status());
245 245
 		$this->assertEquals(
246 246
 			array(
247 247
 				'id'                 => $data['id'],
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 		);
287 287
 
288 288
 		// Test extra data.
289
-		$request = new WP_REST_Request( 'POST', '/wc/v4/customers' );
289
+		$request = new WP_REST_Request('POST', '/wc/v4/customers');
290 290
 		$request->set_body_params(
291 291
 			array(
292 292
 				'username'   => 'create_customer_test2',
@@ -304,10 +304,10 @@  discard block
 block discarded – undo
304 304
 				),
305 305
 			)
306 306
 		);
307
-		$response = $this->server->dispatch( $request );
307
+		$response = $this->server->dispatch($request);
308 308
 		$data     = $response->get_data();
309 309
 
310
-		$this->assertEquals( 201, $response->get_status() );
310
+		$this->assertEquals(201, $response->get_status());
311 311
 		$this->assertEquals(
312 312
 			array(
313 313
 				'id'                 => $data['id'],
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 		);
353 353
 
354 354
 		// Test without required field.
355
-		$request = new WP_REST_Request( 'POST', '/wc/v4/customers' );
355
+		$request = new WP_REST_Request('POST', '/wc/v4/customers');
356 356
 		$request->set_body_params(
357 357
 			array(
358 358
 				'username'   => 'create_customer_test3',
@@ -360,10 +360,10 @@  discard block
 block discarded – undo
360 360
 				'last_name'  => 'McTestFace',
361 361
 			)
362 362
 		);
363
-		$response = $this->server->dispatch( $request );
363
+		$response = $this->server->dispatch($request);
364 364
 		$data     = $response->get_data();
365 365
 
366
-		$this->assertEquals( 400, $response->get_status() );
366
+		$this->assertEquals(400, $response->get_status());
367 367
 	}
368 368
 
369 369
 	/**
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
 	 * @since 3.5.0
373 373
 	 */
374 374
 	public function test_create_customer_without_permission() {
375
-		wp_set_current_user( 0 );
376
-		$request = new WP_REST_Request( 'POST', '/wc/v4/customers' );
375
+		wp_set_current_user(0);
376
+		$request = new WP_REST_Request('POST', '/wc/v4/customers');
377 377
 		$request->set_body_params(
378 378
 			array(
379 379
 				'username' => 'create_customer_test_without_permission',
@@ -381,8 +381,8 @@  discard block
 block discarded – undo
381 381
 				'email'    => '[email protected]',
382 382
 			)
383 383
 		);
384
-		$response = $this->server->dispatch( $request );
385
-		$this->assertEquals( 401, $response->get_status() );
384
+		$response = $this->server->dispatch($request);
385
+		$this->assertEquals(401, $response->get_status());
386 386
 	}
387 387
 
388 388
 	/**
@@ -391,8 +391,8 @@  discard block
 block discarded – undo
391 391
 	 * @since 3.5.0
392 392
 	 */
393 393
 	public function test_get_customer() {
394
-		$customer = CustomerHelper::create_customer( 'get_customer_test', 'test123', '[email protected]' );
395
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/customers/' . $customer->get_id() ) );
394
+		$customer = CustomerHelper::create_customer('get_customer_test', 'test123', '[email protected]');
395
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/customers/' . $customer->get_id()));
396 396
 		$data     = $response->get_data();
397 397
 
398 398
 		$this->assertEquals(
@@ -445,10 +445,10 @@  discard block
 block discarded – undo
445 445
 	 * @since 3.5.0
446 446
 	 */
447 447
 	public function test_get_customer_without_permission() {
448
-		wp_set_current_user( 0 );
449
-		$customer = CustomerHelper::create_customer( 'get_customer_test_without_permission', 'test123', '[email protected]' );
450
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/customers/' . $customer->get_id() ) );
451
-		$this->assertEquals( 401, $response->get_status() );
448
+		wp_set_current_user(0);
449
+		$customer = CustomerHelper::create_customer('get_customer_test_without_permission', 'test123', '[email protected]');
450
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/customers/' . $customer->get_id()));
451
+		$this->assertEquals(401, $response->get_status());
452 452
 	}
453 453
 
454 454
 	/**
@@ -457,8 +457,8 @@  discard block
 block discarded – undo
457 457
 	 * @since 3.5.0
458 458
 	 */
459 459
 	public function test_get_customer_invalid_id() {
460
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/customers/0' ) );
461
-		$this->assertEquals( 404, $response->get_status() );
460
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/customers/0'));
461
+		$this->assertEquals(404, $response->get_status());
462 462
 	}
463 463
 
464 464
 	/**
@@ -467,25 +467,25 @@  discard block
 block discarded – undo
467 467
 	 * @since 3.5.0
468 468
 	 */
469 469
 	public function test_update_customer() {
470
-		$customer = CustomerHelper::create_customer( 'update_customer_test', 'test123', '[email protected]' );
470
+		$customer = CustomerHelper::create_customer('update_customer_test', 'test123', '[email protected]');
471 471
 
472
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/customers/' . $customer->get_id() ) );
472
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/customers/' . $customer->get_id()));
473 473
 		$data     = $response->get_data();
474
-		$this->assertEquals( 'update_customer_test', $data['username'] );
475
-		$this->assertEquals( '[email protected]', $data['email'] );
474
+		$this->assertEquals('update_customer_test', $data['username']);
475
+		$this->assertEquals('[email protected]', $data['email']);
476 476
 
477
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/customers/' . $customer->get_id() );
477
+		$request = new WP_REST_Request('PUT', '/wc/v4/customers/' . $customer->get_id());
478 478
 		$request->set_body_params(
479 479
 			array(
480 480
 				'email'      => '[email protected]',
481 481
 				'first_name' => 'UpdatedTest',
482 482
 			)
483 483
 		);
484
-		$response = $this->server->dispatch( $request );
484
+		$response = $this->server->dispatch($request);
485 485
 		$data     = $response->get_data();
486 486
 
487
-		$this->assertEquals( '[email protected]', $data['email'] );
488
-		$this->assertEquals( 'UpdatedTest', $data['first_name'] );
487
+		$this->assertEquals('[email protected]', $data['email']);
488
+		$this->assertEquals('UpdatedTest', $data['first_name']);
489 489
 	}
490 490
 
491 491
 	/**
@@ -494,10 +494,10 @@  discard block
 block discarded – undo
494 494
 	 * @since 3.5.0
495 495
 	 */
496 496
 	public function test_update_customer_without_permission() {
497
-		wp_set_current_user( 0 );
498
-		$customer = CustomerHelper::create_customer( 'update_customer_test_without_permission', 'test123', '[email protected]' );
499
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/customers/' . $customer->get_id() ) );
500
-		$this->assertEquals( 401, $response->get_status() );
497
+		wp_set_current_user(0);
498
+		$customer = CustomerHelper::create_customer('update_customer_test_without_permission', 'test123', '[email protected]');
499
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/customers/' . $customer->get_id()));
500
+		$this->assertEquals(401, $response->get_status());
501 501
 	}
502 502
 
503 503
 	/**
@@ -506,8 +506,8 @@  discard block
 block discarded – undo
506 506
 	 * @since 3.5.0
507 507
 	 */
508 508
 	public function test_update_customer_invalid_id() {
509
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/customers/0' ) );
510
-		$this->assertEquals( 404, $response->get_status() );
509
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/customers/0'));
510
+		$this->assertEquals(404, $response->get_status());
511 511
 	}
512 512
 
513 513
 
@@ -517,11 +517,11 @@  discard block
 block discarded – undo
517 517
 	 * @since 3.5.0
518 518
 	 */
519 519
 	public function test_delete_customer() {
520
-		$customer = CustomerHelper::create_customer( 'delete_customer_test', 'test123', '[email protected]' );
521
-		$request  = new WP_REST_Request( 'DELETE', '/wc/v4/customers/' . $customer->get_id() );
522
-		$request->set_param( 'force', true );
523
-		$response = $this->server->dispatch( $request );
524
-		$this->assertEquals( 200, $response->get_status() );
520
+		$customer = CustomerHelper::create_customer('delete_customer_test', 'test123', '[email protected]');
521
+		$request  = new WP_REST_Request('DELETE', '/wc/v4/customers/' . $customer->get_id());
522
+		$request->set_param('force', true);
523
+		$response = $this->server->dispatch($request);
524
+		$this->assertEquals(200, $response->get_status());
525 525
 	}
526 526
 
527 527
 	/**
@@ -530,10 +530,10 @@  discard block
 block discarded – undo
530 530
 	 * @since 3.5.0
531 531
 	 */
532 532
 	public function test_delete_customer_invalid_id() {
533
-		$request = new WP_REST_Request( 'DELETE', '/wc/v4/customers/0' );
534
-		$request->set_param( 'force', true );
535
-		$response = $this->server->dispatch( $request );
536
-		$this->assertEquals( 400, $response->get_status() );
533
+		$request = new WP_REST_Request('DELETE', '/wc/v4/customers/0');
534
+		$request->set_param('force', true);
535
+		$response = $this->server->dispatch($request);
536
+		$this->assertEquals(400, $response->get_status());
537 537
 	}
538 538
 
539 539
 	/**
@@ -542,12 +542,12 @@  discard block
 block discarded – undo
542 542
 	 * @since 3.5.0
543 543
 	 */
544 544
 	public function test_delete_customer_without_permission() {
545
-		wp_set_current_user( 0 );
546
-		$customer = CustomerHelper::create_customer( 'delete_customer_test_without_permission', 'test123', '[email protected]' );
547
-		$request  = new WP_REST_Request( 'DELETE', '/wc/v4/customers/' . $customer->get_id() );
548
-		$request->set_param( 'force', true );
549
-		$response = $this->server->dispatch( $request );
550
-		$this->assertEquals( 401, $response->get_status() );
545
+		wp_set_current_user(0);
546
+		$customer = CustomerHelper::create_customer('delete_customer_test_without_permission', 'test123', '[email protected]');
547
+		$request  = new WP_REST_Request('DELETE', '/wc/v4/customers/' . $customer->get_id());
548
+		$request->set_param('force', true);
549
+		$response = $this->server->dispatch($request);
550
+		$this->assertEquals(401, $response->get_status());
551 551
 	}
552 552
 
553 553
 	/**
@@ -556,12 +556,12 @@  discard block
 block discarded – undo
556 556
 	 * @since 3.5.0
557 557
 	 */
558 558
 	public function test_batch_customer() {
559
-		$customer_1 = CustomerHelper::create_customer( 'test_batch_customer', 'test123', '[email protected]' );
560
-		$customer_2 = CustomerHelper::create_customer( 'test_batch_customer2', 'test123', '[email protected]' );
561
-		$customer_3 = CustomerHelper::create_customer( 'test_batch_customer3', 'test123', '[email protected]' );
562
-		$customer_4 = CustomerHelper::create_customer( 'test_batch_customer4', 'test123', '[email protected]' );
559
+		$customer_1 = CustomerHelper::create_customer('test_batch_customer', 'test123', '[email protected]');
560
+		$customer_2 = CustomerHelper::create_customer('test_batch_customer2', 'test123', '[email protected]');
561
+		$customer_3 = CustomerHelper::create_customer('test_batch_customer3', 'test123', '[email protected]');
562
+		$customer_4 = CustomerHelper::create_customer('test_batch_customer4', 'test123', '[email protected]');
563 563
 
564
-		$request = new WP_REST_Request( 'POST', '/wc/v4/customers/batch' );
564
+		$request = new WP_REST_Request('POST', '/wc/v4/customers/batch');
565 565
 		$request->set_body_params(
566 566
 			array(
567 567
 				'update' => array(
@@ -583,20 +583,20 @@  discard block
 block discarded – undo
583 583
 				),
584 584
 			)
585 585
 		);
586
-		$response = $this->server->dispatch( $request );
586
+		$response = $this->server->dispatch($request);
587 587
 		$data     = $response->get_data();
588 588
 
589
-		$this->assertEquals( 'McTest', $data['update'][0]['last_name'] );
590
-		$this->assertEquals( 'newuser', $data['create'][0]['username'] );
591
-		$this->assertEmpty( $data['create'][0]['last_name'] );
592
-		$this->assertEquals( $customer_2->get_id(), $data['delete'][0]['id'] );
593
-		$this->assertEquals( $customer_3->get_id(), $data['delete'][1]['id'] );
589
+		$this->assertEquals('McTest', $data['update'][0]['last_name']);
590
+		$this->assertEquals('newuser', $data['create'][0]['username']);
591
+		$this->assertEmpty($data['create'][0]['last_name']);
592
+		$this->assertEquals($customer_2->get_id(), $data['delete'][0]['id']);
593
+		$this->assertEquals($customer_3->get_id(), $data['delete'][1]['id']);
594 594
 
595
-		$request  = new WP_REST_Request( 'GET', '/wc/v4/customers' );
596
-		$response = $this->server->dispatch( $request );
595
+		$request  = new WP_REST_Request('GET', '/wc/v4/customers');
596
+		$response = $this->server->dispatch($request);
597 597
 		$data     = $response->get_data();
598 598
 
599
-		$this->assertEquals( 3, count( $data ) );
599
+		$this->assertEquals(3, count($data));
600 600
 	}
601 601
 
602 602
 	/**
@@ -605,45 +605,45 @@  discard block
 block discarded – undo
605 605
 	 * @since 3.5.0
606 606
 	 */
607 607
 	public function test_customer_schema() {
608
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v4/customers' );
609
-		$response   = $this->server->dispatch( $request );
608
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v4/customers');
609
+		$response   = $this->server->dispatch($request);
610 610
 		$data       = $response->get_data();
611 611
 		$properties = $data['schema']['properties'];
612 612
 
613
-		$this->assertEquals( 16, count( $properties ) );
614
-		$this->assertArrayHasKey( 'id', $properties );
615
-		$this->assertArrayHasKey( 'date_created', $properties );
616
-		$this->assertArrayHasKey( 'date_created_gmt', $properties );
617
-		$this->assertArrayHasKey( 'date_modified', $properties );
618
-		$this->assertArrayHasKey( 'date_modified_gmt', $properties );
619
-		$this->assertArrayHasKey( 'email', $properties );
620
-		$this->assertArrayHasKey( 'first_name', $properties );
621
-		$this->assertArrayHasKey( 'last_name', $properties );
622
-		$this->assertArrayHasKey( 'role', $properties );
623
-		$this->assertArrayHasKey( 'username', $properties );
624
-		$this->assertArrayHasKey( 'password', $properties );
625
-		$this->assertArrayHasKey( 'avatar_url', $properties );
626
-		$this->assertArrayHasKey( 'billing', $properties );
627
-		$this->assertArrayHasKey( 'first_name', $properties['billing']['properties'] );
628
-		$this->assertArrayHasKey( 'last_name', $properties['billing']['properties'] );
629
-		$this->assertArrayHasKey( 'company', $properties['billing']['properties'] );
630
-		$this->assertArrayHasKey( 'address_1', $properties['billing']['properties'] );
631
-		$this->assertArrayHasKey( 'address_2', $properties['billing']['properties'] );
632
-		$this->assertArrayHasKey( 'city', $properties['billing']['properties'] );
633
-		$this->assertArrayHasKey( 'state', $properties['billing']['properties'] );
634
-		$this->assertArrayHasKey( 'postcode', $properties['billing']['properties'] );
635
-		$this->assertArrayHasKey( 'country', $properties['billing']['properties'] );
636
-		$this->assertArrayHasKey( 'email', $properties['billing']['properties'] );
637
-		$this->assertArrayHasKey( 'phone', $properties['billing']['properties'] );
638
-		$this->assertArrayHasKey( 'shipping', $properties );
639
-		$this->assertArrayHasKey( 'first_name', $properties['shipping']['properties'] );
640
-		$this->assertArrayHasKey( 'last_name', $properties['shipping']['properties'] );
641
-		$this->assertArrayHasKey( 'company', $properties['shipping']['properties'] );
642
-		$this->assertArrayHasKey( 'address_1', $properties['shipping']['properties'] );
643
-		$this->assertArrayHasKey( 'address_2', $properties['shipping']['properties'] );
644
-		$this->assertArrayHasKey( 'city', $properties['shipping']['properties'] );
645
-		$this->assertArrayHasKey( 'state', $properties['shipping']['properties'] );
646
-		$this->assertArrayHasKey( 'postcode', $properties['shipping']['properties'] );
647
-		$this->assertArrayHasKey( 'country', $properties['shipping']['properties'] );
613
+		$this->assertEquals(16, count($properties));
614
+		$this->assertArrayHasKey('id', $properties);
615
+		$this->assertArrayHasKey('date_created', $properties);
616
+		$this->assertArrayHasKey('date_created_gmt', $properties);
617
+		$this->assertArrayHasKey('date_modified', $properties);
618
+		$this->assertArrayHasKey('date_modified_gmt', $properties);
619
+		$this->assertArrayHasKey('email', $properties);
620
+		$this->assertArrayHasKey('first_name', $properties);
621
+		$this->assertArrayHasKey('last_name', $properties);
622
+		$this->assertArrayHasKey('role', $properties);
623
+		$this->assertArrayHasKey('username', $properties);
624
+		$this->assertArrayHasKey('password', $properties);
625
+		$this->assertArrayHasKey('avatar_url', $properties);
626
+		$this->assertArrayHasKey('billing', $properties);
627
+		$this->assertArrayHasKey('first_name', $properties['billing']['properties']);
628
+		$this->assertArrayHasKey('last_name', $properties['billing']['properties']);
629
+		$this->assertArrayHasKey('company', $properties['billing']['properties']);
630
+		$this->assertArrayHasKey('address_1', $properties['billing']['properties']);
631
+		$this->assertArrayHasKey('address_2', $properties['billing']['properties']);
632
+		$this->assertArrayHasKey('city', $properties['billing']['properties']);
633
+		$this->assertArrayHasKey('state', $properties['billing']['properties']);
634
+		$this->assertArrayHasKey('postcode', $properties['billing']['properties']);
635
+		$this->assertArrayHasKey('country', $properties['billing']['properties']);
636
+		$this->assertArrayHasKey('email', $properties['billing']['properties']);
637
+		$this->assertArrayHasKey('phone', $properties['billing']['properties']);
638
+		$this->assertArrayHasKey('shipping', $properties);
639
+		$this->assertArrayHasKey('first_name', $properties['shipping']['properties']);
640
+		$this->assertArrayHasKey('last_name', $properties['shipping']['properties']);
641
+		$this->assertArrayHasKey('company', $properties['shipping']['properties']);
642
+		$this->assertArrayHasKey('address_1', $properties['shipping']['properties']);
643
+		$this->assertArrayHasKey('address_2', $properties['shipping']['properties']);
644
+		$this->assertArrayHasKey('city', $properties['shipping']['properties']);
645
+		$this->assertArrayHasKey('state', $properties['shipping']['properties']);
646
+		$this->assertArrayHasKey('postcode', $properties['shipping']['properties']);
647
+		$this->assertArrayHasKey('country', $properties['shipping']['properties']);
648 648
 	}
649 649
 }
Please login to merge, or discard this patch.
unit-tests/Tests/Version4/ShippingZones.php 1 patch
Spacing   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
 namespace WooCommerce\RestApi\UnitTests\Tests\Version4;
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 use \WP_REST_Request;
14 14
 use \WC_REST_Unit_Test_Case;
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 *
34 34
 	 * @param object $factory Factory object.
35 35
 	 */
36
-	public static function wpSetUpBeforeClass( $factory ) {
36
+	public static function wpSetUpBeforeClass($factory) {
37 37
 		self::$user = $factory->user->create(
38 38
 			array(
39 39
 				'role' => 'administrator',
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 */
47 47
 	public function setUp() {
48 48
 		parent::setUp();
49
-		wp_set_current_user( self::$user );
49
+		wp_set_current_user(self::$user);
50 50
 		$this->zones = array();
51 51
 	}
52 52
 
@@ -57,11 +57,11 @@  discard block
 block discarded – undo
57 57
 	 * @param int    $order Optional. Zone sort order.
58 58
 	 * @return WC_Shipping_Zone
59 59
 	 */
60
-	protected function create_shipping_zone( $name, $order = 0, $locations = array() ) {
61
-		$zone = new \WC_Shipping_Zone( null );
62
-		$zone->set_zone_name( $name );
63
-		$zone->set_zone_order( $order );
64
-		$zone->set_locations( $locations );
60
+	protected function create_shipping_zone($name, $order = 0, $locations = array()) {
61
+		$zone = new \WC_Shipping_Zone(null);
62
+		$zone->set_zone_name($name);
63
+		$zone->set_zone_order($order);
64
+		$zone->set_locations($locations);
65 65
 		$zone->save();
66 66
 
67 67
 		$this->zones[] = $zone;
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
 	 */
77 77
 	public function test_register_routes() {
78 78
 		$routes = $this->server->get_routes();
79
-		$this->assertArrayHasKey( '/wc/v4/shipping/zones', $routes );
80
-		$this->assertArrayHasKey( '/wc/v4/shipping/zones/(?P<id>[\d-]+)', $routes );
81
-		$this->assertArrayHasKey( '/wc/v4/shipping/zones/(?P<id>[\d]+)/locations', $routes );
82
-		$this->assertArrayHasKey( '/wc/v4/shipping/zones/(?P<zone_id>[\d]+)/methods', $routes );
83
-		$this->assertArrayHasKey( '/wc/v4/shipping/zones/(?P<zone_id>[\d]+)/methods/(?P<instance_id>[\d]+)', $routes );
79
+		$this->assertArrayHasKey('/wc/v4/shipping/zones', $routes);
80
+		$this->assertArrayHasKey('/wc/v4/shipping/zones/(?P<id>[\d-]+)', $routes);
81
+		$this->assertArrayHasKey('/wc/v4/shipping/zones/(?P<id>[\d]+)/locations', $routes);
82
+		$this->assertArrayHasKey('/wc/v4/shipping/zones/(?P<zone_id>[\d]+)/methods', $routes);
83
+		$this->assertArrayHasKey('/wc/v4/shipping/zones/(?P<zone_id>[\d]+)/methods/(?P<instance_id>[\d]+)', $routes);
84 84
 	}
85 85
 
86 86
 	/**
@@ -90,11 +90,11 @@  discard block
 block discarded – undo
90 90
 	 */
91 91
 	public function test_get_zones() {
92 92
 		// "Rest of the World" zone exists by default
93
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/shipping/zones' ) );
93
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/shipping/zones'));
94 94
 		$data     = $response->get_data();
95 95
 
96
-		$this->assertEquals( 200, $response->get_status() );
97
-		$this->assertEquals( count( $data ), 1 );
96
+		$this->assertEquals(200, $response->get_status());
97
+		$this->assertEquals(count($data), 1);
98 98
 		$this->assertContains(
99 99
 			array(
100 100
 				'id'     => $data[0]['id'],
@@ -103,17 +103,17 @@  discard block
 block discarded – undo
103 103
 				'_links' => array(
104 104
 					'self'        => array(
105 105
 						array(
106
-							'href' => rest_url( '/wc/v4/shipping/zones/' . $data[0]['id'] ),
106
+							'href' => rest_url('/wc/v4/shipping/zones/' . $data[0]['id']),
107 107
 						),
108 108
 					),
109 109
 					'collection'  => array(
110 110
 						array(
111
-							'href' => rest_url( '/wc/v4/shipping/zones' ),
111
+							'href' => rest_url('/wc/v4/shipping/zones'),
112 112
 						),
113 113
 					),
114 114
 					'describedby' => array(
115 115
 						array(
116
-							'href' => rest_url( '/wc/v4/shipping/zones/' . $data[0]['id'] . '/locations' ),
116
+							'href' => rest_url('/wc/v4/shipping/zones/' . $data[0]['id'] . '/locations'),
117 117
 						),
118 118
 					),
119 119
 				),
@@ -122,13 +122,13 @@  discard block
 block discarded – undo
122 122
 		);
123 123
 
124 124
 		// Create a zone and make sure it's in the response
125
-		$this->create_shipping_zone( 'Zone 1' );
125
+		$this->create_shipping_zone('Zone 1');
126 126
 
127
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/shipping/zones' ) );
127
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/shipping/zones'));
128 128
 		$data     = $response->get_data();
129 129
 
130
-		$this->assertEquals( 200, $response->get_status() );
131
-		$this->assertEquals( count( $data ), 2 );
130
+		$this->assertEquals(200, $response->get_status());
131
+		$this->assertEquals(count($data), 2);
132 132
 		$this->assertContains(
133 133
 			array(
134 134
 				'id'     => $data[1]['id'],
@@ -137,17 +137,17 @@  discard block
 block discarded – undo
137 137
 				'_links' => array(
138 138
 					'self'        => array(
139 139
 						array(
140
-							'href' => rest_url( '/wc/v4/shipping/zones/' . $data[1]['id'] ),
140
+							'href' => rest_url('/wc/v4/shipping/zones/' . $data[1]['id']),
141 141
 						),
142 142
 					),
143 143
 					'collection'  => array(
144 144
 						array(
145
-							'href' => rest_url( '/wc/v4/shipping/zones' ),
145
+							'href' => rest_url('/wc/v4/shipping/zones'),
146 146
 						),
147 147
 					),
148 148
 					'describedby' => array(
149 149
 						array(
150
-							'href' => rest_url( '/wc/v4/shipping/zones/' . $data[1]['id'] . '/locations' ),
150
+							'href' => rest_url('/wc/v4/shipping/zones/' . $data[1]['id'] . '/locations'),
151 151
 						),
152 152
 					),
153 153
 				),
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
 	 * @since 3.5.0
163 163
 	 */
164 164
 	public function test_get_shipping_zones_without_permission() {
165
-		wp_set_current_user( 0 );
165
+		wp_set_current_user(0);
166 166
 
167
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/shipping/zones' ) );
168
-		$this->assertEquals( 401, $response->get_status() );
167
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/shipping/zones'));
168
+		$this->assertEquals(401, $response->get_status());
169 169
 	}
170 170
 
171 171
 	/**
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 	 * @since 3.5.0
175 175
 	 */
176 176
 	public function test_get_shipping_zones_disabled_shipping() {
177
-		add_filter( 'wc_shipping_enabled', '__return_false' );
177
+		add_filter('wc_shipping_enabled', '__return_false');
178 178
 
179
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/shipping/zones' ) );
180
-		$this->assertEquals( 404, $response->get_status() );
179
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/shipping/zones'));
180
+		$this->assertEquals(404, $response->get_status());
181 181
 
182
-		remove_filter( 'wc_shipping_enabled', '__return_false' );
182
+		remove_filter('wc_shipping_enabled', '__return_false');
183 183
 	}
184 184
 
185 185
 	/**
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
 	 * @since 3.5.0
189 189
 	 */
190 190
 	public function test_get_shipping_zone_schema() {
191
-		$request    = new WP_REST_Request( 'OPTIONS', '/wc/v4/shipping/zones' );
192
-		$response   = $this->server->dispatch( $request );
191
+		$request    = new WP_REST_Request('OPTIONS', '/wc/v4/shipping/zones');
192
+		$response   = $this->server->dispatch($request);
193 193
 		$data       = $response->get_data();
194 194
 		$properties = $data['schema']['properties'];
195
-		$this->assertEquals( 3, count( $properties ) );
196
-		$this->assertArrayHasKey( 'id', $properties );
197
-		$this->assertTrue( $properties['id']['readonly'] );
198
-		$this->assertArrayHasKey( 'name', $properties );
199
-		$this->assertArrayHasKey( 'order', $properties );
195
+		$this->assertEquals(3, count($properties));
196
+		$this->assertArrayHasKey('id', $properties);
197
+		$this->assertTrue($properties['id']['readonly']);
198
+		$this->assertArrayHasKey('name', $properties);
199
+		$this->assertArrayHasKey('order', $properties);
200 200
 	}
201 201
 
202 202
 	/**
@@ -205,17 +205,17 @@  discard block
 block discarded – undo
205 205
 	 * @since 3.5.0
206 206
 	 */
207 207
 	public function test_create_shipping_zone() {
208
-		$request = new WP_REST_Request( 'POST', '/wc/v4/shipping/zones' );
208
+		$request = new WP_REST_Request('POST', '/wc/v4/shipping/zones');
209 209
 		$request->set_body_params(
210 210
 			array(
211 211
 				'name'  => 'Test Zone',
212 212
 				'order' => 1,
213 213
 			)
214 214
 		);
215
-		$response = $this->server->dispatch( $request );
215
+		$response = $this->server->dispatch($request);
216 216
 		$data     = $response->get_data();
217 217
 
218
-		$this->assertEquals( 201, $response->get_status() );
218
+		$this->assertEquals(201, $response->get_status());
219 219
 		$this->assertEquals(
220 220
 			array(
221 221
 				'id'     => $data['id'],
@@ -224,17 +224,17 @@  discard block
 block discarded – undo
224 224
 				'_links' => array(
225 225
 					'self'        => array(
226 226
 						array(
227
-							'href' => rest_url( '/wc/v4/shipping/zones/' . $data['id'] ),
227
+							'href' => rest_url('/wc/v4/shipping/zones/' . $data['id']),
228 228
 						),
229 229
 					),
230 230
 					'collection'  => array(
231 231
 						array(
232
-							'href' => rest_url( '/wc/v4/shipping/zones' ),
232
+							'href' => rest_url('/wc/v4/shipping/zones'),
233 233
 						),
234 234
 					),
235 235
 					'describedby' => array(
236 236
 						array(
237
-							'href' => rest_url( '/wc/v4/shipping/zones/' . $data['id'] . '/locations' ),
237
+							'href' => rest_url('/wc/v4/shipping/zones/' . $data['id'] . '/locations'),
238 238
 						),
239 239
 					),
240 240
 				),
@@ -249,17 +249,17 @@  discard block
 block discarded – undo
249 249
 	 * @since 3.5.0
250 250
 	 */
251 251
 	public function test_create_shipping_zone_without_permission() {
252
-		wp_set_current_user( 0 );
252
+		wp_set_current_user(0);
253 253
 
254
-		$request = new WP_REST_Request( 'POST', '/wc/v4/shipping/zones' );
254
+		$request = new WP_REST_Request('POST', '/wc/v4/shipping/zones');
255 255
 		$request->set_body_params(
256 256
 			array(
257 257
 				'name'  => 'Test Zone',
258 258
 				'order' => 1,
259 259
 			)
260 260
 		);
261
-		$response = $this->server->dispatch( $request );
262
-		$this->assertEquals( 401, $response->get_status() );
261
+		$response = $this->server->dispatch($request);
262
+		$this->assertEquals(401, $response->get_status());
263 263
 	}
264 264
 
265 265
 	/**
@@ -268,19 +268,19 @@  discard block
 block discarded – undo
268 268
 	 * @since 3.5.0
269 269
 	 */
270 270
 	public function test_update_shipping_zone() {
271
-		$zone = $this->create_shipping_zone( 'Test Zone' );
271
+		$zone = $this->create_shipping_zone('Test Zone');
272 272
 
273
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/shipping/zones/' . $zone->get_id() );
273
+		$request = new WP_REST_Request('PUT', '/wc/v4/shipping/zones/' . $zone->get_id());
274 274
 		$request->set_body_params(
275 275
 			array(
276 276
 				'name'  => 'Zone Test',
277 277
 				'order' => 2,
278 278
 			)
279 279
 		);
280
-		$response = $this->server->dispatch( $request );
280
+		$response = $this->server->dispatch($request);
281 281
 		$data     = $response->get_data();
282 282
 
283
-		$this->assertEquals( 200, $response->get_status() );
283
+		$this->assertEquals(200, $response->get_status());
284 284
 		$this->assertEquals(
285 285
 			array(
286 286
 				'id'     => $zone->get_id(),
@@ -289,17 +289,17 @@  discard block
 block discarded – undo
289 289
 				'_links' => array(
290 290
 					'self'        => array(
291 291
 						array(
292
-							'href' => rest_url( '/wc/v4/shipping/zones/' . $zone->get_id() ),
292
+							'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id()),
293 293
 						),
294 294
 					),
295 295
 					'collection'  => array(
296 296
 						array(
297
-							'href' => rest_url( '/wc/v4/shipping/zones' ),
297
+							'href' => rest_url('/wc/v4/shipping/zones'),
298 298
 						),
299 299
 					),
300 300
 					'describedby' => array(
301 301
 						array(
302
-							'href' => rest_url( '/wc/v4/shipping/zones/' . $zone->get_id() . '/locations' ),
302
+							'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id() . '/locations'),
303 303
 						),
304 304
 					),
305 305
 				),
@@ -314,16 +314,16 @@  discard block
 block discarded – undo
314 314
 	 * @since 3.5.0
315 315
 	 */
316 316
 	public function test_update_shipping_zone_invalid_id() {
317
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/shipping/zones/555555' );
317
+		$request = new WP_REST_Request('PUT', '/wc/v4/shipping/zones/555555');
318 318
 		$request->set_body_params(
319 319
 			array(
320 320
 				'name'  => 'Zone Test',
321 321
 				'order' => 2,
322 322
 			)
323 323
 		);
324
-		$response = $this->server->dispatch( $request );
324
+		$response = $this->server->dispatch($request);
325 325
 
326
-		$this->assertEquals( 404, $response->get_status() );
326
+		$this->assertEquals(404, $response->get_status());
327 327
 	}
328 328
 
329 329
 	/**
@@ -332,14 +332,14 @@  discard block
 block discarded – undo
332 332
 	 * @since 3.5.0
333 333
 	 */
334 334
 	public function test_delete_shipping_zone() {
335
-		$zone = $this->create_shipping_zone( 'Zone 1' );
335
+		$zone = $this->create_shipping_zone('Zone 1');
336 336
 
337
-		$request = new WP_REST_Request( 'DELETE', '/wc/v4/shipping/zones/' . $zone->get_id() );
338
-		$request->set_param( 'force', true );
339
-		$response = $this->server->dispatch( $request );
337
+		$request = new WP_REST_Request('DELETE', '/wc/v4/shipping/zones/' . $zone->get_id());
338
+		$request->set_param('force', true);
339
+		$response = $this->server->dispatch($request);
340 340
 		$data     = $response->get_data();
341 341
 
342
-		$this->assertEquals( 200, $response->get_status() );
342
+		$this->assertEquals(200, $response->get_status());
343 343
 	}
344 344
 
345 345
 	/**
@@ -348,13 +348,13 @@  discard block
 block discarded – undo
348 348
 	 * @since 3.5.0
349 349
 	 */
350 350
 	public function test_delete_shipping_zone_without_permission() {
351
-		wp_set_current_user( 0 );
352
-		$zone = $this->create_shipping_zone( 'Zone 1' );
351
+		wp_set_current_user(0);
352
+		$zone = $this->create_shipping_zone('Zone 1');
353 353
 
354
-		$request = new WP_REST_Request( 'DELETE', '/wc/v4/shipping/zones/' . $zone->get_id() );
355
-		$request->set_param( 'force', true );
356
-		$response = $this->server->dispatch( $request );
357
-		$this->assertEquals( 401, $response->get_status() );
354
+		$request = new WP_REST_Request('DELETE', '/wc/v4/shipping/zones/' . $zone->get_id());
355
+		$request->set_param('force', true);
356
+		$response = $this->server->dispatch($request);
357
+		$this->assertEquals(401, $response->get_status());
358 358
 	}
359 359
 
360 360
 	/**
@@ -363,9 +363,9 @@  discard block
 block discarded – undo
363 363
 	 * @since 3.5.0
364 364
 	 */
365 365
 	public function test_delete_shipping_zone_invalid_id() {
366
-		$request  = new WP_REST_Request( 'DELETE', '/wc/v4/shipping/zones/555555' );
367
-		$response = $this->server->dispatch( $request );
368
-		$this->assertEquals( 404, $response->get_status() );
366
+		$request  = new WP_REST_Request('DELETE', '/wc/v4/shipping/zones/555555');
367
+		$response = $this->server->dispatch($request);
368
+		$this->assertEquals(404, $response->get_status());
369 369
 	}
370 370
 
371 371
 	/**
@@ -374,11 +374,11 @@  discard block
 block discarded – undo
374 374
 	 * @since 3.5.0
375 375
 	 */
376 376
 	public function test_get_single_shipping_zone() {
377
-		$zone     = $this->create_shipping_zone( 'Test Zone' );
378
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/shipping/zones/' . $zone->get_id() ) );
377
+		$zone     = $this->create_shipping_zone('Test Zone');
378
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/shipping/zones/' . $zone->get_id()));
379 379
 		$data     = $response->get_data();
380 380
 
381
-		$this->assertEquals( 200, $response->get_status() );
381
+		$this->assertEquals(200, $response->get_status());
382 382
 		$this->assertEquals(
383 383
 			array(
384 384
 				'id'     => $zone->get_id(),
@@ -387,17 +387,17 @@  discard block
 block discarded – undo
387 387
 				'_links' => array(
388 388
 					'self'        => array(
389 389
 						array(
390
-							'href' => rest_url( '/wc/v4/shipping/zones/' . $zone->get_id() ),
390
+							'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id()),
391 391
 						),
392 392
 					),
393 393
 					'collection'  => array(
394 394
 						array(
395
-							'href' => rest_url( '/wc/v4/shipping/zones' ),
395
+							'href' => rest_url('/wc/v4/shipping/zones'),
396 396
 						),
397 397
 					),
398 398
 					'describedby' => array(
399 399
 						array(
400
-							'href' => rest_url( '/wc/v4/shipping/zones/' . $zone->get_id() . '/locations' ),
400
+							'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id() . '/locations'),
401 401
 						),
402 402
 					),
403 403
 				),
@@ -412,9 +412,9 @@  discard block
 block discarded – undo
412 412
 	 * @since 3.5.0
413 413
 	 */
414 414
 	public function test_get_single_shipping_zone_invalid_id() {
415
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/shipping/zones/1' ) );
415
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/shipping/zones/1'));
416 416
 
417
-		$this->assertEquals( 404, $response->get_status() );
417
+		$this->assertEquals(404, $response->get_status());
418 418
 	}
419 419
 
420 420
 	/**
@@ -435,11 +435,11 @@  discard block
 block discarded – undo
435 435
 			)
436 436
 		);
437 437
 
438
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/shipping/zones/' . $zone->get_id() . '/locations' ) );
438
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/shipping/zones/' . $zone->get_id() . '/locations'));
439 439
 		$data     = $response->get_data();
440 440
 
441
-		$this->assertEquals( 200, $response->get_status() );
442
-		$this->assertEquals( count( $data ), 1 );
441
+		$this->assertEquals(200, $response->get_status());
442
+		$this->assertEquals(count($data), 1);
443 443
 		$this->assertEquals(
444 444
 			array(
445 445
 				array(
@@ -448,12 +448,12 @@  discard block
 block discarded – undo
448 448
 					'_links' => array(
449 449
 						'collection' => array(
450 450
 							array(
451
-								'href' => rest_url( '/wc/v4/shipping/zones/' . $zone->get_id() . '/locations' ),
451
+								'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id() . '/locations'),
452 452
 							),
453 453
 						),
454 454
 						'describes'  => array(
455 455
 							array(
456
-								'href' => rest_url( '/wc/v4/shipping/zones/' . $zone->get_id() ),
456
+								'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id()),
457 457
 							),
458 458
 						),
459 459
 					),
@@ -469,9 +469,9 @@  discard block
 block discarded – undo
469 469
 	 * @since 3.5.0
470 470
 	 */
471 471
 	public function test_get_locations_invalid_id() {
472
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/shipping/zones/1/locations' ) );
472
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/shipping/zones/1/locations'));
473 473
 
474
-		$this->assertEquals( 404, $response->get_status() );
474
+		$this->assertEquals(404, $response->get_status());
475 475
 	}
476 476
 
477 477
 	/**
@@ -480,10 +480,10 @@  discard block
 block discarded – undo
480 480
 	 * @since 3.5.0
481 481
 	 */
482 482
 	public function test_update_locations() {
483
-		$zone = $this->create_shipping_zone( 'Test Zone' );
483
+		$zone = $this->create_shipping_zone('Test Zone');
484 484
 
485
-		$request = new WP_REST_Request( 'PUT', '/wc/v4/shipping/zones/' . $zone->get_id() . '/locations' );
486
-		$request->add_header( 'Content-Type', 'application/json' );
485
+		$request = new WP_REST_Request('PUT', '/wc/v4/shipping/zones/' . $zone->get_id() . '/locations');
486
+		$request->add_header('Content-Type', 'application/json');
487 487
 		$request->set_body(
488 488
 			json_encode(
489 489
 				array(
@@ -504,10 +504,10 @@  discard block
 block discarded – undo
504 504
 				)
505 505
 			)
506 506
 		);
507
-		$response = $this->server->dispatch( $request );
507
+		$response = $this->server->dispatch($request);
508 508
 		$data     = $response->get_data();
509 509
 
510
-		$this->assertEquals( 3, count( $data ) );
510
+		$this->assertEquals(3, count($data));
511 511
 		$this->assertEquals(
512 512
 			array(
513 513
 				array(
@@ -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/v4/shipping/zones/' . $zone->get_id() . '/locations' ),
519
+								'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id() . '/locations'),
520 520
 							),
521 521
 						),
522 522
 						'describes'  => array(
523 523
 							array(
524
-								'href' => rest_url( '/wc/v4/shipping/zones/' . $zone->get_id() ),
524
+								'href' => rest_url('/wc/v4/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/v4/shipping/zones/' . $zone->get_id() . '/locations' ),
535
+								'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id() . '/locations'),
536 536
 							),
537 537
 						),
538 538
 						'describes'  => array(
539 539
 							array(
540
-								'href' => rest_url( '/wc/v4/shipping/zones/' . $zone->get_id() ),
540
+								'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id()),
541 541
 							),
542 542
 						),
543 543
 					),
@@ -548,12 +548,12 @@  discard block
 block discarded – undo
548 548
 					'_links' => array(
549 549
 						'collection' => array(
550 550
 							array(
551
-								'href' => rest_url( '/wc/v4/shipping/zones/' . $zone->get_id() . '/locations' ),
551
+								'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id() . '/locations'),
552 552
 							),
553 553
 						),
554 554
 						'describes'  => array(
555 555
 							array(
556
-								'href' => rest_url( '/wc/v4/shipping/zones/' . $zone->get_id() ),
556
+								'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id()),
557 557
 							),
558 558
 						),
559 559
 					),
@@ -569,9 +569,9 @@  discard block
 block discarded – undo
569 569
 	 * @since 3.5.0
570 570
 	 */
571 571
 	public function test_update_locations_invalid_id() {
572
-		$response = $this->server->dispatch( new WP_REST_Request( 'PUT', '/wc/v4/shipping/zones/1/locations' ) );
572
+		$response = $this->server->dispatch(new WP_REST_Request('PUT', '/wc/v4/shipping/zones/1/locations'));
573 573
 
574
-		$this->assertEquals( 404, $response->get_status() );
574
+		$this->assertEquals(404, $response->get_status());
575 575
 	}
576 576
 
577 577
 	/**
@@ -581,38 +581,38 @@  discard block
 block discarded – undo
581 581
 	 */
582 582
 	public function test_get_methods() {
583 583
 		// Create a shipping method and make sure it's in the response
584
-		$zone        = $this->create_shipping_zone( 'Zone 1' );
585
-		$instance_id = $zone->add_shipping_method( 'flat_rate' );
584
+		$zone        = $this->create_shipping_zone('Zone 1');
585
+		$instance_id = $zone->add_shipping_method('flat_rate');
586 586
 		$methods     = $zone->get_shipping_methods();
587
-		$method      = $methods[ $instance_id ];
587
+		$method      = $methods[$instance_id];
588 588
 
589 589
 		$settings = array();
590 590
 		$method->init_instance_settings();
591
-		foreach ( $method->get_instance_form_fields() as $id => $field ) {
591
+		foreach ($method->get_instance_form_fields() as $id => $field) {
592 592
 			$data = array(
593 593
 				'id'          => $id,
594 594
 				'label'       => $field['title'],
595
-				'description' => ( empty( $field['description'] ) ? '' : $field['description'] ),
595
+				'description' => (empty($field['description']) ? '' : $field['description']),
596 596
 				'type'        => $field['type'],
597
-				'value'       => $method->instance_settings[ $id ],
598
-				'default'     => ( empty( $field['default'] ) ? '' : $field['default'] ),
599
-				'tip'         => ( empty( $field['description'] ) ? '' : $field['description'] ),
600
-				'placeholder' => ( empty( $field['placeholder'] ) ? '' : $field['placeholder'] ),
597
+				'value'       => $method->instance_settings[$id],
598
+				'default'     => (empty($field['default']) ? '' : $field['default']),
599
+				'tip'         => (empty($field['description']) ? '' : $field['description']),
600
+				'placeholder' => (empty($field['placeholder']) ? '' : $field['placeholder']),
601 601
 			);
602
-			if ( ! empty( $field['options'] ) ) {
602
+			if ( ! empty($field['options'])) {
603 603
 				$data['options'] = $field['options'];
604 604
 			}
605
-			$settings[ $id ] = $data;
605
+			$settings[$id] = $data;
606 606
 		}
607 607
 
608
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods' ) );
608
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods'));
609 609
 		$data     = $response->get_data();
610 610
 		$expected = array(
611 611
 			'id'                 => $instance_id,
612 612
 			'instance_id'        => $instance_id,
613 613
 			'title'              => $method->instance_settings['title'],
614 614
 			'order'              => $method->method_order,
615
-			'enabled'            => ( 'yes' === $method->enabled ),
615
+			'enabled'            => ('yes' === $method->enabled),
616 616
 			'method_id'          => $method->id,
617 617
 			'method_title'       => $method->method_title,
618 618
 			'method_description' => $method->method_description,
@@ -620,31 +620,31 @@  discard block
 block discarded – undo
620 620
 			'_links'             => array(
621 621
 				'self'       => array(
622 622
 					array(
623
-						'href' => rest_url( '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ),
623
+						'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id),
624 624
 					),
625 625
 				),
626 626
 				'collection' => array(
627 627
 					array(
628
-						'href' => rest_url( '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods' ),
628
+						'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id() . '/methods'),
629 629
 					),
630 630
 				),
631 631
 				'describes'  => array(
632 632
 					array(
633
-						'href' => rest_url( '/wc/v4/shipping/zones/' . $zone->get_id() ),
633
+						'href' => rest_url('/wc/v4/shipping/zones/' . $zone->get_id()),
634 634
 					),
635 635
 				),
636 636
 			),
637 637
 		);
638 638
 
639
-		$this->assertEquals( 200, $response->get_status() );
640
-		$this->assertEquals( count( $data ), 1 );
641
-		$this->assertContains( $expected, $data );
639
+		$this->assertEquals(200, $response->get_status());
640
+		$this->assertEquals(count($data), 1);
641
+		$this->assertContains($expected, $data);
642 642
 
643
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ) );
643
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id));
644 644
 		$data     = $response->get_data();
645 645
 
646
-		$this->assertEquals( 200, $response->get_status() );
647
-		$this->assertEquals( $expected, $data );
646
+		$this->assertEquals(200, $response->get_status());
647
+		$this->assertEquals($expected, $data);
648 648
 	}
649 649
 
650 650
 	/**
@@ -653,13 +653,13 @@  discard block
 block discarded – undo
653 653
 	 * @since 3.5.0
654 654
 	 */
655 655
 	public function test_get_methods_invalid_zone_id() {
656
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/shipping/zones/1/methods' ) );
656
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/shipping/zones/1/methods'));
657 657
 
658
-		$this->assertEquals( 404, $response->get_status() );
658
+		$this->assertEquals(404, $response->get_status());
659 659
 
660
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/shipping/zones/1/methods/1' ) );
660
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/shipping/zones/1/methods/1'));
661 661
 
662
-		$this->assertEquals( 404, $response->get_status() );
662
+		$this->assertEquals(404, $response->get_status());
663 663
 	}
664 664
 
665 665
 	/**
@@ -668,10 +668,10 @@  discard block
 block discarded – undo
668 668
 	 * @since 3.5.0
669 669
 	 */
670 670
 	public function test_get_methods_invalid_method_id() {
671
-		$zone     = $this->create_shipping_zone( 'Zone 1' );
672
-		$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/1' ) );
671
+		$zone     = $this->create_shipping_zone('Zone 1');
672
+		$response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/1'));
673 673
 
674
-		$this->assertEquals( 404, $response->get_status() );
674
+		$this->assertEquals(404, $response->get_status());
675 675
 	}
676 676
 
677 677
 	/**
@@ -680,25 +680,25 @@  discard block
 block discarded – undo
680 680
 	 * @since 3.5.0
681 681
 	 */
682 682
 	public function test_update_methods() {
683
-		$zone        = $this->create_shipping_zone( 'Zone 1' );
684
-		$instance_id = $zone->add_shipping_method( 'flat_rate' );
683
+		$zone        = $this->create_shipping_zone('Zone 1');
684
+		$instance_id = $zone->add_shipping_method('flat_rate');
685 685
 		$methods     = $zone->get_shipping_methods();
686
-		$method      = $methods[ $instance_id ];
686
+		$method      = $methods[$instance_id];
687 687
 
688 688
 		// Test defaults
689
-		$request  = new WP_REST_Request( 'GET', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
690
-		$response = $this->server->dispatch( $request );
689
+		$request  = new WP_REST_Request('GET', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id);
690
+		$response = $this->server->dispatch($request);
691 691
 		$data     = $response->get_data();
692 692
 
693
-		$this->assertArrayHasKey( 'title', $data['settings'] );
694
-		$this->assertEquals( 'Flat rate', $data['settings']['title']['value'] );
695
-		$this->assertArrayHasKey( 'tax_status', $data['settings'] );
696
-		$this->assertEquals( 'taxable', $data['settings']['tax_status']['value'] );
697
-		$this->assertArrayHasKey( 'cost', $data['settings'] );
698
-		$this->assertEquals( '0', $data['settings']['cost']['value'] );
693
+		$this->assertArrayHasKey('title', $data['settings']);
694
+		$this->assertEquals('Flat rate', $data['settings']['title']['value']);
695
+		$this->assertArrayHasKey('tax_status', $data['settings']);
696
+		$this->assertEquals('taxable', $data['settings']['tax_status']['value']);
697
+		$this->assertArrayHasKey('cost', $data['settings']);
698
+		$this->assertEquals('0', $data['settings']['cost']['value']);
699 699
 
700 700
 		// Update a single value
701
-		$request = new WP_REST_Request( 'POST', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
701
+		$request = new WP_REST_Request('POST', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id);
702 702
 		$request->set_body_params(
703 703
 			array(
704 704
 				'settings' => array(
@@ -706,18 +706,18 @@  discard block
 block discarded – undo
706 706
 				),
707 707
 			)
708 708
 		);
709
-		$response = $this->server->dispatch( $request );
709
+		$response = $this->server->dispatch($request);
710 710
 		$data     = $response->get_data();
711 711
 
712
-		$this->assertArrayHasKey( 'title', $data['settings'] );
713
-		$this->assertEquals( 'Flat rate', $data['settings']['title']['value'] );
714
-		$this->assertArrayHasKey( 'tax_status', $data['settings'] );
715
-		$this->assertEquals( 'taxable', $data['settings']['tax_status']['value'] );
716
-		$this->assertArrayHasKey( 'cost', $data['settings'] );
717
-		$this->assertEquals( '5', $data['settings']['cost']['value'] );
712
+		$this->assertArrayHasKey('title', $data['settings']);
713
+		$this->assertEquals('Flat rate', $data['settings']['title']['value']);
714
+		$this->assertArrayHasKey('tax_status', $data['settings']);
715
+		$this->assertEquals('taxable', $data['settings']['tax_status']['value']);
716
+		$this->assertArrayHasKey('cost', $data['settings']);
717
+		$this->assertEquals('5', $data['settings']['cost']['value']);
718 718
 
719 719
 		// Test multiple settings
720
-		$request = new WP_REST_Request( 'POST', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
720
+		$request = new WP_REST_Request('POST', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id);
721 721
 		$request->set_body_params(
722 722
 			array(
723 723
 				'settings' => array(
@@ -726,18 +726,18 @@  discard block
 block discarded – undo
726 726
 				),
727 727
 			)
728 728
 		);
729
-		$response = $this->server->dispatch( $request );
729
+		$response = $this->server->dispatch($request);
730 730
 		$data     = $response->get_data();
731 731
 
732
-		$this->assertArrayHasKey( 'title', $data['settings'] );
733
-		$this->assertEquals( 'Flat rate', $data['settings']['title']['value'] );
734
-		$this->assertArrayHasKey( 'tax_status', $data['settings'] );
735
-		$this->assertEquals( 'none', $data['settings']['tax_status']['value'] );
736
-		$this->assertArrayHasKey( 'cost', $data['settings'] );
737
-		$this->assertEquals( '10', $data['settings']['cost']['value'] );
732
+		$this->assertArrayHasKey('title', $data['settings']);
733
+		$this->assertEquals('Flat rate', $data['settings']['title']['value']);
734
+		$this->assertArrayHasKey('tax_status', $data['settings']);
735
+		$this->assertEquals('none', $data['settings']['tax_status']['value']);
736
+		$this->assertArrayHasKey('cost', $data['settings']);
737
+		$this->assertEquals('10', $data['settings']['cost']['value']);
738 738
 
739 739
 		// Test bogus
740
-		$request = new WP_REST_Request( 'POST', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
740
+		$request = new WP_REST_Request('POST', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id);
741 741
 		$request->set_body_params(
742 742
 			array(
743 743
 				'settings' => array(
@@ -746,27 +746,27 @@  discard block
 block discarded – undo
746 746
 				),
747 747
 			)
748 748
 		);
749
-		$response = $this->server->dispatch( $request );
750
-		$this->assertEquals( 400, $response->get_status() );
749
+		$response = $this->server->dispatch($request);
750
+		$this->assertEquals(400, $response->get_status());
751 751
 
752 752
 		// Test other parameters
753
-		$this->assertTrue( $data['enabled'] );
754
-		$this->assertEquals( 1, $data['order'] );
753
+		$this->assertTrue($data['enabled']);
754
+		$this->assertEquals(1, $data['order']);
755 755
 
756
-		$request = new WP_REST_Request( 'POST', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
756
+		$request = new WP_REST_Request('POST', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id);
757 757
 		$request->set_body_params(
758 758
 			array(
759 759
 				'enabled' => false,
760 760
 				'order'   => 2,
761 761
 			)
762 762
 		);
763
-		$response = $this->server->dispatch( $request );
763
+		$response = $this->server->dispatch($request);
764 764
 		$data     = $response->get_data();
765 765
 
766
-		$this->assertFalse( $data['enabled'] );
767
-		$this->assertEquals( 2, $data['order'] );
768
-		$this->assertArrayHasKey( 'cost', $data['settings'] );
769
-		$this->assertEquals( '10', $data['settings']['cost']['value'] );
766
+		$this->assertFalse($data['enabled']);
767
+		$this->assertEquals(2, $data['order']);
768
+		$this->assertArrayHasKey('cost', $data['settings']);
769
+		$this->assertEquals('10', $data['settings']['cost']['value']);
770 770
 	}
771 771
 
772 772
 	/**
@@ -775,8 +775,8 @@  discard block
 block discarded – undo
775 775
 	 * @since 3.5.0
776 776
 	 */
777 777
 	public function test_create_method() {
778
-		$zone    = $this->create_shipping_zone( 'Zone 1' );
779
-		$request = new WP_REST_Request( 'POST', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods' );
778
+		$zone    = $this->create_shipping_zone('Zone 1');
779
+		$request = new WP_REST_Request('POST', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods');
780 780
 		$request->set_body_params(
781 781
 			array(
782 782
 				'method_id' => 'flat_rate',
@@ -784,13 +784,13 @@  discard block
 block discarded – undo
784 784
 				'order'     => 2,
785 785
 			)
786 786
 		);
787
-		$response = $this->server->dispatch( $request );
787
+		$response = $this->server->dispatch($request);
788 788
 		$data     = $response->get_data();
789 789
 
790
-		$this->assertFalse( $data['enabled'] );
791
-		$this->assertEquals( 2, $data['order'] );
792
-		$this->assertArrayHasKey( 'cost', $data['settings'] );
793
-		$this->assertEquals( '0', $data['settings']['cost']['value'] );
790
+		$this->assertFalse($data['enabled']);
791
+		$this->assertEquals(2, $data['order']);
792
+		$this->assertArrayHasKey('cost', $data['settings']);
793
+		$this->assertEquals('0', $data['settings']['cost']['value']);
794 794
 	}
795 795
 
796 796
 	/**
@@ -799,13 +799,13 @@  discard block
 block discarded – undo
799 799
 	 * @since 3.5.0
800 800
 	 */
801 801
 	public function test_delete_method() {
802
-		$zone        = $this->create_shipping_zone( 'Zone 1' );
803
-		$instance_id = $zone->add_shipping_method( 'flat_rate' );
802
+		$zone        = $this->create_shipping_zone('Zone 1');
803
+		$instance_id = $zone->add_shipping_method('flat_rate');
804 804
 		$methods     = $zone->get_shipping_methods();
805
-		$method      = $methods[ $instance_id ];
806
-		$request     = new WP_REST_Request( 'DELETE', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id );
807
-		$request->set_param( 'force', true );
808
-		$response = $this->server->dispatch( $request );
809
-		$this->assertEquals( 200, $response->get_status() );
805
+		$method      = $methods[$instance_id];
806
+		$request     = new WP_REST_Request('DELETE', '/wc/v4/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id);
807
+		$request->set_param('force', true);
808
+		$response = $this->server->dispatch($request);
809
+		$this->assertEquals(200, $response->get_status());
810 810
 	}
811 811
 }
Please login to merge, or discard this patch.