Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/hooks/addFilter.php

    r42200 r42343  
    1212
    1313    public function test_add_filter_with_function() {
    14         $callback = '__return_null';
    15         $hook = new WP_Hook();
    16         $tag = __FUNCTION__;
    17         $priority = rand( 1, 100 );
     14        $callback      = '__return_null';
     15        $hook          = new WP_Hook();
     16        $tag           = __FUNCTION__;
     17        $priority      = rand( 1, 100 );
    1818        $accepted_args = rand( 1, 100 );
    1919
     
    2626
    2727    public function test_add_filter_with_object() {
    28         $a = new MockAction();
    29         $callback = array( $a, 'action' );
    30         $hook = new WP_Hook();
    31         $tag = __FUNCTION__;
    32         $priority = rand( 1, 100 );
     28        $a             = new MockAction();
     29        $callback      = array( $a, 'action' );
     30        $hook          = new WP_Hook();
     31        $tag           = __FUNCTION__;
     32        $priority      = rand( 1, 100 );
    3333        $accepted_args = rand( 1, 100 );
    3434
     
    4141
    4242    public function test_add_filter_with_static_method() {
    43         $callback = array( 'MockAction', 'action' );
    44         $hook = new WP_Hook();
    45         $tag = __FUNCTION__;
    46         $priority = rand( 1, 100 );
     43        $callback      = array( 'MockAction', 'action' );
     44        $hook          = new WP_Hook();
     45        $tag           = __FUNCTION__;
     46        $priority      = rand( 1, 100 );
    4747        $accepted_args = rand( 1, 100 );
    4848
     
    5555
    5656    public function test_add_two_filters_with_same_priority() {
    57         $callback_one = '__return_null';
    58         $callback_two = '__return_false';
    59         $hook = new WP_Hook();
    60         $tag = __FUNCTION__;
    61         $priority = rand( 1, 100 );
     57        $callback_one  = '__return_null';
     58        $callback_two  = '__return_false';
     59        $hook          = new WP_Hook();
     60        $tag           = __FUNCTION__;
     61        $priority      = rand( 1, 100 );
    6262        $accepted_args = rand( 1, 100 );
    6363
     
    7070
    7171    public function test_add_two_filters_with_different_priority() {
    72         $callback_one = '__return_null';
    73         $callback_two = '__return_false';
     72        $callback_one  = '__return_null';
     73        $callback_two  = '__return_false';
     74        $hook          = new WP_Hook();
     75        $tag           = __FUNCTION__;
     76        $priority      = rand( 1, 100 );
     77        $accepted_args = rand( 1, 100 );
     78
     79        $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
     80        $this->assertCount( 1, $hook->callbacks[ $priority ] );
     81
     82        $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
     83        $this->assertCount( 1, $hook->callbacks[ $priority ] );
     84        $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
     85    }
     86
     87    public function test_readd_filter() {
     88        $callback      = '__return_null';
     89        $hook          = new WP_Hook();
     90        $tag           = __FUNCTION__;
     91        $priority      = rand( 1, 100 );
     92        $accepted_args = rand( 1, 100 );
     93
     94        $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     95        $this->assertCount( 1, $hook->callbacks[ $priority ] );
     96
     97        $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     98        $this->assertCount( 1, $hook->callbacks[ $priority ] );
     99    }
     100
     101    public function test_readd_filter_with_different_priority() {
     102        $callback      = '__return_null';
     103        $hook          = new WP_Hook();
     104        $tag           = __FUNCTION__;
     105        $priority      = rand( 1, 100 );
     106        $accepted_args = rand( 1, 100 );
     107
     108        $hook->add_filter( $tag, $callback, $priority, $accepted_args );
     109        $this->assertCount( 1, $hook->callbacks[ $priority ] );
     110
     111        $hook->add_filter( $tag, $callback, $priority + 1, $accepted_args );
     112        $this->assertCount( 1, $hook->callbacks[ $priority ] );
     113        $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
     114    }
     115
     116    public function test_sort_after_add_filter() {
     117        $a    = new MockAction();
     118        $b    = new MockAction();
     119        $c    = new MockAction();
    74120        $hook = new WP_Hook();
    75         $tag = __FUNCTION__;
    76         $priority = rand( 1, 100 );
    77         $accepted_args = rand( 1, 100 );
    78 
    79         $hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
    80         $this->assertCount( 1, $hook->callbacks[ $priority ] );
    81 
    82         $hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
    83         $this->assertCount( 1, $hook->callbacks[ $priority ] );
    84         $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
    85     }
    86 
    87     public function test_readd_filter() {
    88         $callback = '__return_null';
    89         $hook = new WP_Hook();
    90         $tag = __FUNCTION__;
    91         $priority = rand( 1, 100 );
    92         $accepted_args = rand( 1, 100 );
    93 
    94         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
    95         $this->assertCount( 1, $hook->callbacks[ $priority ] );
    96 
    97         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
    98         $this->assertCount( 1, $hook->callbacks[ $priority ] );
    99     }
    100 
    101     public function test_readd_filter_with_different_priority() {
    102         $callback = '__return_null';
    103         $hook = new WP_Hook();
    104         $tag = __FUNCTION__;
    105         $priority = rand( 1, 100 );
    106         $accepted_args = rand( 1, 100 );
    107 
    108         $hook->add_filter( $tag, $callback, $priority, $accepted_args );
    109         $this->assertCount( 1, $hook->callbacks[ $priority ] );
    110 
    111         $hook->add_filter( $tag, $callback, $priority + 1, $accepted_args );
    112         $this->assertCount( 1, $hook->callbacks[ $priority ] );
    113         $this->assertCount( 1, $hook->callbacks[ $priority + 1 ] );
    114     }
    115 
    116     public function test_sort_after_add_filter() {
    117         $a = new MockAction();
    118         $b = new MockAction();
    119         $c = new MockAction();
    120         $hook = new WP_Hook();
    121         $tag = __FUNCTION__;
     121        $tag  = __FUNCTION__;
    122122
    123123        $hook->add_filter( $tag, array( $a, 'action' ), 10, 1 );
     
    202202
    203203    public function test_remove_and_add_action() {
    204         $this->hook = new Wp_Hook();
     204        $this->hook          = new Wp_Hook();
    205205        $this->action_output = '';
    206206
     
    217217
    218218    public function test_remove_and_add_last_action() {
    219         $this->hook = new Wp_Hook();
     219        $this->hook          = new Wp_Hook();
    220220        $this->action_output = '';
    221221
     
    232232
    233233    public function test_remove_and_recurse_and_add_action() {
    234         $this->hook = new Wp_Hook();
     234        $this->hook          = new Wp_Hook();
    235235        $this->action_output = '';
    236236
Note: See TracChangeset for help on using the changeset viewer.