|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Tests for Posts_List_Page_Notification class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package automattic/jetpack |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
use Automattic\Jetpack\Dashboard_Customizations\Posts_List_Page_Notification; |
|
9
|
|
|
|
|
10
|
|
|
require_jetpack_file( 'modules/masterbar/wp-posts-list/class-posts-list-page-notification.php' ); |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class Test_Posts_List_Page_Notification. |
|
14
|
|
|
* |
|
15
|
|
|
* @coversDefaultClass Automattic\Jetpack\Dashboard_Customizations\Posts_List_Page_Notification |
|
16
|
|
|
*/ |
|
17
|
|
|
class Test_Posts_List_Page_Notification extends WP_UnitTestCase { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Check if the actions are attached. |
|
21
|
|
|
*/ |
|
22
|
|
|
public function test_it_has_instance_loaded() { |
|
23
|
|
|
$instance = Posts_List_Page_Notification::init(); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertSame( 10, has_action( 'init', array( $instance, 'init_actions' ) ) ); |
|
26
|
|
|
|
|
27
|
|
|
$instance->init_actions(); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertSame( 10, has_action( 'map_meta_cap', array( $instance, 'disable_posts_page' ) ) ); |
|
30
|
|
|
$this->assertSame( 10, has_action( 'post_class', array( $instance, 'add_posts_page_css_class' ) ) ); |
|
31
|
|
|
$this->assertSame( 10, has_action( 'admin_print_footer_scripts-edit.php', array( $instance, 'add_notification_icon' ) ) ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Check if it appends the CSS class. |
|
36
|
|
|
*/ |
|
37
|
|
|
public function test_it_appends_css_class() { |
|
38
|
|
|
$instance = new Posts_List_Page_Notification( '5' ); |
|
39
|
|
|
|
|
40
|
|
|
$classes = $instance->add_posts_page_css_class( array(), 'fox', 5 ); |
|
41
|
|
|
$this->assertEquals( array( 'posts-page' ), $classes ); |
|
42
|
|
|
|
|
43
|
|
|
$classes = $instance->add_posts_page_css_class( array( 'bar' ), 'fox', 5 ); |
|
44
|
|
|
$this->assertEquals( array( 'bar', 'posts-page' ), $classes ); |
|
45
|
|
|
|
|
46
|
|
|
$classes = $instance->add_posts_page_css_class( array( 'bar' ), 'fox', 6 ); |
|
47
|
|
|
$this->assertEquals( array( 'bar' ), $classes ); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Check if do_not_allow capability is added on Posts Page. |
|
52
|
|
|
*/ |
|
53
|
|
|
public function test_it_disables_posts_page() { |
|
54
|
|
|
$instance = new Posts_List_Page_Notification( '5' ); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertEquals( array( 'do_not_allow' ), $instance->disable_posts_page( array(), 'edit_post', '6', array( 0 => 5 ) ) ); |
|
57
|
|
|
$this->assertEquals( array( 'do_not_allow' ), $instance->disable_posts_page( array(), 'delete_post', '6', array( 0 => 5 ) ) ); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertEquals( array(), $instance->disable_posts_page( array(), 'edit_post', '6', array( 0 => 6 ) ) ); |
|
60
|
|
|
$this->assertEquals( array(), $instance->disable_posts_page( array(), 'delete_post', '6', array( 0 => 6 ) ) ); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|