This repository has been archived by the owner on Aug 19, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass-back-end-test.php
191 lines (145 loc) · 4.08 KB
/
class-back-end-test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
/**
* WP Plugin Rating · Show plugin rating in WordPress administration pages.
*
* @author Josantonius <hello@josantonius.com>
* @package eliasis-framework\wp-plugin-rating
* @copyright 2017 - 2018 (c) Josantonius - WP Plugin Rating
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
* @link https://github.com/eliasis-framework/wp-plugin-rating.git
* @since 1.0.1
*/
namespace Eliasis\Components\WP_Plugin_Rating;
use Eliasis\Complement\Type\Component;
use Eliasis\Framework\App;
use Josantonius\Hook\Hook;
use Josantonius\WP_Register\WP_Register;
/**
* Tests class for WP_Plugin_Rating Eliasis component.
*/
final class Back_End_Test extends \WP_UnitTestCase {
/**
* App instance.
*
* @var object
*/
protected $app;
/**
* Root path.
*
* @var string
*/
protected $root;
/**
* Component instance.
*
* @var object
*/
protected $component;
/**
* Set up.
*/
public function setUp() {
$this->app = new App();
$this->root = realpath( $_SERVER['DOCUMENT_ROOT'] );
$app = $this->app;
$app::run( $this->root );
$component = new Component();
$this->component = $component::WP_Plugin_Rating()->getControllerInstance( 'Main' );
set_current_screen( 'admin.php' );
}
/**
* Check if it is an instance of.
*/
public function test_is_instance_of() {
$this->assertInstanceOf( 'Eliasis\Framework\App', $this->app );
$this->assertInstanceOf(
'Eliasis\Components\WP_Plugin_Rating\Controller\Main',
$this->component
);
}
/**
* Actions should be loaded on the back end.
*/
public function test_actions_should_be_loaded_on_the_back_end() {
$this->assertTrue(
has_action( 'wp_menu_after_add_menu_page' )
);
$this->assertTrue(
has_action( 'wp_menu_after_add_submenu_page' )
);
}
/**
* Actions should add page's hook_suffix after add menu/submenu.
*/
public function test_actions_should_add_new_actions() {
do_action( 'wp_menu_after_add_menu_page', 'test_menu_page' );
do_action( 'wp_menu_after_add_submenu_page', 'test_submenu_page' );
$this->assertTrue(
has_action( 'test_menu_page' )
);
$this->assertTrue(
has_action( 'test_submenu_page' )
);
}
/**
* A new hook should be added when accessing the menu page.
*/
public function test_new_hook_should_be_added_when_access_menu_page() {
do_action( 'wp_menu_after_add_menu_page', 'test_menu_page' );
do_action( 'test_menu_page' );
$this->assertTrue(
Hook::isAction( 'wp-plugin-rating\display' )
);
}
/**
* A new hook should be added when accessing the submenu page.
*/
public function test_new_hook_should_be_added_when_access_submenu_page() {
do_action( 'wp_menu_after_add_submenu_page', 'test_submenu_page' );
do_action( 'test_submenu_page' );
$this->assertTrue(
Hook::isAction( 'wp-plugin-rating\display' )
);
}
/**
* Styles should be added when accessing the menu page.
*/
public function test_styles_should_be_added_when_access_menu_page() {
do_action( 'wp_menu_after_add_menu_page', 'test_menu_page' );
do_action( 'test_menu_page' );
$this->assertTrue(
WP_Register::is_added( 'style', 'WP_Plugin_Rating' )
);
}
/**
* Styles should be added when accessing the submenu page.
*/
public function test_styles_should_be_added_when_access_submenu_page() {
do_action( 'wp_menu_after_add_submenu_page', 'test_submenu_page' );
do_action( 'test_submenu_page' );
$this->assertTrue(
WP_Register::is_added( 'style', 'WP_Plugin_Rating' )
);
}
/**
* It should show five stars if the plugin does not exist.
*/
public function test_should_show_five_stars_if_the_plugin_does_not_exist() {
do_action( 'wp_menu_after_add_menu_page', 'test_menu_page' );
do_action( 'test_menu_page' );
ob_start();
Hook::doAction( 'wp-plugin-rating\display', 'a-unknown-plugin' );
$rating = ob_get_contents();
ob_end_clean();
$stars = substr_count(
$rating,
'<span class="dashicons dashicons-star-filled">'
);
$this->assertSame( 5, $stars );
$this->assertContains(
'https://wordpress.org/support/plugin/a-unknown-plugin/reviews/#new-post/',
$rating
);
}
}