Make WordPress Core

Changeset 33253


Ignore:
Timestamp:
07/14/2015 05:49:28 AM (9 years ago)
Author:
jeremyfelt
Message:

Tests: Move update_blog_details() tests to their own file.

Reduce some of the clutter in tests/multisite/site.php and introduce tests/multisite/updateBlogDetails.php. Tests moved over are verbatum at this point.

See #32988.

Location:
trunk/tests/phpunit/tests/multisite
Files:
1 added
1 edited

Legend:

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

    r32512 r33253  
    318318
    319319    /**
    320      * If `update_blog_details()` is called with any kind of empty arguments, it
    321      * should return false.
    322      */
    323     function test_update_blog_details_with_empty_args() {
    324         $result = update_blog_details( 1, array() );
    325         $this->assertFalse( $result );
    326     }
    327 
    328     /**
    329      * If the ID passed is not that of a current site, we should expect false.
    330      */
    331     function test_update_blog_details_invalid_blog_id() {
    332         $result = update_blog_details( 999, array( 'domain' => 'example.com' ) );
    333         $this->assertFalse( $result );
    334     }
    335 
    336     function test_update_blog_details() {
    337         $blog_id = $this->factory->blog->create();
    338 
    339         $result = update_blog_details( $blog_id, array( 'domain' => 'example.com', 'path' => 'my_path/' ) );
    340 
    341         $this->assertTrue( $result );
    342 
    343         $blog = get_blog_details( $blog_id );
    344 
    345         $this->assertEquals( 'example.com', $blog->domain );
    346         $this->assertEquals( '/my_path/', $blog->path );
    347         $this->assertEquals( '0', $blog->spam );
    348     }
    349 
    350     function test_update_blog_details_make_ham_blog_action() {
    351         global $test_action_counter;
    352         $test_action_counter = 0;
    353 
    354         $blog_id = $this->factory->blog->create();
    355         update_blog_details( $blog_id, array( 'spam' => 1 ) );
    356 
    357         add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 );
    358         update_blog_details( $blog_id, array( 'spam' => 0 ) );
    359         $blog = get_blog_details( $blog_id );
    360 
    361         $this->assertEquals( '0', $blog->spam );
    362         $this->assertEquals( 1, $test_action_counter );
    363 
    364         // The action should not fire if the status of 'spam' stays the same.
    365         update_blog_details( $blog_id, array( 'spam' => 0 ) );
    366         $blog = get_blog_details( $blog_id );
    367 
    368         $this->assertEquals( '0', $blog->spam );
    369         $this->assertEquals( 1, $test_action_counter );
    370 
    371         remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 );
    372     }
    373 
    374     function test_update_blog_details_make_spam_blog_action() {
    375         global $test_action_counter;
    376         $test_action_counter = 0;
    377 
    378         $blog_id = $this->factory->blog->create();
    379 
    380         add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 );
    381         update_blog_details( $blog_id, array( 'spam' => 1 ) );
    382         $blog = get_blog_details( $blog_id );
    383 
    384         $this->assertEquals( '1', $blog->spam );
    385         $this->assertEquals( 1, $test_action_counter );
    386 
    387         // The action should not fire if the status of 'spam' stays the same.
    388         update_blog_details( $blog_id, array( 'spam' => 1 ) );
    389         $blog = get_blog_details( $blog_id );
    390 
    391         $this->assertEquals( '1', $blog->spam );
    392         $this->assertEquals( 1, $test_action_counter );
    393 
    394         remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 );
    395     }
    396 
    397     function test_update_blog_details_archive_blog_action() {
    398         global $test_action_counter;
    399         $test_action_counter = 0;
    400 
    401         $blog_id = $this->factory->blog->create();
    402 
    403         add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 );
    404         update_blog_details( $blog_id, array( 'archived' => 1 ) );
    405         $blog = get_blog_details( $blog_id );
    406 
    407         $this->assertEquals( '1', $blog->archived );
    408         $this->assertEquals( 1, $test_action_counter );
    409 
    410         // The action should not fire if the status of 'archived' stays the same.
    411         update_blog_details( $blog_id, array( 'archived' => 1 ) );
    412         $blog = get_blog_details( $blog_id );
    413 
    414         $this->assertEquals( '1', $blog->archived );
    415         $this->assertEquals( 1, $test_action_counter );
    416 
    417         remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 );
    418     }
    419 
    420     function test_update_blog_details_unarchive_blog_action() {
    421         global $test_action_counter;
    422         $test_action_counter = 0;
    423 
    424         $blog_id = $this->factory->blog->create();
    425         update_blog_details( $blog_id, array( 'archived' => 1 ) );
    426 
    427         add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 );
    428         update_blog_details( $blog_id, array( 'archived' => 0 ) );
    429         $blog = get_blog_details( $blog_id );
    430 
    431         $this->assertEquals( '0', $blog->archived );
    432         $this->assertEquals( 1, $test_action_counter );
    433 
    434         // The action should not fire if the status of 'archived' stays the same.
    435         update_blog_details( $blog_id, array( 'archived' => 0 ) );
    436         $blog = get_blog_details( $blog_id );
    437         $this->assertEquals( '0', $blog->archived );
    438         $this->assertEquals( 1, $test_action_counter );
    439 
    440         remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 );
    441     }
    442 
    443     function test_update_blog_details_make_delete_blog_action() {
    444         global $test_action_counter;
    445         $test_action_counter = 0;
    446 
    447         $blog_id = $this->factory->blog->create();
    448 
    449         add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 );
    450         update_blog_details( $blog_id, array( 'deleted' => 1 ) );
    451         $blog = get_blog_details( $blog_id );
    452 
    453         $this->assertEquals( '1', $blog->deleted );
    454         $this->assertEquals( 1, $test_action_counter );
    455 
    456         // The action should not fire if the status of 'deleted' stays the same.
    457         update_blog_details( $blog_id, array( 'deleted' => 1 ) );
    458         $blog = get_blog_details( $blog_id );
    459 
    460         $this->assertEquals( '1', $blog->deleted );
    461         $this->assertEquals( 1, $test_action_counter );
    462 
    463         remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 );
    464     }
    465 
    466     function test_update_blog_details_make_undelete_blog_action() {
    467         global $test_action_counter;
    468         $test_action_counter = 0;
    469 
    470         $blog_id = $this->factory->blog->create();
    471         update_blog_details( $blog_id, array( 'deleted' => 1 ) );
    472 
    473         add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 );
    474         update_blog_details( $blog_id, array( 'deleted' => 0 ) );
    475         $blog = get_blog_details( $blog_id );
    476 
    477         $this->assertEquals( '0', $blog->deleted );
    478         $this->assertEquals( 1, $test_action_counter );
    479 
    480         // The action should not fire if the status of 'deleted' stays the same.
    481         update_blog_details( $blog_id, array( 'deleted' => 0 ) );
    482         $blog = get_blog_details( $blog_id );
    483 
    484         $this->assertEquals( '0', $blog->deleted );
    485         $this->assertEquals( 1, $test_action_counter );
    486 
    487         remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 );
    488     }
    489 
    490     function test_update_blog_details_mature_blog_action() {
    491         global $test_action_counter;
    492         $test_action_counter = 0;
    493 
    494         $blog_id = $this->factory->blog->create();
    495 
    496         add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 );
    497         update_blog_details( $blog_id, array( 'mature' => 1 ) );
    498         $blog = get_blog_details( $blog_id );
    499 
    500         $this->assertEquals( '1', $blog->mature );
    501         $this->assertEquals( 1, $test_action_counter );
    502 
    503         // The action should not fire if the status of 'mature' stays the same.
    504         update_blog_details( $blog_id, array( 'mature' => 1 ) );
    505         $blog = get_blog_details( $blog_id );
    506 
    507         $this->assertEquals( '1', $blog->mature );
    508         $this->assertEquals( 1, $test_action_counter );
    509 
    510         remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 );
    511     }
    512 
    513     function test_update_blog_details_unmature_blog_action() {
    514         global $test_action_counter;
    515         $test_action_counter = 0;
    516 
    517         $blog_id = $this->factory->blog->create();
    518         update_blog_details( $blog_id, array( 'mature' => 1 ) );
    519 
    520         add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 );
    521         update_blog_details( $blog_id, array( 'mature' => 0 ) );
    522 
    523         $blog = get_blog_details( $blog_id );
    524         $this->assertEquals( '0', $blog->mature );
    525         $this->assertEquals( 1, $test_action_counter );
    526 
    527         // The action should not fire if the status of 'mature' stays the same.
    528         update_blog_details( $blog_id, array( 'mature' => 0 ) );
    529         $blog = get_blog_details( $blog_id );
    530 
    531         $this->assertEquals( '0', $blog->mature );
    532         $this->assertEquals( 1, $test_action_counter );
    533 
    534         remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 );
    535     }
    536 
    537     /**
    538320     * Provide a counter to determine that hooks are firing when intended.
    539321     */
     
    541323        global $test_action_counter;
    542324        $test_action_counter++;
    543     }
    544 
    545     /**
    546      * When the path for a site is updated with update_blog_details(), the final
    547      * path should have a leading and trailing slash. When multiple directories
    548      * are part of the path, only one slash should separate each directory.
    549      *
    550      * @ticket 18117
    551      */
    552     function test_update_blog_details_single_path_no_slashes() {
    553         update_blog_details( 1, array( 'path' => 'my_path' ) );
    554         $blog = get_blog_details( 1 );
    555         $this->assertEquals( '/my_path/', $blog->path );
    556     }
    557 
    558     function test_update_blog_details_single_path_double_trailing_slashes() {
    559         update_blog_details( 1, array( 'path' => 'my_path//' ) );
    560         $blog = get_blog_details( 1 );
    561         $this->assertEquals( '/my_path/', $blog->path );
    562     }
    563 
    564     function test_update_blog_details_single_path_double_leading_slashes() {
    565         update_blog_details( 1, array( 'path' => '//my_path' ) );
    566         $blog = get_blog_details( 1 );
    567         $this->assertEquals( '/my_path/', $blog->path );
    568     }
    569 
    570     function test_update_blog_details_single_path_single_trailing_slash() {
    571         update_blog_details( 1, array( 'path' => 'my_path/' ) );
    572         $blog = get_blog_details( 1 );
    573         $this->assertEquals( '/my_path/', $blog->path );
    574     }
    575 
    576     function test_update_blog_details_single_path_single_leading_slashes() {
    577         update_blog_details( 1, array( 'path' => '/my_path' ) );
    578         $blog = get_blog_details( 1 );
    579         $this->assertEquals( '/my_path/', $blog->path );
    580     }
    581 
    582     function test_update_blog_details_single_path_both_slashes() {
    583         update_blog_details( 1, array( 'path' => '/my_path/' ) );
    584         $blog = get_blog_details( 1 );
    585         $this->assertEquals( '/my_path/', $blog->path );
    586     }
    587 
    588     function test_update_blog_details_multiple_paths_no_slashes() {
    589         update_blog_details( 1, array( 'path' => 'multiple/dirs' ) );
    590         $blog = get_blog_details( 1 );
    591         $this->assertEquals( '/multiple/dirs/', $blog->path );
    592     }
    593 
    594     /**
    595      * `update_blog_details()` does not resolve multiple slashes in the
    596      * middle of a path string.
    597      */
    598     function test_update_blog_details_multiple_paths_middle_slashes() {
    599         update_blog_details( 1, array( 'path' => 'multiple///dirs' ) );
    600         $blog = get_blog_details( 1 );
    601         $this->assertEquals( '/multiple///dirs/', $blog->path );
    602     }
    603 
    604     function test_update_blog_details_multiple_paths_leading_slash() {
    605         update_blog_details( 1, array( 'path' => '/multiple/dirs' ) );
    606         $blog = get_blog_details( 1 );
    607         $this->assertEquals( '/multiple/dirs/', $blog->path );
    608     }
    609 
    610     function test_update_blog_details_multiple_paths_trailing_slash() {
    611         update_blog_details( 1, array( 'path' => 'multiple/dirs/' ) );
    612         $blog = get_blog_details( 1 );
    613         $this->assertEquals( '/multiple/dirs/', $blog->path );
    614     }
    615 
    616     function test_update_blog_details_multiple_paths_both_slashes() {
    617         update_blog_details( 1, array( 'path' => '/multiple/dirs/' ) );
    618         $blog = get_blog_details( 1 );
    619         $this->assertEquals( '/multiple/dirs/', $blog->path );
    620325    }
    621326
Note: See TracChangeset for help on using the changeset viewer.