Skip to content

Commit

Permalink
MslsOptions tested
Browse files Browse the repository at this point in the history
  • Loading branch information
lloc authored May 22, 2024
1 parent 2888439 commit 81c007a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions includes/MslsOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class MslsOptions extends MslsGetSet {
/**
* Available languages
*
* @var array
* @var array<string, string>
*/
private $available_languages;
private array $available_languages;

/**
* Rewrite with front
Expand Down
49 changes: 49 additions & 0 deletions tests/TestMslsOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,53 @@ public function test_get_icon_type_admin_display(): void {

$this->assertEquals( MslsAdminIcon::TYPE_LABEL, $obj->get_icon_type() );
}

public function provide_data_for_slug_check(): array {
return array(
array( '', '', false, false, false, '', false ), // first return
array( null, '', false, false, false, '', false ), // first return
array( 'https://msls.co/blog/test', 'https://msls.co/blog/test', true, true, false, '', false ), // second return
array( 'https://msls.co/blog/test', 'https://msls.co/blog/test', true, false, true, '', false ), // second return
array( 'https://msls.co/blog/test', 'https://msls.co/blog/test', true, true, true, '', false ),
array( 'https://msls.co/blog/2024/05/test', 'https://msls.co/blog/2024/05/test', true, true, true, '/%year%/%monthnum%/%postname%/', false ),
array( 'https://msls.co/blog/2024/05/test', 'https://msls.co/2024/05/test', true, true, true, '/blog/%year%/%monthnum%/%postname%/', false ),
array( 'https://msls.co/blog/test', 'https://msls.co/blog/test', true, true, true, '/%postname%/', false ),
array( 'https://msls.co/blog/test', 'https://msls.co/test', true, true, true, '/blog/%postname%/', false ),
array( 'https://msls.co/blog/2024/05/test', 'https://msls.co/blog/2024/05/test', true, true, true, '/%year%/%monthnum%/%postname%/', true ),
array( 'https://msls.co/blog/2024/05/test', 'https://msls.co/blog/2024/05/test', true, true, true, '/blog/%year%/%monthnum%/%postname%/', true ),
array( 'https://msls.co/blog/test', 'https://msls.co/blog/test', true, true, true, '/%postname%/', true ),
array( 'https://msls.co/blog/test', 'https://msls.co/blog/test', true, true, true, '/blog/%postname%/', true ),
);
}

/**
* @dataProvider provide_data_for_slug_check
*/
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 {
global $wp_rewrite, $current_site;

$options = \Mockery::mock( MslsOptions::class );
$options->with_front = $with_front;
$wp_rewrite = \Mockery::mock( '\WP_Rewrite' );
$wp_rewrite->shouldReceive( 'using_permalinks' )->andReturn( $using_permalinks );
$current_site = \Mockery::mock( '\WP_Network' );
$current_site->blog_id = 1;

Functions\when( 'is_subdomain_install' )->justReturn( $is_subdomain_install );
Functions\expect( 'home_url' )->andReturnUsing(
function ( $url = '' ) {
return 'https://msls.co' . $url;
}
);
Functions\when( 'get_blog_option' )->justReturn( $permalink_structure );
Functions\when( 'is_main_site' )->justReturn( $is_main_site );

$this->assertEquals( $expected, MslsOptions::check_for_blog_slug( $url, $options ) );
}

public function test_get_slug() {
$obj = $this->get_test();

$this->assertEquals( '', $obj->get_slug( 'post' ) );
}
}

0 comments on commit 81c007a

Please sign in to comment.