diff --git a/includes/MslsAdmin.php b/includes/MslsAdmin.php index 6bee6dae..a705c7fa 100644 --- a/includes/MslsAdmin.php +++ b/includes/MslsAdmin.php @@ -126,7 +126,7 @@ public function __call( $method, $args ) { * * @return bool */ - public function has_problems(): bool { + public function has_problems(): void { $message = ''; if ( $this->options->is_empty() ) { @@ -148,7 +148,7 @@ public function has_problems(): bool { ); } - return MslsPlugin::message_handler( $message, 'updated fade' ); + MslsPlugin::message_handler( $message, 'updated fade' ); } /** diff --git a/includes/MslsPlugin.php b/includes/MslsPlugin.php index d401793f..03aaf49b 100644 --- a/includes/MslsPlugin.php +++ b/includes/MslsPlugin.php @@ -190,7 +190,13 @@ public function init_i18n_support(): void { */ public static function message_handler( $message, $css_class = 'error' ) { if ( ! empty( $message ) ) { - printf( '
%s
%s
.*$/' ); - - $this->assertTrue( $obj->has_problems() ); + public static function has_problems_data(): array { + return array( + array( array( 'de_DE', 'it_IT' ), false, '/^$/' ), + array( array( 'de_DE' ), false, '/^
.*$/' ), + array( array(), true, '/^
.*$/' ), + ); } - public function test_has_problems_is_empty(): void { + /** + * @dataProvider has_problems_data + */ + public function test_has_problems( array $languages, bool $is_empty, string $regex ): void { Functions\when( 'get_option' )->justReturn( array() ); Functions\when( 'get_current_blog_id' )->justReturn( 1 ); Functions\when( 'admin_url' )->justReturn( '' ); $options = \Mockery::mock( MslsOptions::class ); - $options->shouldReceive( 'is_empty' )->andReturns( true ); + $options->shouldReceive( 'get_available_languages' )->zeroOrMoreTimes()->andReturns( $languages ); $collection = \Mockery::mock( MslsBlogCollection::class ); + $options->shouldReceive( 'is_empty' )->once()->andReturns( $is_empty ); - $obj = new MslsAdmin( $options, $collection ); - - $this->expectOutputRegex( '/^
.*$/' ); + $this->expectOutputRegex( $regex ); - $this->assertTrue( $obj->has_problems() ); + ( new MslsAdmin( $options, $collection ) )->has_problems(); } public function test_subsubsub(): void {