@@ -1830,13 +1830,49 @@ public function test_multisite_administrator_can_not_edit_users() {
18301830 $ this ->assertFalse ( current_user_can ( 'edit_user ' , $ other_user ->ID ) );
18311831 }
18321832
1833- public function test_user_can_edit_self () {
1834- foreach ( self ::$ users as $ role => $ user ) {
1835- wp_set_current_user ( $ user ->ID );
1836- $ this ->assertTrue ( current_user_can ( 'edit_user ' , $ user ->ID ), "User with role {$ role } should have the capability to edit their own profile " );
1833+ /**
1834+ * Test if a user can edit their own profile based on their role.
1835+ *
1836+ * @ticket 63684
1837+ *
1838+ * @dataProvider data_user_can_edit_self
1839+ *
1840+ * @param string $role The role of the user.
1841+ * @param bool $can_edit_self Whether the user can edit their own profile.
1842+ */
1843+ public function test_user_can_edit_self ( $ role , $ can_edit_self = true ) {
1844+ $ user = self ::$ users [ $ role ];
1845+ wp_set_current_user ( $ user ->ID );
1846+
1847+ if ( $ can_edit_self ) {
1848+ $ this ->assertTrue (
1849+ current_user_can ( 'edit_user ' , $ user ->ID ),
1850+ "User with role ' {$ role }' should have the capability to edit their own profile "
1851+ );
1852+ } else {
1853+ $ this ->assertFalse (
1854+ current_user_can ( 'edit_user ' , $ user ->ID ),
1855+ "User with role ' {$ role }' should not have the capability to edit their own profile "
1856+ );
18371857 }
18381858 }
18391859
1860+ /**
1861+ * Data provider for test_user_can_edit_self.
1862+ *
1863+ * @return array[] Data provider.
1864+ */
1865+ public static function data_user_can_edit_self () {
1866+ return array (
1867+ 'anonymous ' => array ( 'anonymous ' , false ),
1868+ 'administrator ' => array ( 'administrator ' , true ),
1869+ 'editor ' => array ( 'editor ' , true ),
1870+ 'author ' => array ( 'author ' , true ),
1871+ 'contributor ' => array ( 'contributor ' , true ),
1872+ 'subscriber ' => array ( 'subscriber ' , true ),
1873+ );
1874+ }
1875+
18401876 public function test_only_admins_and_super_admins_can_remove_users () {
18411877 if ( is_multisite () ) {
18421878 $ this ->assertTrue ( user_can ( self ::$ super_admin ->ID , 'remove_user ' , self ::$ users ['subscriber ' ]->ID ) );
0 commit comments