Skip to content

Commit

Permalink
Hook timing
Browse files Browse the repository at this point in the history
  • Loading branch information
lloc committed Jan 17, 2024
1 parent 7e69543 commit 88e0ee1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 5 additions & 4 deletions includes/MslsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,10 @@ public static function init() {
}

add_action( 'init', [ $obj, 'admin_bar_init' ] );
add_action( 'admin_enqueue_scripts', [ $obj, 'custom_enqueue' ] );

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

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' ] );
Expand Down Expand Up @@ -268,6 +265,10 @@ public function admin_bar_init() {
* @return boolean
*/
public function custom_enqueue() {
if ( ! is_admin_bar_showing() ) {
return false;
}

$ver = defined( 'MSLS_PLUGIN_VERSION' ) ? constant( 'MSLS_PLUGIN_VERSION' ) : false;
$postfix = defined( 'SCRIPT_DEBUG' ) && constant( 'SCRIPT_DEBUG' ) ? '' : '.min';

Expand Down
16 changes: 15 additions & 1 deletion tests/test-mslsplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class WP_Test_MslsPlugin extends Msls_UnitTestCase {

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

Expand All @@ -21,19 +22,32 @@ function test_admin_menu_without_autocomplete(): void {
}

function test_admin_menu_with_autocomplete(): void {
Functions\expect( 'is_admin_bar_showing' )->once()->andReturnTrue();
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;

$test = new MslsPlugin( $options );

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

function test_init_widget_not_excluded(): void {
function test_admin_menu_admin_bar_not_showing(): void {
Functions\expect( 'is_admin_bar_showing' )->once()->andReturnFalse();

$options = \Mockery::mock( MslsOptions::class );

$options->activate_autocomplete = true;

$test = new MslsPlugin( $options );

$this->assertFalse( $test->custom_enqueue() );
}
function test_init_widget_not_excluded(): void {
Functions\expect( 'register_widget' )->once();

$options = \Mockery::mock( MslsOptions::class );
Expand Down

0 comments on commit 88e0ee1

Please sign in to comment.