Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

git-svn-id: https://develop.svn.wordpress.org/trunk@47122 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-01-29 00:43:23 +00:00
parent bd2cd572aa
commit cfc3b57488
810 changed files with 9893 additions and 8384 deletions
+58 -44
View File
@@ -1,7 +1,8 @@
<?php
// test functions in wp-includes/user.php
/**
* Test functions in wp-includes/user.php
*
* @group user
*/
class Tests_User extends WP_UnitTestCase {
@@ -66,7 +67,7 @@ class Tests_User extends WP_UnitTestCase {
}
function test_get_users_of_blog() {
// add one of each user role
// Add one of each user role.
$nusers = array(
self::$contrib_id,
self::$author_id,
@@ -77,98 +78,102 @@ class Tests_User extends WP_UnitTestCase {
$user_list = get_users();
// find the role of each user as returned by get_users_of_blog
// Find the role of each user as returned by get_users_of_blog().
$found = array();
foreach ( $user_list as $user ) {
// only include the users we just created - there might be some others that existed previously
// Only include the users we just created - there might be some others that existed previously.
if ( in_array( $user->ID, $nusers, true ) ) {
$found[] = $user->ID;
}
}
// make sure every user we created was returned
// Make sure every user we created was returned.
$this->assertEqualSets( $nusers, $found );
}
// simple get/set tests for user_option functions
// Simple get/set tests for user_option functions.
function test_user_option() {
$key = rand_str();
$val = rand_str();
// get an option that doesn't exist
// Get an option that doesn't exist.
$this->assertFalse( get_user_option( $key, self::$author_id ) );
// set and get
// Set and get.
update_user_option( self::$author_id, $key, $val );
$this->assertEquals( $val, get_user_option( $key, self::$author_id ) );
// change and get again
// Change and get again.
$val2 = rand_str();
update_user_option( self::$author_id, $key, $val2 );
$this->assertEquals( $val2, get_user_option( $key, self::$author_id ) );
}
// simple tests for usermeta functions
/**
* Simple tests for usermeta functions.
*/
function test_usermeta() {
$key = 'key';
$val = 'value1';
// get a meta key that doesn't exist
// Get a meta key that doesn't exist.
$this->assertEquals( '', get_user_meta( self::$author_id, $key, true ) );
// set and get
// Set and get.
update_user_meta( self::$author_id, $key, $val );
$this->assertEquals( $val, get_user_meta( self::$author_id, $key, true ) );
// change and get again
// Change and get again.
$val2 = 'value2';
update_user_meta( self::$author_id, $key, $val2 );
$this->assertEquals( $val2, get_user_meta( self::$author_id, $key, true ) );
// delete and get
// Delete and get.
delete_user_meta( self::$author_id, $key );
$this->assertEquals( '', get_user_meta( self::$author_id, $key, true ) );
// delete by key AND value
// Delete by key AND value.
update_user_meta( self::$author_id, $key, $val );
// incorrect key: key still exists
// Incorrect key: key still exists.
delete_user_meta( self::$author_id, $key, rand_str() );
$this->assertEquals( $val, get_user_meta( self::$author_id, $key, true ) );
// correct key: deleted
// Correct key: deleted.
delete_user_meta( self::$author_id, $key, $val );
$this->assertEquals( '', get_user_meta( self::$author_id, $key, true ) );
}
// test usermeta functions in array mode
/**
* Test usermeta functions in array mode.
*/
function test_usermeta_array() {
// some values to set
// Some values to set.
$vals = array(
rand_str() => 'val-' . rand_str(),
rand_str() => 'val-' . rand_str(),
rand_str() => 'val-' . rand_str(),
);
// there is already some stuff in the array
// There is already some stuff in the array.
$this->assertTrue( is_array( get_user_meta( self::$author_id ) ) );
foreach ( $vals as $k => $v ) {
update_user_meta( self::$author_id, $k, $v );
}
// get the complete usermeta array
// Get the complete usermeta array.
$out = get_user_meta( self::$author_id );
// for reasons unclear, the resulting array is indexed numerically; meta keys are not included anywhere.
// so we'll just check to make sure our values are included somewhere.
// For reasons unclear, the resulting array is indexed numerically; meta keys are not included anywhere.
// So we'll just check to make sure our values are included somewhere.
foreach ( $vals as $k => $v ) {
$this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] === $v );
}
// delete one key and check again
// Delete one key and check again.
$keys = array_keys( $vals );
$key_to_delete = array_pop( $keys );
delete_user_meta( self::$author_id, $key_to_delete );
$out = get_user_meta( self::$author_id );
// make sure that key is excluded from the results
// Make sure that key is excluded from the results.
foreach ( $vals as $k => $v ) {
if ( $k === $key_to_delete ) {
$this->assertFalse( isset( $out[ $k ] ) );
@@ -178,7 +183,9 @@ class Tests_User extends WP_UnitTestCase {
}
}
// Test property magic functions for property get/set/isset.
/**
* Test property magic functions for property get/set/isset.
*/
function test_user_properties() {
$user = new WP_User( self::$author_id );
@@ -191,7 +198,7 @@ class Tests_User extends WP_UnitTestCase {
$user->$key = 'foo';
$this->assertEquals( 'foo', $user->$key );
$this->assertEquals( 'foo', $user->data->$key ); // This will fail with WP < 3.3
$this->assertEquals( 'foo', $user->data->$key ); // This will fail with WP < 3.3.
foreach ( get_object_vars( $user ) as $key => $value ) {
$this->assertEquals( $value, $user->$key );
@@ -199,7 +206,7 @@ class Tests_User extends WP_UnitTestCase {
}
/**
* Test the magic __unset method
* Test the magic __unset() method.
*
* @ticket 20043
*/
@@ -207,7 +214,7 @@ class Tests_User extends WP_UnitTestCase {
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$user = new WP_User( self::$author_id );
// Test custom fields
// Test custom fields.
$user->customField = 123;
$this->assertEquals( $user->customField, 123 );
unset( $user->customField );
@@ -217,12 +224,13 @@ class Tests_User extends WP_UnitTestCase {
}
/**
* Test 'id' (lowercase).
*
* @depends test_user_unset
* @expectedDeprecated WP_User->id
* @ticket 20043
*/
function test_user_unset_lowercase_id( $user ) {
// Test 'id' (lowercase)
$id = $user->id;
unset( $user->id );
$this->assertSame( $id, $user->id );
@@ -230,17 +238,20 @@ class Tests_User extends WP_UnitTestCase {
}
/**
* Test 'ID'.
*
* @depends test_user_unset_lowercase_id
* @ticket 20043
*/
function test_user_unset_uppercase_id( $user ) {
// Test 'ID'
$this->assertNotEmpty( $user->ID );
unset( $user->ID );
$this->assertNotEmpty( $user->ID );
}
// Test meta property magic functions for property get/set/isset.
/**
* Test meta property magic functions for property get/set/isset.
*/
function test_user_meta_properties() {
$user = new WP_User( self::$author_id );
@@ -358,10 +369,10 @@ class Tests_User extends WP_UnitTestCase {
$user = new WP_User( self::$author_id );
$this->assertEquals( 'test user', $user->get( 'display_name' ) );
// Make sure there is no collateral damage to fields not in $user_data
// Make sure there is no collateral damage to fields not in $user_data.
$this->assertEquals( 'about me', $user->get( 'description' ) );
// Pass as stdClass
// Pass as stdClass.
$user_data = array(
'ID' => self::$author_id,
'display_name' => 'a test user',
@@ -376,7 +387,7 @@ class Tests_User extends WP_UnitTestCase {
$this->assertEquals( 'some test user', $user->get( 'display_name' ) );
// Test update of fields in _get_additional_user_keys()
// Test update of fields in _get_additional_user_keys().
$user_data = array(
'ID' => self::$author_id,
'use_ssl' => 1,
@@ -452,7 +463,7 @@ class Tests_User extends WP_UnitTestCase {
'post_type' => 'post',
);
// insert a post and make sure the ID is ok
// Insert a post and make sure the ID is OK.
$post_id = wp_insert_post( $post );
$this->assertTrue( is_numeric( $post_id ) );
@@ -477,6 +488,9 @@ class Tests_User extends WP_UnitTestCase {
$this->assertFalse( get_userdata( array( 'array' ) ) );
}
/**
* @ticket 23480
*/
function test_user_get_data_by_id() {
$user = WP_User::get_data_by( 'id', self::$author_id );
$this->assertInstanceOf( 'stdClass', $user );
@@ -569,7 +583,7 @@ class Tests_User extends WP_UnitTestCase {
$pwd_before = $user->user_pass;
wp_update_user( $user );
// Reload the data
// Reload the data.
$pwd_after = get_userdata( $testuserid )->user_pass;
$this->assertEquals( $pwd_before, $pwd_after );
}
@@ -746,7 +760,7 @@ class Tests_User extends WP_UnitTestCase {
array( 'testuser' ),
);
// Multisite doesn't allow mixed case logins ever
// Multisite doesn't allow mixed case logins ever.
if ( ! is_multisite() ) {
$data[] = array( 'TestUser' );
}
@@ -1287,7 +1301,7 @@ class Tests_User extends WP_UnitTestCase {
$existing_email = get_option( 'admin_email' );
$new_email = 'new-admin-email@test.dev';
// Give the site a name containing HTML entities
// Give the site a name containing HTML entities.
update_option( 'blogname', '&#039;Test&#039; blog&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;' );
update_option_new_admin_email( $existing_email, $new_email );
@@ -1297,10 +1311,10 @@ class Tests_User extends WP_UnitTestCase {
$recipient = $mailer->get_recipient( 'to' );
$email = $mailer->get_sent();
// Assert reciepient is correct
// Assert recipient is correct.
$this->assertSame( $new_email, $recipient->address, 'Admin email change notification recipient not as expected' );
// Assert that HTML entites have been decode in body and subject
// Assert that HTML entites have been decode in body and subject.
$this->assertContains( '\'Test\' blog\'s "name" has <html entities> &', $email->subject, 'Email subject does not contain the decoded HTML entities' );
$this->assertNotContains( '&#039;Test&#039; blog&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;', $email->subject, $email->subject, 'Email subject does contains HTML entities' );
}
@@ -1573,7 +1587,7 @@ class Tests_User extends WP_UnitTestCase {
reset_phpmailer_instance();
// Give the site a name containing HTML entities
// Give the site a name containing HTML entities.
update_option( 'blogname', '&#039;Test&#039; blog&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;' );
// Set $_POST['email'] with new e-mail and $_POST['user_id'] with user's ID.
@@ -1587,10 +1601,10 @@ class Tests_User extends WP_UnitTestCase {
$recipient = $mailer->get_recipient( 'to' );
$email = $mailer->get_sent();
// Assert recipient is correct
// Assert recipient is correct.
$this->assertSame( 'new-email@test.dev', $recipient->address, 'User email change confirmation recipient not as expected' );
// Assert that HTML entites have been decoded in body and subject
// Assert that HTML entites have been decoded in body and subject.
$this->assertContains( '\'Test\' blog\'s "name" has <html entities> &', $email->subject, 'Email subject does not contain the decoded HTML entities' );
$this->assertNotContains( '&#039;Test&#039; blog&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;', $email->subject, 'Email subject does contains HTML entities' );
}