-
-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathAssets_Functions_Test.php
More file actions
173 lines (131 loc) · 4.34 KB
/
Assets_Functions_Test.php
File metadata and controls
173 lines (131 loc) · 4.34 KB
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
<?php
/**
* Tests for asset helper functions.
*
* @package WP_Ultimo\Tests
*/
namespace WP_Ultimo\Functions;
use WP_UnitTestCase;
/**
* Test class for asset helper functions.
*/
class Assets_Functions_Test extends WP_UnitTestCase {
/**
* Test wu_get_asset returns URL string.
*/
public function test_wu_get_asset_returns_url(): void {
$result = wu_get_asset('logo.png');
$this->assertIsString($result);
$this->assertStringContainsString('assets/img/', $result);
}
/**
* Test wu_get_asset with custom directory.
*/
public function test_wu_get_asset_custom_dir(): void {
$result = wu_get_asset('style.css', 'css');
$this->assertIsString($result);
$this->assertStringContainsString('assets/css/', $result);
}
/**
* Test wu_get_asset adds .min when SCRIPT_DEBUG is off.
*/
public function test_wu_get_asset_adds_min_suffix(): void {
// SCRIPT_DEBUG is not defined or false in test env.
$result = wu_get_asset('app.js', 'js');
$this->assertStringContainsString('.min.js', $result);
}
/**
* Test wu_get_asset does not double-add .min.
*/
public function test_wu_get_asset_no_double_min(): void {
$result = wu_get_asset('app.min.js', 'js');
// Should not contain .min.min.js.
$this->assertStringNotContainsString('.min.min.js', $result);
}
/**
* Test wu_get_asset with custom base dir.
*/
public function test_wu_get_asset_custom_base_dir(): void {
$result = wu_get_asset('logo.png', 'img', 'static');
$this->assertStringContainsString('static/img/', $result);
}
/**
* Core top-level page hook.
*/
public function test_wu_is_wu_page_matches_core_toplevel(): void {
$this->assertTrue(wu_is_wu_page('toplevel_page_wp-ultimo'));
}
/**
* Core submenu page hook.
*/
public function test_wu_is_wu_page_matches_core_submenu(): void {
$this->assertTrue(wu_is_wu_page('wp-ultimo_page_wp-ultimo-settings'));
}
/**
* Addon page with wu- slug prefix registered as top-level (regression for #706).
*
* When the multinetwork addon adds its `wu-networks` page at top level,
* the hook suffix does not contain `wp-ultimo`. It must still be recognized
* so wu-admin.css / wu-admin.js are enqueued, otherwise wu-form modals
* on that page render un-styled.
*/
public function test_wu_is_wu_page_matches_addon_toplevel_wu_slug(): void {
$this->assertTrue(wu_is_wu_page('toplevel_page_wu-networks'));
}
/**
* Addon page with wu- slug prefix registered as network admin submenu.
*/
public function test_wu_is_wu_page_matches_addon_network_wu_slug(): void {
$this->assertTrue(wu_is_wu_page('toplevel_page_wu-networks-network'));
}
/**
* Addon page submenu of a non-wu parent with wu- slug.
*/
public function test_wu_is_wu_page_matches_addon_submenu_wu_slug(): void {
$this->assertTrue(wu_is_wu_page('settings_page_wu-custom-addon'));
}
/**
* Unrelated WordPress pages must not match.
*/
public function test_wu_is_wu_page_rejects_unrelated_pages(): void {
$this->assertFalse(wu_is_wu_page('edit-post'));
$this->assertFalse(wu_is_wu_page('options-general'));
$this->assertFalse(wu_is_wu_page('plugins'));
$this->assertFalse(wu_is_wu_page('toplevel_page_other-plugin'));
}
/**
* A page slug that merely starts with `wu` (no hyphen) must not match, to
* avoid false positives on slugs like `wunderground`.
*/
public function test_wu_is_wu_page_requires_hyphen_after_wu(): void {
$this->assertFalse(wu_is_wu_page('toplevel_page_wunderground'));
}
/**
* The wu_is_wu_page filter allows addons with non-standard slugs to opt in.
*/
public function test_wu_is_wu_page_filter_opt_in(): void {
$callback = function ($is_wu_page, $hook_suffix) {
if ('toplevel_page_my-custom-addon' === $hook_suffix) {
return true;
}
return $is_wu_page;
};
add_filter('wu_is_wu_page', $callback, 10, 2);
$this->assertTrue(wu_is_wu_page('toplevel_page_my-custom-addon'));
remove_filter('wu_is_wu_page', $callback, 10);
}
/**
* The wu_is_wu_page filter allows opting out of a core match.
*/
public function test_wu_is_wu_page_filter_opt_out(): void {
$callback = function ($is_wu_page, $hook_suffix) {
if ('toplevel_page_wp-ultimo' === $hook_suffix) {
return false;
}
return $is_wu_page;
};
add_filter('wu_is_wu_page', $callback, 10, 2);
$this->assertFalse(wu_is_wu_page('toplevel_page_wp-ultimo'));
remove_filter('wu_is_wu_page', $callback, 10);
}
}