Skip to content

Commit

Permalink
Merge pull request #272 from lloc/count-against-double-output
Browse files Browse the repository at this point in the history
Count against double output
  • Loading branch information
lloc authored Jan 17, 2024
2 parents 322174d + 7e69543 commit a6e4df8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
6 changes: 4 additions & 2 deletions includes/MslsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ public static function init() {

\lloc\Msls\ContentImport\Service::instance()->register();

if ( is_admin() ) {
if ( is_admin() || is_admin_bar_showing() ) {
add_action( 'admin_enqueue_scripts', [ $obj, 'custom_enqueue' ] );
}

if ( is_admin() ) {
add_action( 'admin_menu', [ MslsAdmin::class, 'init' ] );
add_action( 'load-post.php', [ MslsMetaBox::class, 'init' ] );
add_action( 'load-post-new.php', [ MslsMetaBox::class, 'init' ] );
Expand Down Expand Up @@ -261,7 +263,7 @@ public function admin_bar_init() {
/**
* Loads styles and some js if needed
*
* The method returns true if JS is loaded or false if not
* The method returns true if the autocomplete-option is activated, false otherwise.
*
* @return boolean
*/
Expand Down
64 changes: 46 additions & 18 deletions tests/test-mslsplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,48 @@

class WP_Test_MslsPlugin extends Msls_UnitTestCase {

function get_test() {
function test_admin_menu_without_autocomplete(): void {
Functions\expect( 'wp_enqueue_style' )->twice();
Functions\expect( 'plugins_url' )->twice()->andReturn( 'https://lloc.de/wp-content/plugins' );

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

return new MslsPlugin( $options );
$test = new MslsPlugin( $options );

$this->assertFalse( $test->custom_enqueue() );
}

/**
* Verify the static init-method
*/
function test_admin_menu(): void {
Functions\when( 'wp_enqueue_style' )->returnArg();
Functions\when( 'plugins_url' )->justReturn( 'https://lloc.de/wp-content/plugins' );
function test_admin_menu_with_autocomplete(): void {
Functions\expect( 'wp_enqueue_style' )->twice();
Functions\expect( 'plugins_url' )->times( 3 )->andReturn( 'https://lloc.de/wp-content/plugins' );
Functions\expect( 'wp_enqueue_script' )->once();

$options = \Mockery::mock( MslsOptions::class );
$options->activate_autocomplete = true;

$this->assertIsBool( $this->get_test()->custom_enqueue() );
$test = new MslsPlugin( $options );

$this->assertTrue( $test->custom_enqueue() );
}

/**
* Verify the static init_widget-method
*/
function test_init_widget(): void {
Functions\when( 'register_widget' )->justReturn( true );
function test_init_widget_not_excluded(): void {
Functions\expect( 'register_widget' )->once();

$options = \Mockery::mock( MslsOptions::class );
$options->shouldReceive( 'is_excluded' )->andReturnFalse();

$test = new MslsPlugin( $options );

$this->assertIsBool( $this->get_test()->init_widget() );
$this->assertTrue( $test->init_widget() );
}

function test_init_widget_excluded(): void {
$options = \Mockery::mock( MslsOptions::class );
$options->shouldReceive( 'is_excluded' )->andReturnTrue();

$test = new MslsPlugin( $options );

$this->assertFalse( $test->init_widget() );
}

/**
Expand All @@ -41,7 +59,12 @@ function test_init_widget(): void {
function test_init_i18n_support(): void {
Functions\when( 'load_plugin_textdomain' )->justReturn( true );

$this->assertIsBool( $this->get_test()->init_i18n_support() );
$options = \Mockery::mock( MslsOptions::class );
$options->shouldReceive( 'is_excluded' )->andReturn( false );

$test = new MslsPlugin( $options );

$this->assertIsBool( $test->init_i18n_support() );
}

/**
Expand All @@ -59,7 +82,12 @@ function test_message_handler(): void {
function test_uninstall(): void {
Functions\when( 'delete_option' )->justReturn( false );

$this->assertIsBool( $this->get_test()->uninstall() );
$options = \Mockery::mock( MslsOptions::class );
$options->shouldReceive( 'is_excluded' )->andReturn( false );

$test = new MslsPlugin( $options );

$this->assertIsBool( $test->uninstall() );
}

/**
Expand Down

0 comments on commit a6e4df8

Please sign in to comment.