From a66a0fb50d2df03373a91840499d4209af29e881 Mon Sep 17 00:00:00 2001 From: wpalani Date: Thu, 12 Oct 2023 13:26:52 -0700 Subject: [PATCH] Register admin submenu exclusively outside the app --- inc/Admin.php | 21 ++++---- tests/cypress/integration/navigation.cy.js | 58 +++++++++------------- 2 files changed, 35 insertions(+), 44 deletions(-) diff --git a/inc/Admin.php b/inc/Admin.php index 0fb3de94c..754b41667 100644 --- a/inc/Admin.php +++ b/inc/Admin.php @@ -90,15 +90,18 @@ public static function page() { 0 ); - foreach ( self::subpages() as $route => $title ) { - \add_submenu_page( - 'bluehost', - $title, - $title, - 'manage_options', - $route, - array( __CLASS__, 'render' ) - ); + // If we're outside of Bluehost, add subpages to Bluehost menu + if ( false === ( isset( $_GET['page'] ) && strpos( filter_input( INPUT_GET, 'page', FILTER_UNSAFE_RAW ), 'bluehost' ) >= 0 ) ) { // phpcs:ignore + foreach ( self::subpages() as $route => $title ) { + \add_submenu_page( + 'bluehost', + $title, + $title, + 'manage_options', + $route, + array( __CLASS__, 'render' ) + ); + } } } diff --git a/tests/cypress/integration/navigation.cy.js b/tests/cypress/integration/navigation.cy.js index 89237d861..c34e1c580 100644 --- a/tests/cypress/integration/navigation.cy.js +++ b/tests/cypress/integration/navigation.cy.js @@ -8,21 +8,17 @@ describe('Navigation', function () { }); + it('Admin submenu shouldn\'t exist inside app', () => { + cy + .get('#adminmenu #toplevel_page_bluehost ul.wp-submenu') + .should('not.exist'); + }); + it('Logo Links to home', () => { cy.get('.wppbh-logo-wrap').click(); cy.wait(500); cy.hash().should('eq', '#/home'); }); - - it('Admin Subnav properly highlights', () => { - cy - .get('#adminmenu #toplevel_page_bluehost') - .should('have.class', 'wp-has-current-submenu'); - cy - .get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /home/); - }); // test main nav it('Main nav links properly navigates', () => { @@ -35,10 +31,6 @@ describe('Navigation', function () { cy .get('.wppbh-app-navitem-Marketplace') .should('have.class', 'active'); - cy - .get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /marketplace/); cy.get('.wppbh-app-navitem-Performance').click(); cy.wait(500); @@ -49,18 +41,10 @@ describe('Navigation', function () { cy .get('.wppbh-app-navitem-Marketplace') .should('not.have.class', 'active'); - cy - .get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /performance/); cy.get('.wppbh-app-navitem-Settings').click(); cy.wait(500); cy.hash().should('eq', '#/settings'); - cy - .get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /settings/); }); it('Subnav links properly navigates', () => { @@ -76,10 +60,6 @@ describe('Navigation', function () { cy .get('.wppbh-app-navitem-Marketplace') .should('have.class', 'active'); - cy - .get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /marketplace/); cy.get('.wppbh-app-subnavitem-Services').click(); cy.wait(500); @@ -87,10 +67,6 @@ describe('Navigation', function () { cy .get('.wppbh-app-subnavitem-Services') .should('have.class', 'active'); - cy - .get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /marketplace/); cy .get('.wppbh-app-navitem-Marketplace') .should('have.class', 'active'); @@ -105,14 +81,10 @@ describe('Navigation', function () { cy .get('.wppbh-app-subnavitem-Services') .should('not.have.class', 'active'); - cy - .get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li.current a') - .should('have.attr', 'href') - .and('match', /marketplace/); cy .get('.wppbh-app-navitem-Marketplace') .should('have.class', 'active'); - + cy.get('.wppbh-app-navitem-Performance').click(); cy.wait(500); cy @@ -126,6 +98,22 @@ describe('Navigation', function () { .should('not.have.class', 'active'); }); + it('Admin submenu exist outside the app', () => { + cy.visit('/wp-admin/index.php'); + cy + .get('#adminmenu #toplevel_page_bluehost ul.wp-submenu') + .should('exist'); + cy + .get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li a[href="admin.php?page=bluehost#/home"]') + .should('exist'); + cy + .get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li a[href="admin.php?page=bluehost#/marketplace"]') + .should('exist'); + cy + .get('#adminmenu #toplevel_page_bluehost ul.wp-submenu li a[href="admin.php?page=bluehost#/settings"]') + .should('exist'); + }); + // utility nav is no more, leaving this in place un case we bring it back anytime soon. it.skip('Utility nav links properly navigates', () => { cy