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/rest-api/rest-themes-controller.php

    r51367 r51397  
    10301030        $response = self::perform_active_theme_request();
    10311031        $result   = $response->get_data();
    1032         $this->assertTrue( isset( $result[0]['theme_supports'] ) );
    1033         $this->assertTrue( isset( $result[0]['theme_supports']['formats'] ) );
     1032        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     1033        $this->assertArrayHasKey( 'formats', $result[0]['theme_supports'] );
    10341034        $this->assertSame( array( 'standard' ), $result[0]['theme_supports']['formats'] );
    10351035    }
     
    10441044        $response = self::perform_active_theme_request();
    10451045        $result   = $response->get_data();
    1046         $this->assertTrue( isset( $result[0]['theme_supports'] ) );
    1047         $this->assertTrue( isset( $result[0]['theme_supports']['formats'] ) );
     1046        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     1047        $this->assertArrayHasKey( 'formats', $result[0]['theme_supports'] );
    10481048        $this->assertSame( array( 'standard', 'aside', 'video' ), $result[0]['theme_supports']['formats'] );
    10491049    }
     
    10591059
    10601060        $result = $response->get_data();
    1061         $this->assertTrue( isset( $result[0]['theme_supports'] ) );
    1062         $this->assertTrue( isset( $result[0]['theme_supports']['responsive-embeds'] ) );
     1061        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     1062        $this->assertArrayHasKey( 'responsive-embeds', $result[0]['theme_supports'] );
    10631063        $this->assertFalse( $result[0]['theme_supports']['responsive-embeds'] );
    10641064    }
     
    10741074        $response = self::perform_active_theme_request();
    10751075        $result   = $response->get_data();
    1076         $this->assertTrue( isset( $result[0]['theme_supports'] ) );
     1076        $this->assertArrayHasKey( 'theme_supports', $result[0] );
    10771077        $this->assertTrue( $result[0]['theme_supports']['responsive-embeds'] );
    10781078    }
     
    10881088
    10891089        $result = $response->get_data();
    1090         $this->assertTrue( isset( $result[0]['theme_supports'] ) );
    1091         $this->assertTrue( isset( $result[0]['theme_supports']['post-thumbnails'] ) );
     1090        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     1091        $this->assertArrayHasKey( 'post-thumbnails', $result[0]['theme_supports'] );
    10921092        $this->assertFalse( $result[0]['theme_supports']['post-thumbnails'] );
    10931093    }
     
    11031103        $response = self::perform_active_theme_request();
    11041104        $result   = $response->get_data();
    1105         $this->assertTrue( isset( $result[0]['theme_supports'] ) );
     1105        $this->assertArrayHasKey( 'theme_supports', $result[0] );
    11061106        $this->assertTrue( $result[0]['theme_supports']['post-thumbnails'] );
    11071107    }
     
    11171117        $response = self::perform_active_theme_request();
    11181118        $result   = $response->get_data();
    1119         $this->assertTrue( isset( $result[0]['theme_supports'] ) );
     1119        $this->assertArrayHasKey( 'theme_supports', $result[0] );
    11201120        $this->assertSame( array( 'post' ), $result[0]['theme_supports']['post-thumbnails'] );
    11211121    }
     
    11431143        $response = self::perform_active_theme_request();
    11441144        $result   = $response->get_data();
    1145         $this->assertTrue( isset( $result[0]['theme_supports'] ) );
     1145        $this->assertArrayHasKey( 'theme_supports', $result[0] );
    11461146        $this->assertSame( array( 'a', 'b', 'c' ), $result[0]['theme_supports']['test-feature'] );
    11471147    }
Note: See TracChangeset for help on using the changeset viewer.