@@ -40,159 +40,6 @@ public function tear_down() {
4040 parent ::tear_down ();
4141 }
4242
43- /**
44- * Tests handle_xmlwriter_usage when has_blog_sticker returns true.
45- *
46- * @group jetpack-sitemap
47- */
48- #[Group( 'jetpack-sitemap ' )]
49- public function test_handle_xmlwriter_usage_has_blog_sticker_returns_true () {
50- $ blog_id = 12345 ;
51-
52- // Mock Jetpack_Options::get_option to return the blog ID
53- add_filter (
54- 'jetpack_options ' ,
55- function ( $ value , $ option ) use ( $ blog_id ) {
56- if ( 'id ' === $ option ) {
57- return $ blog_id ;
58- }
59- return $ value ;
60- },
61- 10 ,
62- 2
63- );
64-
65- // Set up mock has_blog_sticker to return true
66- $ GLOBALS ['test_has_blog_sticker_args ' ] = array (
67- 'sticker ' => 'jetpack-sitemaps-use-xmlwriter ' ,
68- 'blog_id ' => $ blog_id ,
69- );
70-
71- // Test the method directly - no duplication!
72- $ result = WPCOMSH_Sitemap_Sticker_Handlers::handle_xmlwriter_usage ( false );
73- $ this ->assertTrue ( $ result );
74-
75- $ result = WPCOMSH_Sitemap_Sticker_Handlers::handle_xmlwriter_usage ( true );
76- $ this ->assertTrue ( $ result );
77-
78- $ result = WPCOMSH_Sitemap_Sticker_Handlers::handle_xmlwriter_usage ( null );
79- $ this ->assertTrue ( $ result );
80- }
81-
82- /**
83- * Tests handle_xmlwriter_usage when has_blog_sticker exists but returns false.
84- * Since wpcomsh_is_site_sticker_active is a real function that depends on Atomic_Persistent_Data
85- * (which doesn't exist in test environment), it will return false, so the original value is preserved.
86- *
87- * @group jetpack-sitemap
88- */
89- #[Group( 'jetpack-sitemap ' )]
90- public function test_handle_xmlwriter_usage_has_blog_sticker_false () {
91- $ blog_id = 12345 ;
92-
93- // Mock Jetpack_Options::get_option to return the blog ID
94- add_filter (
95- 'jetpack_options ' ,
96- function ( $ value , $ option ) use ( $ blog_id ) {
97- if ( 'id ' === $ option ) {
98- return $ blog_id ;
99- }
100- return $ value ;
101- },
102- 10 ,
103- 2
104- );
105-
106- // Set up mock has_blog_sticker to return false
107- $ GLOBALS ['test_has_blog_sticker_return ' ] = false ;
108-
109- // Test the method directly - original value preserved
110- $ result = WPCOMSH_Sitemap_Sticker_Handlers::handle_xmlwriter_usage ( false );
111- $ this ->assertFalse ( $ result );
112-
113- $ result = WPCOMSH_Sitemap_Sticker_Handlers::handle_xmlwriter_usage ( true );
114- $ this ->assertTrue ( $ result );
115- }
116-
117- /**
118- * Tests jetpack_sitemap_use_xmlwriter filter when both functions exist but both return false.
119- * This test is now redundant with test_jetpack_sitemap_use_xmlwriter_has_blog_sticker_false_wpcomsh_real_function
120- * since wpcomsh_is_site_sticker_active is a real function that will return false in test environment.
121- *
122- * Note: This test now verifies the same behavior as the previous test but with explicit documentation
123- * that both functions return false in the test environment.
124- *
125- * @group jetpack-sitemap
126- */
127- #[Group( 'jetpack-sitemap ' )]
128- public function test_jetpack_sitemap_use_xmlwriter_both_functions_return_false () {
129- $ blog_id = 12345 ;
130-
131- // Mock Jetpack_Options::get_option to return the blog ID
132- add_filter (
133- 'jetpack_options ' ,
134- function ( $ value , $ option ) use ( $ blog_id ) {
135- if ( 'id ' === $ option ) {
136- return $ blog_id ;
137- }
138- return $ value ;
139- },
140- 10 ,
141- 2
142- );
143-
144- // Set up mock has_blog_sticker to return false
145- $ GLOBALS ['test_has_blog_sticker_return ' ] = false ;
146-
147- // wpcomsh_is_site_sticker_active will return false since \Atomic_Persistent_Data doesn't exist
148- // No need to mock it since it's a real function
149-
150- // Test with false input - should return false (original value)
151- $ result = apply_filters ( 'jetpack_sitemap_use_xmlwriter ' , false );
152- $ this ->assertFalse ( $ result );
153-
154- // Test with true input - should return true (original value)
155- $ result = apply_filters ( 'jetpack_sitemap_use_xmlwriter ' , true );
156- $ this ->assertTrue ( $ result );
157-
158- // Test with null input - should return null (original value)
159- $ result = apply_filters ( 'jetpack_sitemap_use_xmlwriter ' , null );
160- $ this ->assertNull ( $ result );
161-
162- // Test with string input - should return string (original value)
163- $ result = apply_filters ( 'jetpack_sitemap_use_xmlwriter ' , 'test ' );
164- $ this ->assertEquals ( 'test ' , $ result );
165- }
166-
167- /**
168- * Tests jetpack_sitemap_use_xmlwriter filter when neither function exists.
169- * This simulates environments where WordPress.com sticker functions are not available.
170- *
171- * @group jetpack-sitemap
172- */
173- #[Group( 'jetpack-sitemap ' )]
174- public function test_jetpack_sitemap_use_xmlwriter_functions_do_not_exist () {
175- // In normal environment, these functions won't exist
176- // so the filter should return the original value
177-
178- // Test with false input - should return false (original value)
179- $ result = apply_filters ( 'jetpack_sitemap_use_xmlwriter ' , false );
180- $ this ->assertFalse ( $ result );
181-
182- // Test with true input - should return true (original value)
183- $ result = apply_filters ( 'jetpack_sitemap_use_xmlwriter ' , true );
184- $ this ->assertTrue ( $ result );
185-
186- // Test with null input - should return null (original value)
187- $ result = apply_filters ( 'jetpack_sitemap_use_xmlwriter ' , null );
188- $ this ->assertNull ( $ result );
189-
190- // Test with array input - should return array (original value)
191- $ test_array = array ( 'test ' => 'value ' );
192- $ result = apply_filters ( 'jetpack_sitemap_use_xmlwriter ' , $ test_array );
193- $ this ->assertEquals ( $ test_array , $ result );
194- }
195-
19643 /**
19744 * Tests jetpack_sitemap_suspend_cache_addition filter when has_blog_sticker function exists and returns true.
19845 *
@@ -343,40 +190,4 @@ public function test_jetpack_sitemap_suspend_cache_addition_functions_do_not_exi
343190 $ result = apply_filters ( 'jetpack_sitemap_suspend_cache_addition ' , $ test_array );
344191 $ this ->assertEquals ( $ test_array , $ result );
345192 }
346-
347- /**
348- * Tests jetpack_sitemap_use_xmlwriter filter when Jetpack_Options::get_option returns false.
349- * This simulates error conditions where the blog ID cannot be retrieved.
350- *
351- * @group jetpack-sitemap
352- */
353- #[Group( 'jetpack-sitemap ' )]
354- public function test_jetpack_sitemap_use_xmlwriter_jetpack_options_returns_false () {
355- // Mock Jetpack_Options::get_option to return false
356- add_filter (
357- 'jetpack_options ' ,
358- function ( $ value , $ option ) {
359- if ( 'id ' === $ option ) {
360- return false ;
361- }
362- return $ value ;
363- },
364- 10 ,
365- 2
366- );
367-
368- // Set up mock has_blog_sticker to return false (should not be called with false blog ID)
369- $ GLOBALS ['test_has_blog_sticker_return ' ] = false ;
370-
371- // wpcomsh_is_site_sticker_active will return false since \Atomic_Persistent_Data doesn't exist
372- // So the filter should return the original value
373-
374- // Test with false input - should return false (original value)
375- $ result = apply_filters ( 'jetpack_sitemap_use_xmlwriter ' , false );
376- $ this ->assertFalse ( $ result );
377-
378- // Test with true input - should return true (original value)
379- $ result = apply_filters ( 'jetpack_sitemap_use_xmlwriter ' , true );
380- $ this ->assertTrue ( $ result );
381- }
382193}
0 commit comments