Make WordPress Core

Changeset 1089 in tests


Ignore:
Timestamp:
10/24/2012 01:49:01 PM (14 years ago)
Author:
SergeyBiryukov
Message:

Remove closure from ms.php. see [1078]. see #101.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/ms.php

    r1082 r1089  
    371371        }
    372372
     373        function _action_counter_cb( $blog_id ) {
     374                global $test_action_counter;
     375                $test_action_counter++;
     376        }
     377
    373378        function test_update_blog_details() {
    374                 global $current_site;
     379                global $current_site, $test_action_counter;
    375380
    376381                $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
    … …  
    400405                $this->assertEquals( '1', $blog->spam );
    401406
    402                 global $test_action_counter;
    403407                $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 );
     408
     409                add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    410410                $result = update_blog_details( $blog_id, array( 'spam' => 0 ) );
    411411                $this->assertTrue( $result );
    … …  
    420420                $this->assertEquals( '0', $blog->spam );
    421421                $this->assertEquals( 1, $test_action_counter );
    422                 remove_action( 'make_ham_blog', $callback, 10, 1 );
     422                remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    423423               
    424                 add_action( 'make_spam_blog', $callback, 10, 1 );
     424                add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    425425                $result = update_blog_details( $blog_id, array( 'spam' => 1 ) );
    426426                $this->assertTrue( $result );
    … …  
    435435                $this->assertEquals( '1', $blog->spam );
    436436                $this->assertEquals( 2, $test_action_counter );
    437                 remove_action( 'make_spam_blog', $callback, 10, 1 );
    438 
    439                 add_action( 'archive_blog', $callback, 10, 1 );
     437                remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 );
     438
     439                add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    440440                $result = update_blog_details( $blog_id, array( 'archived' => 1 ) );
    441441                $this->assertTrue( $result );
    … …  
    450450                $this->assertEquals( '1', $blog->archived );
    451451                $this->assertEquals( 3, $test_action_counter );
    452                 remove_action( 'archive_blog', $callback, 10, 1 );
    453 
    454                 add_action( 'unarchive_blog', $callback, 10, 1 );
     452                remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 );
     453
     454                add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    455455                $result = update_blog_details( $blog_id, array( 'archived' => 0 ) );
    456456                $this->assertTrue( $result );
    … …  
    465465                $this->assertEquals( '0', $blog->archived );
    466466                $this->assertEquals( 4, $test_action_counter );
    467                 remove_action( 'unarchive_blog', $callback, 10, 1 );
    468 
    469                 add_action( 'make_delete_blog', $callback, 10, 1 );
     467                remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 );
     468
     469                add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    470470                $result = update_blog_details( $blog_id, array( 'deleted' => 1 ) );
    471471                $this->assertTrue( $result );
    … …  
    480480                $this->assertEquals( '1', $blog->deleted );
    481481                $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 );
     482                remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
     483
     484                add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    485485                $result = update_blog_details( $blog_id, array( 'deleted' => 0 ) );
    486486                $this->assertTrue( $result );
    … …  
    495495                $this->assertEquals( '0', $blog->deleted );
    496496                $this->assertEquals( 6, $test_action_counter );
    497                 remove_action( 'make_undelete_blog', $callback, 10, 1 );
    498 
    499                 add_action( 'mature_blog', $callback, 10, 1 );
     497                remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
     498
     499                add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    500500                $result = update_blog_details( $blog_id, array( 'mature' => 1 ) );
    501501                $this->assertTrue( $result );
    … …  
    510510                $this->assertEquals( '1', $blog->mature );
    511511                $this->assertEquals( 7, $test_action_counter );
    512                 remove_action( 'mature_blog', $callback, 10, 1 );
    513 
    514                 add_action( 'unmature_blog', $callback, 10, 1 );
     512                remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
     513
     514                add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    515515                $result = update_blog_details( $blog_id, array( 'mature' => 0 ) );
    516516                $this->assertTrue( $result );
    … …  
    525525                $this->assertEquals( '0', $blog->mature );
    526526                $this->assertEquals( 8, $test_action_counter );
    527                 remove_action( 'unmature_blog', $callback, 10, 1 );
     527                remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    528528        }
    529529
    530530        function test_update_blog_status() {
     531                global $test_action_counter;
     532
    531533                $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
    532534                $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogpath', 'title' => 'Test Title' ) );
    533535                $this->assertInternalType( 'int', $blog_id );
    534536
    535                 global $test_action_counter;
    536537                $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 );
     538
     539                add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    543540                $result = update_blog_status( $blog_id, 'spam', 0 );
    544541                $this->assertEquals( 0, $result );
    … …  
    553550                $this->assertEquals( '0', $blog->spam );
    554551                $this->assertEquals( 2, $test_action_counter );
    555                 remove_action( 'make_ham_blog', $callback, 10, 1 );
     552                remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    556553               
    557                 add_action( 'make_spam_blog', $callback, 10, 1 );
     554                add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    558555                $result = update_blog_status( $blog_id, 'spam', 1 );
    559556                $this->assertEquals( 1, $result );
    … …  
    568565                $this->assertEquals( '1', $blog->spam );
    569566                $this->assertEquals( 4, $test_action_counter );
    570                 remove_action( 'make_spam_blog', $callback, 10, 1 );
    571 
    572                 add_action( 'archive_blog', $callback, 10, 1 );
     567                remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 );
     568
     569                add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    573570                $result = update_blog_status( $blog_id, 'archived', 1 );
    574571                $this->assertEquals( 1, $result );
    … …  
    583580                $this->assertEquals( '1', $blog->archived );
    584581                $this->assertEquals( 6, $test_action_counter );
    585                 remove_action( 'archive_blog', $callback, 10, 1 );
    586 
    587                 add_action( 'unarchive_blog', $callback, 10, 1 );
     582                remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 );
     583
     584                add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    588585                $result = update_blog_status( $blog_id, 'archived', 0 );
    589586                $this->assertEquals( 0, $result );
    … …  
    598595                $this->assertEquals( '0', $blog->archived );
    599596                $this->assertEquals( 8, $test_action_counter );
    600                 remove_action( 'unarchive_blog', $callback, 10, 1 );
    601 
    602                 add_action( 'make_delete_blog', $callback, 10, 1 );
     597                remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 );
     598
     599                add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    603600                $result = update_blog_status( $blog_id, 'deleted', 1 );
    604601                $this->assertEquals( 1, $result );
    … …  
    613610                $this->assertEquals( '1', $blog->deleted );
    614611                $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 );
     612                remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
     613
     614                add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    618615                $result = update_blog_status( $blog_id, 'deleted', 0 );
    619616                $this->assertEquals( 0, $result );
    … …  
    628625                $this->assertEquals( '0', $blog->deleted );
    629626                $this->assertEquals( 12, $test_action_counter );
    630                 remove_action( 'make_undelete_blog', $callback, 10, 1 );
    631 
    632                 add_action( 'mature_blog', $callback, 10, 1 );
     627                remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
     628
     629                add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    633630                $result = update_blog_status( $blog_id, 'mature', 1 );
    634631                $this->assertEquals( 1, $result );
    … …  
    643640                $this->assertEquals( '1', $blog->mature );
    644641                $this->assertEquals( 14, $test_action_counter );
    645                 remove_action( 'mature_blog', $callback, 10, 1 );
    646 
    647                 add_action( 'unmature_blog', $callback, 10, 1 );
     642                remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
     643
     644                add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    648645                $result = update_blog_status( $blog_id, 'mature', 0 );
    649646                $this->assertEquals( 0, $result );
    … …  
    658655                $this->assertEquals( '0', $blog->mature );
    659656                $this->assertEquals( 16, $test_action_counter );
    660                 remove_action( 'unmature_blog', $callback, 10, 1 );
     657                remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
    661658
    662659                // Updating a dummy field returns the value passed. Go fig.
Note: See TracChangeset for help on using the changeset viewer.