diff --git a/includes/Admin/Admin_Page.php b/includes/Admin/Admin_Page.php new file mode 100644 index 000000000..8af87b65b --- /dev/null +++ b/includes/Admin/Admin_Page.php @@ -0,0 +1,74 @@ +get_available_plugins(); + + require WP_PLUGIN_CHECK_PLUGIN_DIR_PATH . '/templates/admin-page.php'; + } +} diff --git a/includes/Checker/Preparations/Use_Minimal_Theme_Preparation.php b/includes/Checker/Preparations/Use_Minimal_Theme_Preparation.php index 015de78c8..6d942ab81 100644 --- a/includes/Checker/Preparations/Use_Minimal_Theme_Preparation.php +++ b/includes/Checker/Preparations/Use_Minimal_Theme_Preparation.php @@ -71,7 +71,7 @@ public function prepare() { add_filter( 'pre_option_template_root', array( $this, 'get_theme_root' ) ); add_filter( 'pre_option_stylesheet_root', array( $this, 'get_theme_root' ) ); - // Register the custom themes directory if relevant. + // Registers the custom themes directory if relevant. if ( ! empty( $this->themes_dir ) ) { register_theme_directory( $this->themes_dir ); diff --git a/includes/Plugin_Main.php b/includes/Plugin_Main.php index 3f0199040..d5e0be9c3 100644 --- a/includes/Plugin_Main.php +++ b/includes/Plugin_Main.php @@ -7,6 +7,8 @@ namespace WordPress\Plugin_Check; +use WordPress\Plugin_Check\Admin\Admin_Page; + /** * Main class for the plugin. * @@ -52,5 +54,8 @@ public function context() { */ public function add_hooks() { // @TODO: Update to register CLI command to WordPress as part of issue #30 + + $admin_page = new Admin_Page(); + $admin_page->add_hooks(); } } diff --git a/templates/admin-page.php b/templates/admin-page.php new file mode 100644 index 000000000..009312801 --- /dev/null +++ b/templates/admin-page.php @@ -0,0 +1,44 @@ + + +
+ +

+ +
+ + + +
+

+ +

+ + + + +
+ + + +

+ + +
+ +
diff --git a/tests/Admin/Admin_Page_Tests.php b/tests/Admin/Admin_Page_Tests.php new file mode 100644 index 000000000..e89d812d3 --- /dev/null +++ b/tests/Admin/Admin_Page_Tests.php @@ -0,0 +1,121 @@ +admin_page = new Admin_Page(); + } + + public function test_add_hooks() { + $this->admin_page->add_hooks(); + $this->assertEquals( 10, has_action( 'admin_menu', array( $this->admin_page, 'add_page' ) ) ); + } + + public function test_add_page() { + global $_parent_pages; + + $current_screen = get_current_screen(); + + $admin_user = self::factory()->user->create( array( 'role' => 'administrator' ) ); + + if ( is_multisite() ) { + grant_super_admin( $admin_user ); + } + + wp_set_current_user( $admin_user ); + set_current_screen( 'dashboard' ); + + $this->admin_page->add_page(); + + $parent_pages = $_parent_pages; + + set_current_screen( $current_screen ); + + $this->assertArrayHasKey( 'plugin-check', $parent_pages ); + $this->assertEquals( 'tools.php', $parent_pages['plugin-check'] ); + } + + public function test_render_page() { + global $wp_object_cache; + + // Backup original plugins in the object cache. + $original_plugins = $wp_object_cache->get( 'plugins', 'plugins' ); + + // Create the basic information required get_available_plugins. + $expected_plugins = array( + 'hello.php' => array( + 'Name' => 'Hello Dolly', + ), + 'akismet/akismet.php' => array( + 'Name' => 'Akistmet', + ), + 'Fake-plugin/load.php' => array( + 'Name' => 'Fake Plugin', + ), + ); + + // Include the Plugin Checker plugin. + $plugin_basename = plugin_basename( WP_PLUGIN_CHECK_MAIN_FILE ); + $expected_plugins[ $plugin_basename ] = array( 'Name' => 'Plugin Checker' ); + + // Set the expected plugins in the cache. + $wp_object_cache->set( 'plugins', array( '' => $expected_plugins ), 'plugins' ); + + // Render the admin page. + ob_start(); + $this->admin_page->render_page(); + $output = ob_get_contents(); + ob_end_clean(); + + // Restore the original cache. + $wp_object_cache->set( 'plugins', $original_plugins, 'plugins' ); + + // Remove the plugin checker from exptected plugins for testing. + unset( $expected_plugins[ $plugin_basename ] ); + + // Assert the Plugin Checker does not appear in the select dropdown. + $this->assertStringNotContainsString( $plugin_basename, $output ); + + // Assert the expected plugins appear in the select dropdown. + foreach ( $expected_plugins as $plugin => $data ) { + $this->assertStringContainsString( '