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/includes/testcase-rest-post-type-controller.php

    r50283 r51397  
    4747            }
    4848        } else {
    49             $this->assertFalse( isset( $data['parent'] ) );
     49            $this->assertArrayNotHasKey( 'parent', $data );
    5050        }
    5151
     
    5454            $this->assertSame( $post->menu_order, $data['menu_order'] );
    5555        } else {
    56             $this->assertFalse( isset( $data['menu_order'] ) );
     56            $this->assertArrayNotHasKey( 'menu_order', $data );
    5757        }
    5858
     
    6262            $this->assertSame( $post->ping_status, $data['ping_status'] );
    6363        } else {
    64             $this->assertFalse( isset( $data['comment_status'] ) );
    65             $this->assertFalse( isset( $data['ping_status'] ) );
     64            $this->assertArrayNotHasKey( 'comment_status', $data );
     65            $this->assertArrayNotHasKey( 'ping_status', $data );
    6666        }
    6767
     
    8181            $this->assertSame( (int) get_post_thumbnail_id( $post->ID ), $data['featured_media'] );
    8282        } else {
    83             $this->assertFalse( isset( $data['featured_media'] ) );
     83            $this->assertArrayNotHasKey( 'featured_media', $data );
    8484        }
    8585
     
    9393            }
    9494        } else {
    95             $this->assertFalse( isset( $data['format'] ) );
     95            $this->assertArrayNotHasKey( 'format', $data );
    9696        }
    9797
     
    104104                $this->assertSame( $post->post_title, $data['title']['raw'] );
    105105            } else {
    106                 $this->assertFalse( isset( $data['title']['raw'] ) );
    107             }
    108         } else {
    109             $this->assertFalse( isset( $data['title'] ) );
     106                $this->assertArrayNotHasKey( 'raw', $data['title'] );
     107            }
     108        } else {
     109            $this->assertArrayNotHasKey( 'title', $data );
    110110        }
    111111
     
    119119                $this->assertSame( $post->post_content, $data['content']['raw'] );
    120120            } else {
    121                 $this->assertFalse( isset( $data['content']['raw'] ) );
    122             }
    123         } else {
    124             $this->assertFalse( isset( $data['content'] ) );
     121                $this->assertArrayNotHasKey( 'raw', $data['content'] );
     122            }
     123        } else {
     124            $this->assertArrayNotHasKey( 'content', $data );
    125125        }
    126126
     
    135135                $this->assertSame( $post->post_excerpt, $data['excerpt']['raw'] );
    136136            } else {
    137                 $this->assertFalse( isset( $data['excerpt']['raw'] ) );
    138             }
    139         } else {
    140             $this->assertFalse( isset( $data['excerpt'] ) );
     137                $this->assertArrayNotHasKey( 'raw', $data['excerpt'] );
     138            }
     139        } else {
     140            $this->assertArrayNotHasKey( 'excerpt', $data );
    141141        }
    142142
     
    150150        $taxonomies = wp_list_filter( get_object_taxonomies( $post->post_type, 'objects' ), array( 'show_in_rest' => true ) );
    151151        foreach ( $taxonomies as $taxonomy ) {
    152             $this->assertTrue( isset( $data[ $taxonomy->rest_base ] ) );
     152            $this->assertArrayHasKey( $taxonomy->rest_base, $data );
    153153            $terms = wp_get_object_terms( $post->ID, $taxonomy->name, array( 'fields' => 'ids' ) );
    154154            sort( $terms );
Note: See TracChangeset for help on using the changeset viewer.