Changeset 51738 for trunk/tests/phpunit/tests/user.php
- Timestamp:
- 09/07/2021 09:30:07 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/user.php
r51568 r51738 1847 1847 1848 1848 /** 1849 * Test `$user_data['meta_input']` args in `wp_insert_user( $user_data )`. 1850 * 1851 * @ticket 41950 1852 */ 1853 public function test_wp_insert_user_with_meta() { 1854 $user_data = array( 1855 'user_login' => 'test_user', 1856 'user_pass' => 'test_password', 1857 'user_email' => 'user@example.com', 1858 'meta_input' => array( 1859 'test_meta_key' => 'test_meta_value', 1860 'custom_meta' => 'custom_value', 1861 ), 1862 ); 1863 $create_user = wp_insert_user( $user_data ); 1864 1865 $this->assertSame( 'test_meta_value', get_user_meta( $create_user, 'test_meta_key', true ) ); 1866 $this->assertSame( 'custom_value', get_user_meta( $create_user, 'custom_meta', true ) ); 1867 1868 // Update the user meta thru wp_insert_user. 1869 $update_data = array( 1870 'ID' => $create_user, 1871 'user_login' => 'test_user', 1872 'meta_input' => array( 1873 'test_meta_key' => 'test_meta_updated', 1874 'custom_meta' => 'updated_value', 1875 'new_meta_k' => 'new_meta_val', 1876 ), 1877 ); 1878 $update_user = wp_insert_user( $update_data ); 1879 1880 $this->assertSame( 'test_meta_updated', get_user_meta( $update_user, 'test_meta_key', true ) ); 1881 $this->assertSame( 'updated_value', get_user_meta( $update_user, 'custom_meta', true ) ); 1882 $this->assertSame( 'new_meta_val', get_user_meta( $update_user, 'new_meta_k', true ) ); 1883 1884 // Create new user. 1885 $new_user_data = array( 1886 'user_login' => 'new_test', 1887 'user_pass' => 'new_password', 1888 'user_email' => 'new_user@newexample.com', 1889 'meta_input' => array( 1890 'test_meta_key' => 'test_meta_value', 1891 'custom_meta' => 'new_user_custom_value', 1892 ), 1893 ); 1894 1895 // Hook filter 1896 add_filter( 'insert_custom_user_meta', array( $this, 'filter_custom_meta' ) ); 1897 1898 $new_user = wp_insert_user( $new_user_data ); 1899 1900 // This meta is updated by the filter. 1901 $this->assertSame( 'update_from_filter', get_user_meta( $new_user, 'test_meta_key', true ) ); 1902 $this->assertSame( 'new_user_custom_value', get_user_meta( $new_user, 'custom_meta', true ) ); 1903 // This meta is inserted by the filter. 1904 $this->assertSame( 'new_from_filter', get_user_meta( $new_user, 'new_meta_from_filter', true ) ); 1905 } 1906 1907 /** 1908 * Hook a filter to alter custom meta when inserting new user. 1909 * This hook is used in `test_wp_insert_user_with_meta()`. 1910 */ 1911 public function filter_custom_meta( $meta_input ) { 1912 // Update some meta inputs 1913 $meta_input['test_meta_key'] = 'update_from_filter'; 1914 // Add a new meta 1915 $meta_input['new_meta_from_filter'] = 'new_from_filter'; 1916 1917 return $meta_input; 1918 } 1919 1920 /** 1849 1921 * Testing the `wp_privacy_additional_user_profile_data` filter works. 1850 1922 *
Note: See TracChangeset
for help on using the changeset viewer.