Changeset 48937 for trunk/tests/phpunit/tests/post/objects.php
- Timestamp:
- 09/02/2020 12:35:36 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/objects.php
r47311 r48937 11 11 $post = get_post( $id ); 12 12 $this->assertInstanceOf( 'WP_Post', $post ); 13 $this->assert Equals( $id, $post->ID );13 $this->assertSame( $id, $post->ID ); 14 14 $this->assertTrue( isset( $post->ancestors ) ); 15 $this->assert Equals( array(), $post->ancestors );15 $this->assertSame( array(), $post->ancestors ); 16 16 17 17 // Unset and then verify that the magic method fills the property again. 18 18 unset( $post->ancestors ); 19 $this->assert Equals( array(), $post->ancestors );19 $this->assertSame( array(), $post->ancestors ); 20 20 21 21 // Magic get should make meta accessible as properties. 22 22 add_post_meta( $id, 'test', 'test' ); 23 $this->assert Equals( 'test', get_post_meta( $id, 'test', true ) );24 $this->assert Equals( 'test', $post->test );23 $this->assertSame( 'test', get_post_meta( $id, 'test', true ) ); 24 $this->assertSame( 'test', $post->test ); 25 25 26 26 // Make sure meta does not eclipse true properties. 27 27 add_post_meta( $id, 'post_type', 'dummy' ); 28 $this->assert Equals( 'dummy', get_post_meta( $id, 'post_type', true ) );29 $this->assert Equals( 'post', $post->post_type );28 $this->assertSame( 'dummy', get_post_meta( $id, 'post_type', true ) ); 29 $this->assertSame( 'post', $post->post_type ); 30 30 31 31 // Excercise the output argument. 32 32 $post = get_post( $id, ARRAY_A ); 33 33 $this->assertInternalType( 'array', $post ); 34 $this->assert Equals( 'post', $post['post_type'] );34 $this->assertSame( 'post', $post['post_type'] ); 35 35 36 36 $post = get_post( $id, ARRAY_N ); … … 42 42 $post = get_post( $post, ARRAY_A ); 43 43 $this->assertInternalType( 'array', $post ); 44 $this->assert Equals( 'post', $post['post_type'] );45 $this->assert Equals( $id, $post['ID'] );44 $this->assertSame( 'post', $post['post_type'] ); 45 $this->assertSame( $id, $post['ID'] ); 46 46 47 47 // Should default to OBJECT when given invalid output argument. 48 48 $post = get_post( $id, 'invalid-output-value' ); 49 49 $this->assertInstanceOf( 'WP_Post', $post ); 50 $this->assert Equals( $id, $post->ID );50 $this->assertSame( $id, $post->ID ); 51 51 52 52 // Make sure stdClass in $GLOBALS['post'] is handled. … … 57 57 $post = get_post( null ); 58 58 $this->assertInstanceOf( 'WP_Post', $post ); 59 $this->assert Equals( $id, $post->ID );59 $this->assertSame( $id, $post->ID ); 60 60 unset( $GLOBALS['post'] ); 61 61 … … 77 77 ) 78 78 ); 79 $this->assert Equals( $updated, $child_id );79 $this->assertSame( $updated, $child_id ); 80 80 $updated = wp_update_post( 81 81 array( … … 84 84 ) 85 85 ); 86 $this->assert Equals( $updated, $grandchild_id );87 88 $this->assert Equals( array( $parent_id ), get_post( $child_id )->ancestors );89 $this->assert Equals( array( $parent_id ), get_post_ancestors( $child_id ) );90 $this->assert Equals( array( $parent_id ), get_post_ancestors( get_post( $child_id ) ) );91 92 $this->assert Equals( array( $child_id, $parent_id ), get_post( $grandchild_id )->ancestors );93 $this->assert Equals( array( $child_id, $parent_id ), get_post_ancestors( $grandchild_id ) );94 $this->assert Equals( array( $child_id, $parent_id ), get_post_ancestors( get_post( $grandchild_id ) ) );95 96 $this->assert Equals( array(), get_post( $parent_id )->ancestors );97 $this->assert Equals( array(), get_post_ancestors( $parent_id ) );98 $this->assert Equals( array(), get_post_ancestors( get_post( $parent_id ) ) );86 $this->assertSame( $updated, $grandchild_id ); 87 88 $this->assertSame( array( $parent_id ), get_post( $child_id )->ancestors ); 89 $this->assertSame( array( $parent_id ), get_post_ancestors( $child_id ) ); 90 $this->assertSame( array( $parent_id ), get_post_ancestors( get_post( $child_id ) ) ); 91 92 $this->assertSame( array( $child_id, $parent_id ), get_post( $grandchild_id )->ancestors ); 93 $this->assertSame( array( $child_id, $parent_id ), get_post_ancestors( $grandchild_id ) ); 94 $this->assertSame( array( $child_id, $parent_id ), get_post_ancestors( get_post( $grandchild_id ) ) ); 95 96 $this->assertSame( array(), get_post( $parent_id )->ancestors ); 97 $this->assertSame( array(), get_post_ancestors( $parent_id ) ); 98 $this->assertSame( array(), get_post_ancestors( get_post( $parent_id ) ) ); 99 99 } 100 100 … … 105 105 foreach ( array( null, 0, false, '0', '' ) as $post_id ) { 106 106 $this->assertInternalType( 'array', get_post_ancestors( $post_id ) ); 107 $this->assert Equals( array(), get_post_ancestors( $post_id ) );107 $this->assertSame( array(), get_post_ancestors( $post_id ) ); 108 108 } 109 109 } … … 114 114 115 115 $this->assertInternalType( 'array', $post->post_category ); 116 $this->assert Equals( 1, count( $post->post_category ) );116 $this->assertSame( 1, count( $post->post_category ) ); 117 117 $this->assertEquals( get_option( 'default_category' ), $post->post_category[0] ); 118 118 $term1 = wp_insert_term( 'Foo', 'category' ); … … 120 120 $term3 = wp_insert_term( 'Baz', 'category' ); 121 121 wp_set_post_categories( $post_id, array( $term1['term_id'], $term2['term_id'], $term3['term_id'] ) ); 122 $this->assert Equals( 3, count( $post->post_category ) );123 $this->assert Equals( array( $term2['term_id'], $term3['term_id'], $term1['term_id'] ), $post->post_category );122 $this->assertSame( 3, count( $post->post_category ) ); 123 $this->assertSame( array( $term2['term_id'], $term3['term_id'], $term1['term_id'] ), $post->post_category ); 124 124 125 125 $post = get_post( $post_id, ARRAY_A ); 126 $this->assert Equals( 3, count( $post['post_category'] ) );127 $this->assert Equals( array( $term2['term_id'], $term3['term_id'], $term1['term_id'] ), $post['post_category'] );126 $this->assertSame( 3, count( $post['post_category'] ) ); 127 $this->assertSame( array( $term2['term_id'], $term3['term_id'], $term1['term_id'] ), $post['post_category'] ); 128 128 } 129 129 … … 136 136 wp_set_post_tags( $post_id, 'Foo, Bar, Baz' ); 137 137 $this->assertInternalType( 'array', $post->tags_input ); 138 $this->assert Equals( 3, count( $post->tags_input ) );139 $this->assert Equals( array( 'Bar', 'Baz', 'Foo' ), $post->tags_input );138 $this->assertSame( 3, count( $post->tags_input ) ); 139 $this->assertSame( array( 'Bar', 'Baz', 'Foo' ), $post->tags_input ); 140 140 141 141 $post = get_post( $post_id, ARRAY_A ); 142 142 $this->assertInternalType( 'array', $post['tags_input'] ); 143 $this->assert Equals( 3, count( $post['tags_input'] ) );144 $this->assert Equals( array( 'Bar', 'Baz', 'Foo' ), $post['tags_input'] );143 $this->assertSame( 3, count( $post['tags_input'] ) ); 144 $this->assertSame( array( 'Bar', 'Baz', 'Foo' ), $post['tags_input'] ); 145 145 } 146 146 … … 151 151 $this->assertInternalType( 'string', $post->page_template ); 152 152 $template = get_post_meta( $post->ID, '_wp_page_template', true ); 153 $this->assert Equals( $template, $post->page_template );153 $this->assertSame( $template, $post->page_template ); 154 154 update_post_meta( $post_id, '_wp_page_template', 'foo.php' ); 155 155 $template = get_post_meta( $post->ID, '_wp_page_template', true ); 156 $this->assert Equals( 'foo.php', $template );157 $this->assert Equals( $template, $post->page_template );156 $this->assertSame( 'foo.php', $template ); 157 $this->assertSame( $template, $post->page_template ); 158 158 } 159 159 … … 167 167 ); 168 168 169 $this->assert Equals( 'raw', $post->filter );169 $this->assertSame( 'raw', $post->filter ); 170 170 $this->assertInternalType( 'int', $post->post_parent ); 171 171 172 172 $display_post = get_post( $post, OBJECT, 'js' ); 173 $this->assert Equals( 'js', $display_post->filter );174 $this->assert Equals( esc_js( "Mary's home" ), $display_post->post_title );173 $this->assertSame( 'js', $display_post->filter ); 174 $this->assertSame( esc_js( "Mary's home" ), $display_post->post_title ); 175 175 176 176 // Pass a js filtered WP_Post to get_post() with the filter set to raw. 177 177 // The post should be fetched from cache instead of using the passed object. 178 178 $raw_post = get_post( $display_post, OBJECT, 'raw' ); 179 $this->assert Equals( 'raw', $raw_post->filter );179 $this->assertSame( 'raw', $raw_post->filter ); 180 180 $this->assertNotEquals( esc_js( "Mary's home" ), $raw_post->post_title ); 181 181 182 182 $raw_post->filter( 'js' ); 183 $this->assert Equals( 'js', $post->filter );184 $this->assert Equals( esc_js( "Mary's home" ), $raw_post->post_title );183 $this->assertSame( 'js', $post->filter ); 184 $this->assertSame( esc_js( "Mary's home" ), $raw_post->post_title ); 185 185 } 186 186 … … 190 190 $post->foo = 'bar'; 191 191 192 $this->assert Equals( 'bar', get_post( $post )->foo );193 $this->assert Equals( 'bar', get_post( $post, OBJECT, 'display' )->foo );192 $this->assertSame( 'bar', get_post( $post )->foo ); 193 $this->assertSame( 'bar', get_post( $post, OBJECT, 'display' )->foo ); 194 194 } 195 195 … … 199 199 $post = get_post( $id, ARRAY_A ); 200 200 201 $this->assert Equals( $id, $post['ID'] );201 $this->assertSame( $id, $post['ID'] ); 202 202 $this->assertInternalType( 'array', $post['ancestors'] ); 203 $this->assert Equals( 'raw', $post['filter'] );203 $this->assertSame( 'raw', $post['filter'] ); 204 204 } 205 205
Note: See TracChangeset
for help on using the changeset viewer.