@@ -21,7 +21,7 @@ |
||
21 | 21 | function __get( $name ) { |
22 | 22 | if ( 'factory' === $name ) { |
23 | 23 | return self::factory(); |
24 | - } |
|
24 | + } |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | protected static function factory() { |
@@ -256,14 +256,16 @@ discard block |
||
256 | 256 | } |
257 | 257 | |
258 | 258 | function _create_temporary_tables( $query ) { |
259 | - if ( 'CREATE TABLE' === substr( trim( $query ), 0, 12 ) ) |
|
260 | - return substr_replace( trim( $query ), 'CREATE TEMPORARY TABLE', 0, 12 ); |
|
259 | + if ( 'CREATE TABLE' === substr( trim( $query ), 0, 12 ) ) { |
|
260 | + return substr_replace( trim( $query ), 'CREATE TEMPORARY TABLE', 0, 12 ); |
|
261 | + } |
|
261 | 262 | return $query; |
262 | 263 | } |
263 | 264 | |
264 | 265 | function _drop_temporary_tables( $query ) { |
265 | - if ( 'DROP TABLE' === substr( trim( $query ), 0, 10 ) ) |
|
266 | - return substr_replace( trim( $query ), 'DROP TEMPORARY TABLE', 0, 10 ); |
|
266 | + if ( 'DROP TABLE' === substr( trim( $query ), 0, 10 ) ) { |
|
267 | + return substr_replace( trim( $query ), 'DROP TEMPORARY TABLE', 0, 10 ); |
|
268 | + } |
|
267 | 269 | return $query; |
268 | 270 | } |
269 | 271 | |
@@ -278,10 +280,12 @@ discard block |
||
278 | 280 | function expectDeprecated() { |
279 | 281 | $annotations = $this->getAnnotations(); |
280 | 282 | foreach ( array( 'class', 'method' ) as $depth ) { |
281 | - if ( ! empty( $annotations[ $depth ]['expectedDeprecated'] ) ) |
|
282 | - $this->expected_deprecated = array_merge( $this->expected_deprecated, $annotations[ $depth ]['expectedDeprecated'] ); |
|
283 | - if ( ! empty( $annotations[ $depth ]['expectedIncorrectUsage'] ) ) |
|
284 | - $this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, $annotations[ $depth ]['expectedIncorrectUsage'] ); |
|
283 | + if ( ! empty( $annotations[ $depth ]['expectedDeprecated'] ) ) { |
|
284 | + $this->expected_deprecated = array_merge( $this->expected_deprecated, $annotations[ $depth ]['expectedDeprecated'] ); |
|
285 | + } |
|
286 | + if ( ! empty( $annotations[ $depth ]['expectedIncorrectUsage'] ) ) { |
|
287 | + $this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, $annotations[ $depth ]['expectedIncorrectUsage'] ); |
|
288 | + } |
|
285 | 289 | } |
286 | 290 | add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) ); |
287 | 291 | add_action( 'deprecated_argument_run', array( $this, 'deprecated_function_run' ) ); |
@@ -344,13 +348,15 @@ discard block |
||
344 | 348 | } |
345 | 349 | |
346 | 350 | function deprecated_function_run( $function ) { |
347 | - if ( ! in_array( $function, $this->caught_deprecated ) ) |
|
348 | - $this->caught_deprecated[] = $function; |
|
351 | + if ( ! in_array( $function, $this->caught_deprecated ) ) { |
|
352 | + $this->caught_deprecated[] = $function; |
|
353 | + } |
|
349 | 354 | } |
350 | 355 | |
351 | 356 | function doing_it_wrong_run( $function ) { |
352 | - if ( ! in_array( $function, $this->caught_doing_it_wrong ) ) |
|
353 | - $this->caught_doing_it_wrong[] = $function; |
|
357 | + if ( ! in_array( $function, $this->caught_doing_it_wrong ) ) { |
|
358 | + $this->caught_doing_it_wrong[] = $function; |
|
359 | + } |
|
354 | 360 | } |
355 | 361 | |
356 | 362 | function assertWPError( $actual, $message = '' ) { |
@@ -394,7 +400,9 @@ discard block |
||
394 | 400 | // to run them more than once without very carefully clearing everything |
395 | 401 | $_GET = $_POST = array(); |
396 | 402 | foreach (array('query_string', 'id', 'postdata', 'authordata', 'day', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages', 'pagenow') as $v) { |
397 | - if ( isset( $GLOBALS[$v] ) ) unset( $GLOBALS[$v] ); |
|
403 | + if ( isset( $GLOBALS[$v] ) ) { |
|
404 | + unset( $GLOBALS[$v] ); |
|
405 | + } |
|
398 | 406 | } |
399 | 407 | $parts = parse_url($url); |
400 | 408 | if (isset($parts['scheme'])) { |
@@ -439,20 +447,23 @@ discard block |
||
439 | 447 | return; |
440 | 448 | } |
441 | 449 | |
442 | - if ( WP_TESTS_FORCE_KNOWN_BUGS ) |
|
443 | - return; |
|
450 | + if ( WP_TESTS_FORCE_KNOWN_BUGS ) { |
|
451 | + return; |
|
452 | + } |
|
444 | 453 | $tickets = PHPUnit_Util_Test::getTickets( get_class( $this ), $this->getName( false ) ); |
445 | 454 | foreach ( $tickets as $ticket ) { |
446 | 455 | if ( is_numeric( $ticket ) ) { |
447 | 456 | $this->knownWPBug( $ticket ); |
448 | 457 | } elseif ( 'UT' == substr( $ticket, 0, 2 ) ) { |
449 | 458 | $ticket = substr( $ticket, 2 ); |
450 | - if ( $ticket && is_numeric( $ticket ) ) |
|
451 | - $this->knownUTBug( $ticket ); |
|
459 | + if ( $ticket && is_numeric( $ticket ) ) { |
|
460 | + $this->knownUTBug( $ticket ); |
|
461 | + } |
|
452 | 462 | } elseif ( 'Plugin' == substr( $ticket, 0, 6 ) ) { |
453 | 463 | $ticket = substr( $ticket, 6 ); |
454 | - if ( $ticket && is_numeric( $ticket ) ) |
|
455 | - $this->knownPluginBug( $ticket ); |
|
464 | + if ( $ticket && is_numeric( $ticket ) ) { |
|
465 | + $this->knownPluginBug( $ticket ); |
|
466 | + } |
|
456 | 467 | } |
457 | 468 | } |
458 | 469 | } |
@@ -461,30 +472,36 @@ discard block |
||
461 | 472 | * Skips the current test if there is an open WordPress ticket with id $ticket_id |
462 | 473 | */ |
463 | 474 | function knownWPBug( $ticket_id ) { |
464 | - if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( $ticket_id, self::$forced_tickets ) ) |
|
465 | - return; |
|
466 | - if ( ! TracTickets::isTracTicketClosed( 'https://core.trac.wordpress.org', $ticket_id ) ) |
|
467 | - $this->markTestSkipped( sprintf( 'WordPress Ticket #%d is not fixed', $ticket_id ) ); |
|
475 | + if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( $ticket_id, self::$forced_tickets ) ) { |
|
476 | + return; |
|
477 | + } |
|
478 | + if ( ! TracTickets::isTracTicketClosed( 'https://core.trac.wordpress.org', $ticket_id ) ) { |
|
479 | + $this->markTestSkipped( sprintf( 'WordPress Ticket #%d is not fixed', $ticket_id ) ); |
|
480 | + } |
|
468 | 481 | } |
469 | 482 | |
470 | 483 | /** |
471 | 484 | * Skips the current test if there is an open unit tests ticket with id $ticket_id |
472 | 485 | */ |
473 | 486 | function knownUTBug( $ticket_id ) { |
474 | - if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'UT' . $ticket_id, self::$forced_tickets ) ) |
|
475 | - return; |
|
476 | - if ( ! TracTickets::isTracTicketClosed( 'https://unit-tests.trac.wordpress.org', $ticket_id ) ) |
|
477 | - $this->markTestSkipped( sprintf( 'Unit Tests Ticket #%d is not fixed', $ticket_id ) ); |
|
487 | + if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'UT' . $ticket_id, self::$forced_tickets ) ) { |
|
488 | + return; |
|
489 | + } |
|
490 | + if ( ! TracTickets::isTracTicketClosed( 'https://unit-tests.trac.wordpress.org', $ticket_id ) ) { |
|
491 | + $this->markTestSkipped( sprintf( 'Unit Tests Ticket #%d is not fixed', $ticket_id ) ); |
|
492 | + } |
|
478 | 493 | } |
479 | 494 | |
480 | 495 | /** |
481 | 496 | * Skips the current test if there is an open plugin ticket with id $ticket_id |
482 | 497 | */ |
483 | 498 | function knownPluginBug( $ticket_id ) { |
484 | - if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'Plugin' . $ticket_id, self::$forced_tickets ) ) |
|
485 | - return; |
|
486 | - if ( ! TracTickets::isTracTicketClosed( 'https://plugins.trac.wordpress.org', $ticket_id ) ) |
|
487 | - $this->markTestSkipped( sprintf( 'WordPress Plugin Ticket #%d is not fixed', $ticket_id ) ); |
|
499 | + if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'Plugin' . $ticket_id, self::$forced_tickets ) ) { |
|
500 | + return; |
|
501 | + } |
|
502 | + if ( ! TracTickets::isTracTicketClosed( 'https://plugins.trac.wordpress.org', $ticket_id ) ) { |
|
503 | + $this->markTestSkipped( sprintf( 'WordPress Plugin Ticket #%d is not fixed', $ticket_id ) ); |
|
504 | + } |
|
488 | 505 | } |
489 | 506 | |
490 | 507 | public static function forceTicket( $ticket ) { |
@@ -506,9 +523,10 @@ discard block |
||
506 | 523 | function temp_filename() { |
507 | 524 | $tmp_dir = ''; |
508 | 525 | $dirs = array( 'TMP', 'TMPDIR', 'TEMP' ); |
509 | - foreach( $dirs as $dir ) |
|
510 | - if ( isset( $_ENV[$dir] ) && !empty( $_ENV[$dir] ) ) { |
|
526 | + foreach( $dirs as $dir ) { |
|
527 | + if ( isset( $_ENV[$dir] ) && !empty( $_ENV[$dir] ) ) { |
|
511 | 528 | $tmp_dir = $dir; |
529 | + } |
|
512 | 530 | break; |
513 | 531 | } |
514 | 532 | if ( empty( $tmp_dir ) ) { |
@@ -579,10 +597,12 @@ discard block |
||
579 | 597 | } |
580 | 598 | |
581 | 599 | $message = ''; |
582 | - if ( count($not_true) ) |
|
583 | - $message .= implode( $not_true, ', ' ) . ' is expected to be true. '; |
|
584 | - if ( count($not_false) ) |
|
585 | - $message .= implode( $not_false, ', ' ) . ' is expected to be false.'; |
|
600 | + if ( count($not_true) ) { |
|
601 | + $message .= implode( $not_true, ', ' ) . ' is expected to be true. '; |
|
602 | + } |
|
603 | + if ( count($not_false) ) { |
|
604 | + $message .= implode( $not_false, ', ' ) . ' is expected to be false.'; |
|
605 | + } |
|
586 | 606 | $this->assertTrue( $passed, $message ); |
587 | 607 | } |
588 | 608 | |
@@ -702,8 +722,9 @@ discard block |
||
702 | 722 | $type = $upload['type']; |
703 | 723 | } else { |
704 | 724 | $mime = wp_check_filetype( $upload['file'] ); |
705 | - if ($mime) |
|
706 | - $type = $mime['type']; |
|
725 | + if ($mime) { |
|
726 | + $type = $mime['type']; |
|
727 | + } |
|
707 | 728 | } |
708 | 729 | |
709 | 730 | $attachment = array( |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once dirname( __FILE__ ) . '/factory.php'; |
|
4 | -require_once dirname( __FILE__ ) . '/trac.php'; |
|
3 | +require_once dirname(__FILE__).'/factory.php'; |
|
4 | +require_once dirname(__FILE__).'/trac.php'; |
|
5 | 5 | |
6 | 6 | class WP_UnitTestCase extends PHPUnit_Framework_TestCase { |
7 | 7 | |
@@ -14,26 +14,26 @@ discard block |
||
14 | 14 | protected static $hooks_saved = array(); |
15 | 15 | protected static $ignore_files; |
16 | 16 | |
17 | - function __isset( $name ) { |
|
17 | + function __isset($name) { |
|
18 | 18 | return 'factory' === $name; |
19 | 19 | } |
20 | 20 | |
21 | - function __get( $name ) { |
|
22 | - if ( 'factory' === $name ) { |
|
21 | + function __get($name) { |
|
22 | + if ('factory' === $name) { |
|
23 | 23 | return self::factory(); |
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
27 | 27 | protected static function factory() { |
28 | 28 | static $factory = null; |
29 | - if ( ! $factory ) { |
|
29 | + if (!$factory) { |
|
30 | 30 | $factory = new WP_UnitTest_Factory(); |
31 | 31 | } |
32 | 32 | return $factory; |
33 | 33 | } |
34 | 34 | |
35 | 35 | public static function get_called_class() { |
36 | - if ( function_exists( 'get_called_class' ) ) { |
|
36 | + if (function_exists('get_called_class')) { |
|
37 | 37 | return get_called_class(); |
38 | 38 | } |
39 | 39 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $backtrace = debug_backtrace(); |
42 | 42 | // [0] WP_UnitTestCase::get_called_class() |
43 | 43 | // [1] WP_UnitTestCase::setUpBeforeClass() |
44 | - if ( 'call_user_func' === $backtrace[2]['function'] ) { |
|
44 | + if ('call_user_func' === $backtrace[2]['function']) { |
|
45 | 45 | return $backtrace[2]['args'][0][0]; |
46 | 46 | } |
47 | 47 | return $backtrace[2]['class']; |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | parent::setUpBeforeClass(); |
52 | 52 | |
53 | 53 | $c = self::get_called_class(); |
54 | - if ( ! method_exists( $c, 'wpSetUpBeforeClass' ) ) { |
|
54 | + if (!method_exists($c, 'wpSetUpBeforeClass')) { |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | - call_user_func( array( $c, 'wpSetUpBeforeClass' ), self::factory() ); |
|
58 | + call_user_func(array($c, 'wpSetUpBeforeClass'), self::factory()); |
|
59 | 59 | |
60 | 60 | self::commit_transaction(); |
61 | 61 | } |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | parent::tearDownAfterClass(); |
65 | 65 | |
66 | 66 | $c = self::get_called_class(); |
67 | - if ( ! method_exists( $c, 'wpTearDownAfterClass' ) ) { |
|
67 | + if (!method_exists($c, 'wpTearDownAfterClass')) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | - call_user_func( array( $c, 'wpTearDownAfterClass' ) ); |
|
71 | + call_user_func(array($c, 'wpTearDownAfterClass')); |
|
72 | 72 | |
73 | 73 | self::commit_transaction(); |
74 | 74 | } |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | function setUp() { |
77 | 77 | set_time_limit(0); |
78 | 78 | |
79 | - if ( ! self::$ignore_files ) { |
|
79 | + if (!self::$ignore_files) { |
|
80 | 80 | self::$ignore_files = $this->scan_user_uploads(); |
81 | 81 | } |
82 | 82 | |
83 | - if ( ! self::$hooks_saved ) { |
|
83 | + if (!self::$hooks_saved) { |
|
84 | 84 | $this->_backup_hooks(); |
85 | 85 | } |
86 | 86 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | $wpdb->suppress_errors = false; |
89 | 89 | $wpdb->show_errors = true; |
90 | 90 | $wpdb->db_connect(); |
91 | - ini_set('display_errors', 1 ); |
|
91 | + ini_set('display_errors', 1); |
|
92 | 92 | $this->clean_up_global_scope(); |
93 | 93 | |
94 | 94 | /* |
@@ -97,19 +97,19 @@ discard block |
||
97 | 97 | * given the large number of plugins that register post types and |
98 | 98 | * taxonomies at 'init'. |
99 | 99 | */ |
100 | - if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) { |
|
100 | + if (defined('WP_RUN_CORE_TESTS') && WP_RUN_CORE_TESTS) { |
|
101 | 101 | $this->reset_post_types(); |
102 | 102 | $this->reset_taxonomies(); |
103 | 103 | $this->reset_post_statuses(); |
104 | 104 | |
105 | - if ( $wp_rewrite->permalink_structure ) { |
|
106 | - $this->set_permalink_structure( '' ); |
|
105 | + if ($wp_rewrite->permalink_structure) { |
|
106 | + $this->set_permalink_structure(''); |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | 110 | $this->start_transaction(); |
111 | 111 | $this->expectDeprecated(); |
112 | - add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) ); |
|
112 | + add_filter('wp_die_handler', array($this, 'get_wp_die_handler')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -125,21 +125,21 @@ discard block |
||
125 | 125 | |
126 | 126 | function tearDown() { |
127 | 127 | global $wpdb, $wp_query, $wp, $post; |
128 | - $wpdb->query( 'ROLLBACK' ); |
|
129 | - if ( is_multisite() ) { |
|
130 | - while ( ms_is_switched() ) { |
|
128 | + $wpdb->query('ROLLBACK'); |
|
129 | + if (is_multisite()) { |
|
130 | + while (ms_is_switched()) { |
|
131 | 131 | restore_current_blog(); |
132 | 132 | } |
133 | 133 | } |
134 | 134 | $wp_query = new WP_Query(); |
135 | 135 | $wp = new WP(); |
136 | 136 | $post = null; |
137 | - remove_theme_support( 'html5' ); |
|
138 | - remove_filter( 'query', array( $this, '_create_temporary_tables' ) ); |
|
139 | - remove_filter( 'query', array( $this, '_drop_temporary_tables' ) ); |
|
140 | - remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) ); |
|
137 | + remove_theme_support('html5'); |
|
138 | + remove_filter('query', array($this, '_create_temporary_tables')); |
|
139 | + remove_filter('query', array($this, '_drop_temporary_tables')); |
|
140 | + remove_filter('wp_die_handler', array($this, 'get_wp_die_handler')); |
|
141 | 141 | $this->_restore_hooks(); |
142 | - wp_set_current_user( 0 ); |
|
142 | + wp_set_current_user(0); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | function clean_up_global_scope() { |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | * it has a chance to do so. |
157 | 157 | */ |
158 | 158 | protected function reset_post_types() { |
159 | - foreach ( get_post_types() as $pt ) { |
|
160 | - _unregister_post_type( $pt ); |
|
159 | + foreach (get_post_types() as $pt) { |
|
160 | + _unregister_post_type($pt); |
|
161 | 161 | } |
162 | 162 | create_initial_post_types(); |
163 | 163 | } |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | * it has a chance to do so. |
171 | 171 | */ |
172 | 172 | protected function reset_taxonomies() { |
173 | - foreach ( get_taxonomies() as $tax ) { |
|
174 | - _unregister_taxonomy( $tax ); |
|
173 | + foreach (get_taxonomies() as $tax) { |
|
174 | + _unregister_taxonomy($tax); |
|
175 | 175 | } |
176 | 176 | create_initial_taxonomies(); |
177 | 177 | } |
@@ -180,8 +180,8 @@ discard block |
||
180 | 180 | * Unregister non-built-in post statuses. |
181 | 181 | */ |
182 | 182 | protected function reset_post_statuses() { |
183 | - foreach ( get_post_stati( array( '_builtin' => false ) ) as $post_status ) { |
|
184 | - _unregister_post_status( $post_status ); |
|
183 | + foreach (get_post_stati(array('_builtin' => false)) as $post_status) { |
|
184 | + _unregister_post_status($post_status); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
@@ -198,9 +198,9 @@ discard block |
||
198 | 198 | * @return void |
199 | 199 | */ |
200 | 200 | protected function _backup_hooks() { |
201 | - $globals = array( 'merged_filters', 'wp_actions', 'wp_current_filter', 'wp_filter' ); |
|
202 | - foreach ( $globals as $key ) { |
|
203 | - self::$hooks_saved[ $key ] = $GLOBALS[ $key ]; |
|
201 | + $globals = array('merged_filters', 'wp_actions', 'wp_current_filter', 'wp_filter'); |
|
202 | + foreach ($globals as $key) { |
|
203 | + self::$hooks_saved[$key] = $GLOBALS[$key]; |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
@@ -215,10 +215,10 @@ discard block |
||
215 | 215 | * @return void |
216 | 216 | */ |
217 | 217 | protected function _restore_hooks() { |
218 | - $globals = array( 'merged_filters', 'wp_actions', 'wp_current_filter', 'wp_filter' ); |
|
219 | - foreach ( $globals as $key ) { |
|
220 | - if ( isset( self::$hooks_saved[ $key ] ) ) { |
|
221 | - $GLOBALS[ $key ] = self::$hooks_saved[ $key ]; |
|
218 | + $globals = array('merged_filters', 'wp_actions', 'wp_current_filter', 'wp_filter'); |
|
219 | + foreach ($globals as $key) { |
|
220 | + if (isset(self::$hooks_saved[$key])) { |
|
221 | + $GLOBALS[$key] = self::$hooks_saved[$key]; |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | } |
@@ -229,20 +229,20 @@ discard block |
||
229 | 229 | $wp_object_cache->stats = array(); |
230 | 230 | $wp_object_cache->memcache_debug = array(); |
231 | 231 | $wp_object_cache->cache = array(); |
232 | - if ( method_exists( $wp_object_cache, '__remoteset' ) ) { |
|
232 | + if (method_exists($wp_object_cache, '__remoteset')) { |
|
233 | 233 | $wp_object_cache->__remoteset(); |
234 | 234 | } |
235 | 235 | wp_cache_flush(); |
236 | - wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache' ) ); |
|
237 | - wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); |
|
236 | + wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache')); |
|
237 | + wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins')); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | function start_transaction() { |
241 | 241 | global $wpdb; |
242 | - $wpdb->query( 'SET autocommit = 0;' ); |
|
243 | - $wpdb->query( 'START TRANSACTION;' ); |
|
244 | - add_filter( 'query', array( $this, '_create_temporary_tables' ) ); |
|
245 | - add_filter( 'query', array( $this, '_drop_temporary_tables' ) ); |
|
242 | + $wpdb->query('SET autocommit = 0;'); |
|
243 | + $wpdb->query('START TRANSACTION;'); |
|
244 | + add_filter('query', array($this, '_create_temporary_tables')); |
|
245 | + add_filter('query', array($this, '_drop_temporary_tables')); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -252,70 +252,70 @@ discard block |
||
252 | 252 | */ |
253 | 253 | public static function commit_transaction() { |
254 | 254 | global $wpdb; |
255 | - $wpdb->query( 'COMMIT;' ); |
|
255 | + $wpdb->query('COMMIT;'); |
|
256 | 256 | } |
257 | 257 | |
258 | - function _create_temporary_tables( $query ) { |
|
259 | - if ( 'CREATE TABLE' === substr( trim( $query ), 0, 12 ) ) |
|
260 | - return substr_replace( trim( $query ), 'CREATE TEMPORARY TABLE', 0, 12 ); |
|
258 | + function _create_temporary_tables($query) { |
|
259 | + if ('CREATE TABLE' === substr(trim($query), 0, 12)) |
|
260 | + return substr_replace(trim($query), 'CREATE TEMPORARY TABLE', 0, 12); |
|
261 | 261 | return $query; |
262 | 262 | } |
263 | 263 | |
264 | - function _drop_temporary_tables( $query ) { |
|
265 | - if ( 'DROP TABLE' === substr( trim( $query ), 0, 10 ) ) |
|
266 | - return substr_replace( trim( $query ), 'DROP TEMPORARY TABLE', 0, 10 ); |
|
264 | + function _drop_temporary_tables($query) { |
|
265 | + if ('DROP TABLE' === substr(trim($query), 0, 10)) |
|
266 | + return substr_replace(trim($query), 'DROP TEMPORARY TABLE', 0, 10); |
|
267 | 267 | return $query; |
268 | 268 | } |
269 | 269 | |
270 | - function get_wp_die_handler( $handler ) { |
|
271 | - return array( $this, 'wp_die_handler' ); |
|
270 | + function get_wp_die_handler($handler) { |
|
271 | + return array($this, 'wp_die_handler'); |
|
272 | 272 | } |
273 | 273 | |
274 | - function wp_die_handler( $message ) { |
|
275 | - throw new WPDieException( $message ); |
|
274 | + function wp_die_handler($message) { |
|
275 | + throw new WPDieException($message); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | function expectDeprecated() { |
279 | 279 | $annotations = $this->getAnnotations(); |
280 | - foreach ( array( 'class', 'method' ) as $depth ) { |
|
281 | - if ( ! empty( $annotations[ $depth ]['expectedDeprecated'] ) ) |
|
282 | - $this->expected_deprecated = array_merge( $this->expected_deprecated, $annotations[ $depth ]['expectedDeprecated'] ); |
|
283 | - if ( ! empty( $annotations[ $depth ]['expectedIncorrectUsage'] ) ) |
|
284 | - $this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, $annotations[ $depth ]['expectedIncorrectUsage'] ); |
|
280 | + foreach (array('class', 'method') as $depth) { |
|
281 | + if (!empty($annotations[$depth]['expectedDeprecated'])) |
|
282 | + $this->expected_deprecated = array_merge($this->expected_deprecated, $annotations[$depth]['expectedDeprecated']); |
|
283 | + if (!empty($annotations[$depth]['expectedIncorrectUsage'])) |
|
284 | + $this->expected_doing_it_wrong = array_merge($this->expected_doing_it_wrong, $annotations[$depth]['expectedIncorrectUsage']); |
|
285 | 285 | } |
286 | - add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) ); |
|
287 | - add_action( 'deprecated_argument_run', array( $this, 'deprecated_function_run' ) ); |
|
288 | - add_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) ); |
|
289 | - add_action( 'deprecated_function_trigger_error', '__return_false' ); |
|
290 | - add_action( 'deprecated_argument_trigger_error', '__return_false' ); |
|
291 | - add_action( 'doing_it_wrong_trigger_error', '__return_false' ); |
|
286 | + add_action('deprecated_function_run', array($this, 'deprecated_function_run')); |
|
287 | + add_action('deprecated_argument_run', array($this, 'deprecated_function_run')); |
|
288 | + add_action('doing_it_wrong_run', array($this, 'doing_it_wrong_run')); |
|
289 | + add_action('deprecated_function_trigger_error', '__return_false'); |
|
290 | + add_action('deprecated_argument_trigger_error', '__return_false'); |
|
291 | + add_action('doing_it_wrong_trigger_error', '__return_false'); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | function expectedDeprecated() { |
295 | 295 | $errors = array(); |
296 | 296 | |
297 | - $not_caught_deprecated = array_diff( $this->expected_deprecated, $this->caught_deprecated ); |
|
298 | - foreach ( $not_caught_deprecated as $not_caught ) { |
|
297 | + $not_caught_deprecated = array_diff($this->expected_deprecated, $this->caught_deprecated); |
|
298 | + foreach ($not_caught_deprecated as $not_caught) { |
|
299 | 299 | $errors[] = "Failed to assert that $not_caught triggered a deprecated notice"; |
300 | 300 | } |
301 | 301 | |
302 | - $unexpected_deprecated = array_diff( $this->caught_deprecated, $this->expected_deprecated ); |
|
303 | - foreach ( $unexpected_deprecated as $unexpected ) { |
|
302 | + $unexpected_deprecated = array_diff($this->caught_deprecated, $this->expected_deprecated); |
|
303 | + foreach ($unexpected_deprecated as $unexpected) { |
|
304 | 304 | $errors[] = "Unexpected deprecated notice for $unexpected"; |
305 | 305 | } |
306 | 306 | |
307 | - $not_caught_doing_it_wrong = array_diff( $this->expected_doing_it_wrong, $this->caught_doing_it_wrong ); |
|
308 | - foreach ( $not_caught_doing_it_wrong as $not_caught ) { |
|
307 | + $not_caught_doing_it_wrong = array_diff($this->expected_doing_it_wrong, $this->caught_doing_it_wrong); |
|
308 | + foreach ($not_caught_doing_it_wrong as $not_caught) { |
|
309 | 309 | $errors[] = "Failed to assert that $not_caught triggered an incorrect usage notice"; |
310 | 310 | } |
311 | 311 | |
312 | - $unexpected_doing_it_wrong = array_diff( $this->caught_doing_it_wrong, $this->expected_doing_it_wrong ); |
|
313 | - foreach ( $unexpected_doing_it_wrong as $unexpected ) { |
|
312 | + $unexpected_doing_it_wrong = array_diff($this->caught_doing_it_wrong, $this->expected_doing_it_wrong); |
|
313 | + foreach ($unexpected_doing_it_wrong as $unexpected) { |
|
314 | 314 | $errors[] = "Unexpected incorrect usage notice for $unexpected"; |
315 | 315 | } |
316 | 316 | |
317 | - if ( ! empty( $errors ) ) { |
|
318 | - $this->fail( implode( "\n", $errors ) ); |
|
317 | + if (!empty($errors)) { |
|
318 | + $this->fail(implode("\n", $errors)); |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
@@ -327,8 +327,8 @@ discard block |
||
327 | 327 | * @param string $deprecated Name of the function, method, class, or argument that is deprecated. Must match |
328 | 328 | * first parameter of the `_deprecated_function()` or `_deprecated_argument()` call. |
329 | 329 | */ |
330 | - public function setExpectedDeprecated( $deprecated ) { |
|
331 | - array_push( $this->expected_deprecated, $deprecated ); |
|
330 | + public function setExpectedDeprecated($deprecated) { |
|
331 | + array_push($this->expected_deprecated, $deprecated); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
@@ -339,75 +339,75 @@ discard block |
||
339 | 339 | * @param string $deprecated Name of the function, method, or class that appears in the first argument of the |
340 | 340 | * source `_doing_it_wrong()` call. |
341 | 341 | */ |
342 | - public function setExpectedIncorrectUsage( $doing_it_wrong ) { |
|
343 | - array_push( $this->expected_doing_it_wrong, $doing_it_wrong ); |
|
342 | + public function setExpectedIncorrectUsage($doing_it_wrong) { |
|
343 | + array_push($this->expected_doing_it_wrong, $doing_it_wrong); |
|
344 | 344 | } |
345 | 345 | |
346 | - function deprecated_function_run( $function ) { |
|
347 | - if ( ! in_array( $function, $this->caught_deprecated ) ) |
|
346 | + function deprecated_function_run($function) { |
|
347 | + if (!in_array($function, $this->caught_deprecated)) |
|
348 | 348 | $this->caught_deprecated[] = $function; |
349 | 349 | } |
350 | 350 | |
351 | - function doing_it_wrong_run( $function ) { |
|
352 | - if ( ! in_array( $function, $this->caught_doing_it_wrong ) ) |
|
351 | + function doing_it_wrong_run($function) { |
|
352 | + if (!in_array($function, $this->caught_doing_it_wrong)) |
|
353 | 353 | $this->caught_doing_it_wrong[] = $function; |
354 | 354 | } |
355 | 355 | |
356 | - function assertWPError( $actual, $message = '' ) { |
|
357 | - $this->assertInstanceOf( 'WP_Error', $actual, $message ); |
|
356 | + function assertWPError($actual, $message = '') { |
|
357 | + $this->assertInstanceOf('WP_Error', $actual, $message); |
|
358 | 358 | } |
359 | 359 | |
360 | - function assertNotWPError( $actual, $message = '' ) { |
|
361 | - if ( is_wp_error( $actual ) && '' === $message ) { |
|
360 | + function assertNotWPError($actual, $message = '') { |
|
361 | + if (is_wp_error($actual) && '' === $message) { |
|
362 | 362 | $message = $actual->get_error_message(); |
363 | 363 | } |
364 | - $this->assertNotInstanceOf( 'WP_Error', $actual, $message ); |
|
364 | + $this->assertNotInstanceOf('WP_Error', $actual, $message); |
|
365 | 365 | } |
366 | 366 | |
367 | - function assertEqualFields( $object, $fields ) { |
|
368 | - foreach( $fields as $field_name => $field_value ) { |
|
369 | - if ( $object->{$field_name} != $field_value ) { |
|
367 | + function assertEqualFields($object, $fields) { |
|
368 | + foreach ($fields as $field_name => $field_value) { |
|
369 | + if ($object->{$field_name} != $field_value) { |
|
370 | 370 | $this->fail(); |
371 | 371 | } |
372 | 372 | } |
373 | 373 | } |
374 | 374 | |
375 | - function assertDiscardWhitespace( $expected, $actual ) { |
|
376 | - $this->assertEquals( preg_replace( '/\s*/', '', $expected ), preg_replace( '/\s*/', '', $actual ) ); |
|
375 | + function assertDiscardWhitespace($expected, $actual) { |
|
376 | + $this->assertEquals(preg_replace('/\s*/', '', $expected), preg_replace('/\s*/', '', $actual)); |
|
377 | 377 | } |
378 | 378 | |
379 | - function assertEqualSets( $expected, $actual ) { |
|
380 | - sort( $expected ); |
|
381 | - sort( $actual ); |
|
382 | - $this->assertEquals( $expected, $actual ); |
|
379 | + function assertEqualSets($expected, $actual) { |
|
380 | + sort($expected); |
|
381 | + sort($actual); |
|
382 | + $this->assertEquals($expected, $actual); |
|
383 | 383 | } |
384 | 384 | |
385 | - function assertEqualSetsWithIndex( $expected, $actual ) { |
|
386 | - ksort( $expected ); |
|
387 | - ksort( $actual ); |
|
388 | - $this->assertEquals( $expected, $actual ); |
|
385 | + function assertEqualSetsWithIndex($expected, $actual) { |
|
386 | + ksort($expected); |
|
387 | + ksort($actual); |
|
388 | + $this->assertEquals($expected, $actual); |
|
389 | 389 | } |
390 | 390 | |
391 | - function go_to( $url ) { |
|
391 | + function go_to($url) { |
|
392 | 392 | // note: the WP and WP_Query classes like to silently fetch parameters |
393 | 393 | // from all over the place (globals, GET, etc), which makes it tricky |
394 | 394 | // to run them more than once without very carefully clearing everything |
395 | 395 | $_GET = $_POST = array(); |
396 | 396 | foreach (array('query_string', 'id', 'postdata', 'authordata', 'day', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages', 'pagenow') as $v) { |
397 | - if ( isset( $GLOBALS[$v] ) ) unset( $GLOBALS[$v] ); |
|
397 | + if (isset($GLOBALS[$v])) unset($GLOBALS[$v]); |
|
398 | 398 | } |
399 | 399 | $parts = parse_url($url); |
400 | 400 | if (isset($parts['scheme'])) { |
401 | - $req = isset( $parts['path'] ) ? $parts['path'] : ''; |
|
401 | + $req = isset($parts['path']) ? $parts['path'] : ''; |
|
402 | 402 | if (isset($parts['query'])) { |
403 | - $req .= '?' . $parts['query']; |
|
403 | + $req .= '?'.$parts['query']; |
|
404 | 404 | // parse the url query vars into $_GET |
405 | 405 | parse_str($parts['query'], $_GET); |
406 | 406 | } |
407 | 407 | } else { |
408 | 408 | $req = $url; |
409 | 409 | } |
410 | - if ( ! isset( $parts['query'] ) ) { |
|
410 | + if (!isset($parts['query'])) { |
|
411 | 411 | $parts['query'] = ''; |
412 | 412 | } |
413 | 413 | |
@@ -435,24 +435,24 @@ discard block |
||
435 | 435 | parent::checkRequirements(); |
436 | 436 | |
437 | 437 | // Core tests no longer check against open Trac tickets, but others using WP_UnitTestCase may do so. |
438 | - if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) { |
|
438 | + if (defined('WP_RUN_CORE_TESTS') && WP_RUN_CORE_TESTS) { |
|
439 | 439 | return; |
440 | 440 | } |
441 | 441 | |
442 | - if ( WP_TESTS_FORCE_KNOWN_BUGS ) |
|
442 | + if (WP_TESTS_FORCE_KNOWN_BUGS) |
|
443 | 443 | return; |
444 | - $tickets = PHPUnit_Util_Test::getTickets( get_class( $this ), $this->getName( false ) ); |
|
445 | - foreach ( $tickets as $ticket ) { |
|
446 | - if ( is_numeric( $ticket ) ) { |
|
447 | - $this->knownWPBug( $ticket ); |
|
448 | - } elseif ( 'UT' == substr( $ticket, 0, 2 ) ) { |
|
449 | - $ticket = substr( $ticket, 2 ); |
|
450 | - if ( $ticket && is_numeric( $ticket ) ) |
|
451 | - $this->knownUTBug( $ticket ); |
|
452 | - } elseif ( 'Plugin' == substr( $ticket, 0, 6 ) ) { |
|
453 | - $ticket = substr( $ticket, 6 ); |
|
454 | - if ( $ticket && is_numeric( $ticket ) ) |
|
455 | - $this->knownPluginBug( $ticket ); |
|
444 | + $tickets = PHPUnit_Util_Test::getTickets(get_class($this), $this->getName(false)); |
|
445 | + foreach ($tickets as $ticket) { |
|
446 | + if (is_numeric($ticket)) { |
|
447 | + $this->knownWPBug($ticket); |
|
448 | + } elseif ('UT' == substr($ticket, 0, 2)) { |
|
449 | + $ticket = substr($ticket, 2); |
|
450 | + if ($ticket && is_numeric($ticket)) |
|
451 | + $this->knownUTBug($ticket); |
|
452 | + } elseif ('Plugin' == substr($ticket, 0, 6)) { |
|
453 | + $ticket = substr($ticket, 6); |
|
454 | + if ($ticket && is_numeric($ticket)) |
|
455 | + $this->knownPluginBug($ticket); |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | } |
@@ -460,44 +460,44 @@ discard block |
||
460 | 460 | /** |
461 | 461 | * Skips the current test if there is an open WordPress ticket with id $ticket_id |
462 | 462 | */ |
463 | - function knownWPBug( $ticket_id ) { |
|
464 | - if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( $ticket_id, self::$forced_tickets ) ) |
|
463 | + function knownWPBug($ticket_id) { |
|
464 | + if (WP_TESTS_FORCE_KNOWN_BUGS || in_array($ticket_id, self::$forced_tickets)) |
|
465 | 465 | return; |
466 | - if ( ! TracTickets::isTracTicketClosed( 'https://core.trac.wordpress.org', $ticket_id ) ) |
|
467 | - $this->markTestSkipped( sprintf( 'WordPress Ticket #%d is not fixed', $ticket_id ) ); |
|
466 | + if (!TracTickets::isTracTicketClosed('https://core.trac.wordpress.org', $ticket_id)) |
|
467 | + $this->markTestSkipped(sprintf('WordPress Ticket #%d is not fixed', $ticket_id)); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /** |
471 | 471 | * Skips the current test if there is an open unit tests ticket with id $ticket_id |
472 | 472 | */ |
473 | - function knownUTBug( $ticket_id ) { |
|
474 | - if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'UT' . $ticket_id, self::$forced_tickets ) ) |
|
473 | + function knownUTBug($ticket_id) { |
|
474 | + if (WP_TESTS_FORCE_KNOWN_BUGS || in_array('UT'.$ticket_id, self::$forced_tickets)) |
|
475 | 475 | return; |
476 | - if ( ! TracTickets::isTracTicketClosed( 'https://unit-tests.trac.wordpress.org', $ticket_id ) ) |
|
477 | - $this->markTestSkipped( sprintf( 'Unit Tests Ticket #%d is not fixed', $ticket_id ) ); |
|
476 | + if (!TracTickets::isTracTicketClosed('https://unit-tests.trac.wordpress.org', $ticket_id)) |
|
477 | + $this->markTestSkipped(sprintf('Unit Tests Ticket #%d is not fixed', $ticket_id)); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | /** |
481 | 481 | * Skips the current test if there is an open plugin ticket with id $ticket_id |
482 | 482 | */ |
483 | - function knownPluginBug( $ticket_id ) { |
|
484 | - if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'Plugin' . $ticket_id, self::$forced_tickets ) ) |
|
483 | + function knownPluginBug($ticket_id) { |
|
484 | + if (WP_TESTS_FORCE_KNOWN_BUGS || in_array('Plugin'.$ticket_id, self::$forced_tickets)) |
|
485 | 485 | return; |
486 | - if ( ! TracTickets::isTracTicketClosed( 'https://plugins.trac.wordpress.org', $ticket_id ) ) |
|
487 | - $this->markTestSkipped( sprintf( 'WordPress Plugin Ticket #%d is not fixed', $ticket_id ) ); |
|
486 | + if (!TracTickets::isTracTicketClosed('https://plugins.trac.wordpress.org', $ticket_id)) |
|
487 | + $this->markTestSkipped(sprintf('WordPress Plugin Ticket #%d is not fixed', $ticket_id)); |
|
488 | 488 | } |
489 | 489 | |
490 | - public static function forceTicket( $ticket ) { |
|
490 | + public static function forceTicket($ticket) { |
|
491 | 491 | self::$forced_tickets[] = $ticket; |
492 | 492 | } |
493 | 493 | |
494 | 494 | /** |
495 | 495 | * Define constants after including files. |
496 | 496 | */ |
497 | - function prepareTemplate( Text_Template $template ) { |
|
498 | - $template->setVar( array( 'constants' => '' ) ); |
|
499 | - $template->setVar( array( 'wp_constants' => PHPUnit_Util_GlobalState::getConstantsAsString() ) ); |
|
500 | - parent::prepareTemplate( $template ); |
|
497 | + function prepareTemplate(Text_Template $template) { |
|
498 | + $template->setVar(array('constants' => '')); |
|
499 | + $template->setVar(array('wp_constants' => PHPUnit_Util_GlobalState::getConstantsAsString())); |
|
500 | + parent::prepareTemplate($template); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | /** |
@@ -505,17 +505,17 @@ discard block |
||
505 | 505 | */ |
506 | 506 | function temp_filename() { |
507 | 507 | $tmp_dir = ''; |
508 | - $dirs = array( 'TMP', 'TMPDIR', 'TEMP' ); |
|
509 | - foreach( $dirs as $dir ) |
|
510 | - if ( isset( $_ENV[$dir] ) && !empty( $_ENV[$dir] ) ) { |
|
508 | + $dirs = array('TMP', 'TMPDIR', 'TEMP'); |
|
509 | + foreach ($dirs as $dir) |
|
510 | + if (isset($_ENV[$dir]) && !empty($_ENV[$dir])) { |
|
511 | 511 | $tmp_dir = $dir; |
512 | 512 | break; |
513 | 513 | } |
514 | - if ( empty( $tmp_dir ) ) { |
|
514 | + if (empty($tmp_dir)) { |
|
515 | 515 | $tmp_dir = '/tmp'; |
516 | 516 | } |
517 | - $tmp_dir = realpath( $tmp_dir ); |
|
518 | - return tempnam( $tmp_dir, 'wpunit' ); |
|
517 | + $tmp_dir = realpath($tmp_dir); |
|
518 | + return tempnam($tmp_dir, 'wpunit'); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |
@@ -564,43 +564,43 @@ discard block |
||
564 | 564 | $passed = true; |
565 | 565 | $not_false = $not_true = array(); // properties that were not set to expected values |
566 | 566 | |
567 | - foreach ( $all as $query_thing ) { |
|
568 | - $result = is_callable( $query_thing ) ? call_user_func( $query_thing ) : $wp_query->{$query_thing}; |
|
567 | + foreach ($all as $query_thing) { |
|
568 | + $result = is_callable($query_thing) ? call_user_func($query_thing) : $wp_query->{$query_thing}; |
|
569 | 569 | |
570 | - if ( in_array( $query_thing, $true ) ) { |
|
571 | - if ( ! $result ) { |
|
572 | - array_push( $not_true, $query_thing ); |
|
570 | + if (in_array($query_thing, $true)) { |
|
571 | + if (!$result) { |
|
572 | + array_push($not_true, $query_thing); |
|
573 | 573 | $passed = false; |
574 | 574 | } |
575 | - } else if ( $result ) { |
|
576 | - array_push( $not_false, $query_thing ); |
|
575 | + } else if ($result) { |
|
576 | + array_push($not_false, $query_thing); |
|
577 | 577 | $passed = false; |
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
581 | 581 | $message = ''; |
582 | - if ( count($not_true) ) |
|
583 | - $message .= implode( $not_true, ', ' ) . ' is expected to be true. '; |
|
584 | - if ( count($not_false) ) |
|
585 | - $message .= implode( $not_false, ', ' ) . ' is expected to be false.'; |
|
586 | - $this->assertTrue( $passed, $message ); |
|
582 | + if (count($not_true)) |
|
583 | + $message .= implode($not_true, ', ').' is expected to be true. '; |
|
584 | + if (count($not_false)) |
|
585 | + $message .= implode($not_false, ', ').' is expected to be false.'; |
|
586 | + $this->assertTrue($passed, $message); |
|
587 | 587 | } |
588 | 588 | |
589 | - function unlink( $file ) { |
|
590 | - $exists = is_file( $file ); |
|
591 | - if ( $exists && ! in_array( $file, self::$ignore_files ) ) { |
|
589 | + function unlink($file) { |
|
590 | + $exists = is_file($file); |
|
591 | + if ($exists && !in_array($file, self::$ignore_files)) { |
|
592 | 592 | //error_log( $file ); |
593 | - unlink( $file ); |
|
594 | - } elseif ( ! $exists ) { |
|
595 | - $this->fail( "Trying to delete a file that doesn't exist: $file" ); |
|
593 | + unlink($file); |
|
594 | + } elseif (!$exists) { |
|
595 | + $this->fail("Trying to delete a file that doesn't exist: $file"); |
|
596 | 596 | } |
597 | 597 | } |
598 | 598 | |
599 | - function rmdir( $path ) { |
|
600 | - $files = $this->files_in_dir( $path ); |
|
601 | - foreach ( $files as $file ) { |
|
602 | - if ( ! in_array( $file, self::$ignore_files ) ) { |
|
603 | - $this->unlink( $file ); |
|
599 | + function rmdir($path) { |
|
600 | + $files = $this->files_in_dir($path); |
|
601 | + foreach ($files as $file) { |
|
602 | + if (!in_array($file, self::$ignore_files)) { |
|
603 | + $this->unlink($file); |
|
604 | 604 | } |
605 | 605 | } |
606 | 606 | } |
@@ -608,16 +608,16 @@ discard block |
||
608 | 608 | function remove_added_uploads() { |
609 | 609 | // Remove all uploads. |
610 | 610 | $uploads = wp_upload_dir(); |
611 | - $this->rmdir( $uploads['basedir'] ); |
|
611 | + $this->rmdir($uploads['basedir']); |
|
612 | 612 | } |
613 | 613 | |
614 | - function files_in_dir( $dir ) { |
|
614 | + function files_in_dir($dir) { |
|
615 | 615 | $files = array(); |
616 | 616 | |
617 | - $iterator = new RecursiveDirectoryIterator( $dir ); |
|
618 | - $objects = new RecursiveIteratorIterator( $iterator ); |
|
619 | - foreach ( $objects as $name => $object ) { |
|
620 | - if ( is_file( $name ) ) { |
|
617 | + $iterator = new RecursiveDirectoryIterator($dir); |
|
618 | + $objects = new RecursiveIteratorIterator($iterator); |
|
619 | + foreach ($objects as $name => $object) { |
|
620 | + if (is_file($name)) { |
|
621 | 621 | $files[] = $name; |
622 | 622 | } |
623 | 623 | } |
@@ -627,33 +627,33 @@ discard block |
||
627 | 627 | |
628 | 628 | function scan_user_uploads() { |
629 | 629 | static $files = array(); |
630 | - if ( ! empty( $files ) ) { |
|
630 | + if (!empty($files)) { |
|
631 | 631 | return $files; |
632 | 632 | } |
633 | 633 | |
634 | 634 | $uploads = wp_upload_dir(); |
635 | - $files = $this->files_in_dir( $uploads['basedir'] ); |
|
635 | + $files = $this->files_in_dir($uploads['basedir']); |
|
636 | 636 | return $files; |
637 | 637 | } |
638 | 638 | |
639 | - function delete_folders( $path ) { |
|
639 | + function delete_folders($path) { |
|
640 | 640 | $this->matched_dirs = array(); |
641 | - if ( ! is_dir( $path ) ) { |
|
641 | + if (!is_dir($path)) { |
|
642 | 642 | return; |
643 | 643 | } |
644 | 644 | |
645 | - $this->scandir( $path ); |
|
646 | - foreach ( array_reverse( $this->matched_dirs ) as $dir ) { |
|
647 | - rmdir( $dir ); |
|
645 | + $this->scandir($path); |
|
646 | + foreach (array_reverse($this->matched_dirs) as $dir) { |
|
647 | + rmdir($dir); |
|
648 | 648 | } |
649 | - rmdir( $path ); |
|
649 | + rmdir($path); |
|
650 | 650 | } |
651 | 651 | |
652 | - function scandir( $dir ) { |
|
653 | - foreach ( scandir( $dir ) as $path ) { |
|
654 | - if ( 0 !== strpos( $path, '.' ) && is_dir( $dir . '/' . $path ) ) { |
|
655 | - $this->matched_dirs[] = $dir . '/' . $path; |
|
656 | - $this->scandir( $dir . '/' . $path ); |
|
652 | + function scandir($dir) { |
|
653 | + foreach (scandir($dir) as $path) { |
|
654 | + if (0 !== strpos($path, '.') && is_dir($dir.'/'.$path)) { |
|
655 | + $this->matched_dirs[] = $dir.'/'.$path; |
|
656 | + $this->scandir($dir.'/'.$path); |
|
657 | 657 | } |
658 | 658 | } |
659 | 659 | } |
@@ -661,9 +661,9 @@ discard block |
||
661 | 661 | /** |
662 | 662 | * Helper to Convert a microtime string into a float |
663 | 663 | */ |
664 | - protected function _microtime_to_float($microtime ){ |
|
665 | - $time_array = explode( ' ', $microtime ); |
|
666 | - return array_sum( $time_array ); |
|
664 | + protected function _microtime_to_float($microtime) { |
|
665 | + $time_array = explode(' ', $microtime); |
|
666 | + return array_sum($time_array); |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
@@ -671,11 +671,11 @@ discard block |
||
671 | 671 | * |
672 | 672 | * @since 4.3.0 |
673 | 673 | */ |
674 | - public static function delete_user( $user_id ) { |
|
675 | - if ( is_multisite() ) { |
|
676 | - return wpmu_delete_user( $user_id ); |
|
674 | + public static function delete_user($user_id) { |
|
675 | + if (is_multisite()) { |
|
676 | + return wpmu_delete_user($user_id); |
|
677 | 677 | } else { |
678 | - return wp_delete_user( $user_id ); |
|
678 | + return wp_delete_user($user_id); |
|
679 | 679 | } |
680 | 680 | } |
681 | 681 | |
@@ -688,36 +688,36 @@ discard block |
||
688 | 688 | * |
689 | 689 | * @param string $structure Optional. Permalink structure to set. Default empty. |
690 | 690 | */ |
691 | - public function set_permalink_structure( $structure = '' ) { |
|
691 | + public function set_permalink_structure($structure = '') { |
|
692 | 692 | global $wp_rewrite; |
693 | 693 | |
694 | 694 | $wp_rewrite->init(); |
695 | - $wp_rewrite->set_permalink_structure( $structure ); |
|
695 | + $wp_rewrite->set_permalink_structure($structure); |
|
696 | 696 | $wp_rewrite->flush_rules(); |
697 | 697 | } |
698 | 698 | |
699 | 699 | function _make_attachment($upload, $parent_post_id = 0) { |
700 | 700 | $type = ''; |
701 | - if ( !empty($upload['type']) ) { |
|
701 | + if (!empty($upload['type'])) { |
|
702 | 702 | $type = $upload['type']; |
703 | 703 | } else { |
704 | - $mime = wp_check_filetype( $upload['file'] ); |
|
704 | + $mime = wp_check_filetype($upload['file']); |
|
705 | 705 | if ($mime) |
706 | 706 | $type = $mime['type']; |
707 | 707 | } |
708 | 708 | |
709 | 709 | $attachment = array( |
710 | - 'post_title' => basename( $upload['file'] ), |
|
710 | + 'post_title' => basename($upload['file']), |
|
711 | 711 | 'post_content' => '', |
712 | 712 | 'post_type' => 'attachment', |
713 | 713 | 'post_parent' => $parent_post_id, |
714 | 714 | 'post_mime_type' => $type, |
715 | - 'guid' => $upload[ 'url' ], |
|
715 | + 'guid' => $upload['url'], |
|
716 | 716 | ); |
717 | 717 | |
718 | 718 | // Save the data |
719 | - $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $parent_post_id ); |
|
720 | - wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); |
|
719 | + $id = wp_insert_attachment($attachment, $upload['file'], $parent_post_id); |
|
720 | + wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $upload['file'])); |
|
721 | 721 | return $id; |
722 | 722 | } |
723 | 723 | } |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | global $wp_filter; |
15 | 15 | static $filter_id_count = 0; |
16 | 16 | |
17 | - if ( is_string($function) ) |
|
18 | - return $function; |
|
17 | + if ( is_string($function) ) { |
|
18 | + return $function; |
|
19 | + } |
|
19 | 20 | |
20 | 21 | if ( is_object($function) ) { |
21 | 22 | // Closures are currently implemented as objects |
@@ -37,8 +38,9 @@ discard block |
||
37 | 38 | |
38 | 39 | $all_posts = $wpdb->get_col("SELECT ID from {$wpdb->posts}"); |
39 | 40 | if ($all_posts) { |
40 | - foreach ($all_posts as $id) |
|
41 | - wp_delete_post( $id, true ); |
|
41 | + foreach ($all_posts as $id) { |
|
42 | + wp_delete_post( $id, true ); |
|
43 | + } |
|
42 | 44 | } |
43 | 45 | } |
44 | 46 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | |
7 | 7 | $idx = _test_filter_build_unique_id($tag, $function_to_add, $priority); |
8 | 8 | $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); |
9 | - unset( $merged_filters[ $tag ] ); |
|
9 | + unset($merged_filters[$tag]); |
|
10 | 10 | return true; |
11 | 11 | } |
12 | 12 | |
@@ -14,19 +14,19 @@ discard block |
||
14 | 14 | global $wp_filter; |
15 | 15 | static $filter_id_count = 0; |
16 | 16 | |
17 | - if ( is_string($function) ) |
|
17 | + if (is_string($function)) |
|
18 | 18 | return $function; |
19 | 19 | |
20 | - if ( is_object($function) ) { |
|
20 | + if (is_object($function)) { |
|
21 | 21 | // Closures are currently implemented as objects |
22 | - $function = array( $function, '' ); |
|
22 | + $function = array($function, ''); |
|
23 | 23 | } else { |
24 | 24 | $function = (array) $function; |
25 | 25 | } |
26 | 26 | |
27 | - if (is_object($function[0]) ) { |
|
28 | - return spl_object_hash($function[0]) . $function[1]; |
|
29 | - } else if ( is_string($function[0]) ) { |
|
27 | + if (is_object($function[0])) { |
|
28 | + return spl_object_hash($function[0]).$function[1]; |
|
29 | + } else if (is_string($function[0])) { |
|
30 | 30 | // Static Calling |
31 | 31 | return $function[0].$function[1]; |
32 | 32 | } |
@@ -38,31 +38,31 @@ discard block |
||
38 | 38 | $all_posts = $wpdb->get_col("SELECT ID from {$wpdb->posts}"); |
39 | 39 | if ($all_posts) { |
40 | 40 | foreach ($all_posts as $id) |
41 | - wp_delete_post( $id, true ); |
|
41 | + wp_delete_post($id, true); |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | 45 | class Basic_Object { |
46 | 46 | private $foo = 'bar'; |
47 | 47 | |
48 | - public function __get( $name ) { |
|
48 | + public function __get($name) { |
|
49 | 49 | return $this->{$name}; |
50 | 50 | } |
51 | 51 | |
52 | - public function __set( $name, $value ) { |
|
52 | + public function __set($name, $value) { |
|
53 | 53 | return $this->{$name} = $value; |
54 | 54 | } |
55 | 55 | |
56 | - public function __isset( $name ) { |
|
57 | - return isset( $this->{$name} ); |
|
56 | + public function __isset($name) { |
|
57 | + return isset($this->{$name} ); |
|
58 | 58 | } |
59 | 59 | |
60 | - public function __unset( $name ) { |
|
61 | - unset( $this->{$name} ); |
|
60 | + public function __unset($name) { |
|
61 | + unset($this->{$name} ); |
|
62 | 62 | } |
63 | 63 | |
64 | - public function __call( $name, $arguments ) { |
|
65 | - return call_user_func_array( array( $this, $name ), $arguments ); |
|
64 | + public function __call($name, $arguments) { |
|
65 | + return call_user_func_array(array($this, $name), $arguments); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | private function callMe() { |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | |
73 | 73 | class Basic_Subclass extends Basic_Object {} |
74 | 74 | |
75 | -function _wp_die_handler( $message, $title = '', $args = array() ) { |
|
76 | - if ( !$GLOBALS['_wp_die_disabled'] ) { |
|
77 | - _wp_die_handler_txt( $message, $title, $args); |
|
75 | +function _wp_die_handler($message, $title = '', $args = array()) { |
|
76 | + if (!$GLOBALS['_wp_die_disabled']) { |
|
77 | + _wp_die_handler_txt($message, $title, $args); |
|
78 | 78 | } else { |
79 | 79 | //Ignore at our peril |
80 | 80 | } |
@@ -92,13 +92,13 @@ discard block |
||
92 | 92 | return '_wp_die_handler'; |
93 | 93 | } |
94 | 94 | |
95 | -function _wp_die_handler_txt( $message, $title, $args ) { |
|
95 | +function _wp_die_handler_txt($message, $title, $args) { |
|
96 | 96 | echo "\nwp_die called\n"; |
97 | 97 | echo "Message : $message\n"; |
98 | 98 | echo "Title : $title\n"; |
99 | - if ( ! empty( $args ) ) { |
|
99 | + if (!empty($args)) { |
|
100 | 100 | echo "Args: \n"; |
101 | - foreach( $args as $k => $v ){ |
|
101 | + foreach ($args as $k => $v) { |
|
102 | 102 | echo "\t $k : $v\n"; |
103 | 103 | } |
104 | 104 | } |
@@ -113,5 +113,5 @@ discard block |
||
113 | 113 | * @since 4.2.0 |
114 | 114 | */ |
115 | 115 | function _set_default_permalink_structure_for_tests() { |
116 | - update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' ); |
|
116 | + update_option('permalink_structure', '/%year%/%monthnum%/%day%/%postname%/'); |
|
117 | 117 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (class_exists( 'WP_Image_Editor' ) ) : |
|
3 | +if (class_exists('WP_Image_Editor')) : |
|
4 | 4 | |
5 | 5 | class WP_Image_Editor_Mock extends WP_Image_Editor { |
6 | 6 | |
@@ -9,38 +9,38 @@ discard block |
||
9 | 9 | public static $save_return = array(); |
10 | 10 | |
11 | 11 | // Allow testing of jpeg_quality filter. |
12 | - public function set_mime_type( $mime_type = null ) { |
|
12 | + public function set_mime_type($mime_type = null) { |
|
13 | 13 | $this->mime_type = $mime_type; |
14 | 14 | } |
15 | 15 | |
16 | 16 | public function load() { |
17 | 17 | return self::$load_return; |
18 | 18 | } |
19 | - public static function test( $args = array() ) { |
|
19 | + public static function test($args = array()) { |
|
20 | 20 | return self::$test_return; |
21 | 21 | } |
22 | - public static function supports_mime_type( $mime_type ) { |
|
22 | + public static function supports_mime_type($mime_type) { |
|
23 | 23 | return true; |
24 | 24 | } |
25 | - public function resize( $max_w, $max_h, $crop = false ) { |
|
25 | + public function resize($max_w, $max_h, $crop = false) { |
|
26 | 26 | |
27 | 27 | } |
28 | - public function multi_resize( $sizes ) { |
|
28 | + public function multi_resize($sizes) { |
|
29 | 29 | |
30 | 30 | } |
31 | - public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) { |
|
31 | + public function crop($src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false) { |
|
32 | 32 | |
33 | 33 | } |
34 | - public function rotate( $angle ) { |
|
34 | + public function rotate($angle) { |
|
35 | 35 | |
36 | 36 | } |
37 | - public function flip( $horz, $vert ) { |
|
37 | + public function flip($horz, $vert) { |
|
38 | 38 | |
39 | 39 | } |
40 | - public function save( $destfilename = null, $mime_type = null ) { |
|
40 | + public function save($destfilename = null, $mime_type = null) { |
|
41 | 41 | return self::$save_return; |
42 | 42 | } |
43 | - public function stream( $mime_type = null ) { |
|
43 | + public function stream($mime_type = null) { |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | } |
@@ -1,19 +1,19 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | abstract class WP_Test_REST_TestCase extends WP_UnitTestCase { |
4 | - protected function assertErrorResponse( $code, $response, $status = null ) { |
|
4 | + protected function assertErrorResponse($code, $response, $status = null) { |
|
5 | 5 | |
6 | - if ( is_a( $response, 'WP_REST_Response' ) ) { |
|
6 | + if (is_a($response, 'WP_REST_Response')) { |
|
7 | 7 | $response = $response->as_error(); |
8 | 8 | } |
9 | 9 | |
10 | - $this->assertInstanceOf( 'WP_Error', $response ); |
|
11 | - $this->assertEquals( $code, $response->get_error_code() ); |
|
10 | + $this->assertInstanceOf('WP_Error', $response); |
|
11 | + $this->assertEquals($code, $response->get_error_code()); |
|
12 | 12 | |
13 | - if ( null !== $status ) { |
|
13 | + if (null !== $status) { |
|
14 | 14 | $data = $response->get_error_data(); |
15 | - $this->assertArrayHasKey( 'status', $data ); |
|
16 | - $this->assertEquals( $status, $data['status'] ); |
|
15 | + $this->assertArrayHasKey('status', $data); |
|
16 | + $this->assertEquals($status, $data['status']); |
|
17 | 17 | } |
18 | 18 | } |
19 | 19 | } |
@@ -7,9 +7,10 @@ discard block |
||
7 | 7 | $config_file_path = dirname( dirname( __FILE__ ) ); |
8 | 8 | if ( ! file_exists( $config_file_path . '/wp-tests-config.php' ) ) { |
9 | 9 | // Support the config file from the root of the develop repository. |
10 | - if ( basename( $config_file_path ) === 'phpunit' && basename( dirname( $config_file_path ) ) === 'tests' ) |
|
11 | - $config_file_path = dirname( dirname( $config_file_path ) ); |
|
12 | -} |
|
10 | + if ( basename( $config_file_path ) === 'phpunit' && basename( dirname( $config_file_path ) ) === 'tests' ) { |
|
11 | + $config_file_path = dirname( dirname( $config_file_path ) ); |
|
12 | + } |
|
13 | + } |
|
13 | 14 | $config_file_path .= '/wp-tests-config.php'; |
14 | 15 | |
15 | 16 | /* |
@@ -26,8 +27,9 @@ discard block |
||
26 | 27 | define( 'WP_TESTS_TABLE_PREFIX', $table_prefix ); |
27 | 28 | define( 'DIR_TESTDATA', dirname( __FILE__ ) . '/../data' ); |
28 | 29 | |
29 | -if ( ! defined( 'WP_TESTS_FORCE_KNOWN_BUGS' ) ) |
|
30 | +if ( ! defined( 'WP_TESTS_FORCE_KNOWN_BUGS' ) ) { |
|
30 | 31 | define( 'WP_TESTS_FORCE_KNOWN_BUGS', false ); |
32 | +} |
|
31 | 33 | |
32 | 34 | // Cron tries to make an HTTP request to the blog, which always fails, because tests are run in CLI mode only |
33 | 35 | define( 'DISABLE_WP_CRON', true ); |
@@ -126,8 +128,7 @@ discard block |
||
126 | 128 | if ( strlen( $arg ) > 1 && $arg[0] === '-' && $arg[1] === '-' ) { |
127 | 129 | PHPUnit_Util_Getopt::parseLongOption( substr( $arg, 2 ), $this->longOptions, $options, $argv ); |
128 | 130 | } |
129 | - } |
|
130 | - catch ( PHPUnit_Framework_Exception $e ) { |
|
131 | + } catch ( PHPUnit_Framework_Exception $e ) { |
|
131 | 132 | // Enforcing recognized arguments or correctly formed arguments is |
132 | 133 | // not really the concern here. |
133 | 134 | continue; |
@@ -175,6 +175,6 @@ |
||
175 | 175 | echo 'If this changeset includes changes to HTTP, make sure there are no timeouts.' . PHP_EOL; |
176 | 176 | echo PHP_EOL; |
177 | 177 | } |
178 | - } |
|
178 | + } |
|
179 | 179 | } |
180 | 180 | new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] ); |
@@ -4,11 +4,11 @@ discard block |
||
4 | 4 | */ |
5 | 5 | |
6 | 6 | |
7 | -$config_file_path = dirname( dirname( __FILE__ ) ); |
|
8 | -if ( ! file_exists( $config_file_path . '/wp-tests-config.php' ) ) { |
|
7 | +$config_file_path = dirname(dirname(__FILE__)); |
|
8 | +if (!file_exists($config_file_path.'/wp-tests-config.php')) { |
|
9 | 9 | // Support the config file from the root of the develop repository. |
10 | - if ( basename( $config_file_path ) === 'phpunit' && basename( dirname( $config_file_path ) ) === 'tests' ) |
|
11 | - $config_file_path = dirname( dirname( $config_file_path ) ); |
|
10 | + if (basename($config_file_path) === 'phpunit' && basename(dirname($config_file_path)) === 'tests') |
|
11 | + $config_file_path = dirname(dirname($config_file_path)); |
|
12 | 12 | } |
13 | 13 | $config_file_path .= '/wp-tests-config.php'; |
14 | 14 | |
@@ -18,22 +18,22 @@ discard block |
||
18 | 18 | */ |
19 | 19 | global $wpdb, $current_site, $current_blog, $wp_rewrite, $shortcode_tags, $wp, $phpmailer; |
20 | 20 | |
21 | -if ( !is_readable( $config_file_path ) ) { |
|
22 | - die( "ERROR: wp-tests-config.php is missing! Please use wp-tests-config-sample.php to create a config file.\n" ); |
|
21 | +if (!is_readable($config_file_path)) { |
|
22 | + die("ERROR: wp-tests-config.php is missing! Please use wp-tests-config-sample.php to create a config file.\n"); |
|
23 | 23 | } |
24 | 24 | require_once $config_file_path; |
25 | 25 | |
26 | -define( 'WP_TESTS_TABLE_PREFIX', $table_prefix ); |
|
27 | -define( 'DIR_TESTDATA', dirname( __FILE__ ) . '/../data' ); |
|
26 | +define('WP_TESTS_TABLE_PREFIX', $table_prefix); |
|
27 | +define('DIR_TESTDATA', dirname(__FILE__).'/../data'); |
|
28 | 28 | |
29 | -if ( ! defined( 'WP_TESTS_FORCE_KNOWN_BUGS' ) ) |
|
30 | - define( 'WP_TESTS_FORCE_KNOWN_BUGS', false ); |
|
29 | +if (!defined('WP_TESTS_FORCE_KNOWN_BUGS')) |
|
30 | + define('WP_TESTS_FORCE_KNOWN_BUGS', false); |
|
31 | 31 | |
32 | 32 | // Cron tries to make an HTTP request to the blog, which always fails, because tests are run in CLI mode only |
33 | -define( 'DISABLE_WP_CRON', true ); |
|
33 | +define('DISABLE_WP_CRON', true); |
|
34 | 34 | |
35 | -define( 'WP_MEMORY_LIMIT', -1 ); |
|
36 | -define( 'WP_MAX_MEMORY_LIMIT', -1 ); |
|
35 | +define('WP_MEMORY_LIMIT', -1); |
|
36 | +define('WP_MAX_MEMORY_LIMIT', -1); |
|
37 | 37 | |
38 | 38 | $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; |
39 | 39 | $_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN; |
@@ -43,62 +43,62 @@ discard block |
||
43 | 43 | |
44 | 44 | $PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php'; |
45 | 45 | |
46 | -if ( "1" == getenv( 'WP_MULTISITE' ) || |
|
47 | - ( defined( 'WP_TESTS_MULTISITE') && WP_TESTS_MULTISITE ) ) { |
|
46 | +if ("1" == getenv('WP_MULTISITE') || |
|
47 | + (defined('WP_TESTS_MULTISITE') && WP_TESTS_MULTISITE)) { |
|
48 | 48 | $multisite = true; |
49 | 49 | } else { |
50 | 50 | $multisite = false; |
51 | 51 | } |
52 | 52 | |
53 | 53 | // Override the PHPMailer |
54 | -require_once( dirname( __FILE__ ) . '/mock-mailer.php' ); |
|
54 | +require_once(dirname(__FILE__).'/mock-mailer.php'); |
|
55 | 55 | $phpmailer = new MockPHPMailer(); |
56 | 56 | |
57 | -system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite ); |
|
57 | +system(WP_PHP_BINARY.' '.escapeshellarg(dirname(__FILE__).'/install.php').' '.escapeshellarg($config_file_path).' '.$multisite); |
|
58 | 58 | |
59 | -if ( $multisite ) { |
|
60 | - echo "Running as multisite..." . PHP_EOL; |
|
61 | - define( 'MULTISITE', true ); |
|
62 | - define( 'SUBDOMAIN_INSTALL', false ); |
|
59 | +if ($multisite) { |
|
60 | + echo "Running as multisite...".PHP_EOL; |
|
61 | + define('MULTISITE', true); |
|
62 | + define('SUBDOMAIN_INSTALL', false); |
|
63 | 63 | $GLOBALS['base'] = '/'; |
64 | 64 | } else { |
65 | - echo "Running as single site... To run multisite, use -c tests/phpunit/multisite.xml" . PHP_EOL; |
|
65 | + echo "Running as single site... To run multisite, use -c tests/phpunit/multisite.xml".PHP_EOL; |
|
66 | 66 | } |
67 | -unset( $multisite ); |
|
67 | +unset($multisite); |
|
68 | 68 | |
69 | -require_once dirname( __FILE__ ) . '/functions.php'; |
|
69 | +require_once dirname(__FILE__).'/functions.php'; |
|
70 | 70 | |
71 | 71 | $GLOBALS['_wp_die_disabled'] = false; |
72 | 72 | // Allow tests to override wp_die |
73 | -tests_add_filter( 'wp_die_handler', '_wp_die_handler_filter' ); |
|
73 | +tests_add_filter('wp_die_handler', '_wp_die_handler_filter'); |
|
74 | 74 | |
75 | 75 | // Preset WordPress options defined in bootstrap file. |
76 | 76 | // Used to activate themes, plugins, as well as other settings. |
77 | -if(isset($GLOBALS['wp_tests_options'])) { |
|
78 | - function wp_tests_options( $value ) { |
|
79 | - $key = substr( current_filter(), strlen( 'pre_option_' ) ); |
|
77 | +if (isset($GLOBALS['wp_tests_options'])) { |
|
78 | + function wp_tests_options($value) { |
|
79 | + $key = substr(current_filter(), strlen('pre_option_')); |
|
80 | 80 | return $GLOBALS['wp_tests_options'][$key]; |
81 | 81 | } |
82 | 82 | |
83 | - foreach ( array_keys( $GLOBALS['wp_tests_options'] ) as $key ) { |
|
84 | - tests_add_filter( 'pre_option_'.$key, 'wp_tests_options' ); |
|
83 | + foreach (array_keys($GLOBALS['wp_tests_options']) as $key) { |
|
84 | + tests_add_filter('pre_option_'.$key, 'wp_tests_options'); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | 88 | // Load WordPress |
89 | -require_once ABSPATH . '/wp-settings.php'; |
|
89 | +require_once ABSPATH.'/wp-settings.php'; |
|
90 | 90 | |
91 | 91 | // Delete any default posts & related data |
92 | 92 | _delete_all_posts(); |
93 | 93 | |
94 | -require dirname( __FILE__ ) . '/testcase.php'; |
|
95 | -require dirname( __FILE__ ) . '/testcase-rest-api.php'; |
|
96 | -require dirname( __FILE__ ) . '/testcase-xmlrpc.php'; |
|
97 | -require dirname( __FILE__ ) . '/testcase-ajax.php'; |
|
98 | -require dirname( __FILE__ ) . '/testcase-canonical.php'; |
|
99 | -require dirname( __FILE__ ) . '/exceptions.php'; |
|
100 | -require dirname( __FILE__ ) . '/utils.php'; |
|
101 | -require dirname( __FILE__ ) . '/spy-rest-server.php'; |
|
94 | +require dirname(__FILE__).'/testcase.php'; |
|
95 | +require dirname(__FILE__).'/testcase-rest-api.php'; |
|
96 | +require dirname(__FILE__).'/testcase-xmlrpc.php'; |
|
97 | +require dirname(__FILE__).'/testcase-ajax.php'; |
|
98 | +require dirname(__FILE__).'/testcase-canonical.php'; |
|
99 | +require dirname(__FILE__).'/exceptions.php'; |
|
100 | +require dirname(__FILE__).'/utils.php'; |
|
101 | +require dirname(__FILE__).'/spy-rest-server.php'; |
|
102 | 102 | |
103 | 103 | /** |
104 | 104 | * A child class of the PHP test runner. |
@@ -118,16 +118,16 @@ discard block |
||
118 | 118 | 'exclude-group=', |
119 | 119 | 'group=', |
120 | 120 | ); |
121 | - function __construct( $argv ) { |
|
122 | - array_shift( $argv ); |
|
121 | + function __construct($argv) { |
|
122 | + array_shift($argv); |
|
123 | 123 | $options = array(); |
124 | - while ( list( $i, $arg ) = each( $argv ) ) { |
|
124 | + while (list($i, $arg) = each($argv)) { |
|
125 | 125 | try { |
126 | - if ( strlen( $arg ) > 1 && $arg[0] === '-' && $arg[1] === '-' ) { |
|
127 | - PHPUnit_Util_Getopt::parseLongOption( substr( $arg, 2 ), $this->longOptions, $options, $argv ); |
|
126 | + if (strlen($arg) > 1 && $arg[0] === '-' && $arg[1] === '-') { |
|
127 | + PHPUnit_Util_Getopt::parseLongOption(substr($arg, 2), $this->longOptions, $options, $argv); |
|
128 | 128 | } |
129 | 129 | } |
130 | - catch ( PHPUnit_Framework_Exception $e ) { |
|
130 | + catch (PHPUnit_Framework_Exception $e) { |
|
131 | 131 | // Enforcing recognized arguments or correctly formed arguments is |
132 | 132 | // not really the concern here. |
133 | 133 | continue; |
@@ -140,41 +140,41 @@ discard block |
||
140 | 140 | 'external-http' => true, |
141 | 141 | ); |
142 | 142 | |
143 | - foreach ( $options as $option ) { |
|
144 | - switch ( $option[0] ) { |
|
143 | + foreach ($options as $option) { |
|
144 | + switch ($option[0]) { |
|
145 | 145 | case '--exclude-group' : |
146 | - foreach ( $skipped_groups as $group_name => $skipped ) { |
|
147 | - $skipped_groups[ $group_name ] = false; |
|
146 | + foreach ($skipped_groups as $group_name => $skipped) { |
|
147 | + $skipped_groups[$group_name] = false; |
|
148 | 148 | } |
149 | 149 | continue 2; |
150 | 150 | case '--group' : |
151 | - $groups = explode( ',', $option[1] ); |
|
152 | - foreach ( $groups as $group ) { |
|
153 | - if ( is_numeric( $group ) || preg_match( '/^(UT|Plugin)\d+$/', $group ) ) { |
|
154 | - WP_UnitTestCase::forceTicket( $group ); |
|
151 | + $groups = explode(',', $option[1]); |
|
152 | + foreach ($groups as $group) { |
|
153 | + if (is_numeric($group) || preg_match('/^(UT|Plugin)\d+$/', $group)) { |
|
154 | + WP_UnitTestCase::forceTicket($group); |
|
155 | 155 | } |
156 | 156 | } |
157 | 157 | |
158 | - foreach ( $skipped_groups as $group_name => $skipped ) { |
|
159 | - if ( in_array( $group_name, $groups ) ) { |
|
160 | - $skipped_groups[ $group_name ] = false; |
|
158 | + foreach ($skipped_groups as $group_name => $skipped) { |
|
159 | + if (in_array($group_name, $groups)) { |
|
160 | + $skipped_groups[$group_name] = false; |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | continue 2; |
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
167 | - $skipped_groups = array_filter( $skipped_groups ); |
|
168 | - foreach ( $skipped_groups as $group_name => $skipped ) { |
|
169 | - echo sprintf( 'Not running %1$s tests. To execute these, use --group %1$s.', $group_name ) . PHP_EOL; |
|
167 | + $skipped_groups = array_filter($skipped_groups); |
|
168 | + foreach ($skipped_groups as $group_name => $skipped) { |
|
169 | + echo sprintf('Not running %1$s tests. To execute these, use --group %1$s.', $group_name).PHP_EOL; |
|
170 | 170 | } |
171 | 171 | |
172 | - if ( ! isset( $skipped_groups['external-http'] ) ) { |
|
172 | + if (!isset($skipped_groups['external-http'])) { |
|
173 | 173 | echo PHP_EOL; |
174 | - echo 'External HTTP skipped tests can be caused by timeouts.' . PHP_EOL; |
|
175 | - echo 'If this changeset includes changes to HTTP, make sure there are no timeouts.' . PHP_EOL; |
|
174 | + echo 'External HTTP skipped tests can be caused by timeouts.'.PHP_EOL; |
|
175 | + echo 'If this changeset includes changes to HTTP, make sure there are no timeouts.'.PHP_EOL; |
|
176 | 176 | echo PHP_EOL; |
177 | 177 | } |
178 | 178 | } |
179 | 179 | } |
180 | -new WP_PHPUnit_Util_Getopt( $_SERVER['argv'] ); |
|
180 | +new WP_PHPUnit_Util_Getopt($_SERVER['argv']); |
@@ -168,19 +168,22 @@ discard block |
||
168 | 168 | public function assertCanonical( $test_url, $expected, $ticket = 0, $expected_doing_it_wrong = array() ) { |
169 | 169 | $this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, (array) $expected_doing_it_wrong ); |
170 | 170 | |
171 | - if ( $ticket ) |
|
172 | - $this->knownWPBug( $ticket ); |
|
171 | + if ( $ticket ) { |
|
172 | + $this->knownWPBug( $ticket ); |
|
173 | + } |
|
173 | 174 | |
174 | 175 | $ticket_ref = ($ticket > 0) ? 'Ticket #' . $ticket : null; |
175 | 176 | global $wpdb; |
176 | 177 | //print_r( $wpdb->get_results( "SELECT * FROM $wpdb->terms" ) ); |
177 | - if ( is_string($expected) ) |
|
178 | - $expected = array('url' => $expected); |
|
179 | - elseif ( is_array($expected) && !isset($expected['url']) && !isset($expected['qv']) ) |
|
180 | - $expected = array( 'qv' => $expected ); |
|
178 | + if ( is_string($expected) ) { |
|
179 | + $expected = array('url' => $expected); |
|
180 | + } elseif ( is_array($expected) && !isset($expected['url']) && !isset($expected['qv']) ) { |
|
181 | + $expected = array( 'qv' => $expected ); |
|
182 | + } |
|
181 | 183 | |
182 | - if ( !isset($expected['url']) && !isset($expected['qv']) ) |
|
183 | - $this->markTestSkipped('No valid expected output was provided'); |
|
184 | + if ( !isset($expected['url']) && !isset($expected['qv']) ) { |
|
185 | + $this->markTestSkipped('No valid expected output was provided'); |
|
186 | + } |
|
184 | 187 | |
185 | 188 | $this->go_to( home_url( $test_url ) ); |
186 | 189 | |
@@ -193,8 +196,9 @@ discard block |
||
193 | 196 | $this->assertEquals( $expected['url'], $parsed_can_url['path'] . (!empty($parsed_can_url['query']) ? '?' . $parsed_can_url['query'] : ''), $ticket_ref ); |
194 | 197 | } |
195 | 198 | |
196 | - if ( ! isset($expected['qv']) ) |
|
197 | - return; |
|
199 | + if ( ! isset($expected['qv']) ) { |
|
200 | + return; |
|
201 | + } |
|
198 | 202 | |
199 | 203 | // "make" that the request and check the query is correct |
200 | 204 | $this->go_to( $can_url ); |
@@ -227,8 +231,10 @@ discard block |
||
227 | 231 | $test_url = home_url( $test_url ); |
228 | 232 | |
229 | 233 | $can_url = redirect_canonical( $test_url, false ); |
230 | - if ( ! $can_url ) |
|
231 | - return $test_url; // No redirect will take place for this request |
|
234 | + if ( ! $can_url ) { |
|
235 | + return $test_url; |
|
236 | + } |
|
237 | + // No redirect will take place for this request |
|
232 | 238 | |
233 | 239 | return $can_url; |
234 | 240 | } |
@@ -18,13 +18,13 @@ discard block |
||
18 | 18 | public function setUp() { |
19 | 19 | parent::setUp(); |
20 | 20 | |
21 | - update_option( 'page_comments', true ); |
|
22 | - update_option( 'comments_per_page', 5 ); |
|
23 | - update_option( 'posts_per_page', 5 ); |
|
21 | + update_option('page_comments', true); |
|
22 | + update_option('comments_per_page', 5); |
|
23 | + update_option('posts_per_page', 5); |
|
24 | 24 | |
25 | 25 | global $wp_rewrite; |
26 | 26 | $wp_rewrite->init(); |
27 | - $wp_rewrite->set_permalink_structure( $this->structure ); |
|
27 | + $wp_rewrite->set_permalink_structure($this->structure); |
|
28 | 28 | |
29 | 29 | create_initial_taxonomies(); |
30 | 30 | |
@@ -38,94 +38,94 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @since 4.1.0 |
40 | 40 | */ |
41 | - public static function generate_shared_fixtures( $factory ) { |
|
41 | + public static function generate_shared_fixtures($factory) { |
|
42 | 42 | self::$old_current_user = get_current_user_id(); |
43 | - self::$author_id = $factory->user->create( array( 'user_login' => 'canonical-author' ) ); |
|
43 | + self::$author_id = $factory->user->create(array('user_login' => 'canonical-author')); |
|
44 | 44 | |
45 | 45 | /* |
46 | 46 | * Also set in self::setUp(), but we must configure here to make sure that |
47 | 47 | * post authorship is properly attributed for fixtures. |
48 | 48 | */ |
49 | - wp_set_current_user( self::$author_id ); |
|
49 | + wp_set_current_user(self::$author_id); |
|
50 | 50 | |
51 | 51 | // Already created by install defaults: |
52 | 52 | // self::factory()->term->create( array( 'taxonomy' => 'category', 'name' => 'uncategorized' ) ); |
53 | 53 | |
54 | - self::$post_ids[] = $factory->post->create( array( 'import_id' => 587, 'post_title' => 'post-format-test-audio', 'post_date' => '2008-06-02 00:00:00' ) ); |
|
55 | - self::$post_ids[] = $post_id = $factory->post->create( array( 'post_title' => 'post-format-test-gallery', 'post_date' => '2008-06-10 00:00:00' ) ); |
|
56 | - self::$post_ids[] = $factory->post->create( array( 'import_id' => 611, 'post_type' => 'attachment', 'post_title' => 'canola2', 'post_parent' => $post_id ) ); |
|
54 | + self::$post_ids[] = $factory->post->create(array('import_id' => 587, 'post_title' => 'post-format-test-audio', 'post_date' => '2008-06-02 00:00:00')); |
|
55 | + self::$post_ids[] = $post_id = $factory->post->create(array('post_title' => 'post-format-test-gallery', 'post_date' => '2008-06-10 00:00:00')); |
|
56 | + self::$post_ids[] = $factory->post->create(array('import_id' => 611, 'post_type' => 'attachment', 'post_title' => 'canola2', 'post_parent' => $post_id)); |
|
57 | 57 | |
58 | - self::$post_ids[] = $factory->post->create( array( |
|
58 | + self::$post_ids[] = $factory->post->create(array( |
|
59 | 59 | 'post_title' => 'images-test', |
60 | 60 | 'post_date' => '2008-09-03 00:00:00', |
61 | 61 | 'post_content' => 'Page 1 <!--nextpage--> Page 2 <!--nextpage--> Page 3' |
62 | - ) ); |
|
62 | + )); |
|
63 | 63 | |
64 | - self::$post_ids[] = $post_id = $factory->post->create( array( 'import_id' => 149, 'post_title' => 'comment-test', 'post_date' => '2008-03-03 00:00:00' ) ); |
|
65 | - self::$comment_ids = $factory->comment->create_post_comments( $post_id, 15 ); |
|
64 | + self::$post_ids[] = $post_id = $factory->post->create(array('import_id' => 149, 'post_title' => 'comment-test', 'post_date' => '2008-03-03 00:00:00')); |
|
65 | + self::$comment_ids = $factory->comment->create_post_comments($post_id, 15); |
|
66 | 66 | |
67 | - self::$post_ids[] = $factory->post->create( array( 'post_date' => '2008-09-05 00:00:00' ) ); |
|
67 | + self::$post_ids[] = $factory->post->create(array('post_date' => '2008-09-05 00:00:00')); |
|
68 | 68 | |
69 | - self::$post_ids[] = $factory->post->create( array( 'import_id' => 123 ) ); |
|
70 | - self::$post_ids[] = $factory->post->create( array( 'import_id' => 1 ) ); |
|
71 | - self::$post_ids[] = $factory->post->create( array( 'import_id' => 358 ) ); |
|
69 | + self::$post_ids[] = $factory->post->create(array('import_id' => 123)); |
|
70 | + self::$post_ids[] = $factory->post->create(array('import_id' => 1)); |
|
71 | + self::$post_ids[] = $factory->post->create(array('import_id' => 358)); |
|
72 | 72 | |
73 | - self::$post_ids[] = $factory->post->create( array( 'post_type' => 'page', 'post_title' => 'sample-page' ) ); |
|
74 | - self::$post_ids[] = $factory->post->create( array( 'post_type' => 'page', 'post_title' => 'about' ) ); |
|
75 | - self::$post_ids[] = $post_id = $factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) ); |
|
73 | + self::$post_ids[] = $factory->post->create(array('post_type' => 'page', 'post_title' => 'sample-page')); |
|
74 | + self::$post_ids[] = $factory->post->create(array('post_type' => 'page', 'post_title' => 'about')); |
|
75 | + self::$post_ids[] = $post_id = $factory->post->create(array('post_type' => 'page', 'post_title' => 'parent-page')); |
|
76 | 76 | self::$post_ids[] = $factory->post->create( |
77 | - array( 'import_id' => 144, 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $post_id, |
|
77 | + array('import_id' => 144, 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $post_id, |
|
78 | 78 | ) ); |
79 | 79 | |
80 | - self::$post_ids[] = $parent_id = $factory->post->create( array( |
|
80 | + self::$post_ids[] = $parent_id = $factory->post->create(array( |
|
81 | 81 | 'post_name' => 'parent', |
82 | 82 | 'post_type' => 'page', |
83 | - ) ); |
|
84 | - self::$post_ids[] = $child_id_1 = $factory->post->create( array( |
|
83 | + )); |
|
84 | + self::$post_ids[] = $child_id_1 = $factory->post->create(array( |
|
85 | 85 | 'post_name' => 'child1', |
86 | 86 | 'post_type' => 'page', |
87 | 87 | 'post_parent' => $parent_id, |
88 | - ) ); |
|
89 | - self::$post_ids[] = $child_id_2 = $factory->post->create( array( |
|
88 | + )); |
|
89 | + self::$post_ids[] = $child_id_2 = $factory->post->create(array( |
|
90 | 90 | 'post_name' => 'child2', |
91 | 91 | 'post_type' => 'page', |
92 | 92 | 'post_parent' => $parent_id, |
93 | - ) ); |
|
94 | - self::$post_ids[] = $grandchild_id_1 = $factory->post->create( array( |
|
93 | + )); |
|
94 | + self::$post_ids[] = $grandchild_id_1 = $factory->post->create(array( |
|
95 | 95 | 'post_name' => 'grandchild', |
96 | 96 | 'post_type' => 'page', |
97 | 97 | 'post_parent' => $child_id_1, |
98 | - ) ); |
|
99 | - self::$post_ids[] = $grandchild_id_2 = $factory->post->create( array( |
|
98 | + )); |
|
99 | + self::$post_ids[] = $grandchild_id_2 = $factory->post->create(array( |
|
100 | 100 | 'post_name' => 'grandchild', |
101 | 101 | 'post_type' => 'page', |
102 | 102 | 'post_parent' => $child_id_2, |
103 | - ) ); |
|
103 | + )); |
|
104 | 104 | |
105 | - $cat1 = $factory->term->create( array( 'taxonomy' => 'category', 'name' => 'parent' ) ); |
|
105 | + $cat1 = $factory->term->create(array('taxonomy' => 'category', 'name' => 'parent')); |
|
106 | 106 | self::$terms['/category/parent/'] = $cat1; |
107 | - self::$term_ids[ $cat1 ] = 'category'; |
|
107 | + self::$term_ids[$cat1] = 'category'; |
|
108 | 108 | |
109 | - $cat2 = $factory->term->create( array( |
|
109 | + $cat2 = $factory->term->create(array( |
|
110 | 110 | 'taxonomy' => 'category', 'name' => 'child-1', 'parent' => self::$terms['/category/parent/'], |
111 | - ) ); |
|
111 | + )); |
|
112 | 112 | self::$terms['/category/parent/child-1/'] = $cat2; |
113 | - self::$term_ids[ $cat2 ] = 'category'; |
|
113 | + self::$term_ids[$cat2] = 'category'; |
|
114 | 114 | |
115 | - $cat3 = $factory->term->create( array( |
|
115 | + $cat3 = $factory->term->create(array( |
|
116 | 116 | 'taxonomy' => 'category', 'name' => 'child-2', 'parent' => self::$terms['/category/parent/child-1/'], |
117 | - ) ); |
|
117 | + )); |
|
118 | 118 | self::$terms['/category/parent/child-1/child-2/'] = $cat3; |
119 | - self::$term_ids[ $cat3 ] = 'category'; |
|
119 | + self::$term_ids[$cat3] = 'category'; |
|
120 | 120 | |
121 | - $cat4 = $factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-a' ) ); |
|
122 | - self::$term_ids[ $cat4 ] = 'category'; |
|
121 | + $cat4 = $factory->term->create(array('taxonomy' => 'category', 'name' => 'cat-a')); |
|
122 | + self::$term_ids[$cat4] = 'category'; |
|
123 | 123 | |
124 | - $cat5 = $factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-b' ) ); |
|
125 | - self::$term_ids[ $cat5 ] = 'category'; |
|
124 | + $cat5 = $factory->term->create(array('taxonomy' => 'category', 'name' => 'cat-b')); |
|
125 | + self::$term_ids[$cat5] = 'category'; |
|
126 | 126 | |
127 | - $tag1 = $factory->term->create( array( 'name' => 'post-formats' ) ); |
|
128 | - self::$term_ids[ $tag1 ] = 'post_tag'; |
|
127 | + $tag1 = $factory->term->create(array('name' => 'post-formats')); |
|
128 | + self::$term_ids[$tag1] = 'post_tag'; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -134,18 +134,18 @@ discard block |
||
134 | 134 | * @since 4.1.0 |
135 | 135 | */ |
136 | 136 | public static function delete_shared_fixtures() { |
137 | - self::delete_user( self::$author_id ); |
|
137 | + self::delete_user(self::$author_id); |
|
138 | 138 | |
139 | - foreach ( self::$post_ids as $pid ) { |
|
140 | - wp_delete_post( $pid, true ); |
|
139 | + foreach (self::$post_ids as $pid) { |
|
140 | + wp_delete_post($pid, true); |
|
141 | 141 | } |
142 | 142 | |
143 | - foreach ( self::$comment_ids as $cid ) { |
|
144 | - wp_delete_comment( $cid, true ); |
|
143 | + foreach (self::$comment_ids as $cid) { |
|
144 | + wp_delete_comment($cid, true); |
|
145 | 145 | } |
146 | 146 | |
147 | - foreach ( self::$term_ids as $tid => $tax ) { |
|
148 | - wp_delete_term( $tid, $tax ); |
|
147 | + foreach (self::$term_ids as $tid => $tax) { |
|
148 | + wp_delete_term($tid, $tax); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | self::$author_id = null; |
@@ -165,54 +165,54 @@ discard block |
||
165 | 165 | * @param int $ticket Optional. Trac ticket number. |
166 | 166 | * @param array $expected_doing_it_wrong Array of class/function names expected to throw _doing_it_wrong() notices. |
167 | 167 | */ |
168 | - public function assertCanonical( $test_url, $expected, $ticket = 0, $expected_doing_it_wrong = array() ) { |
|
169 | - $this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, (array) $expected_doing_it_wrong ); |
|
168 | + public function assertCanonical($test_url, $expected, $ticket = 0, $expected_doing_it_wrong = array()) { |
|
169 | + $this->expected_doing_it_wrong = array_merge($this->expected_doing_it_wrong, (array) $expected_doing_it_wrong); |
|
170 | 170 | |
171 | - if ( $ticket ) |
|
172 | - $this->knownWPBug( $ticket ); |
|
171 | + if ($ticket) |
|
172 | + $this->knownWPBug($ticket); |
|
173 | 173 | |
174 | - $ticket_ref = ($ticket > 0) ? 'Ticket #' . $ticket : null; |
|
174 | + $ticket_ref = ($ticket > 0) ? 'Ticket #'.$ticket : null; |
|
175 | 175 | global $wpdb; |
176 | 176 | //print_r( $wpdb->get_results( "SELECT * FROM $wpdb->terms" ) ); |
177 | - if ( is_string($expected) ) |
|
177 | + if (is_string($expected)) |
|
178 | 178 | $expected = array('url' => $expected); |
179 | - elseif ( is_array($expected) && !isset($expected['url']) && !isset($expected['qv']) ) |
|
180 | - $expected = array( 'qv' => $expected ); |
|
179 | + elseif (is_array($expected) && !isset($expected['url']) && !isset($expected['qv'])) |
|
180 | + $expected = array('qv' => $expected); |
|
181 | 181 | |
182 | - if ( !isset($expected['url']) && !isset($expected['qv']) ) |
|
182 | + if (!isset($expected['url']) && !isset($expected['qv'])) |
|
183 | 183 | $this->markTestSkipped('No valid expected output was provided'); |
184 | 184 | |
185 | - $this->go_to( home_url( $test_url ) ); |
|
185 | + $this->go_to(home_url($test_url)); |
|
186 | 186 | |
187 | 187 | // Does the redirect match what's expected? |
188 | - $can_url = $this->get_canonical( $test_url ); |
|
188 | + $can_url = $this->get_canonical($test_url); |
|
189 | 189 | $parsed_can_url = parse_url($can_url); |
190 | 190 | |
191 | 191 | // Just test the Path and Query if present |
192 | - if ( isset($expected['url']) ) { |
|
193 | - $this->assertEquals( $expected['url'], $parsed_can_url['path'] . (!empty($parsed_can_url['query']) ? '?' . $parsed_can_url['query'] : ''), $ticket_ref ); |
|
192 | + if (isset($expected['url'])) { |
|
193 | + $this->assertEquals($expected['url'], $parsed_can_url['path'].(!empty($parsed_can_url['query']) ? '?'.$parsed_can_url['query'] : ''), $ticket_ref); |
|
194 | 194 | } |
195 | 195 | |
196 | - if ( ! isset($expected['qv']) ) |
|
196 | + if (!isset($expected['qv'])) |
|
197 | 197 | return; |
198 | 198 | |
199 | 199 | // "make" that the request and check the query is correct |
200 | - $this->go_to( $can_url ); |
|
200 | + $this->go_to($can_url); |
|
201 | 201 | |
202 | 202 | // Are all query vars accounted for, And correct? |
203 | 203 | global $wp; |
204 | 204 | |
205 | 205 | $query_vars = array_diff($wp->query_vars, $wp->extra_query_vars); |
206 | - if ( !empty($parsed_can_url['query']) ) { |
|
206 | + if (!empty($parsed_can_url['query'])) { |
|
207 | 207 | parse_str($parsed_can_url['query'], $_qv); |
208 | 208 | |
209 | 209 | // $_qv should not contain any elements which are set in $query_vars already (ie. $_GET vars should not be present in the Rewrite) |
210 | - $this->assertEquals( array(), array_intersect( $query_vars, $_qv ), 'Query vars are duplicated from the Rewrite into $_GET; ' . $ticket_ref ); |
|
210 | + $this->assertEquals(array(), array_intersect($query_vars, $_qv), 'Query vars are duplicated from the Rewrite into $_GET; '.$ticket_ref); |
|
211 | 211 | |
212 | 212 | $query_vars = array_merge($query_vars, $_qv); |
213 | 213 | } |
214 | 214 | |
215 | - $this->assertEquals( $expected['qv'], $query_vars ); |
|
215 | + $this->assertEquals($expected['qv'], $query_vars); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -223,11 +223,11 @@ discard block |
||
223 | 223 | * @return $can_url Returns the original $test_url if no canonical can be generated, otherwise returns |
224 | 224 | * the fully-qualified URL as generated by redirect_canonical(). |
225 | 225 | */ |
226 | - public function get_canonical( $test_url ) { |
|
227 | - $test_url = home_url( $test_url ); |
|
226 | + public function get_canonical($test_url) { |
|
227 | + $test_url = home_url($test_url); |
|
228 | 228 | |
229 | - $can_url = redirect_canonical( $test_url, false ); |
|
230 | - if ( ! $can_url ) |
|
229 | + $can_url = redirect_canonical($test_url, false); |
|
230 | + if (!$can_url) |
|
231 | 231 | return $test_url; // No redirect will take place for this request |
232 | 232 | |
233 | 233 | return $can_url; |
@@ -21,18 +21,18 @@ |
||
21 | 21 | * @param array $args Arguments to pass to the method |
22 | 22 | * @return mixed |
23 | 23 | */ |
24 | - public function __call( $method, $args ) { |
|
25 | - return call_user_func_array( array( $this, $method ), $args ); |
|
24 | + public function __call($method, $args) { |
|
25 | + return call_user_func_array(array($this, $method), $args); |
|
26 | 26 | } |
27 | 27 | |
28 | - public function send_header( $header, $value ) { |
|
29 | - $this->sent_headers[ $header ] = $value; |
|
28 | + public function send_header($header, $value) { |
|
29 | + $this->sent_headers[$header] = $value; |
|
30 | 30 | } |
31 | 31 | |
32 | - public function serve_request( $path = null ) { |
|
32 | + public function serve_request($path = null) { |
|
33 | 33 | |
34 | 34 | ob_start(); |
35 | - $result = parent::serve_request( $path ); |
|
35 | + $result = parent::serve_request($path); |
|
36 | 36 | $this->sent_body = ob_get_clean(); |
37 | 37 | return $result; |
38 | 38 | } |
@@ -412,37 +412,37 @@ |
||
412 | 412 | ini_set( 'pcre.backtrack_limit', $i ); |
413 | 413 | |
414 | 414 | switch( $strategy ) { |
415 | - case 'split': |
|
416 | - preg_split( $pattern, $subject ); |
|
417 | - break; |
|
418 | - case 'match': |
|
419 | - preg_match( $pattern, $subject ); |
|
420 | - break; |
|
421 | - case 'match_all': |
|
422 | - $matches = array(); |
|
423 | - preg_match_all( $pattern, $subject, $matches ); |
|
424 | - break; |
|
415 | + case 'split': |
|
416 | + preg_split( $pattern, $subject ); |
|
417 | + break; |
|
418 | + case 'match': |
|
419 | + preg_match( $pattern, $subject ); |
|
420 | + break; |
|
421 | + case 'match_all': |
|
422 | + $matches = array(); |
|
423 | + preg_match_all( $pattern, $subject, $matches ); |
|
424 | + break; |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | ini_set( 'pcre.backtrack_limit', $saved_config ); |
428 | 428 | |
429 | 429 | switch( preg_last_error() ) { |
430 | - case PREG_NO_ERROR: |
|
431 | - return $i; |
|
432 | - case PREG_BACKTRACK_LIMIT_ERROR: |
|
433 | - continue; |
|
434 | - case PREG_RECURSION_LIMIT_ERROR: |
|
435 | - trigger_error('PCRE recursion limit encountered before backtrack limit.'); |
|
436 | - return; |
|
437 | - case PREG_BAD_UTF8_ERROR: |
|
438 | - trigger_error('UTF-8 error during PCRE benchmark.'); |
|
439 | - return; |
|
440 | - case PREG_INTERNAL_ERROR: |
|
441 | - trigger_error('Internal error during PCRE benchmark.'); |
|
442 | - return; |
|
443 | - default: |
|
444 | - trigger_error('Unexpected error during PCRE benchmark.'); |
|
445 | - return; |
|
430 | + case PREG_NO_ERROR: |
|
431 | + return $i; |
|
432 | + case PREG_BACKTRACK_LIMIT_ERROR: |
|
433 | + continue; |
|
434 | + case PREG_RECURSION_LIMIT_ERROR: |
|
435 | + trigger_error('PCRE recursion limit encountered before backtrack limit.'); |
|
436 | + return; |
|
437 | + case PREG_BAD_UTF8_ERROR: |
|
438 | + trigger_error('UTF-8 error during PCRE benchmark.'); |
|
439 | + return; |
|
440 | + case PREG_INTERNAL_ERROR: |
|
441 | + trigger_error('Internal error during PCRE benchmark.'); |
|
442 | + return; |
|
443 | + default: |
|
444 | + trigger_error('Unexpected error during PCRE benchmark.'); |
|
445 | + return; |
|
446 | 446 | } |
447 | 447 | } |
448 | 448 |
@@ -10,9 +10,10 @@ discard block |
||
10 | 10 | function strip_ws($txt) { |
11 | 11 | $lines = explode("\n", $txt); |
12 | 12 | $result = array(); |
13 | - foreach ($lines as $line) |
|
14 | - if (trim($line)) |
|
13 | + foreach ($lines as $line) { |
|
14 | + if (trim($line)) |
|
15 | 15 | $result[] = trim($line); |
16 | + } |
|
16 | 17 | |
17 | 18 | return trim(join("\n", $result)); |
18 | 19 | } |
@@ -38,21 +39,26 @@ discard block |
||
38 | 39 | } |
39 | 40 | |
40 | 41 | function current_filter() { |
41 | - if (is_callable('current_filter')) |
|
42 | - return current_filter(); |
|
42 | + if (is_callable('current_filter')) { |
|
43 | + return current_filter(); |
|
44 | + } |
|
43 | 45 | global $wp_actions; |
44 | 46 | return end($wp_actions); |
45 | 47 | } |
46 | 48 | |
47 | 49 | function action($arg) { |
48 | -if ($this->debug) dmp(__FUNCTION__, $this->current_filter()); |
|
50 | +if ($this->debug) { |
|
51 | + dmp(__FUNCTION__, $this->current_filter()); |
|
52 | +} |
|
49 | 53 | $args = func_get_args(); |
50 | 54 | $this->events[] = array('action' => __FUNCTION__, 'tag'=>$this->current_filter(), 'args'=>$args); |
51 | 55 | return $arg; |
52 | 56 | } |
53 | 57 | |
54 | 58 | function action2($arg) { |
55 | -if ($this->debug) dmp(__FUNCTION__, $this->current_filter()); |
|
59 | +if ($this->debug) { |
|
60 | + dmp(__FUNCTION__, $this->current_filter()); |
|
61 | +} |
|
56 | 62 | |
57 | 63 | $args = func_get_args(); |
58 | 64 | $this->events[] = array('action' => __FUNCTION__, 'tag'=>$this->current_filter(), 'args'=>$args); |
@@ -60,7 +66,9 @@ discard block |
||
60 | 66 | } |
61 | 67 | |
62 | 68 | function filter($arg) { |
63 | -if ($this->debug) dmp(__FUNCTION__, $this->current_filter()); |
|
69 | +if ($this->debug) { |
|
70 | + dmp(__FUNCTION__, $this->current_filter()); |
|
71 | +} |
|
64 | 72 | |
65 | 73 | $args = func_get_args(); |
66 | 74 | $this->events[] = array('filter' => __FUNCTION__, 'tag'=>$this->current_filter(), 'args'=>$args); |
@@ -68,7 +76,9 @@ discard block |
||
68 | 76 | } |
69 | 77 | |
70 | 78 | function filter2($arg) { |
71 | -if ($this->debug) dmp(__FUNCTION__, $this->current_filter()); |
|
79 | +if ($this->debug) { |
|
80 | + dmp(__FUNCTION__, $this->current_filter()); |
|
81 | +} |
|
72 | 82 | |
73 | 83 | $args = func_get_args(); |
74 | 84 | $this->events[] = array('filter' => __FUNCTION__, 'tag'=>$this->current_filter(), 'args'=>$args); |
@@ -76,7 +86,9 @@ discard block |
||
76 | 86 | } |
77 | 87 | |
78 | 88 | function filter_append($arg) { |
79 | -if ($this->debug) dmp(__FUNCTION__, $this->current_filter()); |
|
89 | +if ($this->debug) { |
|
90 | + dmp(__FUNCTION__, $this->current_filter()); |
|
91 | +} |
|
80 | 92 | |
81 | 93 | $args = func_get_args(); |
82 | 94 | $this->events[] = array('filter' => __FUNCTION__, 'tag'=>$this->current_filter(), 'args'=>$args); |
@@ -85,7 +97,9 @@ discard block |
||
85 | 97 | |
86 | 98 | function filterall($tag, $arg=NULL) { |
87 | 99 | // this one doesn't return the result, so it's safe to use with the new 'all' filter |
88 | -if ($this->debug) dmp(__FUNCTION__, $this->current_filter()); |
|
100 | +if ($this->debug) { |
|
101 | + dmp(__FUNCTION__, $this->current_filter()); |
|
102 | +} |
|
89 | 103 | |
90 | 104 | $args = func_get_args(); |
91 | 105 | $this->events[] = array('filter' => __FUNCTION__, 'tag'=>$tag, 'args'=>array_slice($args, 1)); |
@@ -100,9 +114,10 @@ discard block |
||
100 | 114 | function get_call_count($tag='') { |
101 | 115 | if ($tag) { |
102 | 116 | $count = 0; |
103 | - foreach ($this->events as $e) |
|
104 | - if ($e['action'] == $tag) |
|
117 | + foreach ($this->events as $e) { |
|
118 | + if ($e['action'] == $tag) |
|
105 | 119 | ++$count; |
120 | + } |
|
106 | 121 | return $count; |
107 | 122 | } |
108 | 123 | return count($this->events); |
@@ -120,8 +135,9 @@ discard block |
||
120 | 135 | // return an array of args passed in calls to this action |
121 | 136 | function get_args() { |
122 | 137 | $out = array(); |
123 | - foreach ($this->events as $e) |
|
124 | - $out[] = $e['args']; |
|
138 | + foreach ($this->events as $e) { |
|
139 | + $out[] = $e['args']; |
|
140 | + } |
|
125 | 141 | return $out; |
126 | 142 | } |
127 | 143 | } |
@@ -186,17 +202,18 @@ discard block |
||
186 | 202 | $n = count($a); |
187 | 203 | $out = array(); |
188 | 204 | |
189 | - if ($n < 1) |
|
190 | - return $out; |
|
205 | + if ($n < 1) { |
|
206 | + return $out; |
|
207 | + } |
|
191 | 208 | |
192 | 209 | for ($i=0; $i<count($tree); $i++) { |
193 | 210 | # echo "checking '{$tree[$i][name]}' == '{$a[0]}'\n"; |
194 | 211 | # var_dump($tree[$i]['name'], $a[0]); |
195 | 212 | if ($tree[$i]['name'] == $a[0]) { |
196 | 213 | # echo "n == {$n}\n"; |
197 | - if ($n == 1) |
|
198 | - $out[] = $tree[$i]; |
|
199 | - else { |
|
214 | + if ($n == 1) { |
|
215 | + $out[] = $tree[$i]; |
|
216 | + } else { |
|
200 | 217 | $subtree =& $tree[$i]['child']; |
201 | 218 | $call_args = array($subtree); |
202 | 219 | $call_args = array_merge($call_args, array_slice($a, 1)); |
@@ -210,8 +227,9 @@ discard block |
||
210 | 227 | |
211 | 228 | function xml_join_atts($atts) { |
212 | 229 | $a = array(); |
213 | - foreach ($atts as $k=>$v) |
|
214 | - $a[] = $k.'="'.$v.'"'; |
|
230 | + foreach ($atts as $k=>$v) { |
|
231 | + $a[] = $k.'="'.$v.'"'; |
|
232 | + } |
|
215 | 233 | return join(' ', $a); |
216 | 234 | } |
217 | 235 | |
@@ -220,14 +238,15 @@ discard block |
||
220 | 238 | |
221 | 239 | foreach (array_keys($data) as $i) { |
222 | 240 | $name = $data[$i]['name']; |
223 | - if (!empty($data[$i]['attributes'])) |
|
224 | - $name .= ' '.xml_join_atts($data[$i]['attributes']); |
|
241 | + if (!empty($data[$i]['attributes'])) { |
|
242 | + $name .= ' '.xml_join_atts($data[$i]['attributes']); |
|
243 | + } |
|
225 | 244 | |
226 | 245 | if (!empty($data[$i]['child'])) { |
227 | 246 | $out[$name][] = xml_array_dumbdown($data[$i]['child']); |
247 | + } else { |
|
248 | + $out[$name] = $data[$i]['content']; |
|
228 | 249 | } |
229 | - else |
|
230 | - $out[$name] = $data[$i]['content']; |
|
231 | 250 | } |
232 | 251 | |
233 | 252 | return $out; |
@@ -236,9 +255,10 @@ discard block |
||
236 | 255 | function dmp() { |
237 | 256 | $args = func_get_args(); |
238 | 257 | |
239 | - foreach ($args as $thing) |
|
240 | - echo (is_scalar($thing) ? strval($thing) : var_export($thing, true)), "\n"; |
|
241 | -} |
|
258 | + foreach ($args as $thing) { |
|
259 | + echo (is_scalar($thing) ? strval($thing) : var_export($thing, true)), "\n"; |
|
260 | + } |
|
261 | + } |
|
242 | 262 | |
243 | 263 | function dmp_filter($a) { |
244 | 264 | dmp($a); |
@@ -255,18 +275,17 @@ discard block |
||
255 | 275 | function gen_tests_array($name, $array) { |
256 | 276 | $out = array(); |
257 | 277 | foreach ($array as $k=>$v) { |
258 | - if (is_numeric($k)) |
|
259 | - $index = strval($k); |
|
260 | - else |
|
261 | - $index = "'".addcslashes($k, "\n\r\t'\\")."'"; |
|
278 | + if (is_numeric($k)) { |
|
279 | + $index = strval($k); |
|
280 | + } else { |
|
281 | + $index = "'".addcslashes($k, "\n\r\t'\\")."'"; |
|
282 | + } |
|
262 | 283 | |
263 | 284 | if (is_string($v)) { |
264 | 285 | $out[] = '$this->assertEquals( \'' . addcslashes($v, "\n\r\t'\\") . '\', $'.$name.'['.$index.'] );'; |
265 | - } |
|
266 | - elseif (is_numeric($v)) { |
|
286 | + } elseif (is_numeric($v)) { |
|
267 | 287 | $out[] = '$this->assertEquals( ' . $v . ', $'.$name.'['.$index.'] );'; |
268 | - } |
|
269 | - elseif (is_array($v)) { |
|
288 | + } elseif (is_array($v)) { |
|
270 | 289 | $out[] = gen_tests_array("{$name}[{$index}]", $v); |
271 | 290 | } |
272 | 291 | } |
@@ -284,9 +303,10 @@ discard block |
||
284 | 303 | function drop_tables() { |
285 | 304 | global $wpdb; |
286 | 305 | $tables = $wpdb->get_col('SHOW TABLES;'); |
287 | - foreach ($tables as $table) |
|
288 | - $wpdb->query("DROP TABLE IF EXISTS {$table}"); |
|
289 | -} |
|
306 | + foreach ($tables as $table) { |
|
307 | + $wpdb->query("DROP TABLE IF EXISTS {$table}"); |
|
308 | + } |
|
309 | + } |
|
290 | 310 | |
291 | 311 | function print_backtrace() { |
292 | 312 | $bt = debug_backtrace(); |
@@ -294,10 +314,12 @@ discard block |
||
294 | 314 | $i = 0; |
295 | 315 | foreach ($bt as $stack) { |
296 | 316 | echo ++$i, ": "; |
297 | - if ( isset($stack['class']) ) |
|
298 | - echo $stack['class'].'::'; |
|
299 | - if ( isset($stack['function']) ) |
|
300 | - echo $stack['function'].'() '; |
|
317 | + if ( isset($stack['class']) ) { |
|
318 | + echo $stack['class'].'::'; |
|
319 | + } |
|
320 | + if ( isset($stack['function']) ) { |
|
321 | + echo $stack['function'].'() '; |
|
322 | + } |
|
301 | 323 | echo "line {$stack[line]} in {$stack[file]}\n"; |
302 | 324 | } |
303 | 325 | echo "\n"; |
@@ -350,20 +372,24 @@ discard block |
||
350 | 372 | |
351 | 373 | function _cleanup_query_vars() { |
352 | 374 | // clean out globals to stop them polluting wp and wp_query |
353 | - foreach ( $GLOBALS['wp']->public_query_vars as $v ) |
|
354 | - unset( $GLOBALS[$v] ); |
|
375 | + foreach ( $GLOBALS['wp']->public_query_vars as $v ) { |
|
376 | + unset( $GLOBALS[$v] ); |
|
377 | + } |
|
355 | 378 | |
356 | - foreach ( $GLOBALS['wp']->private_query_vars as $v ) |
|
357 | - unset( $GLOBALS[$v] ); |
|
379 | + foreach ( $GLOBALS['wp']->private_query_vars as $v ) { |
|
380 | + unset( $GLOBALS[$v] ); |
|
381 | + } |
|
358 | 382 | |
359 | 383 | foreach ( get_taxonomies( array() , 'objects' ) as $t ) { |
360 | - if ( $t->public && ! empty( $t->query_var ) ) |
|
361 | - $GLOBALS['wp']->add_query_var( $t->query_var ); |
|
384 | + if ( $t->public && ! empty( $t->query_var ) ) { |
|
385 | + $GLOBALS['wp']->add_query_var( $t->query_var ); |
|
386 | + } |
|
362 | 387 | } |
363 | 388 | |
364 | 389 | foreach ( get_post_types( array() , 'objects' ) as $t ) { |
365 | - if ( is_post_type_viewable( $t ) && ! empty( $t->query_var ) ) |
|
366 | - $GLOBALS['wp']->add_query_var( $t->query_var ); |
|
390 | + if ( is_post_type_viewable( $t ) && ! empty( $t->query_var ) ) { |
|
391 | + $GLOBALS['wp']->add_query_var( $t->query_var ); |
|
392 | + } |
|
367 | 393 | } |
368 | 394 | } |
369 | 395 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | // misc help functions and utilities |
4 | 4 | |
5 | -function rand_str($len=32) { |
|
5 | +function rand_str($len = 32) { |
|
6 | 6 | return substr(md5(uniqid(rand())), 0, $len); |
7 | 7 | } |
8 | 8 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * PHP5 constructor. |
30 | 30 | */ |
31 | - function __construct( $debug = 0 ) { |
|
31 | + function __construct($debug = 0) { |
|
32 | 32 | $this->reset(); |
33 | 33 | $this->debug = $debug; |
34 | 34 | } |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | |
81 | 81 | $args = func_get_args(); |
82 | 82 | $this->events[] = array('filter' => __FUNCTION__, 'tag'=>$this->current_filter(), 'args'=>$args); |
83 | - return $arg . '_append'; |
|
83 | + return $arg.'_append'; |
|
84 | 84 | } |
85 | 85 | |
86 | - function filterall($tag, $arg=NULL) { |
|
86 | + function filterall($tag, $arg = NULL) { |
|
87 | 87 | // this one doesn't return the result, so it's safe to use with the new 'all' filter |
88 | 88 | if ($this->debug) dmp(__FUNCTION__, $this->current_filter()); |
89 | 89 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | // return a count of the number of times the action was called since the last reset |
100 | - function get_call_count($tag='') { |
|
100 | + function get_call_count($tag = '') { |
|
101 | 101 | if ($tag) { |
102 | 102 | $count = 0; |
103 | 103 | foreach ($this->events as $e) |
@@ -135,10 +135,10 @@ discard block |
||
135 | 135 | /** |
136 | 136 | * PHP5 constructor. |
137 | 137 | */ |
138 | - function __construct( $in ) { |
|
138 | + function __construct($in) { |
|
139 | 139 | $this->xml = xml_parser_create(); |
140 | 140 | xml_set_object($this->xml, $this); |
141 | - xml_parser_set_option($this->xml,XML_OPTION_CASE_FOLDING, 0); |
|
141 | + xml_parser_set_option($this->xml, XML_OPTION_CASE_FOLDING, 0); |
|
142 | 142 | xml_set_element_handler($this->xml, array($this, 'startHandler'), array($this, 'endHandler')); |
143 | 143 | xml_set_character_data_handler($this->xml, array($this, 'dataHandler')); |
144 | 144 | $this->parse($in); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | if ($n < 1) |
190 | 190 | return $out; |
191 | 191 | |
192 | - for ($i=0; $i<count($tree); $i++) { |
|
192 | + for ($i = 0; $i < count($tree); $i++) { |
|
193 | 193 | # echo "checking '{$tree[$i][name]}' == '{$a[0]}'\n"; |
194 | 194 | # var_dump($tree[$i]['name'], $a[0]); |
195 | 195 | if ($tree[$i]['name'] == $a[0]) { |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | if ($n == 1) |
198 | 198 | $out[] = $tree[$i]; |
199 | 199 | else { |
200 | - $subtree =& $tree[$i]['child']; |
|
200 | + $subtree = & $tree[$i]['child']; |
|
201 | 201 | $call_args = array($subtree); |
202 | 202 | $call_args = array_merge($call_args, array_slice($a, 1)); |
203 | 203 | $out = array_merge($out, call_user_func_array('xml_find', $call_args)); |
@@ -261,10 +261,10 @@ discard block |
||
261 | 261 | $index = "'".addcslashes($k, "\n\r\t'\\")."'"; |
262 | 262 | |
263 | 263 | if (is_string($v)) { |
264 | - $out[] = '$this->assertEquals( \'' . addcslashes($v, "\n\r\t'\\") . '\', $'.$name.'['.$index.'] );'; |
|
264 | + $out[] = '$this->assertEquals( \''.addcslashes($v, "\n\r\t'\\").'\', $'.$name.'['.$index.'] );'; |
|
265 | 265 | } |
266 | 266 | elseif (is_numeric($v)) { |
267 | - $out[] = '$this->assertEquals( ' . $v . ', $'.$name.'['.$index.'] );'; |
|
267 | + $out[] = '$this->assertEquals( '.$v.', $'.$name.'['.$index.'] );'; |
|
268 | 268 | } |
269 | 269 | elseif (is_array($v)) { |
270 | 270 | $out[] = gen_tests_array("{$name}[{$index}]", $v); |
@@ -294,9 +294,9 @@ discard block |
||
294 | 294 | $i = 0; |
295 | 295 | foreach ($bt as $stack) { |
296 | 296 | echo ++$i, ": "; |
297 | - if ( isset($stack['class']) ) |
|
297 | + if (isset($stack['class'])) |
|
298 | 298 | echo $stack['class'].'::'; |
299 | - if ( isset($stack['function']) ) |
|
299 | + if (isset($stack['function'])) |
|
300 | 300 | echo $stack['function'].'() '; |
301 | 301 | echo "line {$stack[line]} in {$stack[file]}\n"; |
302 | 302 | } |
@@ -304,17 +304,17 @@ discard block |
||
304 | 304 | } |
305 | 305 | |
306 | 306 | // mask out any input fields matching the given name |
307 | -function mask_input_value($in, $name='_wpnonce') { |
|
307 | +function mask_input_value($in, $name = '_wpnonce') { |
|
308 | 308 | return preg_replace('@<input([^>]*) name="'.preg_quote($name).'"([^>]*) value="[^>]*" />@', '<input$1 name="'.preg_quote($name).'"$2 value="***" />', $in); |
309 | 309 | } |
310 | 310 | |
311 | -if ( !function_exists( 'str_getcsv' ) ) { |
|
312 | - function str_getcsv( $input, $delimiter = ',', $enclosure = '"', $escape = "\\" ) { |
|
313 | - $fp = fopen( 'php://temp/', 'r+' ); |
|
314 | - fputs( $fp, $input ); |
|
315 | - rewind( $fp ); |
|
316 | - $data = fgetcsv( $fp, strlen( $input ), $delimiter, $enclosure ); |
|
317 | - fclose( $fp ); |
|
311 | +if (!function_exists('str_getcsv')) { |
|
312 | + function str_getcsv($input, $delimiter = ',', $enclosure = '"', $escape = "\\") { |
|
313 | + $fp = fopen('php://temp/', 'r+'); |
|
314 | + fputs($fp, $input); |
|
315 | + rewind($fp); |
|
316 | + $data = fgetcsv($fp, strlen($input), $delimiter, $enclosure); |
|
317 | + fclose($fp); |
|
318 | 318 | return $data; |
319 | 319 | } |
320 | 320 | } |
@@ -322,19 +322,19 @@ discard block |
||
322 | 322 | /** |
323 | 323 | * Removes the post type and its taxonomy associations. |
324 | 324 | */ |
325 | -function _unregister_post_type( $cpt_name ) { |
|
326 | - unset( $GLOBALS['wp_post_types'][ $cpt_name ] ); |
|
327 | - unset( $GLOBALS['_wp_post_type_features'][ $cpt_name ] ); |
|
325 | +function _unregister_post_type($cpt_name) { |
|
326 | + unset($GLOBALS['wp_post_types'][$cpt_name]); |
|
327 | + unset($GLOBALS['_wp_post_type_features'][$cpt_name]); |
|
328 | 328 | |
329 | - foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy ) { |
|
330 | - if ( false !== $key = array_search( $cpt_name, $taxonomy->object_type ) ) { |
|
331 | - unset( $taxonomy->object_type[$key] ); |
|
329 | + foreach ($GLOBALS['wp_taxonomies'] as $taxonomy) { |
|
330 | + if (false !== $key = array_search($cpt_name, $taxonomy->object_type)) { |
|
331 | + unset($taxonomy->object_type[$key]); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | } |
335 | 335 | |
336 | -function _unregister_taxonomy( $taxonomy_name ) { |
|
337 | - unset( $GLOBALS['wp_taxonomies'][$taxonomy_name] ); |
|
336 | +function _unregister_taxonomy($taxonomy_name) { |
|
337 | + unset($GLOBALS['wp_taxonomies'][$taxonomy_name]); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
@@ -344,32 +344,32 @@ discard block |
||
344 | 344 | * |
345 | 345 | * @param string $status |
346 | 346 | */ |
347 | -function _unregister_post_status( $status ) { |
|
348 | - unset( $GLOBALS['wp_post_statuses'][ $status ] ); |
|
347 | +function _unregister_post_status($status) { |
|
348 | + unset($GLOBALS['wp_post_statuses'][$status]); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | function _cleanup_query_vars() { |
352 | 352 | // clean out globals to stop them polluting wp and wp_query |
353 | - foreach ( $GLOBALS['wp']->public_query_vars as $v ) |
|
354 | - unset( $GLOBALS[$v] ); |
|
353 | + foreach ($GLOBALS['wp']->public_query_vars as $v) |
|
354 | + unset($GLOBALS[$v]); |
|
355 | 355 | |
356 | - foreach ( $GLOBALS['wp']->private_query_vars as $v ) |
|
357 | - unset( $GLOBALS[$v] ); |
|
356 | + foreach ($GLOBALS['wp']->private_query_vars as $v) |
|
357 | + unset($GLOBALS[$v]); |
|
358 | 358 | |
359 | - foreach ( get_taxonomies( array() , 'objects' ) as $t ) { |
|
360 | - if ( $t->public && ! empty( $t->query_var ) ) |
|
361 | - $GLOBALS['wp']->add_query_var( $t->query_var ); |
|
359 | + foreach (get_taxonomies(array(), 'objects') as $t) { |
|
360 | + if ($t->public && !empty($t->query_var)) |
|
361 | + $GLOBALS['wp']->add_query_var($t->query_var); |
|
362 | 362 | } |
363 | 363 | |
364 | - foreach ( get_post_types( array() , 'objects' ) as $t ) { |
|
365 | - if ( is_post_type_viewable( $t ) && ! empty( $t->query_var ) ) |
|
366 | - $GLOBALS['wp']->add_query_var( $t->query_var ); |
|
364 | + foreach (get_post_types(array(), 'objects') as $t) { |
|
365 | + if (is_post_type_viewable($t) && !empty($t->query_var)) |
|
366 | + $GLOBALS['wp']->add_query_var($t->query_var); |
|
367 | 367 | } |
368 | 368 | } |
369 | 369 | |
370 | 370 | function _clean_term_filters() { |
371 | - remove_filter( 'get_terms', array( 'Featured_Content', 'hide_featured_term' ), 10, 2 ); |
|
372 | - remove_filter( 'get_the_terms', array( 'Featured_Content', 'hide_the_featured_term' ), 10, 3 ); |
|
371 | + remove_filter('get_terms', array('Featured_Content', 'hide_featured_term'), 10, 2); |
|
372 | + remove_filter('get_the_terms', array('Featured_Content', 'hide_the_featured_term'), 10, 3); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -386,8 +386,8 @@ discard block |
||
386 | 386 | $this->charset = $wpdb->charset; |
387 | 387 | } |
388 | 388 | |
389 | - public function __call( $name, $arguments ) { |
|
390 | - return call_user_func_array( array( $this, $name ), $arguments ); |
|
389 | + public function __call($name, $arguments) { |
|
390 | + return call_user_func_array(array($this, $name), $arguments); |
|
391 | 391 | } |
392 | 392 | } |
393 | 393 | |
@@ -396,37 +396,37 @@ discard block |
||
396 | 396 | * |
397 | 397 | * @return int The backtrack count. |
398 | 398 | */ |
399 | -function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) { |
|
400 | - $saved_config = ini_get( 'pcre.backtrack_limit' ); |
|
399 | +function benchmark_pcre_backtracking($pattern, $subject, $strategy) { |
|
400 | + $saved_config = ini_get('pcre.backtrack_limit'); |
|
401 | 401 | |
402 | 402 | // Attempt to prevent PHP crashes. Adjust these lower when needed. |
403 | - if ( version_compare( phpversion(), '5.4.8', '>' ) ) { |
|
403 | + if (version_compare(phpversion(), '5.4.8', '>')) { |
|
404 | 404 | $limit = 1000000; |
405 | 405 | } else { |
406 | - $limit = 20000; // 20,000 is a reasonable upper limit, but see also https://core.trac.wordpress.org/ticket/29557#comment:10 |
|
406 | + $limit = 20000; // 20,000 is a reasonable upper limit, but see also https://core.trac.wordpress.org/ticket/29557#comment:10 |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | // Start with small numbers, so if a crash is encountered at higher numbers we can still debug the problem. |
410 | - for( $i = 4; $i <= $limit; $i *= 2 ) { |
|
410 | + for ($i = 4; $i <= $limit; $i *= 2) { |
|
411 | 411 | |
412 | - ini_set( 'pcre.backtrack_limit', $i ); |
|
412 | + ini_set('pcre.backtrack_limit', $i); |
|
413 | 413 | |
414 | - switch( $strategy ) { |
|
414 | + switch ($strategy) { |
|
415 | 415 | case 'split': |
416 | - preg_split( $pattern, $subject ); |
|
416 | + preg_split($pattern, $subject); |
|
417 | 417 | break; |
418 | 418 | case 'match': |
419 | - preg_match( $pattern, $subject ); |
|
419 | + preg_match($pattern, $subject); |
|
420 | 420 | break; |
421 | 421 | case 'match_all': |
422 | 422 | $matches = array(); |
423 | - preg_match_all( $pattern, $subject, $matches ); |
|
423 | + preg_match_all($pattern, $subject, $matches); |
|
424 | 424 | break; |
425 | 425 | } |
426 | 426 | |
427 | - ini_set( 'pcre.backtrack_limit', $saved_config ); |
|
427 | + ini_set('pcre.backtrack_limit', $saved_config); |
|
428 | 428 | |
429 | - switch( preg_last_error() ) { |
|
429 | + switch (preg_last_error()) { |
|
430 | 430 | case PREG_NO_ERROR: |
431 | 431 | return $i; |
432 | 432 | case PREG_BACKTRACK_LIMIT_ERROR: |
@@ -119,8 +119,9 @@ discard block |
||
119 | 119 | public function logout() { |
120 | 120 | unset( $GLOBALS['current_user'] ); |
121 | 121 | $cookies = array(AUTH_COOKIE, SECURE_AUTH_COOKIE, LOGGED_IN_COOKIE, USER_COOKIE, PASS_COOKIE); |
122 | - foreach ( $cookies as $c ) |
|
123 | - unset( $_COOKIE[$c] ); |
|
122 | + foreach ( $cookies as $c ) { |
|
123 | + unset( $_COOKIE[$c] ); |
|
124 | + } |
|
124 | 125 | } |
125 | 126 | |
126 | 127 | /** |
@@ -195,7 +196,8 @@ discard block |
||
195 | 196 | |
196 | 197 | // Save the output |
197 | 198 | $buffer = ob_get_clean(); |
198 | - if ( !empty( $buffer ) ) |
|
199 | - $this->_last_response = $buffer; |
|
199 | + if ( !empty( $buffer ) ) { |
|
200 | + $this->_last_response = $buffer; |
|
201 | + } |
|
200 | 202 | } |
201 | 203 | } |
@@ -57,18 +57,18 @@ discard block |
||
57 | 57 | ); |
58 | 58 | |
59 | 59 | public static function setUpBeforeClass() { |
60 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
61 | - define( 'DOING_AJAX', true ); |
|
60 | + if (!defined('DOING_AJAX')) { |
|
61 | + define('DOING_AJAX', true); |
|
62 | 62 | } |
63 | 63 | |
64 | - remove_action( 'admin_init', '_maybe_update_core' ); |
|
65 | - remove_action( 'admin_init', '_maybe_update_plugins' ); |
|
66 | - remove_action( 'admin_init', '_maybe_update_themes' ); |
|
64 | + remove_action('admin_init', '_maybe_update_core'); |
|
65 | + remove_action('admin_init', '_maybe_update_plugins'); |
|
66 | + remove_action('admin_init', '_maybe_update_themes'); |
|
67 | 67 | |
68 | 68 | // Register the core actions |
69 | - foreach ( array_merge( self::$_core_actions_get, self::$_core_actions_post ) as $action ) { |
|
70 | - if ( function_exists( 'wp_ajax_' . str_replace( '-', '_', $action ) ) ) { |
|
71 | - add_action( 'wp_ajax_' . $action, 'wp_ajax_' . str_replace( '-', '_', $action ), 1 ); |
|
69 | + foreach (array_merge(self::$_core_actions_get, self::$_core_actions_post) as $action) { |
|
70 | + if (function_exists('wp_ajax_'.str_replace('-', '_', $action))) { |
|
71 | + add_action('wp_ajax_'.$action, 'wp_ajax_'.str_replace('-', '_', $action), 1); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
@@ -82,19 +82,19 @@ discard block |
||
82 | 82 | public function setUp() { |
83 | 83 | parent::setUp(); |
84 | 84 | |
85 | - add_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 ); |
|
85 | + add_filter('wp_die_ajax_handler', array($this, 'getDieHandler'), 1, 1); |
|
86 | 86 | |
87 | - set_current_screen( 'ajax' ); |
|
87 | + set_current_screen('ajax'); |
|
88 | 88 | |
89 | 89 | // Clear logout cookies |
90 | - add_action( 'clear_auth_cookie', array( $this, 'logout' ) ); |
|
90 | + add_action('clear_auth_cookie', array($this, 'logout')); |
|
91 | 91 | |
92 | 92 | // Suppress warnings from "Cannot modify header information - headers already sent by" |
93 | 93 | $this->_error_level = error_reporting(); |
94 | - error_reporting( $this->_error_level & ~E_WARNING ); |
|
94 | + error_reporting($this->_error_level & ~E_WARNING); |
|
95 | 95 | |
96 | 96 | // Make some posts |
97 | - self::factory()->post->create_many( 5 ); |
|
97 | + self::factory()->post->create_many(5); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -105,22 +105,22 @@ discard block |
||
105 | 105 | parent::tearDown(); |
106 | 106 | $_POST = array(); |
107 | 107 | $_GET = array(); |
108 | - unset( $GLOBALS['post'] ); |
|
109 | - unset( $GLOBALS['comment'] ); |
|
110 | - remove_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 ); |
|
111 | - remove_action( 'clear_auth_cookie', array( $this, 'logout' ) ); |
|
112 | - error_reporting( $this->_error_level ); |
|
113 | - set_current_screen( 'front' ); |
|
108 | + unset($GLOBALS['post']); |
|
109 | + unset($GLOBALS['comment']); |
|
110 | + remove_filter('wp_die_ajax_handler', array($this, 'getDieHandler'), 1, 1); |
|
111 | + remove_action('clear_auth_cookie', array($this, 'logout')); |
|
112 | + error_reporting($this->_error_level); |
|
113 | + set_current_screen('front'); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
117 | 117 | * Clear login cookies, unset the current user |
118 | 118 | */ |
119 | 119 | public function logout() { |
120 | - unset( $GLOBALS['current_user'] ); |
|
120 | + unset($GLOBALS['current_user']); |
|
121 | 121 | $cookies = array(AUTH_COOKIE, SECURE_AUTH_COOKIE, LOGGED_IN_COOKIE, USER_COOKIE, PASS_COOKIE); |
122 | - foreach ( $cookies as $c ) |
|
123 | - unset( $_COOKIE[$c] ); |
|
122 | + foreach ($cookies as $c) |
|
123 | + unset($_COOKIE[$c]); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return callback |
129 | 129 | */ |
130 | 130 | public function getDieHandler() { |
131 | - return array( $this, 'dieHandler' ); |
|
131 | + return array($this, 'dieHandler'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -146,17 +146,17 @@ discard block |
||
146 | 146 | * </code> |
147 | 147 | * @param string $message |
148 | 148 | */ |
149 | - public function dieHandler( $message ) { |
|
149 | + public function dieHandler($message) { |
|
150 | 150 | $this->_last_response .= ob_get_clean(); |
151 | 151 | |
152 | - if ( '' === $this->_last_response ) { |
|
153 | - if ( is_scalar( $message ) ) { |
|
154 | - throw new WPAjaxDieStopException( (string) $message ); |
|
152 | + if ('' === $this->_last_response) { |
|
153 | + if (is_scalar($message)) { |
|
154 | + throw new WPAjaxDieStopException((string) $message); |
|
155 | 155 | } else { |
156 | - throw new WPAjaxDieStopException( '0' ); |
|
156 | + throw new WPAjaxDieStopException('0'); |
|
157 | 157 | } |
158 | 158 | } else { |
159 | - throw new WPAjaxDieContinueException( $message ); |
|
159 | + throw new WPAjaxDieContinueException($message); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | * E.g. administrator, editor, author, contributor, subscriber |
166 | 166 | * @param string $role |
167 | 167 | */ |
168 | - protected function _setRole( $role ) { |
|
168 | + protected function _setRole($role) { |
|
169 | 169 | $post = $_POST; |
170 | - $user_id = self::factory()->user->create( array( 'role' => $role ) ); |
|
171 | - wp_set_current_user( $user_id ); |
|
170 | + $user_id = self::factory()->user->create(array('role' => $role)); |
|
171 | + wp_set_current_user($user_id); |
|
172 | 172 | $_POST = array_merge($_POST, $post); |
173 | 173 | } |
174 | 174 | |
@@ -181,21 +181,21 @@ discard block |
||
181 | 181 | protected function _handleAjax($action) { |
182 | 182 | |
183 | 183 | // Start output buffering |
184 | - ini_set( 'implicit_flush', false ); |
|
184 | + ini_set('implicit_flush', false); |
|
185 | 185 | ob_start(); |
186 | 186 | |
187 | 187 | // Build the request |
188 | 188 | $_POST['action'] = $action; |
189 | 189 | $_GET['action'] = $action; |
190 | - $_REQUEST = array_merge( $_POST, $_GET ); |
|
190 | + $_REQUEST = array_merge($_POST, $_GET); |
|
191 | 191 | |
192 | 192 | // Call the hooks |
193 | - do_action( 'admin_init' ); |
|
194 | - do_action( 'wp_ajax_' . $_REQUEST['action'], null ); |
|
193 | + do_action('admin_init'); |
|
194 | + do_action('wp_ajax_'.$_REQUEST['action'], null); |
|
195 | 195 | |
196 | 196 | // Save the output |
197 | 197 | $buffer = ob_get_clean(); |
198 | - if ( !empty( $buffer ) ) |
|
198 | + if (!empty($buffer)) |
|
199 | 199 | $this->_last_response = $buffer; |
200 | 200 | } |
201 | 201 | } |