diff --git a/admin/class-admin.php b/admin/class-admin.php index 0fce92c2..c1b05bbb 100644 --- a/admin/class-admin.php +++ b/admin/class-admin.php @@ -16,9 +16,21 @@ class Admin { /** - * Class constructor. + * Meta boxes instance. + * + * @since 1.10.0 + * + * @var Meta_Boxes */ - public function __construct() { + private Meta_Boxes $meta_boxes; + + /** + * Class constructor for injecting dependencies. + * + * @param Meta_Boxes|null $meta_boxes Meta boxes instance. + */ + public function __construct( Meta_Boxes $meta_boxes = null ) { + $this->meta_boxes = $meta_boxes; } /** @@ -26,7 +38,7 @@ public function __construct() { * * @return void */ - public function init() { + public function init(): void { $update_database = new Update_Database(); $update_database->init_hooks(); @@ -44,6 +56,8 @@ public function init() { $site_health_info->init_hooks(); $this->init_ajax(); + + $this->meta_boxes->init_hooks(); } /** @@ -51,7 +65,7 @@ public function init() { * * @return void */ - private function init_ajax() { + private function init_ajax(): void { if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) { return; } diff --git a/includes/classes/class-plugin.php b/includes/classes/class-plugin.php index 9108e268..b2ea553d 100644 --- a/includes/classes/class-plugin.php +++ b/includes/classes/class-plugin.php @@ -8,6 +8,7 @@ namespace EDAC\Inc; use EDAC\Admin\Admin; +use EDAC\Admin\Meta_Boxes; /** * Main plugin functionality class. @@ -19,7 +20,8 @@ class Plugin { */ public function __construct() { if ( \is_admin() ) { - $admin = new Admin(); + $meta_boxes = new Meta_Boxes(); + $admin = new Admin( $meta_boxes ); $admin->init(); } else { $this->init(); @@ -36,9 +38,9 @@ public function __construct() { * @return void */ private function init() { - + add_action( 'wp_enqueue_scripts', array( 'EDAC\Inc\Enqueue_Frontend', 'enqueue' ) ); - + $accessibility_statement = new Accessibility_Statement(); $accessibility_statement->init_hooks(); diff --git a/tests/phpunit/Admin/MetaBoxesTest.php b/tests/phpunit/Admin/MetaBoxesTest.php new file mode 100644 index 00000000..fbab350a --- /dev/null +++ b/tests/phpunit/Admin/MetaBoxesTest.php @@ -0,0 +1,77 @@ +getMockBuilder( Meta_Boxes::class ) + ->onlyMethods( array( 'register_meta_boxes' ) ) + ->getMock(); + + $meta_boxes->expects( $this->once() ) + ->method( 'register_meta_boxes' ); + + $this->invoke_admin_init( $meta_boxes ); + do_action( 'add_meta_boxes' ); + } + + /** + * Test the init_hooks method. + * + * @return void + */ + public function test_init_hooks(): void { + $meta_boxes = new Meta_Boxes(); + $meta_boxes->init_hooks(); + + $this->assertEquals( + 10, + has_action( + 'add_meta_boxes', + array( + $meta_boxes, + 'register_meta_boxes', + ) + ) + ); + } + + /** + * Test the render method. + * + * @return void + */ + public function test_render(): void { + $meta_boxes = new Meta_Boxes(); + $meta_boxes->render(); + + $this->expectOutputRegex( '/^