wordpress-develop/tests/phpunit/tests/user/updateUserCaches.php
Sergey Biryukov 164b22cf6a Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.
This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-02 00:35:36 +00:00

71 lines
2.0 KiB
PHP

<?php
/**
* @group user
*/
class Tests_User_UpdateUserCaches extends WP_UnitTestCase {
public function test_should_store_entire_database_row_in_users_bucket() {
global $wpdb;
$u = self::factory()->user->create();
$raw_userdata = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE ID = %d", $u ) );
update_user_caches( $raw_userdata );
$this->assertEquals( $raw_userdata, wp_cache_get( $u, 'users' ) );
}
public function test_should_store_user_id_in_userlogins_bucket() {
$data = new stdClass();
$data->ID = 12345;
$data->user_login = 'foo';
$data->user_email = 'foo@example.com';
$data->user_nicename = 'bar';
update_user_caches( $data );
$this->assertSame( 12345, wp_cache_get( 'foo', 'userlogins' ) );
}
public function test_should_store_user_id_in_useremail_bucket() {
$data = new stdClass();
$data->ID = 12345;
$data->user_login = 'foo';
$data->user_email = 'foo@example.com';
$data->user_nicename = 'bar';
update_user_caches( $data );
$this->assertSame( 12345, wp_cache_get( 'foo@example.com', 'useremail' ) );
}
public function test_should_store_user_id_in_userslugs_bucket() {
$data = new stdClass();
$data->ID = 12345;
$data->user_login = 'foo';
$data->user_email = 'foo@example.com';
$data->user_nicename = 'bar';
update_user_caches( $data );
$this->assertSame( 12345, wp_cache_get( 'bar', 'userslugs' ) );
}
/**
* @ticket 24635
*/
public function test_should_store_raw_data_in_users_bucket_when_passed_a_wp_user_object() {
global $wpdb;
$u = self::factory()->user->create();
$raw_userdata = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE ID = %d", $u ) );
$user_object = new WP_User( $u );
update_user_caches( $user_object );
$cached = wp_cache_get( $u, 'users' );
$this->assertFalse( $cached instanceof WP_User );
$this->assertEquals( $raw_userdata, $cached );
}
}