You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b8631aa
Browse filesBrowse the repository at this point in the historyBrowse files
Tests: Cover private field visibility in core/users-query
Extend two existing tests to check that every private user field is returned only to the user and to callers who can edit them. Until now, only `email` and `roles` were checked for each role.
Developed in #16246.
Follow-up to r64346.
Props hmbashar, lancewillett.
See #66549.
git-svn-id: https://develop.svn.wordpress.org/trunk@65845 602fd350-edb4-49c9-b593-d223f7449a82
$this->assertIsArray( $result, 'A user should be able to read themselves by ID.' );
558
-
$this->assertSameSets( array( 'id', 'email', 'username', 'roles' ), array_keys( $result['items'][0] ), 'The current user should receive only the requested fields.' );
580
+
$this->assertSameSets( $fields, array_keys( $result['items'][0] ), 'The current user should receive only the requested fields.' );
559
581
$this->assertSame( self::$fixture_ids['public_author'], $result['items'][0]['id'], 'The ID lookup should return the current user.' );
560
582
$this->assertSame( 'core-users-ability-author@example.com', $result['items'][0]['email'], 'The current user should receive their own email.' );
561
583
$this->assertSame( 'core_users_ability_author', $result['items'][0]['username'], 'The current user should receive their own username.' );
584
+
$this->assertSame( 'Private', $result['items'][0]['first_name'], 'The current user should receive their own first name.' );
585
+
$this->assertSame( 'Person', $result['items'][0]['last_name'], 'The current user should receive their own last name.' );
586
+
$this->assertSame( 'hidden-nickname', $result['items'][0]['nickname'], 'The current user should receive their own nickname.' );
587
+
$this->assertSame( 'de_DE', $result['items'][0]['locale'], 'The current user should receive their own locale.' );
562
588
$this->assertContains( 'author', $result['items'][0]['roles'], 'The current user should receive their own roles.' );
$this->assertIsArray( $result, sprintf( 'The %s role should be able to execute a public-author lookup.', $role ) );
1887
1917
$this->assertSame( self::$fixture_ids['public_author'], $result['items'][0]['id'], sprintf( 'The %s role should receive the requested public author.', $role ) );
1888
-
$this->assertSame( $can_view_sensitive, array_key_exists( 'email', $result['items'][0] ), sprintf( 'The %s role email visibility should match expectations.', $role ) );
1918
+
$this->assertSame( 'A public biography.', $result['items'][0]['description'], sprintf( 'The %s role should receive the public description.', $role ) );
1919
+
$this->assertSame( 'https://example.org/author', $result['items'][0]['url'], sprintf( 'The %s role should receive the public URL.', $role ) );
1920
+
foreach ( $sensitive_fieldsas$field ) {
1921
+
$this->assertSame( $can_view_sensitive, array_key_exists( $field, $result['items'][0] ), sprintf( 'The %1$s role %2$s visibility should match expectations.', $role, $field ) );
1922
+
}
1889
1923
$this->assertSame( $can_view_roles, array_key_exists( 'roles', $result['items'][0] ), sprintf( 'The %s role roles visibility should match expectations.', $role ) );
1890
1924
1891
1925
if ( $can_view_sensitive ) {
1892
1926
$this->assertSame( 'core-users-ability-author@example.com', $result['items'][0]['email'], sprintf( 'The %s role should receive the public author email when allowed.', $role ) );
1927
+
$this->assertSame( 'Private', $result['items'][0]['first_name'], sprintf( 'The %s role should receive the public author first name when allowed.', $role ) );
1928
+
$this->assertSame( 'hidden-nickname', $result['items'][0]['nickname'], sprintf( 'The %s role should receive the public author nickname when allowed.', $role ) );
0 commit comments