Skip to content

Refactoring version 2 8 #308

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 3 commits into from
May 25, 2024
Merged
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
138 changes: 75 additions & 63 deletions tests/TestMslsBlogCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,61 @@ class TestMslsBlogCollection extends MslsUnitTestCase {
protected function setUp(): void {
parent::setUp(); // TODO: Change the autogenerated stub

$options = \Mockery::mock( MslsOptions::class );
$options->shouldReceive( 'get_order' )->andReturn( 'description' );
$options->shouldReceive( 'is_excluded' )->andReturn( false );
$options->shouldReceive( 'has_value' )->andReturn( false );

Functions\expect( 'msls_options' )->atLeast()->once()->andReturn( $options );

$a = \Mockery::mock( MslsBlog::class );
$b = \Mockery::mock( MslsBlog::class );
$c = \Mockery::mock( MslsBlog::class );

$a->userblog_id = 1;
$b->userblog_id = 2;
$c->userblog_id = 3;

Functions\expect( 'get_current_blog_id' )->atLeast()->once()->andReturn( 1 );
Functions\expect( 'get_users' )->atLeast()->once()->andReturn( [] );
Functions\expect( 'get_blogs_of_user' )->atLeast()->once()->andReturn( [ $a, $b, $c ] );

Functions\expect( 'get_blog_option' )->atLeast()->once()->andReturnUsing( function ( $blog_id, $option ) {
$wplang = [
1 => 'de_DE',
2 => 'it_IT',
3 => 'fr_FR',
];

$msls = [
1 => [ 'description' => 'Deutsch' ],
2 => [ 'description' => 'Italiano' ],
3 => [ 'description' => 'Français' ],
];

switch ( $option ) {
case 'active_plugins':
$value = in_array( $blog_id, [ 1, 2 ]
) ? [ 'multisite-language-switcher/MultisiteLanguageSwitcher.php' ] : [];
break;
case 'WPLANG':
$value = $wplang[ $blog_id ] ?? false;
break;
case 'msls':
$value = $msls[ $blog_id ] ?? false;
break;
$options = \Mockery::mock( MslsOptions::class );
$options->shouldReceive( 'get_order' )->andReturn( 'description' );
$options->shouldReceive( 'is_excluded' )->andReturn( false );
$options->shouldReceive( 'has_value' )->andReturn( false );

Functions\expect( 'msls_options' )->atLeast()->once()->andReturn( $options );

$a = \Mockery::mock( MslsBlog::class );
$b = \Mockery::mock( MslsBlog::class );
$c = \Mockery::mock( MslsBlog::class );

$a->userblog_id = 1;
$b->userblog_id = 2;
$c->userblog_id = 3;

Functions\expect( 'get_current_blog_id' )->atLeast()->once()->andReturn( 1 );
Functions\expect( 'get_users' )->atLeast()->once()->andReturn( array() );
Functions\expect( 'get_blogs_of_user' )->atLeast()->once()->andReturn( array( $a, $b, $c ) );

Functions\expect( 'get_blog_option' )->atLeast()->once()->andReturnUsing(
function ( $blog_id, $option ) {
$wplang = array(
1 => 'de_DE',
2 => 'it_IT',
3 => 'fr_FR',
);

$msls = array(
1 => array( 'description' => 'Deutsch' ),
2 => array( 'description' => 'Italiano' ),
3 => array( 'description' => 'Français' ),
);

switch ( $option ) {
case 'active_plugins':
$value = in_array(
$blog_id,
array( 1, 2 )
) ? array( 'multisite-language-switcher/MultisiteLanguageSwitcher.php' ) : array();
break;
case 'WPLANG':
$value = $wplang[ $blog_id ] ?? false;
break;
case 'msls':
$value = $msls[ $blog_id ] ?? false;
break;
}

return $value;
}

return $value;
} );
);
}

public function test_get_configured_blog_description_empty(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

Expand All @@ -81,7 +85,7 @@ public function test_get_configured_blog_description_empty(): void {
}

public function test_get_blogs_of_reference_user(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$options = \Mockery::mock( MslsOptions::class );
$options->shouldReceive( 'has_value' )->andReturn( true );
Expand All @@ -92,23 +96,23 @@ public function test_get_blogs_of_reference_user(): void {
}

public function test_get_current_blog_id(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

$this->assertIsInt( $obj->get_current_blog_id() );
}

public function test_has_current_blog(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

$this->assertIsBool( $obj->has_current_blog() );
}

public function test_is_current_blog_true(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

Expand All @@ -119,7 +123,7 @@ public function test_is_current_blog_true(): void {
}

public function test_is_current_blog_false(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

Expand All @@ -130,16 +134,25 @@ public function test_is_current_blog_false(): void {
}

public function test_get_objects(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

$this->assertIsArray( $obj->get_objects() );
}

public function test_get_object(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

$this->assertInstanceOf( MslsBlog::class, $obj->get_object( 1 ) );
$this->assertNull( $obj->get_object( 4 ) );
}

public function test_is_plugin_active_networkwide(): void {
Functions\expect( 'get_site_option' )->once()->andReturn(
[ 'multisite-language-switcher/MultisiteLanguageSwitcher.php' => 'Multisite Language Switcher' ]
array( 'multisite-language-switcher/MultisiteLanguageSwitcher.php' => 'Multisite Language Switcher' )
);

$obj = new MslsBlogCollection();
Expand All @@ -148,7 +161,7 @@ public function test_is_plugin_active_networkwide(): void {
}

public function test_is_plugin_active(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

Expand All @@ -159,23 +172,23 @@ public function test_is_plugin_active(): void {
}

public function test_get_plugin_active_blogs(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

$this->assertIsArray( $obj->get_plugin_active_blogs() );
}

public function test_get(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

$this->assertIsArray( $obj->get() );
}

public function test_get_filtered(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

Expand All @@ -184,23 +197,23 @@ public function test_get_filtered(): void {
}

public function test_get_users(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

$this->assertIsArray( $obj->get_users() );
}

public function test_get_current_blog(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

$this->assertInstanceOf( MslsBlog::class, $obj->get_current_blog() );
}

public function test_get_blog_language(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

Expand All @@ -212,7 +225,7 @@ public function test_get_blog_language(): void {
}

public function test_get_blog_id(): void {
Functions\expect( 'get_site_option' )->once()->andReturn( [] );
Functions\expect( 'get_site_option' )->once()->andReturn( array() );

$obj = new MslsBlogCollection();

Expand All @@ -221,5 +234,4 @@ public function test_get_blog_id(): void {

$this->assertNull( $obj->get_blog_id( 'fr_FR' ) );
}

}
Loading