WordPress.org

Make WordPress Core

Changeset 1078 in tests


Ignore:
Timestamp:
10/11/12 12:38:26 (19 months ago)
Author:
ryan
Message:

Tests for update_blog_details() and update_blog_status(). see #WP20305

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/ms.php

    r1074 r1078  
    399399        $this->assertEquals( 'my_path/', $blog->path ); 
    400400        $this->assertEquals( '1', $blog->spam ); 
    401         $this->assertFalse( $result ); 
     401 
     402        global $test_action_counter; 
     403        $test_action_counter = 0; 
     404        $callback = function( $blog_id ) { 
     405            global $test_action_counter; 
     406            $test_action_counter++; 
     407        }; 
     408 
     409        add_action( 'make_ham_blog', $callback, 10, 1 ); 
     410        $result = update_blog_details( $blog_id, array( 'spam' => 0 ) ); 
     411        $this->assertTrue( $result ); 
     412        $blog = get_blog_details( $blog_id ); 
     413        $this->assertEquals( '0', $blog->spam ); 
     414        $this->assertEquals( 1, $test_action_counter ); 
     415 
     416        // Same again 
     417        $result = update_blog_details( $blog_id, array( 'spam' => 0 ) ); 
     418        $this->assertTrue( $result ); 
     419        $blog = get_blog_details( $blog_id ); 
     420        $this->assertEquals( '0', $blog->spam ); 
     421        $this->assertEquals( 1, $test_action_counter ); 
     422        remove_action( 'make_ham_blog', $callback, 10, 1 ); 
     423         
     424        add_action( 'make_spam_blog', $callback, 10, 1 ); 
     425        $result = update_blog_details( $blog_id, array( 'spam' => 1 ) ); 
     426        $this->assertTrue( $result ); 
     427        $blog = get_blog_details( $blog_id ); 
     428        $this->assertEquals( '1', $blog->spam ); 
     429        $this->assertEquals( 2, $test_action_counter ); 
     430 
     431        // Same again 
     432        $result = update_blog_details( $blog_id, array( 'spam' => 1 ) ); 
     433        $this->assertTrue( $result ); 
     434        $blog = get_blog_details( $blog_id ); 
     435        $this->assertEquals( '1', $blog->spam ); 
     436        $this->assertEquals( 2, $test_action_counter ); 
     437        remove_action( 'make_spam_blog', $callback, 10, 1 ); 
     438 
     439        add_action( 'archive_blog', $callback, 10, 1 ); 
     440        $result = update_blog_details( $blog_id, array( 'archived' => 1 ) ); 
     441        $this->assertTrue( $result ); 
     442        $blog = get_blog_details( $blog_id ); 
     443        $this->assertEquals( '1', $blog->archived ); 
     444        $this->assertEquals( 3, $test_action_counter ); 
     445 
     446        // Same again 
     447        $result = update_blog_details( $blog_id, array( 'archived' => 1 ) ); 
     448        $this->assertTrue( $result ); 
     449        $blog = get_blog_details( $blog_id ); 
     450        $this->assertEquals( '1', $blog->archived ); 
     451        $this->assertEquals( 3, $test_action_counter ); 
     452        remove_action( 'archive_blog', $callback, 10, 1 ); 
     453 
     454        add_action( 'unarchive_blog', $callback, 10, 1 ); 
     455        $result = update_blog_details( $blog_id, array( 'archived' => 0 ) ); 
     456        $this->assertTrue( $result ); 
     457        $blog = get_blog_details( $blog_id ); 
     458        $this->assertEquals( '0', $blog->archived ); 
     459        $this->assertEquals( 4, $test_action_counter ); 
     460 
     461        // Same again 
     462        $result = update_blog_details( $blog_id, array( 'archived' => 0 ) ); 
     463        $this->assertTrue( $result ); 
     464        $blog = get_blog_details( $blog_id ); 
     465        $this->assertEquals( '0', $blog->archived ); 
     466        $this->assertEquals( 4, $test_action_counter ); 
     467        remove_action( 'unarchive_blog', $callback, 10, 1 ); 
     468 
     469        add_action( 'make_delete_blog', $callback, 10, 1 ); 
     470        $result = update_blog_details( $blog_id, array( 'deleted' => 1 ) ); 
     471        $this->assertTrue( $result ); 
     472        $blog = get_blog_details( $blog_id ); 
     473        $this->assertEquals( '1', $blog->deleted ); 
     474        $this->assertEquals( 5, $test_action_counter ); 
     475 
     476        // Same again 
     477        $result = update_blog_details( $blog_id, array( 'deleted' => 1 ) ); 
     478        $this->assertTrue( $result ); 
     479        $blog = get_blog_details( $blog_id ); 
     480        $this->assertEquals( '1', $blog->deleted ); 
     481        $this->assertEquals( 5, $test_action_counter ); 
     482        remove_action( 'make_delete_blog', $callback, 10, 1 ); 
     483 
     484        add_action( 'make_undelete_blog', $callback, 10, 1 ); 
     485        $result = update_blog_details( $blog_id, array( 'deleted' => 0 ) ); 
     486        $this->assertTrue( $result ); 
     487        $blog = get_blog_details( $blog_id ); 
     488        $this->assertEquals( '0', $blog->deleted ); 
     489        $this->assertEquals( 6, $test_action_counter ); 
     490 
     491        // Same again 
     492        $result = update_blog_details( $blog_id, array( 'deleted' => 0 ) ); 
     493        $this->assertTrue( $result ); 
     494        $blog = get_blog_details( $blog_id ); 
     495        $this->assertEquals( '0', $blog->deleted ); 
     496        $this->assertEquals( 6, $test_action_counter ); 
     497        remove_action( 'make_undelete_blog', $callback, 10, 1 ); 
     498 
     499        add_action( 'mature_blog', $callback, 10, 1 ); 
     500        $result = update_blog_details( $blog_id, array( 'mature' => 1 ) ); 
     501        $this->assertTrue( $result ); 
     502        $blog = get_blog_details( $blog_id ); 
     503        $this->assertEquals( '1', $blog->mature ); 
     504        $this->assertEquals( 7, $test_action_counter ); 
     505 
     506        // Same again 
     507        $result = update_blog_details( $blog_id, array( 'mature' => 1 ) ); 
     508        $this->assertTrue( $result ); 
     509        $blog = get_blog_details( $blog_id ); 
     510        $this->assertEquals( '1', $blog->mature ); 
     511        $this->assertEquals( 7, $test_action_counter ); 
     512        remove_action( 'mature_blog', $callback, 10, 1 ); 
     513 
     514        add_action( 'unmature_blog', $callback, 10, 1 ); 
     515        $result = update_blog_details( $blog_id, array( 'mature' => 0 ) ); 
     516        $this->assertTrue( $result ); 
     517        $blog = get_blog_details( $blog_id ); 
     518        $this->assertEquals( '0', $blog->mature ); 
     519        $this->assertEquals( 8, $test_action_counter ); 
     520 
     521        // Same again 
     522        $result = update_blog_details( $blog_id, array( 'mature' => 0 ) ); 
     523        $this->assertTrue( $result ); 
     524        $blog = get_blog_details( $blog_id ); 
     525        $this->assertEquals( '0', $blog->mature ); 
     526        $this->assertEquals( 8, $test_action_counter ); 
     527        remove_action( 'unmature_blog', $callback, 10, 1 ); 
     528    } 
     529 
     530    function test_update_blog_status() { 
     531        $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); 
     532        $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogpath', 'title' => 'Test Title' ) ); 
     533        $this->assertInternalType( 'int', $blog_id ); 
     534 
     535        global $test_action_counter; 
     536        $test_action_counter = 0; 
     537        $callback = function( $blog_id ) { 
     538            global $test_action_counter; 
     539            $test_action_counter++; 
     540        }; 
     541 
     542        add_action( 'make_ham_blog', $callback, 10, 1 ); 
     543        $result = update_blog_status( $blog_id, 'spam', 0 ); 
     544        $this->assertEquals( 0, $result ); 
     545        $blog = get_blog_details( $blog_id ); 
     546        $this->assertEquals( '0', $blog->spam ); 
     547        $this->assertEquals( 1, $test_action_counter ); 
     548 
     549        // Same again 
     550        $result = update_blog_status( $blog_id, 'spam', 0 ); 
     551        $this->assertEquals( 0, $result ); 
     552        $blog = get_blog_details( $blog_id ); 
     553        $this->assertEquals( '0', $blog->spam ); 
     554        $this->assertEquals( 2, $test_action_counter ); 
     555        remove_action( 'make_ham_blog', $callback, 10, 1 ); 
     556         
     557        add_action( 'make_spam_blog', $callback, 10, 1 ); 
     558        $result = update_blog_status( $blog_id, 'spam', 1 ); 
     559        $this->assertEquals( 1, $result ); 
     560        $blog = get_blog_details( $blog_id ); 
     561        $this->assertEquals( '1', $blog->spam ); 
     562        $this->assertEquals( 3, $test_action_counter ); 
     563 
     564        // Same again 
     565        $result = update_blog_status( $blog_id, 'spam', 1 ); 
     566        $this->assertEquals( 1, $result ); 
     567        $blog = get_blog_details( $blog_id ); 
     568        $this->assertEquals( '1', $blog->spam ); 
     569        $this->assertEquals( 4, $test_action_counter ); 
     570        remove_action( 'make_spam_blog', $callback, 10, 1 ); 
     571 
     572        add_action( 'archive_blog', $callback, 10, 1 ); 
     573        $result = update_blog_status( $blog_id, 'archived', 1 ); 
     574        $this->assertEquals( 1, $result ); 
     575        $blog = get_blog_details( $blog_id ); 
     576        $this->assertEquals( '1', $blog->archived ); 
     577        $this->assertEquals( 5, $test_action_counter ); 
     578 
     579        // Same again 
     580        $result = update_blog_status( $blog_id, 'archived', 1 ); 
     581        $this->assertEquals( 1, $result ); 
     582        $blog = get_blog_details( $blog_id ); 
     583        $this->assertEquals( '1', $blog->archived ); 
     584        $this->assertEquals( 6, $test_action_counter ); 
     585        remove_action( 'archive_blog', $callback, 10, 1 ); 
     586 
     587        add_action( 'unarchive_blog', $callback, 10, 1 ); 
     588        $result = update_blog_status( $blog_id, 'archived', 0 ); 
     589        $this->assertEquals( 0, $result ); 
     590        $blog = get_blog_details( $blog_id ); 
     591        $this->assertEquals( '0', $blog->archived ); 
     592        $this->assertEquals( 7, $test_action_counter ); 
     593 
     594        // Same again 
     595        $result = update_blog_status( $blog_id, 'archived', 0 ); 
     596        $this->assertEquals( 0, $result ); 
     597        $blog = get_blog_details( $blog_id ); 
     598        $this->assertEquals( '0', $blog->archived ); 
     599        $this->assertEquals( 8, $test_action_counter ); 
     600        remove_action( 'unarchive_blog', $callback, 10, 1 ); 
     601 
     602        add_action( 'make_delete_blog', $callback, 10, 1 ); 
     603        $result = update_blog_status( $blog_id, 'deleted', 1 ); 
     604        $this->assertEquals( 1, $result ); 
     605        $blog = get_blog_details( $blog_id ); 
     606        $this->assertEquals( '1', $blog->deleted ); 
     607        $this->assertEquals( 9, $test_action_counter ); 
     608 
     609        // Same again 
     610        $result = update_blog_status( $blog_id, 'deleted', 1 ); 
     611        $this->assertEquals( 1, $result ); 
     612        $blog = get_blog_details( $blog_id ); 
     613        $this->assertEquals( '1', $blog->deleted ); 
     614        $this->assertEquals( 10, $test_action_counter ); 
     615        remove_action( 'make_delete_blog', $callback, 10, 1 ); 
     616 
     617        add_action( 'make_undelete_blog', $callback, 10, 1 ); 
     618        $result = update_blog_status( $blog_id, 'deleted', 0 ); 
     619        $this->assertEquals( 0, $result ); 
     620        $blog = get_blog_details( $blog_id ); 
     621        $this->assertEquals( '0', $blog->deleted ); 
     622        $this->assertEquals( 11, $test_action_counter ); 
     623 
     624        // Same again 
     625        $result = update_blog_status( $blog_id, 'deleted', 0 ); 
     626        $this->assertEquals( 0, $result ); 
     627        $blog = get_blog_details( $blog_id ); 
     628        $this->assertEquals( '0', $blog->deleted ); 
     629        $this->assertEquals( 12, $test_action_counter ); 
     630        remove_action( 'make_undelete_blog', $callback, 10, 1 ); 
     631 
     632        add_action( 'mature_blog', $callback, 10, 1 ); 
     633        $result = update_blog_status( $blog_id, 'mature', 1 ); 
     634        $this->assertEquals( 1, $result ); 
     635        $blog = get_blog_details( $blog_id ); 
     636        $this->assertEquals( '1', $blog->mature ); 
     637        $this->assertEquals( 13, $test_action_counter ); 
     638 
     639        // Same again 
     640        $result = update_blog_status( $blog_id, 'mature', 1 ); 
     641        $this->assertEquals( 1, $result ); 
     642        $blog = get_blog_details( $blog_id ); 
     643        $this->assertEquals( '1', $blog->mature ); 
     644        $this->assertEquals( 14, $test_action_counter ); 
     645        remove_action( 'mature_blog', $callback, 10, 1 ); 
     646 
     647        add_action( 'unmature_blog', $callback, 10, 1 ); 
     648        $result = update_blog_status( $blog_id, 'mature', 0 ); 
     649        $this->assertEquals( 0, $result ); 
     650        $blog = get_blog_details( $blog_id ); 
     651        $this->assertEquals( '0', $blog->mature ); 
     652        $this->assertEquals( 15, $test_action_counter ); 
     653 
     654        // Same again 
     655        $result = update_blog_status( $blog_id, 'mature', 0 ); 
     656        $this->assertEquals( 0, $result ); 
     657        $blog = get_blog_details( $blog_id ); 
     658        $this->assertEquals( '0', $blog->mature ); 
     659        $this->assertEquals( 16, $test_action_counter ); 
     660        remove_action( 'unmature_blog', $callback, 10, 1 ); 
     661 
     662        // Updating a dummy field returns the value passed. Go fig. 
     663        $result = update_blog_status( $blog_id, 'doesnotexist', 1 ); 
     664        $this->assertEquals( 1, $result ); 
    402665    } 
    403666 
Note: See TracChangeset for help on using the changeset viewer.