Repository navigation
Expand file tree
/
Copy pathAdminStylesTest.php
More file actions
90 lines (73 loc) · 2.34 KB
/
Copy pathAdminStylesTest.php
File metadata and controls
90 lines (73 loc) · 2.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
<?php
/**
* Tests for the admin stylesheet enqueue.
*
* @package ucsc-communications-functionality
*/
namespace UCSC\UcscCommunicationsFunctionality\Tests;
/**
* Admin stylesheet enqueue.
*/
final class AdminStylesTest extends TestCase {
/**
* Put us on the plugin's settings screen.
*
* @return void
*/
private function on_settings_screen(): void {
ucsccomms_test_set_screen(
new \WP_Screen( 'settings_page_ucsc-communications-functionality-settings' )
);
}
/**
* The stylesheet URL resolves from the plugin root, not from lib/functions/.
*
* Guards ROADMAP item 1: the enqueue previously built its URL from __FILE__
* inside lib/functions/, so the path picked up a lib/functions/ segment and
* the stylesheet 404'd.
*
* @return void
*/
public function test_admin_stylesheet_url_resolves_from_plugin_root(): void {
$this->on_settings_screen();
ucsccomms_enqueue_admin_styles();
$style = $GLOBALS['ucsccomms_test']['styles']['ucsccomms-cf-admin-settings'];
$this->assertSame( UCSCCOMMS_PLUGIN_URL . 'lib/css/admin-settings.css', $style['src'] );
$this->assertStringNotContainsString( 'lib/functions', $style['src'] );
}
/**
* The stylesheet is versioned with the plugin version, for cache busting.
*
* @return void
*/
public function test_admin_stylesheet_is_versioned(): void {
$this->on_settings_screen();
ucsccomms_enqueue_admin_styles();
$style = $GLOBALS['ucsccomms_test']['styles']['ucsccomms-cf-admin-settings'];
$this->assertSame( '9.9.9', $style['ver'] );
}
/**
* Nothing is enqueued on other admin screens.
*
* @return void
*/
public function test_no_styles_enqueued_on_other_admin_screens(): void {
ucsccomms_test_set_screen( new \WP_Screen( 'edit-post' ) );
ucsccomms_enqueue_admin_styles();
$this->assertSame( array(), $GLOBALS['ucsccomms_test']['enqueued'] );
$this->assertSame( array(), $GLOBALS['ucsccomms_test']['styles'] );
}
/**
* The function bails when there is no screen at all.
*
* get_current_screen() returns null outside a real admin screen, and the
* instanceof check is what stops a fatal on ->base.
*
* @return void
*/
public function test_no_styles_enqueued_when_there_is_no_screen(): void {
ucsccomms_test_set_screen( null );
ucsccomms_enqueue_admin_styles();
$this->assertSame( array(), $GLOBALS['ucsccomms_test']['enqueued'] );
}
}