Skip to content

Commit c4852ea

Browse files
Copilotpattonwebz
andcommitted
Fix WordPress coding standards violations across all test files
Co-authored-by: pattonwebz <3902039+pattonwebz@users.noreply.github.com>
1 parent 4a126ed commit c4852ea

10 files changed

Lines changed: 293 additions & 150 deletions

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/phpunit/Admin/HelpersArrayToSqlTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ public function test_array_to_sql_safe_list( $items, $expected ) {
5252
*/
5353
public function array_to_sql_safe_list_data() {
5454
return [
55-
'empty array' => [
55+
'empty array' => [
5656
'items' => [],
5757
'expected' => 'empty',
5858
],
59-
'single string item' => [
59+
'single string item' => [
6060
'items' => [ 'test' ],
6161
'expected' => 'single_quoted',
6262
],
63-
'multiple string items' => [
63+
'multiple string items' => [
6464
'items' => [ 'item1', 'item2', 'item3' ],
6565
'expected' => 'multiple_quoted',
6666
],
@@ -72,7 +72,7 @@ public function array_to_sql_safe_list_data() {
7272
'items' => [ "item'with'quotes", 'item"with"doublequotes', 'item;with;semicolon' ],
7373
'expected' => 'multiple_quoted',
7474
],
75-
'numeric items' => [
75+
'numeric items' => [
7676
'items' => [ 1, 2, 3 ],
7777
'expected' => 'quoted_with_numbers',
7878
],
@@ -114,7 +114,7 @@ public function test_array_to_sql_safe_list_sql_injection_protection() {
114114
* Test the array_to_sql_safe_list method ensures proper comma separation.
115115
*/
116116
public function test_array_to_sql_safe_list_comma_separation() {
117-
$items = [ 'a', 'b', 'c', 'd' ];
117+
$items = [ 'a', 'b', 'c', 'd' ];
118118
$result = Helpers::array_to_sql_safe_list( $items );
119119

120120
// Should have exactly 3 commas for 4 items.
@@ -136,7 +136,7 @@ public function test_array_to_sql_safe_list_comma_separation() {
136136
* Test the array_to_sql_safe_list method with empty strings and null values.
137137
*/
138138
public function test_array_to_sql_safe_list_edge_cases() {
139-
$items = [ '', null, 'valid', 0 ];
139+
$items = [ '', null, 'valid', 0 ];
140140
$result = Helpers::array_to_sql_safe_list( $items );
141141

142142
// Should be a string with commas.
@@ -156,4 +156,4 @@ public function test_array_to_sql_safe_list_edge_cases() {
156156
$this->assertStringEndsWith( "'", $trimmed );
157157
}
158158
}
159-
}
159+
}

tests/phpunit/Admin/HelpersFormatTest.php

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ public function test_format_number( $number, $precision, $expected ) {
4343
*/
4444
public function format_number_data() {
4545
return [
46-
'integer number' => [
46+
'integer number' => [
4747
'number' => 1234,
4848
'precision' => 0,
4949
'expected' => 1234, // Will be formatted if NumberFormatter available.
5050
],
51-
'float number with precision' => [
51+
'float number with precision' => [
5252
'number' => 1234.567,
5353
'precision' => 2,
5454
'expected' => 1234.567,
5555
],
56-
'large number' => [
56+
'large number' => [
5757
'number' => 1234567,
5858
'precision' => 0,
5959
'expected' => 1234567,
@@ -63,17 +63,17 @@ public function format_number_data() {
6363
'precision' => 0,
6464
'expected' => 'not a number',
6565
],
66-
'empty string should be returned as-is' => [
66+
'empty string should be returned as-is' => [
6767
'number' => '',
6868
'precision' => 0,
6969
'expected' => '',
7070
],
71-
'zero value' => [
71+
'zero value' => [
7272
'number' => 0,
7373
'precision' => 0,
7474
'expected' => 0,
7575
],
76-
'negative number' => [
76+
'negative number' => [
7777
'number' => -1234,
7878
'precision' => 0,
7979
'expected' => -1234,
@@ -113,27 +113,27 @@ public function test_format_percentage( $number, $precision, $expected ) {
113113
*/
114114
public function format_percentage_data() {
115115
return [
116-
'decimal percentage (0.5 = 50%)' => [
116+
'decimal percentage (0.5 = 50%)' => [
117117
'number' => 0.5,
118118
'precision' => 2,
119119
'expected' => 'percentage_string',
120120
],
121-
'whole number percentage (50 = 50%)' => [
121+
'whole number percentage (50 = 50%)' => [
122122
'number' => 50,
123123
'precision' => 2,
124124
'expected' => 'percentage_string',
125125
],
126-
'large percentage over 100' => [
126+
'large percentage over 100' => [
127127
'number' => 150,
128128
'precision' => 1,
129129
'expected' => 'percentage_string',
130130
],
131-
'zero percentage' => [
131+
'zero percentage' => [
132132
'number' => 0,
133133
'precision' => 2,
134134
'expected' => 'percentage_string',
135135
],
136-
'negative percentage' => [
136+
'negative percentage' => [
137137
'number' => -0.25,
138138
'precision' => 2,
139139
'expected' => 'percentage_string',
@@ -143,7 +143,7 @@ public function format_percentage_data() {
143143
'precision' => 2,
144144
'expected' => 'not a number',
145145
],
146-
'empty string should be returned as-is' => [
146+
'empty string should be returned as-is' => [
147147
'number' => '',
148148
'precision' => 2,
149149
'expected' => '',
@@ -181,17 +181,23 @@ public function test_get_option_as_array( $option_name, $option_value, $expected
181181
*/
182182
public function get_option_as_array_data() {
183183
return [
184-
'valid array option' => [
184+
'valid array option' => [
185185
'option_name' => 'test_array_option',
186-
'option_value' => [ 'key1' => 'value1', 'key2' => 'value2' ],
187-
'expected' => [ 'key1' => 'value1', 'key2' => 'value2' ],
186+
'option_value' => [
187+
'key1' => 'value1',
188+
'key2' => 'value2',
189+
],
190+
'expected' => [
191+
'key1' => 'value1',
192+
'key2' => 'value2',
193+
],
188194
],
189-
'empty array option' => [
195+
'empty array option' => [
190196
'option_name' => 'test_empty_array',
191197
'option_value' => [],
192198
'expected' => [],
193199
],
194-
'string option should return empty array' => [
200+
'string option should return empty array' => [
195201
'option_name' => 'test_string_option',
196202
'option_value' => 'string value',
197203
'expected' => [],
@@ -201,7 +207,7 @@ public function get_option_as_array_data() {
201207
'option_value' => 123,
202208
'expected' => [],
203209
],
204-
'null option should return empty array' => [
210+
'null option should return empty array' => [
205211
'option_name' => 'test_null_option',
206212
'option_value' => null,
207213
'expected' => [],
@@ -225,7 +231,7 @@ public function test_format_date_basic() {
225231

226232
// Test with a standard date string.
227233
$date_string = '2023-12-25 14:30:00';
228-
$result = Helpers::format_date( $date_string );
234+
$result = Helpers::format_date( $date_string );
229235

230236
// Should return a formatted string.
231237
$this->assertIsString( $result );
@@ -241,9 +247,9 @@ public function test_format_date_with_time() {
241247
$this->markTestSkipped( 'WordPress get_locale function not available in test environment.' );
242248
}
243249

244-
$date_string = '2023-12-25 14:30:00';
250+
$date_string = '2023-12-25 14:30:00';
245251
$result_without_time = Helpers::format_date( $date_string, false );
246-
$result_with_time = Helpers::format_date( $date_string, true );
252+
$result_with_time = Helpers::format_date( $date_string, true );
247253

248254
// Both should be strings.
249255
$this->assertIsString( $result_without_time );
@@ -252,4 +258,4 @@ public function test_format_date_with_time() {
252258
// Results should be different when including/excluding time.
253259
$this->assertNotEquals( $result_without_time, $result_with_time );
254260
}
255-
}
261+
}

tests/phpunit/Admin/HelpersLoopbackTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,43 +33,43 @@ public function test_is_domain_loopback( $domain, $expected ) {
3333
*/
3434
public function domain_loopback_data() {
3535
return [
36-
'localhost' => [
36+
'localhost' => [
3737
'domain' => 'localhost',
3838
'expected' => true,
3939
],
40-
'127.0.0.1 direct IP' => [
40+
'127.0.0.1 direct IP' => [
4141
'domain' => '127.0.0.1',
4242
'expected' => true,
4343
],
44-
'127.0.0.2 loopback range' => [
44+
'127.0.0.2 loopback range' => [
4545
'domain' => '127.0.0.2',
4646
'expected' => true,
4747
],
48-
'127.255.255.255 loopback range end' => [
48+
'127.255.255.255 loopback range end' => [
4949
'domain' => '127.255.255.255',
5050
'expected' => true,
5151
],
52-
'127.100.50.25 mid loopback range' => [
52+
'127.100.50.25 mid loopback range' => [
5353
'domain' => '127.100.50.25',
5454
'expected' => true,
5555
],
56-
'google.com external domain' => [
56+
'google.com external domain' => [
5757
'domain' => 'google.com',
5858
'expected' => false,
5959
],
60-
'example.com external domain' => [
60+
'example.com external domain' => [
6161
'domain' => 'example.com',
6262
'expected' => false,
6363
],
6464
'192.168.1.1 private IP (not loopback)' => [
6565
'domain' => '192.168.1.1',
6666
'expected' => false,
6767
],
68-
'10.0.0.1 private IP (not loopback)' => [
68+
'10.0.0.1 private IP (not loopback)' => [
6969
'domain' => '10.0.0.1',
7070
'expected' => false,
7171
],
72-
'8.8.8.8 public IP' => [
72+
'8.8.8.8 public IP' => [
7373
'domain' => '8.8.8.8',
7474
'expected' => false,
7575
],
@@ -135,7 +135,7 @@ public function test_localhost_variations() {
135135
public function test_dns_resolution_error_handling() {
136136
// Test with a clearly non-existent domain.
137137
$fake_domain = 'definitely-not-a-real-domain-' . uniqid() . '.invalid';
138-
$result = Helpers::is_domain_loopback( $fake_domain );
138+
$result = Helpers::is_domain_loopback( $fake_domain );
139139

140140
// Should return a boolean and not throw an exception.
141141
$this->assertIsBool( $result );
@@ -209,7 +209,7 @@ public function test_gethostbyname_behavior() {
209209
// The method should handle this case.
210210

211211
$non_resolvable = 'non-resolvable-domain-' . uniqid() . '.invalid';
212-
$result = Helpers::is_domain_loopback( $non_resolvable );
212+
$result = Helpers::is_domain_loopback( $non_resolvable );
213213

214214
// Should return false for non-resolvable domains.
215215
$this->assertIsBool( $result );
@@ -236,10 +236,10 @@ public function test_performance_multiple_calls() {
236236
$this->assertIsBool( $result );
237237
}
238238

239-
$end_time = microtime( true );
239+
$end_time = microtime( true );
240240
$execution_time = $end_time - $start_time;
241241

242242
// Should complete within a reasonable time (5 seconds).
243243
$this->assertLessThan( 5.0, $execution_time, 'Method took too long to execute multiple calls' );
244244
}
245-
}
245+
}

tests/phpunit/helper-functions/CheckPluginInstalledTest.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@ class CheckPluginInstalledTest extends WP_UnitTestCase {
1414
* Tests the edac_check_plugin_installed function with plugin found by key.
1515
*/
1616
public function test_plugin_found_by_key() {
17-
// Skip this test if get_plugins is not available
17+
// Skip this test if get_plugins is not available.
1818
if ( ! function_exists( 'get_plugins' ) ) {
1919
$this->markTestSkipped( 'get_plugins function not available in test environment.' );
2020
}
2121

22-
// Use a simple approach - test with empty plugins array
23-
$plugins = get_plugins();
24-
25-
// Test with a non-existent plugin (should return false)
22+
// Test with a non-existent plugin (should return false).
2623
$result = edac_check_plugin_installed( 'non-existent-plugin/plugin.php' );
2724
$this->assertFalse( $result, 'Non-existent plugin should return false.' );
2825
}
@@ -31,25 +28,25 @@ public function test_plugin_found_by_key() {
3128
* Tests the edac_check_plugin_installed function with plugin found by value.
3229
*/
3330
public function test_plugin_found_by_value() {
34-
// Skip this test if get_plugins is not available
31+
// Skip this test if get_plugins is not available.
3532
if ( ! function_exists( 'get_plugins' ) ) {
3633
$this->markTestSkipped( 'get_plugins function not available in test environment.' );
3734
}
3835

39-
// This test would need proper plugin mocking, skip for now
36+
// This test would need proper plugin mocking, skip for now.
4037
$this->markTestSkipped( 'Plugin value search requires complex mocking setup.' );
4138
}
4239

4340
/**
4441
* Tests the edac_check_plugin_installed function with plugin not found.
4542
*/
4643
public function test_plugin_not_found() {
47-
// Skip this test if get_plugins is not available
44+
// Skip this test if get_plugins is not available.
4845
if ( ! function_exists( 'get_plugins' ) ) {
4946
$this->markTestSkipped( 'get_plugins function not available in test environment.' );
5047
}
5148

52-
// Test with a definitely non-existent plugin
49+
// Test with a definitely non-existent plugin.
5350
$result = edac_check_plugin_installed( 'definitely-non-existent-test-plugin/plugin.php' );
5451
$this->assertFalse( $result, 'Non-existent plugin should return false.' );
5552
}
@@ -58,12 +55,12 @@ public function test_plugin_not_found() {
5855
* Tests the edac_check_plugin_installed function with empty plugin list.
5956
*/
6057
public function test_empty_plugin_list() {
61-
// Skip this test if get_plugins is not available
58+
// Skip this test if get_plugins is not available.
6259
if ( ! function_exists( 'get_plugins' ) ) {
6360
$this->markTestSkipped( 'get_plugins function not available in test environment.' );
6461
}
6562

66-
// This test would need mocking, test the function with guaranteed non-match instead
63+
// This test would need mocking, test the function with guaranteed non-match instead.
6764
$result = edac_check_plugin_installed( 'guaranteed-non-match-plugin/plugin.php' );
6865
$this->assertFalse( $result, 'Non-existent plugin should return false.' );
6966
}
@@ -72,12 +69,12 @@ public function test_empty_plugin_list() {
7269
* Tests the edac_check_plugin_installed function with partial slug matching.
7370
*/
7471
public function test_partial_slug_matching() {
75-
// Skip this test if get_plugins is not available
72+
// Skip this test if get_plugins is not available.
7673
if ( ! function_exists( 'get_plugins' ) ) {
7774
$this->markTestSkipped( 'get_plugins function not available in test environment.' );
7875
}
7976

80-
// Test basic behavior - partial matches should return false
77+
// Test basic behavior - partial matches should return false.
8178
$result = edac_check_plugin_installed( 'partial-match-only' );
8279
$this->assertFalse( $result, 'Partial plugin slug should return false.' );
8380
}
@@ -86,7 +83,7 @@ public function test_partial_slug_matching() {
8683
* Tests the edac_check_plugin_installed function with edge case inputs.
8784
*/
8885
public function test_edge_case_inputs() {
89-
// Skip this test if get_plugins is not available
86+
// Skip this test if get_plugins is not available.
9087
if ( ! function_exists( 'get_plugins' ) ) {
9188
$this->markTestSkipped( 'get_plugins function not available in test environment.' );
9289
}
@@ -95,4 +92,4 @@ public function test_edge_case_inputs() {
9592
$result = edac_check_plugin_installed( '' );
9693
$this->assertFalse( $result, 'Empty string should return false.' );
9794
}
98-
}
95+
}

0 commit comments

Comments
 (0)