Changeset 35194
- Timestamp:
- 10/15/2015 06:39:43 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/thumbnails.php
r34855 r35194 6 6 */ 7 7 class Tests_Post_Thumbnail_Template extends WP_UnitTestCase { 8 protected $post;9 protected $attachment_id;8 protected static $post; 9 protected static $attachment_id; 10 10 11 function setUp() { 12 parent::setUp(); 13 14 $this->post = $this->factory->post->create_and_get(); 15 $file = DIR_TESTDATA . '/images/canola.jpg'; 16 $this->attachment_id = $this->factory->attachment->create_upload_object( $file, $this->post->ID, array( 11 public static function wpSetUpBeforeClass( $factory ) { 12 self::$post = $factory->post->create_and_get(); 13 $file = DIR_TESTDATA . '/images/canola.jpg'; 14 self::$attachment_id = $factory->attachment->create_upload_object( $file, self::$post->ID, array( 17 15 'post_mime_type' => 'image/jpeg', 18 16 ) ); 19 17 } 20 18 19 public static function wpTearDownAfterClass() { 20 wp_delete_post( self::$post->ID ); 21 wp_delete_attachment( self::$attachment_id ); 22 } 23 21 24 function test_has_post_thumbnail() { 22 $this->assertFalse( has_post_thumbnail( $this->post ) );23 $this->assertFalse( has_post_thumbnail( $this->post->ID ) );25 $this->assertFalse( has_post_thumbnail( self::$post ) ); 26 $this->assertFalse( has_post_thumbnail( self::$post->ID ) ); 24 27 $this->assertFalse( has_post_thumbnail() ); 25 28 26 $GLOBALS['post'] = $this->post;29 $GLOBALS['post'] = self::$post; 27 30 28 31 $this->assertFalse( has_post_thumbnail() ); … … 30 33 unset( $GLOBALS['post'] ); 31 34 32 set_post_thumbnail( $this->post, $this->attachment_id );35 set_post_thumbnail( self::$post, self::$attachment_id ); 33 36 34 $this->assertTrue( has_post_thumbnail( $this->post ) );35 $this->assertTrue( has_post_thumbnail( $this->post->ID ) );37 $this->assertTrue( has_post_thumbnail( self::$post ) ); 38 $this->assertTrue( has_post_thumbnail( self::$post->ID ) ); 36 39 $this->assertFalse( has_post_thumbnail() ); 37 40 38 $GLOBALS['post'] = $this->post;41 $GLOBALS['post'] = self::$post; 39 42 40 43 $this->assertTrue( has_post_thumbnail() ); … … 42 45 43 46 function test_get_post_thumbnail_id() { 44 $this->assertEmpty( get_post_thumbnail_id( $this->post ) );45 $this->assertEmpty( get_post_thumbnail_id( $this->post->ID ) );47 $this->assertEmpty( get_post_thumbnail_id( self::$post ) ); 48 $this->assertEmpty( get_post_thumbnail_id( self::$post->ID ) ); 46 49 $this->assertEmpty( get_post_thumbnail_id() ); 47 50 48 set_post_thumbnail( $this->post, $this->attachment_id );51 set_post_thumbnail( self::$post, self::$attachment_id ); 49 52 50 $this->assertEquals( $this->attachment_id, get_post_thumbnail_id( $this->post ) );51 $this->assertEquals( $this->attachment_id, get_post_thumbnail_id( $this->post->ID ) );53 $this->assertEquals( self::$attachment_id, get_post_thumbnail_id( self::$post ) ); 54 $this->assertEquals( self::$attachment_id, get_post_thumbnail_id( self::$post->ID ) ); 52 55 53 $GLOBALS['post'] = $this->post;56 $GLOBALS['post'] = self::$post; 54 57 55 $this->assertEquals( $this->attachment_id, get_post_thumbnail_id() );58 $this->assertEquals( self::$attachment_id, get_post_thumbnail_id() ); 56 59 } 57 60 58 61 function test_update_post_thumbnail_cache() { 59 set_post_thumbnail( $this->post, $this->attachment_id );62 set_post_thumbnail( self::$post, self::$attachment_id ); 60 63 61 64 $WP_Query = new WP_Query( array( 62 65 'post_type' => 'any', 63 'post__in' => array( $this->post->ID ),66 'post__in' => array( self::$post->ID ), 64 67 'orderby' => 'post__in', 65 68 ) ); … … 74 77 function test_get_the_post_thumbnail() { 75 78 $this->assertEquals( '', get_the_post_thumbnail() ); 76 $this->assertEquals( '', get_the_post_thumbnail( $this->post ) );77 set_post_thumbnail( $this->post, $this->attachment_id );79 $this->assertEquals( '', get_the_post_thumbnail( self::$post ) ); 80 set_post_thumbnail( self::$post, self::$attachment_id ); 78 81 79 $expected = wp_get_attachment_image( $this->attachment_id, 'post-thumbnail', false, array(82 $expected = wp_get_attachment_image( self::$attachment_id, 'post-thumbnail', false, array( 80 83 'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image' 81 84 ) ); 82 85 83 $this->assertEquals( $expected, get_the_post_thumbnail( $this->post ) );86 $this->assertEquals( $expected, get_the_post_thumbnail( self::$post ) ); 84 87 85 $GLOBALS['post'] = $this->post;88 $GLOBALS['post'] = self::$post; 86 89 87 90 $this->assertEquals( $expected, get_the_post_thumbnail() ); … … 95 98 $this->assertEquals( '', $actual ); 96 99 97 $GLOBALS['post'] = $this->post;100 $GLOBALS['post'] = self::$post; 98 101 99 102 ob_start(); … … 103 106 $this->assertEquals( '', $actual ); 104 107 105 set_post_thumbnail( $this->post, $this->attachment_id );108 set_post_thumbnail( self::$post, self::$attachment_id ); 106 109 107 $expected = wp_get_attachment_image( $this->attachment_id, 'post-thumbnail', false, array(110 $expected = wp_get_attachment_image( self::$attachment_id, 'post-thumbnail', false, array( 108 111 'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image' 109 112 ) ); … … 120 123 */ 121 124 function test_get_the_post_thumbnail_url() { 122 $this->assertFalse( has_post_thumbnail( $this->post ) );125 $this->assertFalse( has_post_thumbnail( self::$post ) ); 123 126 $this->assertFalse( get_the_post_thumbnail_url() ); 124 $this->assertFalse( get_the_post_thumbnail_url( $this->post ) );127 $this->assertFalse( get_the_post_thumbnail_url( self::$post ) ); 125 128 126 set_post_thumbnail( $this->post, $this->attachment_id );129 set_post_thumbnail( self::$post, self::$attachment_id ); 127 130 128 131 $this->assertFalse( get_the_post_thumbnail_url() ); 129 $this->assertEquals( wp_get_attachment_url( $this->attachment_id ), get_the_post_thumbnail_url( $this->post ) );132 $this->assertEquals( wp_get_attachment_url( self::$attachment_id ), get_the_post_thumbnail_url( self::$post ) ); 130 133 131 $GLOBALS['post'] = $this->post;134 $GLOBALS['post'] = self::$post; 132 135 133 $this->assertEquals( wp_get_attachment_url( $this->attachment_id ), get_the_post_thumbnail_url() );136 $this->assertEquals( wp_get_attachment_url( self::$attachment_id ), get_the_post_thumbnail_url() ); 134 137 } 135 138 … … 138 141 */ 139 142 function test_get_the_post_thumbnail_url_with_invalid_post() { 140 $post = $this->factory->post->create_and_get();143 set_post_thumbnail( self::$post, self::$attachment_id ); 141 144 142 set_post_thumbnail( $post, $this->attachment_id);145 $this->assertTrue( false !== get_the_post_thumbnail_url( self::$post->ID ) ); 143 146 144 $this->assertTrue( false !== get_the_post_thumbnail_url( $post->ID ) ); 145 146 $deleted = wp_delete_post( $post->ID, true ); 147 $deleted = wp_delete_post( self::$post->ID, true ); 147 148 $this->assertNotEmpty( $deleted ); 148 149 149 $this->assertFalse( get_the_post_thumbnail_url( $post->ID ) );150 $this->assertFalse( get_the_post_thumbnail_url( self::$post->ID ) ); 150 151 } 151 152 … … 154 155 */ 155 156 function test_the_post_thumbnail_url() { 156 $GLOBALS['post'] = $this->post;157 $GLOBALS['post'] = self::$post; 157 158 158 159 ob_start(); … … 168 169 $this->assertEmpty( $actual ); 169 170 170 set_post_thumbnail( $this->post, $this->attachment_id );171 set_post_thumbnail( self::$post, self::$attachment_id ); 171 172 172 173 ob_start(); … … 174 175 $actual = ob_get_clean(); 175 176 176 $this->assertEquals( wp_get_attachment_url( $this->attachment_id ), $actual );177 $this->assertEquals( wp_get_attachment_url( self::$attachment_id ), $actual ); 177 178 } 178 179 }
Note: See TracChangeset
for help on using the changeset viewer.