1010
1111class InitOptionsTest extends TestCase {
1212 /**
13- * @return void
1413 * @see InitOptions::maybe_add_pageview_props()
14+ * @return void
1515 */
1616 public function testAddPageviewProps () {
1717 try {
18- global $ post ;
18+ global $ post , $ wp_query ;
19+ $ old_post = $ post ;
20+ $ old_query = $ wp_query ;
1921
20- $ post_id = wp_insert_post (
22+ $ post_id = wp_insert_post (
2123 [
2224 'id ' => 1 ,
2325 'post_author ' => 1 ,
2426 'post_title ' => 'Test ' ,
2527 'post_content ' => 'Test ' ,
2628 ]
2729 );
28- $ test_post = get_post ( $ post_id );
29- $ post = $ test_post ;
30+ $ test_post = get_post ( $ post_id );
31+ $ post = $ test_post ;
32+ $ wp_query = new \WP_Query ();
33+ $ wp_query ->is_single = true ;
3034
3135 add_filter ( 'plausible_analytics_settings ' , [ $ this , 'enablePageviewProps ' ] );
3236
@@ -40,15 +44,16 @@ public function testAddPageviewProps() {
4044 $ this ->assertArrayHasKey ( 'category ' , $ options ['customProperties ' ] );
4145 $ this ->assertEquals ( 'Uncategorized ' , $ options ['customProperties ' ]['category ' ] );
4246 } finally {
43- $ post = null ;
47+ $ post = $ old_post ;
48+ $ wp_query = $ old_query ;
4449 remove_filter ( 'plausible_analytics_settings ' , [ $ this , 'enablePageviewProps ' ] );
4550 }
4651 }
4752
4853 /**
54+ * @see InitOptions::maybe_add_proxy_options()
4955 * @return void
5056 * @throws \Exception
51- * @see InitOptions::maybe_add_proxy_options()
5257 */
5358 public function testAddProxyOptions () {
5459 try {
@@ -65,8 +70,8 @@ public function testAddProxyOptions() {
6570 }
6671
6772 /**
68- * @return void
6973 * @see InitOptions::maybe_exclude_pageview()
74+ * @return void
7075 */
7176 public function testExcludePageview () {
7277 /**
@@ -76,7 +81,7 @@ public function testExcludePageview() {
7681 add_filter ( 'plausible_analytics_settings ' , [ $ this , 'setExcludePageview ' ] );
7782
7883 $ class = $ this ->getMockBuilder ( InitOptions::class )->disableOriginalConstructor ()->onlyMethods ( [
79- 'get_current_request '
84+ 'get_current_request ' ,
8085 ] )->getMock ();
8186
8287 $ class ->method ( 'get_current_request ' )->willReturn ( 'http://example.com/category/test ' );
@@ -86,7 +91,7 @@ public function testExcludePageview() {
8691 $ this ->assertArrayNotHasKey ( 'transformRequest ' , $ options );
8792
8893 $ class = $ this ->getMockBuilder ( InitOptions::class )->disableOriginalConstructor ()->onlyMethods ( [
89- 'get_current_request '
94+ 'get_current_request ' ,
9095 ] )->getMock ();
9196
9297 $ class ->method ( 'get_current_request ' )->willReturn ( 'http://test.example.com/test ' );
@@ -105,7 +110,7 @@ public function testExcludePageview() {
105110 add_filter ( 'plausible_analytics_settings ' , [ $ this , 'setExcludePageviewEdgeCaseAsterisk ' ] );
106111
107112 $ class = $ this ->getMockBuilder ( InitOptions::class )->disableOriginalConstructor ()->onlyMethods ( [
108- 'get_current_request '
113+ 'get_current_request ' ,
109114 ] )->getMock ();
110115
111116 $ class ->method ( 'get_current_request ' )->willReturn ( 'http://example.com/test ' );
@@ -124,7 +129,7 @@ public function testExcludePageview() {
124129 add_filter ( 'plausible_analytics_settings ' , [ $ this , 'setExcludePageviewEdgeCaseSpace ' ] );
125130
126131 $ class = $ this ->getMockBuilder ( InitOptions::class )->disableOriginalConstructor ()->onlyMethods ( [
127- 'get_current_request '
132+ 'get_current_request ' ,
128133 ] )->getMock ();
129134
130135 $ class ->method ( 'get_current_request ' )->willReturn ( 'http://example.com/test ' );
@@ -138,8 +143,8 @@ public function testExcludePageview() {
138143 }
139144
140145 /**
141- * @return void
142146 * @see InitOptions::maybe_track_logged_in_users()
147+ * @return void
143148 */
144149 public function testTrackLoggedInUsers () {
145150 try {
0 commit comments