Make WordPress Core


Ignore:
Timestamp:
07/10/2021 11:15:44 AM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use more appropriate assertions in various tests.

This replaces instances of assertTrue( isset( ... ) ) with assertArrayHasKey() to use native PHPUnit functionality.

Follow-up to [51335], [51337], [51367].

See #53363.

File:
1 edited

Legend:

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

    r51331 r51397  
    703703        $nodes = $wp_admin_bar->get_nodes();
    704704        foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) {
    705             $this->assertFalse( isset( $nodes[ $id ] ), sprintf( 'Menu item %s must not display for a regular user.', $id ) );
     705            $this->assertArrayNotHasKey( $id, $nodes, sprintf( 'Menu item %s must not display for a regular user.', $id ) );
    706706        }
    707707    }
     
    720720        $nodes = $wp_admin_bar->get_nodes();
    721721        foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) {
    722             $this->assertTrue( isset( $nodes[ $id ] ), sprintf( 'Menu item %s must display for a super admin.', $id ) );
     722            $this->assertArrayHasKey( $id, $nodes, sprintf( 'Menu item %s must display for a super admin.', $id ) );
    723723        }
    724724    }
     
    746746        foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) {
    747747            if ( in_array( $cap, $network_user_caps, true ) ) {
    748                 $this->assertTrue( isset( $nodes[ $id ] ), sprintf( 'Menu item %1$s must display for a user with the %2$s cap.', $id, $cap ) );
     748                $this->assertArrayHasKey( $id, $nodes, sprintf( 'Menu item %1$s must display for a user with the %2$s cap.', $id, $cap ) );
    749749            } else {
    750                 $this->assertFalse( isset( $nodes[ $id ] ), sprintf( 'Menu item %1$s must not display for a user without the %2$s cap.', $id, $cap ) );
     750                $this->assertArrayNotHasKey( $id, $nodes, sprintf( 'Menu item %1$s must not display for a user without the %2$s cap.', $id, $cap ) );
    751751            }
    752752        }
Note: See TracChangeset for help on using the changeset viewer.