Skip to content

Commit ec17b8e

Browse files
committed
Merge branch 'trunk' into trac-63842
2 parents a0e9ae0 + abc5dd8 commit ec17b8e

File tree

3 files changed

+68
-55
lines changed

3 files changed

+68
-55
lines changed

.github/workflows/phpunit-tests.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ jobs:
202202
matrix:
203203
os: [ ubuntu-24.04 ]
204204
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
205-
db-type: [ 'mysql' ]
206-
db-version: [ '9.4' ]
205+
db-type: [ 'mysql', 'mariadb' ]
206+
db-version: [ '9.4', '12.0' ]
207207
multisite: [ false, true ]
208208
memcached: [ false ]
209209
db-innovation: [ true ]
@@ -214,6 +214,11 @@ jobs:
214214
db-version: '9.4'
215215
- php: '7.3'
216216
db-version: '9.4'
217+
# Exclude version combinations that don't exist.
218+
- db-type: 'mariadb'
219+
db-version: '9.4'
220+
- db-type: 'mysql'
221+
db-version: '12.0'
217222
with:
218223
os: ${{ matrix.os }}
219224
php: ${{ matrix.php }}

tests/phpunit/tests/adminbar.php

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -731,40 +731,39 @@ public function test_customize_link() {
731731
/**
732732
* @ticket 39082
733733
* @group ms-required
734+
* @dataProvider data_my_sites_network_menu_items
734735
*/
735-
public function test_my_sites_network_menu_for_regular_user() {
736+
public function test_my_sites_network_menu_for_regular_user( $id, $cap ) {
736737
wp_set_current_user( self::$editor_id );
737738

738739
$wp_admin_bar = $this->get_standard_admin_bar();
739740

740741
$nodes = $wp_admin_bar->get_nodes();
741-
foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) {
742-
$this->assertArrayNotHasKey( $id, $nodes, sprintf( 'Menu item %s must not display for a regular user.', $id ) );
743-
}
742+
$this->assertArrayNotHasKey( $id, $nodes, sprintf( 'Menu item %s must not display for a regular user.', $id ) );
744743
}
745744

746745
/**
747746
* @ticket 39082
748747
* @group ms-required
748+
* @dataProvider data_my_sites_network_menu_items
749749
*/
750-
public function test_my_sites_network_menu_for_super_admin() {
750+
public function test_my_sites_network_menu_for_super_admin( $id, $cap ) {
751751
wp_set_current_user( self::$editor_id );
752752

753753
grant_super_admin( self::$editor_id );
754754
$wp_admin_bar = $this->get_standard_admin_bar();
755755
revoke_super_admin( self::$editor_id );
756756

757757
$nodes = $wp_admin_bar->get_nodes();
758-
foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) {
759-
$this->assertArrayHasKey( $id, $nodes, sprintf( 'Menu item %s must display for a super admin.', $id ) );
760-
}
758+
$this->assertArrayHasKey( $id, $nodes, sprintf( 'Menu item %s must display for a super admin.', $id ) );
761759
}
762760

763761
/**
764762
* @ticket 39082
765763
* @group ms-required
764+
* @dataProvider data_my_sites_network_menu_items
766765
*/
767-
public function test_my_sites_network_menu_for_regular_user_with_network_caps() {
766+
public function test_my_sites_network_menu_for_regular_user_with_network_caps( $id, $cap ) {
768767
global $current_user;
769768

770769
$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()
780779
}
781780

782781
$nodes = $wp_admin_bar->get_nodes();
783-
foreach ( $this->get_my_sites_network_menu_items() as $id => $cap ) {
784-
if ( in_array( $cap, $network_user_caps, true ) ) {
785-
$this->assertArrayHasKey( $id, $nodes, sprintf( 'Menu item %1$s must display for a user with the %2$s cap.', $id, $cap ) );
786-
} else {
787-
$this->assertArrayNotHasKey( $id, $nodes, sprintf( 'Menu item %1$s must not display for a user without the %2$s cap.', $id, $cap ) );
788-
}
782+
if ( in_array( $cap, $network_user_caps, true ) ) {
783+
$this->assertArrayHasKey( $id, $nodes, sprintf( 'Menu item %1$s must display for a user with the %2$s cap.', $id, $cap ) );
784+
} else {
785+
$this->assertArrayNotHasKey( $id, $nodes, sprintf( 'Menu item %1$s must not display for a user without the %2$s cap.', $id, $cap ) );
789786
}
790787
}
791788

792-
private function get_my_sites_network_menu_items() {
789+
/**
790+
* Data provider for test_my_sites_network_menu_for_regular_user() and
791+
* test_my_sites_network_menu_for_super_admin().
792+
*
793+
* @return array {
794+
* @type array {
795+
* @type string $id The ID of the menu item.
796+
* @type string $cap The capability required to see the menu item.
797+
* }
798+
* }
799+
*/
800+
public function data_my_sites_network_menu_items() {
793801
return array(
794-
'my-sites-super-admin' => 'manage_network',
795-
'network-admin' => 'manage_network',
796-
'network-admin-d' => 'manage_network',
797-
'network-admin-s' => 'manage_sites',
798-
'network-admin-u' => 'manage_network_users',
799-
'network-admin-t' => 'manage_network_themes',
800-
'network-admin-p' => 'manage_network_plugins',
801-
'network-admin-o' => 'manage_network_options',
802+
array( 'my-sites-super-admin', 'manage_network' ),
803+
array( 'network-admin', 'manage_network' ),
804+
array( 'network-admin-d', 'manage_network' ),
805+
array( 'network-admin-s', 'manage_sites' ),
806+
array( 'network-admin-u', 'manage_network_users' ),
807+
array( 'network-admin-t', 'manage_network_themes' ),
808+
array( 'network-admin-p', 'manage_network_plugins' ),
809+
array( 'network-admin-o', 'manage_network_options' ),
802810
);
803811
}
804812

tests/phpunit/tests/auth.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,26 @@ public function test_auth_cookie_generated_with_plain_bcrypt_hash_remains_valid(
132132

133133
/**
134134
* @ticket 23494
135+
* @dataProvider data_passwords_for_trimming
135136
*/
136-
public function test_password_trimming() {
137-
$passwords_to_test = array(
138-
'a password with no trailing or leading spaces',
139-
'a password with trailing spaces ',
140-
' a password with leading spaces',
141-
' a password with trailing and leading spaces ',
142-
);
137+
public function test_password_trimming( $password_to_test ) {
138+
wp_set_password( $password_to_test, $this->user->ID );
139+
$authed_user = wp_authenticate( $this->user->user_login, $password_to_test );
143140

144-
foreach ( $passwords_to_test as $password_to_test ) {
145-
wp_set_password( $password_to_test, $this->user->ID );
146-
$authed_user = wp_authenticate( $this->user->user_login, $password_to_test );
141+
$this->assertNotWPError( $authed_user );
142+
$this->assertInstanceOf( 'WP_User', $authed_user );
143+
$this->assertSame( $this->user->ID, $authed_user->ID );
144+
}
147145

148-
$this->assertNotWPError( $authed_user );
149-
$this->assertInstanceOf( 'WP_User', $authed_user );
150-
$this->assertSame( $this->user->ID, $authed_user->ID );
151-
}
146+
public function data_passwords_for_trimming() {
147+
return array(
148+
'no spaces' => array( 'a password with no trailing or leading spaces' ),
149+
'trailing space' => array( 'a password with trailing spaces ' ),
150+
'leading space' => array( ' a password with leading spaces' ),
151+
'leading and trailing' => array( ' a password with trailing and leading spaces ' ),
152+
'multiple leading spaces' => array( ' a password with multiple leading spaces' ),
153+
'multiple trailing spaces' => array( 'a password with multiple trailing spaces ' ),
154+
);
152155
}
153156

154157
/**
@@ -180,23 +183,20 @@ public function test_wp_set_password_action() {
180183
* wp_hash_password function
181184
*
182185
* @ticket 24973
186+
* @dataProvider data_passwords_with_whitespace
183187
*/
184-
public function test_wp_hash_password_trimming() {
185-
186-
$password = ' pass with leading whitespace';
187-
$this->assertTrue( wp_check_password( 'pass with leading whitespace', wp_hash_password( $password ) ) );
188-
189-
$password = 'pass with trailing whitespace ';
190-
$this->assertTrue( wp_check_password( 'pass with trailing whitespace', wp_hash_password( $password ) ) );
191-
192-
$password = ' pass with whitespace ';
193-
$this->assertTrue( wp_check_password( 'pass with whitespace', wp_hash_password( $password ) ) );
194-
195-
$password = "pass with new line \n";
196-
$this->assertTrue( wp_check_password( 'pass with new line', wp_hash_password( $password ) ) );
188+
public function test_wp_hash_password_trimming( $password_with_whitespace, $expected_password ) {
189+
$this->assertTrue( wp_check_password( $expected_password, wp_hash_password( $password_with_whitespace ) ) );
190+
}
197191

198-
$password = "pass with vertical tab o_O\x0B";
199-
$this->assertTrue( wp_check_password( 'pass with vertical tab o_O', wp_hash_password( $password ) ) );
192+
public function data_passwords_with_whitespace() {
193+
return array(
194+
'leading whitespace' => array( ' pass with leading whitespace', 'pass with leading whitespace' ),
195+
'trailing whitespace' => array( 'pass with trailing whitespace ', 'pass with trailing whitespace' ),
196+
'both whitespace' => array( ' pass with whitespace ', 'pass with whitespace' ),
197+
'new line' => array( "pass with new line \n", 'pass with new line' ),
198+
'vertical tab' => array( "pass with vertical tab o_O\x0B", 'pass with vertical tab o_O' ),
199+
);
200200
}
201201

202202
/**

0 commit comments

Comments
 (0)