Skip to content

Tests added #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' ) );
}
}
Loading