Completed
Push — add/wpcom-posts-package ( 981416...ed2200 )
by
unknown
10:46
created

Test_Thumbnail::test_thumbnail_column_content()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
/**
3
 * Test methods from Automattic\Jetpack\WPcom\Posts\Thumbnail
4
 *
5
 * @package automattic/jetpack-wpcom-posts
6
 */
7
8
namespace Automattic\Jetpack\WPcom\Posts;
9
10
use WorDBless\BaseTestCase;
11
12
/**
13
 * Class Test_Thumbnail
14
 */
15
class Test_Thumbnail extends BaseTestCase {
16
	/**
17
	 * Core class used to implement displaying posts in a list table.
18
	 *
19
	 * @var WP_Posts_List_Table
20
	 */
21
	protected $table;
22
23
	/**
24
	 * Test post.
25
	 *
26
	 * @var WP_Post
27
	 */
28
	protected $post;
29
30
	/**
31
	 * Setup runs before each test.
32
	 *
33
	 * @before
34
	 */
35
	public function set_up() {
36
		new Thumbnail();
37
		$this->table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => 'edit-page' ) );
38
39
		$this->post = wp_insert_post(
40
			array(
41
				'post_status'  => 'publish',
42
				'post_title'   => 'Post title',
43
				'post_content' => 'Post content',
44
				'post_excerpt' => 'Post excerpt',
45
				'post_type'    => 'post',
46
			)
47
		);
48
49
		add_filter( 'post_thumbnail_html', array( $this, 'mock_post_thumbnail_html' ), 10, 4 );
50
	}
51
52
	public function tear_down() {
53
		remove_filter( 'post_thumbnail_html', array( $this, 'mock_post_thumbnail_html' ) );
54
	}
55
56
	public function mock_post_thumbnail_html( $html, $post_id, $size, $attr ) {
57
		$width  = $size[0];
58
		$height = $size[1];
59
		$style  = $attr['style'];
60
61
		return "My thumbnail of $width x $height with a $style style";
62
	}
63
64
	/**
65
	 * Checks that a new column header for thumbnails is added to the posts list table.
66
	 */
67
	public function test_thumbnail_column_header() {
68
		$columns = $this->table->get_columns();
69
		$this->assertSame( '', $columns['thumbnail'] );
70
	}
71
72
	/**
73
	 * Checks that the post thumbnail is displayed in the new column cell new.
74
	 */
75
	public function test_thumbnail_column_content() {
76
		$this->table->column_default( 'thumbnail' );
77
	}
78
}
79