post->create_and_get();
$file = DIR_TESTDATA . '/images/canola.jpg';
self::$attachment_id = self::factory()->attachment->create_upload_object(
$file,
self::$post->ID,
array(
'post_mime_type' => 'image/jpeg',
)
);
set_post_thumbnail( self::$post, self::$attachment_id );
}
/**
* Tear down method.
*/
public static function wpTearDownAfterClass() {
wp_delete_post( self::$post->ID, true );
wp_delete_post( self::$attachment_id, true );
}
/**
* Helper method for $wp_query.
*/
public static function setup_query() {
global $wp_query;
$wp_query->in_the_loop = true;
$wp_query->post = self::$post;
$wp_query->posts = array( self::$post );
$GLOBALS['post'] = self::$post;
}
/**
* Test gutenberg_render_block_core_media_text with the featured image on the left.
*/
public function test_render_block_core_media_text_featured_image() {
self::setup_query();
$content = '
';
// Assert that the rendered block contains the featured image.
$attributes = array(
'useFeaturedImage' => true,
);
$rendered = gutenberg_render_block_core_media_text( $attributes, $content );
$this->assertStringContainsString( '
true,
'imageFill' => true,
);
$rendered = gutenberg_render_block_core_media_text( $attributes, $content );
$this->assertStringContainsString( '
';
// Assert that the rendered block contains the featured image.
$attributes = array(
'useFeaturedImage' => true,
);
$rendered = gutenberg_render_block_core_media_text( $attributes, $content );
$this->assertStringContainsString( '
true,
'imageFill' => true,
);
$rendered = gutenberg_render_block_core_media_text( $attributes, $content );
$this->assertStringContainsString( '
';
// Assert that the rendered block contains the featured image when media is on the right.
$attributes = array(
'useFeaturedImage' => true,
'mediaPosition' => 'right',
);
$rendered = gutenberg_render_block_core_media_text( $attributes, $content );
$this->assertStringContainsString( '
true,
'mediaPosition' => 'right',
'imageFill' => true,
);
$rendered = gutenberg_render_block_core_media_text( $attributes, $content );
$this->assertStringContainsString( '
';
// Assert that the rendered block contains the featured image when media is on the right.
$attributes = array(
'useFeaturedImage' => true,
'mediaPosition' => 'right',
);
$rendered = gutenberg_render_block_core_media_text( $attributes, $content );
$this->assertStringContainsString( '
true,
'mediaPosition' => 'right',
'imageFill' => true,
);
$rendered = gutenberg_render_block_core_media_text( $attributes, $content );
$this->assertStringContainsString( ' . ')