Make WordPress Core

Changeset 53806


Ignore:
Timestamp:
07/31/2022 04:41:53 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Move the test for actions using closures to the general action tests file.

This was previously moved to a separate file to be excluded when running the tests on PHP 5.2.x.

Now that WordPress supports PHP 5.6.x or later, this can be moved back with the other action tests.

Follow-up to [299/tests], [301/tests], [862/tests], [866/tests], [963/tests].

See #55652.

Location:
trunk/tests/phpunit/tests
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/actions.php

    r53805 r53806  
    352352                $args = $a->get_args();
    353353                $this->assertSame( $args[1][0], $context2 );
    354 
     354        }
     355
     356        /**
     357         * @ticket 10493
     358         *
     359         * @covers ::add_action
     360         * @covers ::has_action
     361         * @covers ::do_action
     362         */
     363        public function test_action_closure() {
     364                $hook_name = 'test_action_closure';
     365                $closure   = static function( $a, $b ) {
     366                        $GLOBALS[ $a ] = $b;
     367                };
     368                add_action( $hook_name, $closure, 10, 2 );
     369
     370                $this->assertSame( 10, has_action( $hook_name, $closure ) );
     371
     372                $context = array( 'val1', 'val2' );
     373                do_action( $hook_name, $context[0], $context[1] );
     374
     375                $this->assertSame( $GLOBALS[ $context[0] ], $context[1] );
     376
     377                $hook_name2 = 'test_action_closure_2';
     378                $closure2   = static function() {
     379                        $GLOBALS['closure_no_args'] = true;
     380                };
     381                add_action( $hook_name2, $closure2 );
     382
     383                $this->assertSame( 10, has_action( $hook_name2, $closure2 ) );
     384
     385                do_action( $hook_name2 );
     386
     387                $this->assertTrue( $GLOBALS['closure_no_args'] );
     388
     389                remove_action( $hook_name, $closure );
     390                remove_action( $hook_name2, $closure2 );
    355391        }
    356392
Note: See TracChangeset for help on using the changeset viewer.