-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Use a real dataprovider instead of a method called and looped. #10137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
aaronjorbin
wants to merge
1
commit into
WordPress:trunk
from
aaronjorbin:trac-63167/admin-bar-dataprovider
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -731,40 +731,39 @@ public function test_customize_link() { | |||||||||||||
/** | ||||||||||||||
* @ticket 39082 | ||||||||||||||
* @group ms-required | ||||||||||||||
* @dataProvider data_my_sites_network_menu_items | ||||||||||||||
*/ | ||||||||||||||
public function test_my_sites_network_menu_for_regular_user() { | ||||||||||||||
public function test_my_sites_network_menu_for_regular_user( $id, $cap ) { | ||||||||||||||
wp_set_current_user( self::$editor_id ); | ||||||||||||||
|
||||||||||||||
$wp_admin_bar = $this->get_standard_admin_bar(); | ||||||||||||||
|
||||||||||||||
$nodes = $wp_admin_bar->get_nodes(); | ||||||||||||||
foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) { | ||||||||||||||
$this->assertArrayNotHasKey( $id, $nodes, sprintf( 'Menu item %s must not display for a regular user.', $id ) ); | ||||||||||||||
} | ||||||||||||||
$this->assertArrayNotHasKey( $id, $nodes, sprintf( 'Menu item %s must not display for a regular user.', $id ) ); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* @ticket 39082 | ||||||||||||||
* @group ms-required | ||||||||||||||
* @dataProvider data_my_sites_network_menu_items | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
*/ | ||||||||||||||
public function test_my_sites_network_menu_for_super_admin() { | ||||||||||||||
public function test_my_sites_network_menu_for_super_admin( $id, $cap ) { | ||||||||||||||
wp_set_current_user( self::$editor_id ); | ||||||||||||||
|
||||||||||||||
grant_super_admin( self::$editor_id ); | ||||||||||||||
$wp_admin_bar = $this->get_standard_admin_bar(); | ||||||||||||||
revoke_super_admin( self::$editor_id ); | ||||||||||||||
|
||||||||||||||
$nodes = $wp_admin_bar->get_nodes(); | ||||||||||||||
foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) { | ||||||||||||||
$this->assertArrayHasKey( $id, $nodes, sprintf( 'Menu item %s must display for a super admin.', $id ) ); | ||||||||||||||
} | ||||||||||||||
$this->assertArrayHasKey( $id, $nodes, sprintf( 'Menu item %s must display for a super admin.', $id ) ); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* @ticket 39082 | ||||||||||||||
* @group ms-required | ||||||||||||||
* @dataProvider data_my_sites_network_menu_items | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
*/ | ||||||||||||||
public function test_my_sites_network_menu_for_regular_user_with_network_caps() { | ||||||||||||||
public function test_my_sites_network_menu_for_regular_user_with_network_caps( $id, $cap ) { | ||||||||||||||
global $current_user; | ||||||||||||||
|
||||||||||||||
$network_user_caps = array( 'manage_network', 'manage_network_themes', 'manage_network_plugins' ); | ||||||||||||||
|
@@ -780,25 +779,34 @@ public function test_my_sites_network_menu_for_regular_user_with_network_caps() | |||||||||||||
} | ||||||||||||||
|
||||||||||||||
$nodes = $wp_admin_bar->get_nodes(); | ||||||||||||||
foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) { | ||||||||||||||
if ( in_array( $cap, $network_user_caps, true ) ) { | ||||||||||||||
$this->assertArrayHasKey( $id, $nodes, sprintf( 'Menu item %1$s must display for a user with the %2$s cap.', $id, $cap ) ); | ||||||||||||||
} else { | ||||||||||||||
$this->assertArrayNotHasKey( $id, $nodes, sprintf( 'Menu item %1$s must not display for a user without the %2$s cap.', $id, $cap ) ); | ||||||||||||||
} | ||||||||||||||
if ( in_array( $cap, $network_user_caps, true ) ) { | ||||||||||||||
$this->assertArrayHasKey( $id, $nodes, sprintf( 'Menu item %1$s must display for a user with the %2$s cap.', $id, $cap ) ); | ||||||||||||||
} else { | ||||||||||||||
$this->assertArrayNotHasKey( $id, $nodes, sprintf( 'Menu item %1$s must not display for a user without the %2$s cap.', $id, $cap ) ); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private function get_my_sites_network_menu_items() { | ||||||||||||||
/** | ||||||||||||||
* Data provider for test_my_sites_network_menu_for_regular_user() and | ||||||||||||||
* test_my_sites_network_menu_for_super_admin(). | ||||||||||||||
* | ||||||||||||||
* @return array { | ||||||||||||||
* @type array { | ||||||||||||||
* @type string $id The ID of the menu item. | ||||||||||||||
* @type string $cap The capability required to see the menu item. | ||||||||||||||
* } | ||||||||||||||
* } | ||||||||||||||
*/ | ||||||||||||||
public function data_my_sites_network_menu_items() { | ||||||||||||||
return array( | ||||||||||||||
'my-sites-super-admin' => 'manage_network', | ||||||||||||||
'network-admin' => 'manage_network', | ||||||||||||||
'network-admin-d' => 'manage_network', | ||||||||||||||
'network-admin-s' => 'manage_sites', | ||||||||||||||
'network-admin-u' => 'manage_network_users', | ||||||||||||||
'network-admin-t' => 'manage_network_themes', | ||||||||||||||
'network-admin-p' => 'manage_network_plugins', | ||||||||||||||
'network-admin-o' => 'manage_network_options', | ||||||||||||||
array( 'my-sites-super-admin', 'manage_network' ), | ||||||||||||||
array( 'network-admin', 'manage_network' ), | ||||||||||||||
array( 'network-admin-d', 'manage_network' ), | ||||||||||||||
array( 'network-admin-s', 'manage_sites' ), | ||||||||||||||
array( 'network-admin-u', 'manage_network_users' ), | ||||||||||||||
array( 'network-admin-t', 'manage_network_themes' ), | ||||||||||||||
array( 'network-admin-p', 'manage_network_plugins' ), | ||||||||||||||
array( 'network-admin-o', 'manage_network_options' ), | ||||||||||||||
); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.