-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Admin Menu: Adding tests to test Jetpack admin menu 'current' menu it…
…em class and menu order (#39374)
- Loading branch information
1 parent
09ea56a
commit 6861b10
Showing
3 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/add-jetpack-admin-menu-tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: other | ||
|
||
Admin menu: Adding tests to check for 'current' class when menu item selected. |
106 changes: 106 additions & 0 deletions
106
projects/plugins/jetpack/tests/php/general/test_jetpack-admin-menu.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
/** | ||
* @package automattic/jetpack | ||
*/ | ||
|
||
use Automattic\Jetpack\Backup\V0004\Jetpack_Backup; | ||
use Automattic\Jetpack\Stats_Admin\Dashboard; | ||
use Automattic\Jetpack\VideoPress\Admin_UI; | ||
use Automattic\Jetpack\WordAds\Dashboard as WordAdsDashboard; | ||
/** | ||
* Class WP_Test_Jetpack_Admin_Menu | ||
*/ | ||
class WP_Test_Jetpack_Admin_Menu extends WP_UnitTestCase { | ||
|
||
/** | ||
* Set up. | ||
*/ | ||
public function set_up() { | ||
parent::set_up(); | ||
// Create a user and set it up as current. | ||
$user_id = self::factory()->user->create_and_get( | ||
array( | ||
'role' => 'administrator', | ||
) | ||
); | ||
wp_set_current_user( $user_id->ID ); | ||
|
||
// Mock a connection | ||
Jetpack_Options::update_option( 'master_user', $user_id->ID ); | ||
Jetpack_Options::update_option( 'id', 1234 ); | ||
Jetpack_Options::update_option( 'blog_token', 'asdasd.123123' ); | ||
Jetpack_Options::update_option( 'user_tokens', array( $user_id->ID => "honey.badger.$user_id->ID" ) ); | ||
} | ||
|
||
/** | ||
* Tear down. | ||
*/ | ||
public function tear_down() { | ||
parent::tear_down(); | ||
Jetpack_Options::delete_option( 'master_user' ); | ||
Jetpack_Options::delete_option( 'id' ); | ||
Jetpack_Options::delete_option( 'blog_token' ); | ||
Jetpack_Options::delete_option( 'user_tokens' ); | ||
} | ||
|
||
/** | ||
* Test the order of many of the Jetpack admin menu items. | ||
* | ||
* @see https://github.com/Automattic/jetpack-roadmap/issues/856#issuecomment-2308599496 | ||
*/ | ||
public function test_jetpack_admin_menu_order() { | ||
global $submenu; | ||
|
||
require_once JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class.jetpack-react-page.php'; | ||
$jetpack_react = new Jetpack_React_Page(); | ||
$jetpack_react->jetpack_add_dashboard_sub_nav_item(); | ||
$jetpack_react->jetpack_add_settings_sub_nav_item(); | ||
|
||
$jetpack_stats = new Dashboard(); | ||
$jetpack_stats::init(); | ||
|
||
$jetpack_video = new Admin_UI(); | ||
$jetpack_video->init(); | ||
|
||
$jetpack_wordads = new WordAdsDashboard(); | ||
$jetpack_wordads->init_hooks(); | ||
|
||
$jetpack_backup = new Jetpack_Backup(); | ||
$jetpack_backup->initialize(); | ||
|
||
do_action( 'admin_menu' ); | ||
|
||
if ( ! isset( $submenu['jetpack'] ) ) { | ||
return; | ||
} | ||
|
||
$submenu_names = array_column( $submenu['jetpack'], 3 ); | ||
// Capture the positions of these submenu items. | ||
$stats_submenu_position = array_search( 'Stats', $submenu_names, true ); | ||
$videopress_submenu_position = array_search( 'Jetpack VideoPress', $submenu_names, true ); | ||
$backup_submenu_position = array_search( 'Jetpack VaultPress Backup', $submenu_names, true ); | ||
$search_submenu_position = array_search( 'Jetpack Search', $submenu_names, true ); | ||
$wordads_submenu_position = array_search( 'WordAds Settings', $submenu_names, true ); | ||
$settings_submenu_position = array_search( 'Settings', $submenu_names, true ); | ||
$dashboard_submenu_position = array_search( 'Dashboard', $submenu_names, true ); | ||
|
||
// Some sites - multisites / WoA for example - may not have all of the menu items. | ||
if ( in_array( 'My Jetpack', $submenu_names, true ) ) { | ||
$my_jetpack_submenu_position = array_search( 'My Jetpack', $submenu_names, true ); | ||
$this->assertTrue( $my_jetpack_submenu_position < $stats_submenu_position, 'My Jetpack should be above Stats in the submenu order.' ); | ||
} | ||
|
||
if ( in_array( 'Activity Log', $submenu_names, true ) ) { | ||
$activity_log_submenu_position = array_search( 'Activity Log', $submenu_names, true ); | ||
$this->assertTrue( $activity_log_submenu_position < $search_submenu_position, 'Activity Log should be above Search in the submenu order.' ); | ||
$this->assertTrue( $backup_submenu_position < $activity_log_submenu_position, 'Jetpack VaultPress Backup should be above Activity Log in the submenu order.' ); | ||
} | ||
|
||
$this->assertTrue( $stats_submenu_position < $videopress_submenu_position, 'Stats should be above VideoPress in the submenu order.' ); | ||
$this->assertTrue( $videopress_submenu_position < $backup_submenu_position, 'Jetpack VideoPress should be above Jetpack VaultPress Backup in the submenu order.' ); | ||
$this->assertTrue( $backup_submenu_position < $search_submenu_position, 'Jetpack VaultPress Backup should be above Search in the submenu order.' ); | ||
$this->assertTrue( $search_submenu_position < $wordads_submenu_position, 'Search should be above WordAds in the submenu order.' ); | ||
$this->assertTrue( $wordads_submenu_position < $settings_submenu_position, 'WordAds should be above Settings in the submenu order.' ); | ||
$this->assertTrue( $settings_submenu_position < $dashboard_submenu_position, 'Settings should be above Dashboard in the submenu order.' ); | ||
} | ||
} |