1010
1111class AssetsTest extends TestCase {
1212 /**
13+ * @see Assets::maybe_enqueue_cloaked_affiliate_links_assets()
1314 * @return void
1415 * @throws \Exception
15- * @see Assets::maybe_enqueue_main_script()
1616 */
17- public function testEnqueueMainScript () {
17+ public function testEnqueueCloakedAffiliateLinksScript () {
1818 try {
19- add_filter ( 'plausible_analytics_settings ' , [ $ this , 'enableAdministratorTracking ' ] );
19+ add_filter ( 'plausible_analytics_settings ' , [ $ this , 'enableCloakedAffiliateLinks ' ] );
2020
2121 $ class = $ this ->getMockBuilder ( Assets::class )
2222 ->disableOriginalConstructor ()
@@ -29,94 +29,94 @@ public function testEnqueueMainScript() {
2929 $ class ->method ( 'get_js_url ' )
3030 ->willReturn ( 'https://plausible.test/js/plausible.js ' );
3131
32- wp_set_current_user ( 1 );
33- $ user = wp_get_current_user ();
34- $ user ->add_role ( 'administrator ' );
32+ ob_start ();
3533
3634 $ class ->maybe_enqueue_main_script ();
35+ $ class ->maybe_enqueue_cloaked_affiliate_links_assets ();
3736
38- global $ wp_scripts ;
39- $ data = $ wp_scripts ->get_data ( 'plausible-analytics ' , 'after ' );
37+ do_action ( 'wp_footer ' );
4038
41- $ this ->assertStringContainsString ( 'window.plausible ' , implode ( '' , $ data ) );
42- $ this ->assertStringContainsString ( 'plausible.init ' , implode ( '' , $ data ) );
39+ $ output = ob_get_clean ();
40+
41+ $ this ->assertStringContainsString ( 'plausible-affiliate-links.js ' , $ output );
42+ $ this ->assertStringContainsString ( 'const plausibleAffiliateLinks ' , $ output );
4343 } finally {
44- remove_filter ( 'plausible_analytics_settings ' , [ $ this , 'enableAdministratorTracking ' ] );
45- wp_set_current_user ( null );
44+ remove_filter ( 'plausible_analytics_settings ' , [ $ this , 'enableCloakedAffiliateLinks ' ] );
4645 }
4746 }
4847
4948 /**
49+ * @see Assets::maybe_enqueue_four_o_four_script()
5050 * @return void
5151 * @throws \Exception
52- * @see Assets::maybe_enqueue_cloaked_affiliate_links_assets()
5352 */
54- public function testEnqueueCloakedAffiliateLinksScript () {
53+ public function testEnqueueFourOFourScript () {
5554 try {
56- add_filter ( 'plausible_analytics_settings ' , [ $ this , 'enableCloakedAffiliateLinks ' ] );
55+ add_filter ( 'plausible_analytics_settings ' , [ $ this , 'enableFourOFour ' ] );
56+ add_filter ( 'plausible_analytics_is_404 ' , '__return_true ' );
5757
5858 $ class = $ this ->getMockBuilder ( Assets::class )
5959 ->disableOriginalConstructor ()
6060 ->onlyMethods ( [ 'get_js_url ' ] )
6161 ->getMock ();
6262
63- $ this ->removeAction ( 'wp_enqueue_scripts ' , 'maybe_enqueue ' );
64- $ this ->removeAction ( 'wp_enqueue_scripts ' , 'maybe_enqueue ' , 11 );
65-
6663 $ class ->method ( 'get_js_url ' )
6764 ->willReturn ( 'https://plausible.test/js/plausible.js ' );
6865
69- ob_start ();
70-
7166 $ class ->maybe_enqueue_main_script ();
72- $ class ->maybe_enqueue_cloaked_affiliate_links_assets ();
73-
74- do_action ( 'wp_head ' );
67+ $ class ->maybe_enqueue_four_o_four_script ();
7568
76- $ output = ob_get_clean () ;
69+ global $ wp_scripts ;
7770
78- $ this ->assertStringContainsString ( 'plausible-affiliate-links.js ' , $ output );
79- $ this ->assertStringContainsString ( ' const plausibleAffiliateLinks ' , $ output );
71+ $ this ->assertArrayHasKey ( 'plausible-analytics ' , $ wp_scripts -> registered );
72+ $ this ->assertTrue ( $ this -> arrayHasString ( ' 404 ' , $ wp_scripts -> registered [ ' plausible-analytics ' ]-> extra [ ' after ' ] ) );
8073 } finally {
81- remove_filter ( 'plausible_analytics_settings ' , [ $ this , 'enableCloakedAffiliateLinks ' ] );
74+ remove_filter ( 'plausible_analytics_settings ' , [ $ this , 'enableFourOFour ' ] );
75+ remove_filter ( 'plausible_analytics_is_404 ' , '__return_true ' );
8276 }
8377 }
8478
8579 /**
80+ * @see Assets::maybe_enqueue_main_script()
8681 * @return void
8782 * @throws \Exception
88- * @see Assets::maybe_enqueue_four_o_four_script()
8983 */
90- public function testEnqueueFourOFourScript () {
84+ public function testEnqueueMainScript () {
9185 try {
92- add_filter ( 'plausible_analytics_settings ' , [ $ this , 'enableFourOFour ' ] );
93- add_filter ( 'plausible_analytics_is_404 ' , '__return_true ' );
86+ add_filter ( 'plausible_analytics_settings ' , [ $ this , 'enableAdministratorTracking ' ] );
9487
9588 $ class = $ this ->getMockBuilder ( Assets::class )
9689 ->disableOriginalConstructor ()
9790 ->onlyMethods ( [ 'get_js_url ' ] )
9891 ->getMock ();
9992
93+ $ this ->removeAction ( 'wp_enqueue_scripts ' , 'maybe_enqueue ' );
94+ $ this ->removeAction ( 'wp_enqueue_scripts ' , 'maybe_enqueue ' , 11 );
95+
10096 $ class ->method ( 'get_js_url ' )
10197 ->willReturn ( 'https://plausible.test/js/plausible.js ' );
10298
99+ wp_set_current_user ( 1 );
100+ $ user = wp_get_current_user ();
101+ $ user ->add_role ( 'administrator ' );
102+
103103 $ class ->maybe_enqueue_main_script ();
104- $ class ->maybe_enqueue_four_o_four_script ();
105104
106105 global $ wp_scripts ;
106+ $ data = $ wp_scripts ->get_data ( 'plausible-analytics ' , 'after ' );
107107
108- $ this ->assertArrayHasKey ( 'plausible-analytics ' , $ wp_scripts -> registered );
109- $ this ->assertTrue ( $ this -> arrayHasString ( '404 ' , $ wp_scripts -> registered [ ' plausible-analytics ' ]-> extra [ ' after ' ] ) );
108+ $ this ->assertStringContainsString ( 'window. plausible ' , implode ( '' , $ data ) );
109+ $ this ->assertStringContainsString ( ' plausible.init ' , implode ( '' , $ data ) );
110110 } finally {
111- remove_filter ( 'plausible_analytics_settings ' , [ $ this , 'enableFourOFour ' ] );
112- remove_filter ( ' plausible_analytics_is_404 ' , ' __return_true ' );
111+ remove_filter ( 'plausible_analytics_settings ' , [ $ this , 'enableAdministratorTracking ' ] );
112+ wp_set_current_user ( null );
113113 }
114114 }
115115
116116 /**
117+ * @see Assets::maybe_enqueue_query_params_script()
117118 * @return void
118119 * @throws \Exception
119- * @see Assets::maybe_enqueue_query_params_script()
120120 */
121121 public function testEnqueueQueryParamsScript () {
122122 try {
@@ -146,9 +146,9 @@ public function testEnqueueQueryParamsScript() {
146146 }
147147
148148 /**
149+ * @see Assets::maybe_enqueue_search_queries_script()
149150 * @return void
150151 * @throws \Exception
151- * @see Assets::maybe_enqueue_search_queries_script()
152152 */
153153 public function testEnqueueSearchQueriesScript () {
154154 try {
0 commit comments