@@ -163,4 +163,53 @@ public function test_get_icon_type_admin_display(): void {
163163
164164 $ this ->assertEquals ( MslsAdminIcon::TYPE_LABEL , $ obj ->get_icon_type () );
165165 }
166+
167+ public function provide_data_for_slug_check (): array {
168+ return array (
169+ array ( '' , '' , false , false , false , '' , false ), // first return
170+ array ( null , '' , false , false , false , '' , false ), // first return
171+ array ( 'https://msls.co/blog/test ' , 'https://msls.co/blog/test ' , true , true , false , '' , false ), // second return
172+ array ( 'https://msls.co/blog/test ' , 'https://msls.co/blog/test ' , true , false , true , '' , false ), // second return
173+ array ( 'https://msls.co/blog/test ' , 'https://msls.co/blog/test ' , true , true , true , '' , false ),
174+ array ( 'https://msls.co/blog/2024/05/test ' , 'https://msls.co/blog/2024/05/test ' , true , true , true , '/%year%/%monthnum%/%postname%/ ' , false ),
175+ array ( 'https://msls.co/blog/2024/05/test ' , 'https://msls.co/2024/05/test ' , true , true , true , '/blog/%year%/%monthnum%/%postname%/ ' , false ),
176+ array ( 'https://msls.co/blog/test ' , 'https://msls.co/blog/test ' , true , true , true , '/%postname%/ ' , false ),
177+ array ( 'https://msls.co/blog/test ' , 'https://msls.co/test ' , true , true , true , '/blog/%postname%/ ' , false ),
178+ array ( 'https://msls.co/blog/2024/05/test ' , 'https://msls.co/blog/2024/05/test ' , true , true , true , '/%year%/%monthnum%/%postname%/ ' , true ),
179+ array ( 'https://msls.co/blog/2024/05/test ' , 'https://msls.co/blog/2024/05/test ' , true , true , true , '/blog/%year%/%monthnum%/%postname%/ ' , true ),
180+ array ( 'https://msls.co/blog/test ' , 'https://msls.co/blog/test ' , true , true , true , '/%postname%/ ' , true ),
181+ array ( 'https://msls.co/blog/test ' , 'https://msls.co/blog/test ' , true , true , true , '/blog/%postname%/ ' , true ),
182+ );
183+ }
184+
185+ /**
186+ * @dataProvider provide_data_for_slug_check
187+ */
188+ public function test_check_for_blog_slug ( ?string $ url , string $ expected , bool $ with_front , bool $ is_subdomain_install , bool $ using_permalinks , string $ permalink_structure , bool $ is_main_site ): void {
189+ global $ wp_rewrite , $ current_site ;
190+
191+ $ options = \Mockery::mock ( MslsOptions::class );
192+ $ options ->with_front = $ with_front ;
193+ $ wp_rewrite = \Mockery::mock ( '\WP_Rewrite ' );
194+ $ wp_rewrite ->shouldReceive ( 'using_permalinks ' )->andReturn ( $ using_permalinks );
195+ $ current_site = \Mockery::mock ( '\WP_Network ' );
196+ $ current_site ->blog_id = 1 ;
197+
198+ Functions \when ( 'is_subdomain_install ' )->justReturn ( $ is_subdomain_install );
199+ Functions \expect ( 'home_url ' )->andReturnUsing (
200+ function ( $ url = '' ) {
201+ return 'https://msls.co ' . $ url ;
202+ }
203+ );
204+ Functions \when ( 'get_blog_option ' )->justReturn ( $ permalink_structure );
205+ Functions \when ( 'is_main_site ' )->justReturn ( $ is_main_site );
206+
207+ $ this ->assertEquals ( $ expected , MslsOptions::check_for_blog_slug ( $ url , $ options ) );
208+ }
209+
210+ public function test_get_slug () {
211+ $ obj = $ this ->get_test ();
212+
213+ $ this ->assertEquals ( '' , $ obj ->get_slug ( 'post ' ) );
214+ }
166215}
0 commit comments