Make WordPress Core

Changeset 33255


Ignore:
Timestamp:
07/14/2015 06:38:19 AM (9 years ago)
Author:
jeremyfelt
Message:

Tests: Use a data provider when testing site flags in update_blog_details().

See #32988.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/updateBlogDetails.php

    r33254 r33255  
    3939    }
    4040
    41     function test_update_blog_details_make_ham_blog_action() {
    42         global $test_action_counter;
    43         $test_action_counter = 0;
    44 
    45         $blog_id = $this->factory->blog->create();
    46         update_blog_details( $blog_id, array( 'spam' => 1 ) );
    47 
    48         add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 );
    49         update_blog_details( $blog_id, array( 'spam' => 0 ) );
    50         $blog = get_blog_details( $blog_id );
    51 
    52         $this->assertEquals( '0', $blog->spam );
    53         $this->assertEquals( 1, $test_action_counter );
    54 
    55         // The action should not fire if the status of 'spam' stays the same.
    56         update_blog_details( $blog_id, array( 'spam' => 0 ) );
    57         $blog = get_blog_details( $blog_id );
    58 
    59         $this->assertEquals( '0', $blog->spam );
    60         $this->assertEquals( 1, $test_action_counter );
    61 
    62         remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 );
    63     }
    64 
    65     function test_update_blog_details_make_spam_blog_action() {
     41    /**
     42     * Test each of the actions that should fire in update_blog_details() depending on
     43     * the flag and flag value being set. Each action should fire once and should not
     44     * fire if a flag is already set for the given flag value.
     45     *
     46     * @param string $flag       The name of the flag being set or unset on a site.
     47     * @param string $flag_value '0' or '1'. The value of the flag being set.
     48     * @param string $action     The hook expected to fire for the flag name and flag combination.
     49     *
     50     * @dataProvider data_flag_hooks
     51     */
     52    public function test_update_blog_details_flag_action( $flag, $flag_value, $hook ) {
    6653        global $test_action_counter;
    6754        $test_action_counter = 0;
     
    6956        $blog_id = $this->factory->blog->create();
    7057
    71         add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 );
    72         update_blog_details( $blog_id, array( 'spam' => 1 ) );
     58        // Set an initial value of '1' for the flag when '0' is the flag value being tested.
     59        if ( '0' === $flag_value ) {
     60            update_blog_details( $blog_id, array( $flag => '1' ) );
     61        }
     62
     63        add_action( $hook, array( $this, '_action_counter_cb' ), 10 );
     64
     65        update_blog_details( $blog_id, array( $flag => $flag_value ) );
    7366        $blog = get_blog_details( $blog_id );
    7467
    75         $this->assertEquals( '1', $blog->spam );
     68        $this->assertEquals( $flag_value, $blog->{$flag} );
     69
     70        // The hook attached to this flag should have fired once during update_blog_details().
    7671        $this->assertEquals( 1, $test_action_counter );
    7772
    78         // The action should not fire if the status of 'spam' stays the same.
    79         update_blog_details( $blog_id, array( 'spam' => 1 ) );
    80         $blog = get_blog_details( $blog_id );
     73        // Update the site to the exact same flag value for this flag.
     74        update_blog_details( $blog_id, array( $flag => $flag_value ) );
    8175
    82         $this->assertEquals( '1', $blog->spam );
     76        // The hook attached to this flag should not have fired again.
    8377        $this->assertEquals( 1, $test_action_counter );
    8478
    85         remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 );
     79        remove_action( $hook, array( $this, '_action_counter_cb' ), 10 );
    8680    }
    8781
    88     function test_update_blog_details_archive_blog_action() {
    89         global $test_action_counter;
    90         $test_action_counter = 0;
    91 
    92         $blog_id = $this->factory->blog->create();
    93 
    94         add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 );
    95         update_blog_details( $blog_id, array( 'archived' => 1 ) );
    96         $blog = get_blog_details( $blog_id );
    97 
    98         $this->assertEquals( '1', $blog->archived );
    99         $this->assertEquals( 1, $test_action_counter );
    100 
    101         // The action should not fire if the status of 'archived' stays the same.
    102         update_blog_details( $blog_id, array( 'archived' => 1 ) );
    103         $blog = get_blog_details( $blog_id );
    104 
    105         $this->assertEquals( '1', $blog->archived );
    106         $this->assertEquals( 1, $test_action_counter );
    107 
    108         remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 );
    109     }
    110 
    111     function test_update_blog_details_unarchive_blog_action() {
    112         global $test_action_counter;
    113         $test_action_counter = 0;
    114 
    115         $blog_id = $this->factory->blog->create();
    116         update_blog_details( $blog_id, array( 'archived' => 1 ) );
    117 
    118         add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 );
    119         update_blog_details( $blog_id, array( 'archived' => 0 ) );
    120         $blog = get_blog_details( $blog_id );
    121 
    122         $this->assertEquals( '0', $blog->archived );
    123         $this->assertEquals( 1, $test_action_counter );
    124 
    125         // The action should not fire if the status of 'archived' stays the same.
    126         update_blog_details( $blog_id, array( 'archived' => 0 ) );
    127         $blog = get_blog_details( $blog_id );
    128         $this->assertEquals( '0', $blog->archived );
    129         $this->assertEquals( 1, $test_action_counter );
    130 
    131         remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 );
    132     }
    133 
    134     function test_update_blog_details_make_delete_blog_action() {
    135         global $test_action_counter;
    136         $test_action_counter = 0;
    137 
    138         $blog_id = $this->factory->blog->create();
    139 
    140         add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 );
    141         update_blog_details( $blog_id, array( 'deleted' => 1 ) );
    142         $blog = get_blog_details( $blog_id );
    143 
    144         $this->assertEquals( '1', $blog->deleted );
    145         $this->assertEquals( 1, $test_action_counter );
    146 
    147         // The action should not fire if the status of 'deleted' stays the same.
    148         update_blog_details( $blog_id, array( 'deleted' => 1 ) );
    149         $blog = get_blog_details( $blog_id );
    150 
    151         $this->assertEquals( '1', $blog->deleted );
    152         $this->assertEquals( 1, $test_action_counter );
    153 
    154         remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 );
    155     }
    156 
    157     function test_update_blog_details_make_undelete_blog_action() {
    158         global $test_action_counter;
    159         $test_action_counter = 0;
    160 
    161         $blog_id = $this->factory->blog->create();
    162         update_blog_details( $blog_id, array( 'deleted' => 1 ) );
    163 
    164         add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 );
    165         update_blog_details( $blog_id, array( 'deleted' => 0 ) );
    166         $blog = get_blog_details( $blog_id );
    167 
    168         $this->assertEquals( '0', $blog->deleted );
    169         $this->assertEquals( 1, $test_action_counter );
    170 
    171         // The action should not fire if the status of 'deleted' stays the same.
    172         update_blog_details( $blog_id, array( 'deleted' => 0 ) );
    173         $blog = get_blog_details( $blog_id );
    174 
    175         $this->assertEquals( '0', $blog->deleted );
    176         $this->assertEquals( 1, $test_action_counter );
    177 
    178         remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 );
    179     }
    180 
    181     function test_update_blog_details_mature_blog_action() {
    182         global $test_action_counter;
    183         $test_action_counter = 0;
    184 
    185         $blog_id = $this->factory->blog->create();
    186 
    187         add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 );
    188         update_blog_details( $blog_id, array( 'mature' => 1 ) );
    189         $blog = get_blog_details( $blog_id );
    190 
    191         $this->assertEquals( '1', $blog->mature );
    192         $this->assertEquals( 1, $test_action_counter );
    193 
    194         // The action should not fire if the status of 'mature' stays the same.
    195         update_blog_details( $blog_id, array( 'mature' => 1 ) );
    196         $blog = get_blog_details( $blog_id );
    197 
    198         $this->assertEquals( '1', $blog->mature );
    199         $this->assertEquals( 1, $test_action_counter );
    200 
    201         remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 );
    202     }
    203 
    204     function test_update_blog_details_unmature_blog_action() {
    205         global $test_action_counter;
    206         $test_action_counter = 0;
    207 
    208         $blog_id = $this->factory->blog->create();
    209         update_blog_details( $blog_id, array( 'mature' => 1 ) );
    210 
    211         add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 );
    212         update_blog_details( $blog_id, array( 'mature' => 0 ) );
    213 
    214         $blog = get_blog_details( $blog_id );
    215         $this->assertEquals( '0', $blog->mature );
    216         $this->assertEquals( 1, $test_action_counter );
    217 
    218         // The action should not fire if the status of 'mature' stays the same.
    219         update_blog_details( $blog_id, array( 'mature' => 0 ) );
    220         $blog = get_blog_details( $blog_id );
    221 
    222         $this->assertEquals( '0', $blog->mature );
    223         $this->assertEquals( 1, $test_action_counter );
    224 
    225         remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 );
     82    public function data_flag_hooks() {
     83        return array(
     84            array( 'spam',     '0', 'make_ham_blog' ),
     85            array( 'spam',     '1', 'make_spam_blog' ),
     86            array( 'archived', '1', 'archive_blog' ),
     87            array( 'archived', '0', 'unarchive_blog' ),
     88            array( 'deleted',  '1', 'make_delete_blog' ),
     89            array( 'deleted',  '0', 'make_undelete_blog' ),
     90            array( 'mature',   '1', 'mature_blog' ),
     91            array( 'mature',   '0', 'unmature_blog' ),
     92        );
    22693    }
    22794
Note: See TracChangeset for help on using the changeset viewer.