Changeset 60253
- Timestamp:
- 05/26/2025 02:34:12 PM (10 months ago)
- Location:
- trunk/tests/phpunit/tests
- Files:
-
- 28 edited
-
admin/includesPlugin.php (modified) (7 diffs)
-
admin/includesTemplate.php (modified) (3 diffs)
-
ajax/wpAjaxSendAttachmentToEditor.php (modified) (3 diffs)
-
ajax/wpCustomizeNavMenus.php (modified) (7 diffs)
-
auth.php (modified) (2 diffs)
-
comment/wpHandleCommentSubmission.php (modified) (7 diffs)
-
customize/control.php (modified) (1 diff)
-
customize/custom-css-setting.php (modified) (2 diffs)
-
customize/manager.php (modified) (8 diffs)
-
customize/nav-menu-item-setting.php (modified) (2 diffs)
-
customize/nav-menu-setting.php (modified) (2 diffs)
-
customize/nav-menus.php (modified) (3 diffs)
-
customize/panel.php (modified) (5 diffs)
-
customize/selective-refresh-ajax.php (modified) (6 diffs)
-
customize/setting.php (modified) (9 diffs)
-
customize/widgets.php (modified) (2 diffs)
-
general/template.php (modified) (4 diffs)
-
l10n.php (modified) (4 diffs)
-
l10n/getUserLocale.php (modified) (6 diffs)
-
meta.php (modified) (13 diffs)
-
oembed/controller.php (modified) (4 diffs)
-
oembed/wpOembed.php (modified) (6 diffs)
-
post/getPages.php (modified) (6 diffs)
-
post/getPostsByAuthorSql.php (modified) (6 diffs)
-
query/conditionals.php (modified) (9 diffs)
-
taxonomy.php (modified) (3 diffs)
-
url.php (modified) (4 diffs)
-
user.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/admin/includesPlugin.php
r58876 r60253 5 5 */ 6 6 class Tests_Admin_IncludesPlugin extends WP_UnitTestCase { 7 8 /** 9 * Admin user ID. 10 * 11 * @var int $admin_id 12 */ 13 public static $admin_id; 14 7 15 public static function wpSetUpBeforeClass( $factory ) { 16 self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) ); 8 17 self::_back_up_mu_plugins(); 9 18 } … … 38 47 public function test_menu_page_url() { 39 48 $current_user = get_current_user_id(); 40 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));49 wp_set_current_user( self::$admin_id ); 41 50 update_option( 'siteurl', 'http://example.com' ); 42 51 … … 82 91 global $menu; 83 92 $current_user = get_current_user_id(); 84 $admin_user = self:: factory()->user->create( array( 'role' => 'administrator' ) );93 $admin_user = self::$admin_id; 85 94 wp_set_current_user( $admin_user ); 86 95 set_current_screen( 'dashboard' ); … … 135 144 136 145 $current_user = get_current_user_id(); 137 $admin_user = self:: factory()->user->create( array( 'role' => 'administrator' ) );146 $admin_user = self::$admin_id; 138 147 wp_set_current_user( $admin_user ); 139 148 set_current_screen( 'dashboard' ); … … 284 293 $menu = array(); 285 294 $current_user = get_current_user_id(); 286 $admin_user = self:: factory()->user->create( array( 'role' => 'administrator' ) );295 $admin_user = self::$admin_id; 287 296 wp_set_current_user( $admin_user ); 288 297 set_current_screen( 'dashboard' ); … … 317 326 $menu = array(); 318 327 $current_user = get_current_user_id(); 319 $admin_user = self:: factory()->user->create( array( 'role' => 'administrator' ) );328 $admin_user = self::$admin_id; 320 329 wp_set_current_user( $admin_user ); 321 330 set_current_screen( 'dashboard' ); … … 345 354 $menu = array(); 346 355 $current_user = get_current_user_id(); 347 $admin_user = self:: factory()->user->create( array( 'role' => 'administrator' ) );356 $admin_user = self::$admin_id; 348 357 wp_set_current_user( $admin_user ); 349 358 set_current_screen( 'dashboard' ); -
trunk/tests/phpunit/tests/admin/includesTemplate.php
r59564 r60253 4 4 */ 5 5 class Tests_Admin_IncludesTemplate extends WP_UnitTestCase { 6 /** 7 * Editor user ID. 8 * 9 * @var int $editor_id 10 */ 11 public static $editor_id; 12 13 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 14 self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) ); 15 } 6 16 7 17 /** … … 65 75 66 76 // Test that get_inline_data() has `post_category` div containing the assigned term. 67 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'editor' ) ));77 wp_set_current_user( self::$editor_id ); 68 78 get_inline_data( $post ); 69 79 $this->expectOutputRegex( '/<div class="post_category" id="wptests_tax_1_' . $post->ID . '">' . $term['term_id'] . '<\/div>/' ); … … 91 101 92 102 // Test that get_inline_data() has `tags_input` div containing the assigned term. 93 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'editor' ) ));103 wp_set_current_user( self::$editor_id ); 94 104 get_inline_data( $post ); 95 105 $this->expectOutputRegex( '/<div class="tags_input" id="wptests_tax_1_' . $post->ID . '">Test<\/div>/' ); -
trunk/tests/phpunit/tests/ajax/wpAjaxSendAttachmentToEditor.php
r55764 r60253 13 13 */ 14 14 class Tests_Ajax_wpAjaxSendAttachmentToEditor extends WP_Ajax_UnitTestCase { 15 16 /** 17 * Shared user ID for the tests. 18 * 19 * @var int 20 */ 21 public static $user_id = 0; 22 23 /** 24 * Set up shared fixtures. 25 * 26 * @param WP_UnitTest_Factory $factory 27 */ 28 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 29 self::$user_id = $factory->user->create( 30 array( 31 'role' => 'administrator', 32 'user_login' => 'user_36578_administrator', 33 'user_email' => 'user_36578_administrator@example.com', 34 ) 35 ); 36 } 15 37 16 38 /** … … 106 128 // Become an administrator. 107 129 $post = $_POST; 108 $user_id = self::factory()->user->create( 109 array( 110 'role' => 'administrator', 111 'user_login' => 'user_36578_administrator', 112 'user_email' => 'user_36578_administrator@example.com', 113 ) 114 ); 130 $user_id = self::$user_id; 115 131 wp_set_current_user( $user_id ); 116 132 $_POST = array_merge( $_POST, $post ); … … 152 168 // Become an administrator. 153 169 $post = $_POST; 154 $user_id = self::factory()->user->create( 155 array( 156 'role' => 'administrator', 157 'user_login' => 'user_36578_administrator', 158 'user_email' => 'user_36578_administrator@example.com', 159 ) 160 ); 170 $user_id = self::$user_id; 161 171 wp_set_current_user( $user_id ); 162 172 $_POST = array_merge( $_POST, $post ); -
trunk/tests/phpunit/tests/ajax/wpCustomizeNavMenus.php
r57099 r60253 39 39 public static $terms; 40 40 41 42 /** 43 * Admin user ID. 44 * 45 * @var int 46 */ 47 public static $admin_user_id = 0; 48 49 /** 50 * User IDs keyed by role. 51 * 52 * @var int[] 53 */ 54 public static $user_ids = array(); 55 56 /** 57 * Set up shared fixtures. 58 * 59 * @param WP_UnitTest_Factory $factory The factory. 60 */ 41 61 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 42 62 // Make some post objects. … … 46 66 // Some terms too. 47 67 self::$terms = $factory->term->create_many( 5 ); 68 69 // Create an admin user. 70 self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) ); 71 72 foreach ( array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' ) as $role ) { 73 self::$user_ids[ $role ] = $factory->user->create( array( 'role' => $role ) ); 74 } 48 75 } 49 76 … … 54 81 parent::set_up(); 55 82 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 56 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));83 wp_set_current_user( self::$admin_user_id ); 57 84 global $wp_customize; 58 85 $this->wp_customize = new WP_Customize_Manager(); … … 92 119 } 93 120 94 wp_set_current_user( self:: factory()->user->create( array( 'role' => $role ) ));121 wp_set_current_user( self::$user_ids[ $role ] ); 95 122 96 123 $_POST = array( … … 486 513 } 487 514 488 wp_set_current_user( self:: factory()->user->create( array( 'role' => $role ) ));515 wp_set_current_user( self::$user_ids[ $role ] ); 489 516 490 517 $_POST = array( … … 706 733 707 734 // Bad nonce. 708 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'subscriber' ) ));735 wp_set_current_user( self::$user_ids['subscriber'] ); 709 736 $_POST = wp_slash( 710 737 array( … … 719 746 720 747 // Missing params. 721 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));748 wp_set_current_user( self::$user_ids['administrator'] ); 722 749 $_POST = wp_slash( 723 750 array( -
trunk/tests/phpunit/tests/auth.php
r60124 r60253 1580 1580 */ 1581 1581 public function test_application_password_authentication() { 1582 $user_id = self::factory()->user->create( 1583 array( 1584 'user_login' => 'http_auth_login', 1585 'user_pass' => 'http_auth_pass', // Shouldn't be allowed for API login. 1586 ) 1587 ); 1582 $user_id = self::$_user->ID; 1588 1583 1589 1584 // Create a new app-only password. … … 1595 1590 1596 1591 // Fake an HTTP Auth request with the regular account password first. 1597 $_SERVER['PHP_AUTH_USER'] = 'http_auth_login';1598 $_SERVER['PHP_AUTH_PW'] = 'http_auth_pass';1592 $_SERVER['PHP_AUTH_USER'] = self::USER_LOGIN; 1593 $_SERVER['PHP_AUTH_PW'] = self::USER_PASS; 1599 1594 1600 1595 $this->assertNull( -
trunk/tests/phpunit/tests/comment/wpHandleCommentSubmission.php
r59319 r60253 10 10 protected static $post; 11 11 protected static $author_id; 12 protected static $author_id2; 12 13 protected static $editor_id; 13 14 … … 20 21 array( 21 22 'role' => 'author', 23 ) 24 ); 25 26 self::$author_id2 = $factory->user->create( 27 array( 28 'role' => 'author', 29 'user_url' => 'http://user.example.org', 22 30 ) 23 31 ); … … 224 232 public function test_submitting_valid_comment_as_logged_in_user_succeeds() { 225 233 226 $user = self::factory()->user->create_and_get( 227 array( 228 'user_url' => 'http://user.example.org', 229 ) 230 ); 234 $user = get_user_by( 'id', self::$author_id2 ); 231 235 232 236 wp_set_current_user( $user->ID ); … … 315 319 $error = 'comment_id_not_found'; 316 320 317 $user = self::factory()->user->create_and_get( 318 array( 319 'role' => 'author', 320 ) 321 ); 321 $user = get_user_by( 'id', self::$author_id2 ); 322 322 323 323 wp_set_current_user( $user->ID ); … … 344 344 $error = 'comment_id_not_found'; 345 345 346 $user = self::factory()->user->create_and_get( 347 array( 348 'role' => 'author', 349 ) 350 ); 346 $user = get_user_by( 'id', self::$author_id2 ); 351 347 352 348 wp_set_current_user( $user->ID ); … … 835 831 * @ticket 36901 836 832 */ 837 public function test_comments_flood_user_is_admin() { 838 $user = self::factory()->user->create_and_get( 839 array( 840 'role' => 'administrator', 841 ) 842 ); 833 public function test_comments_flood_user_can_moderate_comments() { 834 $user = get_user_by( 'id', self::$editor_id ); 843 835 wp_set_current_user( $user->ID ); 844 836 … … 854 846 $second_comment = wp_handle_comment_submission( $data ); 855 847 856 $this->assertNotWPError( $second_comment ); 857 $this->assertSame( (string) self::$post->ID, $second_comment->comment_post_ID ); 848 $this->assertTrue( current_user_can( 'moderate_comments' ), 'Test user should have the moderate_comments capability' ); 849 $this->assertNotWPError( $second_comment, 'Second comment should not trigger comment flooding error.' ); 850 $this->assertSame( (string) self::$post->ID, $second_comment->comment_post_ID, 'Second comment should be made against initial post.' ); 858 851 } 859 852 -
trunk/tests/phpunit/tests/customize/control.php
r55457 r60253 19 19 20 20 /** 21 * Shared user ID for the tests. 22 23 * @var int 24 */ 25 public static $user_id = 0; 26 27 /** 28 * Set up shared fixtures. 29 * 30 * @param WP_UnitTest_Factory $factory Factory. 31 */ 32 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 33 self::$user_id = $factory->user->create( array( 'role' => 'administrator' ) ); 34 } 35 36 /** 21 37 * Set up. 22 38 */ 23 39 public function set_up() { 24 40 parent::set_up(); 25 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));41 wp_set_current_user( self::$user_id ); 26 42 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 27 43 $GLOBALS['wp_customize'] = new WP_Customize_Manager(); -
trunk/tests/phpunit/tests/customize/custom-css-setting.php
r54865 r60253 24 24 25 25 /** 26 * The user ID to use for the tests. 27 * 28 * @var int 29 */ 30 public static $user_id = 0; 31 32 /** 33 * Set up the test case. 34 * 35 * @see WP_UnitTestCase::set_up() 36 */ 37 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 38 // Create a user to use for the tests. 39 self::$user_id = $factory->user->create( 40 array( 41 'role' => 'administrator', 42 ) 43 ); 44 45 if ( is_multisite() ) { 46 grant_super_admin( self::$user_id ); 47 } 48 } 49 50 /** 26 51 * Set up the test case. 27 52 * … … 32 57 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 33 58 34 $user_id = self::factory()->user->create( 35 array( 36 'role' => 'administrator', 37 ) 38 ); 39 if ( is_multisite() ) { 40 grant_super_admin( $user_id ); 41 } 42 43 wp_set_current_user( $user_id ); 59 wp_set_current_user( self::$user_id ); 44 60 45 61 global $wp_customize; -
trunk/tests/phpunit/tests/customize/manager.php
r57242 r60253 28 28 29 29 /** 30 * Second admin user ID. 31 * 32 * @var int 33 */ 34 protected static $other_admin_user_id; 35 36 /** 30 37 * Subscriber user ID. 31 38 * … … 47 54 */ 48 55 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 49 self::$subscriber_user_id = $factory->user->create( array( 'role' => 'subscriber' ) ); 50 self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) ); 56 self::$subscriber_user_id = $factory->user->create( array( 'role' => 'subscriber' ) ); 57 self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) ); 58 self::$other_admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) ); 51 59 } 52 60 … … 154 162 public function test_constructor_deferred_changeset_uuid() { 155 163 wp_set_current_user( self::$admin_user_id ); 156 $other_admin_user_id = self:: factory()->user->create( array( 'role' => 'admin' ) );164 $other_admin_user_id = self::$other_admin_user_id; 157 165 158 166 $data = array( … … 1255 1263 public function test_save_changeset_post_without_kses_corrupting_json() { 1256 1264 global $wp_customize; 1257 $lesser_admin_user_id = self:: factory()->user->create( array( 'role' => 'administrator' ) );1265 $lesser_admin_user_id = self::$other_admin_user_id; 1258 1266 1259 1267 $uuid = wp_generate_uuid4(); … … 1500 1508 add_theme_support( 'custom-background' ); 1501 1509 wp_set_current_user( self::$admin_user_id ); 1502 $other_admin_user_id = self:: factory()->user->create( array( 'role' => 'administrator' ) );1510 $other_admin_user_id = self::$other_admin_user_id; 1503 1511 1504 1512 $uuid = wp_generate_uuid4(); … … 1715 1723 add_theme_support( 'custom-background' ); 1716 1724 wp_set_current_user( self::$admin_user_id ); 1717 $other_admin_user_id = self:: factory()->user->create( array( 'role' => 'administrator' ) );1725 $other_admin_user_id = self::$other_admin_user_id; 1718 1726 1719 1727 $uuid = wp_generate_uuid4(); … … 1878 1886 array( 1879 1887 'autosave' => true, 1880 'user_id' => self:: factory()->user->create( array( 'role' => 'administrator' ) ),1888 'user_id' => self::$other_admin_user_id, 1881 1889 ) 1882 1890 ); … … 3010 3018 */ 3011 3019 public function test_return_url() { 3012 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'author' ) ));3020 wp_set_current_user( self::$subscriber_user_id ); 3013 3021 $this->assertSame( home_url( '/' ), $this->manager->get_return_url() ); 3014 3022 -
trunk/tests/phpunit/tests/customize/nav-menu-item-setting.php
r56421 r60253 15 15 16 16 /** 17 * ID of the administrator user. 18 * 19 * @var int 20 */ 21 public static $administrator_id; 22 23 /** 24 * Set up the shared fixture. 25 * 26 * @param WP_UnitTest_Factory $factory Factory instance. 27 */ 28 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 29 self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) ); 30 } 31 32 /** 17 33 * Set up a test case. 18 34 * … … 22 38 parent::set_up(); 23 39 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 24 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));40 wp_set_current_user( self::$administrator_id ); 25 41 26 42 global $wp_customize; -
trunk/tests/phpunit/tests/customize/nav-menu-setting.php
r54865 r60253 16 16 17 17 /** 18 * ID of the administrator user. 19 * 20 * @var int 21 */ 22 public static $administrator_id; 23 24 /** 25 * Set up the shared fixture. 26 * 27 * @param WP_UnitTest_Factory $factory Factory instance. 28 */ 29 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 30 self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) ); 31 } 32 33 /** 18 34 * Set up a test case. 19 35 * … … 23 39 parent::set_up(); 24 40 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 25 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));41 wp_set_current_user( self::$administrator_id ); 26 42 27 43 global $wp_customize; -
trunk/tests/phpunit/tests/customize/nav-menus.php
r60251 r60253 16 16 17 17 /** 18 * ID of the administrator user. 19 * 20 * @var int 21 */ 22 public static $administrator_id; 23 24 /** 25 * Set up the shared fixture. 26 * 27 * @param WP_UnitTest_Factory $factory Factory instance. 28 */ 29 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 30 self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) ); 31 } 32 33 /** 18 34 * Set up a test case. 19 35 * … … 23 39 parent::set_up(); 24 40 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 25 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));41 wp_set_current_user( self::$administrator_id ); 26 42 global $wp_customize; 27 43 $this->wp_customize = new WP_Customize_Manager(); … … 855 871 $contributor_user_id = self::factory()->user->create( array( 'role' => 'contributor' ) ); 856 872 $author_user_id = self::factory()->user->create( array( 'role' => 'author' ) ); 857 $administrator_user_id = self:: factory()->user->create( array( 'role' => 'administrator' ) );873 $administrator_user_id = self::$administrator_id; 858 874 859 875 $contributor_post_id = self::factory()->post->create( -
trunk/tests/phpunit/tests/customize/panel.php
r56547 r60253 7 7 */ 8 8 class Tests_WP_Customize_Panel extends WP_UnitTestCase { 9 10 /** 11 * ID of the administrator user. 12 * 13 * @var int 14 */ 15 public static $administrator_id; 16 17 /** 18 * Set up the shared fixture. 19 * 20 * @param WP_UnitTest_Factory $factory Factory instance. 21 */ 22 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 23 self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) ); 24 } 9 25 10 26 /** … … 132 148 */ 133 149 public function test_check_capabilities() { 134 $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 135 wp_set_current_user( $user_id ); 150 wp_set_current_user( self::$administrator_id ); 136 151 137 152 $panel = new WP_Customize_Panel( $this->manager, 'foo' ); … … 158 173 */ 159 174 public function test_maybe_render() { 160 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));175 wp_set_current_user( self::$administrator_id ); 161 176 $panel = new WP_Customize_Panel( $this->manager, 'bar' ); 162 177 $customize_render_panel_count = did_action( 'customize_render_panel' ); … … 183 198 */ 184 199 public function test_print_templates_standard() { 185 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));200 wp_set_current_user( self::$administrator_id ); 186 201 187 202 $panel = new WP_Customize_Panel( $this->manager, 'baz' ); … … 201 216 */ 202 217 public function test_print_templates_custom() { 203 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));218 wp_set_current_user( self::$administrator_id ); 204 219 205 220 $panel = new Custom_Panel_Test( $this->manager, 'baz' ); -
trunk/tests/phpunit/tests/customize/selective-refresh-ajax.php
r56971 r60253 30 30 31 31 /** 32 * Shared user ID for the tests. 33 * 34 * @var int 35 */ 36 public static $user_id = 0; 37 38 /** 39 * Set up shared fixtures. 40 * 41 * @param WP_UnitTest_Factory $factory Factory. 42 */ 43 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 44 self::$user_id = $factory->user->create( array( 'role' => 'administrator' ) ); 45 } 46 47 /** 32 48 * Set up the test fixture. 33 49 */ … … 80 96 81 97 // Check expected_customize_preview. 82 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));98 wp_set_current_user( self::$user_id ); 83 99 $_REQUEST['nonce'] = wp_create_nonce( 'preview-customize_' . $this->wp_customize->theme()->get_stylesheet() ); 84 100 ob_start(); … … 122 138 */ 123 139 private function setup_valid_render_partials_request_environment() { 124 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));140 wp_set_current_user( self::$user_id ); 125 141 $_REQUEST['nonce'] = wp_create_nonce( 'preview-customize_' . $this->wp_customize->theme()->get_stylesheet() ); 126 142 $_POST[ WP_Customize_Selective_Refresh::RENDER_QUERY_VAR ] = '1'; … … 172 188 public function test_handle_render_partials_request_for_non_rendering_partial() { 173 189 $this->setup_valid_render_partials_request_environment(); 174 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));190 wp_set_current_user( self::$user_id ); 175 191 $this->wp_customize->add_setting( 'home' ); 176 192 $this->wp_customize->selective_refresh->add_partial( 'foo', array( 'settings' => array( 'home' ) ) ); … … 209 225 public function test_handle_rendering_disallowed_partial() { 210 226 $this->setup_valid_render_partials_request_environment(); 211 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));227 wp_set_current_user( self::$user_id ); 212 228 $this->wp_customize->add_setting( 213 229 'secret_message', … … 245 261 public function test_handle_rendering_partial_with_missing_settings() { 246 262 $this->setup_valid_render_partials_request_environment(); 247 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));263 wp_set_current_user( self::$user_id ); 248 264 $this->wp_customize->selective_refresh->add_partial( 'bar', array( 'settings' => 'bar' ) ); 249 265 -
trunk/tests/phpunit/tests/customize/setting.php
r57920 r60253 17 17 */ 18 18 public $undefined; 19 20 /** 21 * Shared admin user ID for the tests. 22 * 23 * @var int 24 */ 25 public static $admin_id = 0; 26 27 /** 28 * Set up shared fixtures. 29 * 30 * @param WP_UnitTest_Factory $factory Factory. 31 */ 32 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 33 self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) ); 34 } 19 35 20 36 public function set_up() { … … 138 154 */ 139 155 public function test_preview_standard_types_non_multidimensional() { 140 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));156 wp_set_current_user( self::$admin_id ); 141 157 $_POST['customized'] = wp_slash( wp_json_encode( $this->post_data_overrides ) ); 142 158 … … 217 233 */ 218 234 public function test_preview_standard_types_multidimensional() { 219 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));235 wp_set_current_user( self::$admin_id ); 220 236 $_POST['customized'] = wp_slash( wp_json_encode( $this->post_data_overrides ) ); 221 237 … … 363 379 */ 364 380 public function test_preview_custom_type() { 365 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));381 wp_set_current_user( self::$admin_id ); 366 382 $type = 'custom_type'; 367 383 $post_data_overrides = array( … … 514 530 515 531 // Satisfy all requirements for save to happen. 516 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));532 wp_set_current_user( self::$admin_id ); 517 533 $this->assertNotFalse( $setting->save() ); 518 534 $this->assertTrue( 1 === did_action( 'customize_update_custom' ) ); … … 552 568 */ 553 569 public function test_is_current_blog_previewed() { 554 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));570 wp_set_current_user( self::$admin_id ); 555 571 $type = 'option'; 556 572 $name = 'blogname'; … … 574 590 */ 575 591 public function test_previewing_with_switch_to_blog() { 576 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));592 wp_set_current_user( self::$admin_id ); 577 593 $type = 'option'; 578 594 $name = 'blogdescription'; … … 597 613 public function test_option_autoloading() { 598 614 global $wpdb; 599 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));615 wp_set_current_user( self::$admin_id ); 600 616 601 617 $name = 'autoloaded1'; … … 744 760 */ 745 761 public function test_multidimensional_value_when_previewed() { 746 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));762 wp_set_current_user( self::$admin_id ); 747 763 WP_Customize_Setting::reset_aggregated_multidimensionals(); 748 764 -
trunk/tests/phpunit/tests/customize/widgets.php
r56746 r60253 21 21 protected $backup_registered_sidebars; 22 22 23 /** 24 * ID of the administrator user. 25 * 26 * @var int 27 */ 28 public static $administrator_id; 29 30 /** 31 * Set up the shared fixture. 32 * 33 * @param WP_UnitTest_Factory $factory Factory instance. 34 */ 35 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 36 self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) ); 37 } 38 23 39 public function set_up() { 24 40 parent::set_up(); … … 28 44 add_action( 'widgets_init', array( $this, 'remove_widgets_block_editor' ) ); 29 45 30 $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 31 wp_set_current_user( $user_id ); 46 wp_set_current_user( self::$administrator_id ); 32 47 33 48 update_option( -
trunk/tests/phpunit/tests/general/template.php
r60062 r60253 33 33 public static $home_page_id; 34 34 35 /** 36 * ID of the administrator user. 37 * 38 * @var int 39 */ 40 public static $administrator_id; 41 42 /** 43 * ID of the author user. 44 * 45 * @var int 46 */ 47 public static $author_id; 48 49 /** 50 * Set up the shared fixtures. 51 * 52 * @param WP_UnitTest_Factory $factory Factory instance. 53 */ 35 54 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 55 self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) ); 56 self::$author_id = $factory->user->create( array( 'role' => 'author' ) ); 57 36 58 /* 37 59 * Declare theme support for custom logo. … … 213 235 public function test_customize_preview_wp_site_icon_empty() { 214 236 global $wp_customize; 215 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));237 wp_set_current_user( self::$administrator_id ); 216 238 217 239 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; … … 231 253 public function test_customize_preview_wp_site_icon_dirty() { 232 254 global $wp_customize; 233 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));255 wp_set_current_user( self::$administrator_id ); 234 256 235 257 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; … … 764 786 */ 765 787 public function test_get_the_archive_title_is_correct_for_author_queries() { 766 $user_with_posts = self::factory()->user->create_and_get( 767 array( 768 'role' => 'author', 769 ) 770 ); 771 $user_with_no_posts = self::factory()->user->create_and_get( 772 array( 773 'role' => 'author', 774 ) 775 ); 788 $user_with_posts = get_user_by( 'id', self::$administrator_id ); 789 $user_with_no_posts = get_user_by( 'id', self::$author_id ); 776 790 777 791 self::factory()->post->create( -
trunk/tests/phpunit/tests/l10n.php
r58062 r60253 15 15 */ 16 16 private $long_text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'; 17 18 /** 19 * Editor user ID. 20 * 21 * @var int $editor_id 22 */ 23 public static $editor_id; 24 25 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 26 self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) ); 27 } 17 28 18 29 /** … … 465 476 * "passing null to non-nullable" deprecation notice. 466 477 */ 467 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'editor' ) ));478 wp_set_current_user( self::$editor_id ); 468 479 469 480 $args = array( … … 504 515 * "passing null to non-nullable" deprecation notice. 505 516 */ 506 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'editor' ) ));517 wp_set_current_user( self::$editor_id ); 507 518 508 519 $args = array( … … 543 554 * "passing null to non-nullable" deprecation notice. 544 555 */ 545 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'editor' ) ));556 wp_set_current_user( self::$editor_id ); 546 557 547 558 $args = array( -
trunk/tests/phpunit/tests/l10n/getUserLocale.php
r57008 r60253 10 10 protected $user_id; 11 11 12 public function set_up() { 13 parent::set_up(); 12 /** 13 * ID of the administrator user with de_DE local. 14 * 15 * @var int 16 */ 17 public static $administrator_de_de; 14 18 15 $this->user_id = self::factory()->user->create( 19 /** 20 * ID of the user with es_ES local. 21 * 22 * @var int 23 */ 24 public static $user_es_es; 25 26 /** 27 * Set up the shared fixtures. 28 * 29 * @param WP_UnitTest_Factory $factory Factory instance. 30 */ 31 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 32 self::$administrator_de_de = $factory->user->create( 16 33 array( 17 34 'role' => 'administrator', … … 20 37 ); 21 38 22 wp_set_current_user( $this->user_id ); 39 self::$user_es_es = self::factory()->user->create( 40 array( 41 'locale' => 'es_ES', 42 ) 43 ); 44 } 45 46 public function set_up() { 47 parent::set_up(); 48 49 wp_set_current_user( self::$administrator_de_de ); 23 50 } 24 51 … … 26 53 set_current_screen( 'dashboard' ); 27 54 $this->assertSame( 'de_DE', get_user_locale() ); 28 $this->assertSame( get_user_by( 'id', $this->user_id)->locale, get_user_locale() );55 $this->assertSame( get_user_by( 'id', self::$administrator_de_de )->locale, get_user_locale() ); 29 56 } 30 57 31 58 public function test_update_user_locale() { 32 59 set_current_screen( 'dashboard' ); 33 update_user_meta( $this->user_id, 'locale', 'fr_FR' );60 update_user_meta( self::$administrator_de_de, 'locale', 'fr_FR' ); 34 61 $this->assertSame( 'fr_FR', get_user_locale() ); 35 62 } … … 37 64 public function test_returns_site_locale_if_empty() { 38 65 set_current_screen( 'dashboard' ); 39 update_user_meta( $this->user_id, 'locale', '' );66 update_user_meta( self::$administrator_de_de, 'locale', '' ); 40 67 $this->assertSame( get_locale(), get_user_locale() ); 41 68 } … … 79 106 80 107 public function test_user_id_argument_with_id() { 81 $user_id = self::factory()->user->create( 82 array( 83 'locale' => 'es_ES', 84 ) 85 ); 108 $user_id = self::$user_es_es; 86 109 87 110 $user_locale1 = get_user_locale( $user_id ); … … 96 119 97 120 public function test_user_id_argument_with_wp_user_object() { 98 $user_id = self::factory()->user->create( 99 array( 100 'locale' => 'es_ES', 101 ) 102 ); 121 $user_id = self::$user_es_es; 103 122 104 123 $user = get_user_by( 'id', $user_id ); -
trunk/tests/phpunit/tests/meta.php
r60251 r60253 10 10 * @var \WP_User 11 11 */ 12 private $author; 13 14 private $meta_id; 15 private $delete_meta_id; 16 17 public function set_up() { 18 parent::set_up(); 19 $this->author = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) ); 20 $this->meta_id = add_metadata( 'user', $this->author->ID, 'meta_key', 'meta_value' ); 21 $this->delete_meta_id = add_metadata( 'user', $this->author->ID, 'delete_meta_key', 'delete_meta_value' ); 12 private static $author; 13 14 private static $meta_id; 15 private static $delete_meta_id; 16 17 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 18 self::$author = new WP_User( $factory->user->create( array( 'role' => 'author' ) ) ); 19 self::$meta_id = add_metadata( 'user', self::$author->ID, 'meta_key', 'meta_value' ); 20 self::$delete_meta_id = add_metadata( 'user', self::$author->ID, 'delete_meta_key', 'delete_meta_value' ); 22 21 } 23 22 … … 38 37 // Let's try and delete a non-existing ID, non existing meta. 39 38 $this->assertFalse( delete_metadata_by_mid( 'user', 0 ) ); 40 $this->assertFalse( delete_metadata_by_mid( 'non_existing_meta', $this->delete_meta_id ) );39 $this->assertFalse( delete_metadata_by_mid( 'non_existing_meta', self::$delete_meta_id ) ); 41 40 42 41 // Now let's delete the real meta data. 43 $this->assertTrue( delete_metadata_by_mid( 'user', $this->delete_meta_id ) );42 $this->assertTrue( delete_metadata_by_mid( 'user', self::$delete_meta_id ) ); 44 43 45 44 // And make sure it's been deleted. 46 $this->assertFalse( get_metadata_by_mid( 'user', $this->delete_meta_id ) );45 $this->assertFalse( get_metadata_by_mid( 'user', self::$delete_meta_id ) ); 47 46 48 47 // Make sure the caches are cleared. 49 $this->assertFalse( (bool) get_user_meta( $this->author->ID, 'delete_meta_key' ) );48 $this->assertFalse( (bool) get_user_meta( self::$author->ID, 'delete_meta_key' ) ); 50 49 } 51 50 52 51 public function test_update_metadata_by_mid() { 53 52 // Setup. 54 $meta = get_metadata_by_mid( 'user', $this->meta_id );53 $meta = get_metadata_by_mid( 'user', self::$meta_id ); 55 54 56 55 // Update the meta value. 57 $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, 'meta_new_value' ) );58 $meta = get_metadata_by_mid( 'user', $this->meta_id );56 $this->assertTrue( update_metadata_by_mid( 'user', self::$meta_id, 'meta_new_value' ) ); 57 $meta = get_metadata_by_mid( 'user', self::$meta_id ); 59 58 $this->assertSame( 'meta_new_value', $meta->meta_value ); 60 59 61 60 // Update the meta value. 62 $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, 'meta_new_value', 'meta_new_key' ) );63 $meta = get_metadata_by_mid( 'user', $this->meta_id );61 $this->assertTrue( update_metadata_by_mid( 'user', self::$meta_id, 'meta_new_value', 'meta_new_key' ) ); 62 $meta = get_metadata_by_mid( 'user', self::$meta_id ); 64 63 $this->assertSame( 'meta_new_key', $meta->meta_key ); 65 64 66 65 // Update the key and value. 67 $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, 'meta_value', 'meta_key' ) );68 $meta = get_metadata_by_mid( 'user', $this->meta_id );66 $this->assertTrue( update_metadata_by_mid( 'user', self::$meta_id, 'meta_value', 'meta_key' ) ); 67 $meta = get_metadata_by_mid( 'user', self::$meta_id ); 69 68 $this->assertSame( 'meta_key', $meta->meta_key ); 70 69 $this->assertSame( 'meta_value', $meta->meta_value ); 71 70 72 71 // Update the value that has to be serialized. 73 $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, array( 'first', 'second' ) ) );74 $meta = get_metadata_by_mid( 'user', $this->meta_id );72 $this->assertTrue( update_metadata_by_mid( 'user', self::$meta_id, array( 'first', 'second' ) ) ); 73 $meta = get_metadata_by_mid( 'user', self::$meta_id ); 75 74 $this->assertSame( array( 'first', 'second' ), $meta->meta_value ); 76 75 77 76 // Let's try some invalid meta data. 78 77 $this->assertFalse( update_metadata_by_mid( 'user', 0, 'meta_value' ) ); 79 $this->assertFalse( update_metadata_by_mid( 'user', $this->meta_id, 'meta_value', array( 'invalid', 'key' ) ) );78 $this->assertFalse( update_metadata_by_mid( 'user', self::$meta_id, 'meta_value', array( 'invalid', 'key' ) ) ); 80 79 81 80 // Let's see if caches get cleared after updates. 82 $meta = get_metadata_by_mid( 'user', $this->meta_id );81 $meta = get_metadata_by_mid( 'user', self::$meta_id ); 83 82 $first = get_user_meta( $meta->user_id, $meta->meta_key ); 84 $this->assertTrue( update_metadata_by_mid( 'user', $this->meta_id, 'other_meta_value' ) );83 $this->assertTrue( update_metadata_by_mid( 'user', self::$meta_id, 'other_meta_value' ) ); 85 84 $second = get_user_meta( $meta->user_id, $meta->meta_key ); 86 85 $this->assertFalse( $first === $second ); … … 116 115 117 116 public function test_metadata_exists() { 118 $this->assertFalse( metadata_exists( 'user', $this->author->ID, 'foobarbaz' ) );119 $this->assertTrue( metadata_exists( 'user', $this->author->ID, 'meta_key' ) );117 $this->assertFalse( metadata_exists( 'user', self::$author->ID, 'foobarbaz' ) ); 118 $this->assertTrue( metadata_exists( 'user', self::$author->ID, 'meta_key' ) ); 120 119 $this->assertFalse( metadata_exists( 'user', 1234567890, 'foobarbaz' ) ); 121 120 $this->assertFalse( metadata_exists( 'user', 1234567890, 'meta_key' ) ); … … 128 127 // Let's see if it returns the correct value when adding a filter. 129 128 add_filter( 'get_user_metadata', '__return_zero' ); 130 $this->assertFalse( metadata_exists( 'user', $this->author->ID, 'meta_key' ) ); // Existing meta key.129 $this->assertFalse( metadata_exists( 'user', self::$author->ID, 'meta_key' ) ); // Existing meta key. 131 130 $this->assertFalse( metadata_exists( 'user', 1234567890, 'meta_key' ) ); 132 131 remove_filter( 'get_user_metadata', '__return_zero' ); … … 151 150 152 151 // User found is not locally defined author (it's the admin). 153 $this->assertNotEquals( $this->author->user_login, $u[0]->user_login );152 $this->assertNotEquals( self::$author->user_login, $u[0]->user_login ); 154 153 155 154 // Test EXISTS and NOT EXISTS together, no users should be found. … … 186 185 ); 187 186 188 delete_metadata( 'user', $this->author->ID, 'meta_key' );187 delete_metadata( 'user', self::$author->ID, 'meta_key' ); 189 188 190 189 $this->assertCount( … … 209 208 $value2 = 'Test\\\\doubleslash'; 210 209 $expected2 = 'Test\\doubleslash'; 211 $this->assertFalse( metadata_exists( 'user', $this->author->ID, $key ) );212 $this->assertFalse( delete_metadata( 'user', $this->author->ID, $key ) );213 $this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) );214 $this->assertIsInt( add_metadata( 'user', $this->author->ID, $key, $value ) );215 $this->assertSame( $expected, get_metadata( 'user', $this->author->ID, $key, true ) );216 $this->assertTrue( delete_metadata( 'user', $this->author->ID, $key ) );217 $this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) );218 $this->assertIsInt( update_metadata( 'user', $this->author->ID, $key, $value ) );219 $this->assertSame( $expected, get_metadata( 'user', $this->author->ID, $key, true ) );220 $this->assertTrue( update_metadata( 'user', $this->author->ID, $key, 'blah' ) );221 $this->assertSame( 'blah', get_metadata( 'user', $this->author->ID, $key, true ) );222 $this->assertTrue( delete_metadata( 'user', $this->author->ID, $key ) );223 $this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) );224 $this->assertFalse( metadata_exists( 'user', $this->author->ID, $key ) );210 $this->assertFalse( metadata_exists( 'user', self::$author->ID, $key ) ); 211 $this->assertFalse( delete_metadata( 'user', self::$author->ID, $key ) ); 212 $this->assertSame( '', get_metadata( 'user', self::$author->ID, $key, true ) ); 213 $this->assertIsInt( add_metadata( 'user', self::$author->ID, $key, $value ) ); 214 $this->assertSame( $expected, get_metadata( 'user', self::$author->ID, $key, true ) ); 215 $this->assertTrue( delete_metadata( 'user', self::$author->ID, $key ) ); 216 $this->assertSame( '', get_metadata( 'user', self::$author->ID, $key, true ) ); 217 $this->assertIsInt( update_metadata( 'user', self::$author->ID, $key, $value ) ); 218 $this->assertSame( $expected, get_metadata( 'user', self::$author->ID, $key, true ) ); 219 $this->assertTrue( update_metadata( 'user', self::$author->ID, $key, 'blah' ) ); 220 $this->assertSame( 'blah', get_metadata( 'user', self::$author->ID, $key, true ) ); 221 $this->assertTrue( delete_metadata( 'user', self::$author->ID, $key ) ); 222 $this->assertSame( '', get_metadata( 'user', self::$author->ID, $key, true ) ); 223 $this->assertFalse( metadata_exists( 'user', self::$author->ID, $key ) ); 225 224 226 225 // Test overslashing. 227 $this->assertIsInt( add_metadata( 'user', $this->author->ID, $key, $value2 ) );228 $this->assertSame( $expected2, get_metadata( 'user', $this->author->ID, $key, true ) );229 $this->assertTrue( delete_metadata( 'user', $this->author->ID, $key ) );230 $this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) );231 $this->assertIsInt( update_metadata( 'user', $this->author->ID, $key, $value2 ) );232 $this->assertSame( $expected2, get_metadata( 'user', $this->author->ID, $key, true ) );226 $this->assertIsInt( add_metadata( 'user', self::$author->ID, $key, $value2 ) ); 227 $this->assertSame( $expected2, get_metadata( 'user', self::$author->ID, $key, true ) ); 228 $this->assertTrue( delete_metadata( 'user', self::$author->ID, $key ) ); 229 $this->assertSame( '', get_metadata( 'user', self::$author->ID, $key, true ) ); 230 $this->assertIsInt( update_metadata( 'user', self::$author->ID, $key, $value2 ) ); 231 $this->assertSame( $expected2, get_metadata( 'user', self::$author->ID, $key, true ) ); 233 232 } 234 233 … … 347 346 */ 348 347 public function test_negative_meta_id() { 349 $negative_mid = $this->meta_id * -1;348 $negative_mid = self::$meta_id * -1; 350 349 351 350 $this->assertLessThan( 0, $negative_mid ); … … 359 358 */ 360 359 public function test_floating_meta_id() { 361 $floating_mid = $this->meta_id + 0.1337;360 $floating_mid = self::$meta_id + 0.1337; 362 361 363 362 $this->assertTrue( floor( $floating_mid ) !== $floating_mid ); … … 371 370 */ 372 371 public function test_string_point_zero_meta_id() { 373 $meta_id = add_metadata( 'user', $this->author->ID, 'meta_key', 'meta_value_2' );372 $meta_id = add_metadata( 'user', self::$author->ID, 'meta_key', 'meta_value_2' ); 374 373 375 374 $string_mid = "{$meta_id}.0"; … … 388 387 $data = array( 1, 2 ); 389 388 $value = serialize( $data ); 390 add_metadata( 'user', $this->author->ID, 'foo', $data );391 $found = get_metadata( 'user', $this->author->ID );389 add_metadata( 'user', self::$author->ID, 'foo', $data ); 390 $found = get_metadata( 'user', self::$author->ID ); 392 391 393 392 $this->assertSame( array( $value ), $found['foo'] ); … … 401 400 $data->foo = 'bar'; 402 401 $value = serialize( $data ); 403 add_metadata( 'user', $this->author->ID, 'foo', $data );404 $found = get_metadata( 'user', $this->author->ID );402 add_metadata( 'user', self::$author->ID, 'foo', $data ); 403 $found = get_metadata( 'user', self::$author->ID ); 405 404 406 405 $this->assertSame( array( $value ), $found['foo'] ); … … 416 415 ); 417 416 $value = serialize( $data ); 418 add_metadata( 'user', $this->author->ID, 'foo', $data );419 $found = get_metadata( 'user', $this->author->ID );417 add_metadata( 'user', self::$author->ID, 'foo', $data ); 418 $found = get_metadata( 'user', self::$author->ID ); 420 419 421 420 $this->assertSame( array( $value ), $found['foo'] ); -
trunk/tests/phpunit/tests/oembed/controller.php
r58286 r60253 305 305 306 306 public function test_request_json() { 307 $user = self::factory()->user->create_and_get( 308 array( 309 'display_name' => 'John Doe', 310 ) 311 ); 307 $user = get_user_by( 'id', self::$subscriber ); 312 308 $post = self::factory()->post->create_and_get( 313 309 array( … … 392 388 393 389 public function test_request_xml() { 394 $user = self::factory()->user->create_and_get( 395 array( 396 'display_name' => 'John Doe', 397 ) 398 ); 390 $user = get_user_by( 'id', self::$subscriber ); 399 391 $post = self::factory()->post->create_and_get( 400 392 array( … … 462 454 463 455 public function test_rest_pre_serve_request() { 464 $user = self::factory()->user->create_and_get( 465 array( 466 'display_name' => 'John Doe', 467 ) 468 ); 456 $user = get_user_by( 'id', self::$subscriber ); 469 457 $post = self::factory()->post->create_and_get( 470 458 array( … … 678 666 wp_set_current_user( self::$editor ); 679 667 680 $user = self::factory()->user->create_and_get( 681 array( 682 'display_name' => 'John Doe', 683 ) 684 ); 668 $user = get_user_by( 'id', self::$subscriber ); 685 669 $post = self::factory()->post->create_and_get( 686 670 array( -
trunk/tests/phpunit/tests/oembed/wpOembed.php
r51568 r60253 12 12 public $pre_oembed_result_filtered = false; 13 13 14 /** 15 * ID of the user. 16 * 17 * @var int 18 */ 19 public static $user_id; 20 21 /** 22 * Set up the shared fixture. 23 * 24 * @param WP_UnitTest_Factory $factory Factory instance. 25 */ 26 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 27 self::$user_id = $factory->user->create(); 28 } 29 14 30 public function set_up() { 15 31 parent::set_up(); … … 97 113 */ 98 114 public function test_wp_filter_pre_oembed_result_multisite_sub_samesub() { 99 $user_id = self:: factory()->user->create();115 $user_id = self::$user_id; 100 116 101 117 $blog_id = self::factory()->blog->create( … … 126 142 */ 127 143 public function test_wp_filter_pre_oembed_result_multisite_sub_othersub() { 128 $user_id = self:: factory()->user->create();144 $user_id = self::$user_id; 129 145 130 146 $blog_id = self::factory()->blog->create( … … 165 181 $post_id = self::factory()->post->create(); 166 182 $permalink = get_permalink( $post_id ); 167 $user_id = self:: factory()->user->create();183 $user_id = self::$user_id; 168 184 $blog_id = self::factory()->blog->create( 169 185 array( … … 190 206 */ 191 207 public function test_wp_filter_pre_oembed_result_multisite_preserves_switched_state() { 192 $user_id = self:: factory()->user->create();208 $user_id = self::$user_id; 193 209 194 210 $blog_id = self::factory()->blog->create( array( 'user_id' => $user_id ) ); … … 221 237 $current_blog_id = get_current_blog_id(); 222 238 223 $user_id = self:: factory()->user->create();239 $user_id = self::$user_id; 224 240 $blog_id = self::factory()->blog->create( 225 241 array( -
trunk/tests/phpunit/tests/post/getPages.php
r56746 r60253 7 7 */ 8 8 class Tests_Post_GetPages extends WP_UnitTestCase { 9 10 /** 11 * ID of the first author. 12 * 13 * @var int 14 */ 15 public static $author_id_1; 16 17 /** 18 * ID of the second author. 19 * 20 * @var int 21 */ 22 public static $author_id_2; 23 24 /** 25 * Set up the shared fixture. 26 * 27 * @param WP_UnitTest_Factory $factory Factory instance. 28 */ 29 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 30 self::$author_id_1 = $factory->user->create( 31 array( 32 'user_login' => 'author1', 33 'role' => 'author', 34 ) 35 ); 36 37 self::$author_id_2 = $factory->user->create( 38 array( 39 'user_login' => 'author2', 40 'role' => 'author', 41 ) 42 ); 43 } 44 9 45 /** 10 46 * @ticket 23167 … … 964 1000 */ 965 1001 public function test_get_pages_author() { 966 $author_1 = self::factory()->user->create( 967 array( 968 'user_login' => 'author1', 969 'role' => 'author', 970 ) 971 ); 1002 $author_1 = self::$author_id_1; 972 1003 $posts = self::factory()->post->create_many( 973 1004 2, … … 990 1021 */ 991 1022 public function test_get_pages_multiple_authors() { 992 $author_1 = self::factory()->user->create( 993 array( 994 'user_login' => 'author1', 995 'role' => 'author', 996 ) 997 ); 1023 $author_1 = self::$author_id_1; 998 1024 $post_1 = self::factory()->post->create( 999 1025 array( … … 1005 1031 ); 1006 1032 1007 $author_2 = self::factory()->user->create( 1008 array( 1009 'user_login' => 'author2', 1010 'role' => 'author', 1011 ) 1012 ); 1033 $author_2 = self::$author_id_2; 1013 1034 $post_2 = self::factory()->post->create( 1014 1035 array( … … 1032 1053 */ 1033 1054 public function test_get_pages_multiple_authors_by_user_login() { 1034 $author_1 = self::factory()->user->create( 1035 array( 1036 'user_login' => 'author1', 1037 'role' => 'author', 1038 ) 1039 ); 1055 $author_1 = self::$author_id_1; 1040 1056 $post_1 = self::factory()->post->create( 1041 1057 array( … … 1047 1063 ); 1048 1064 1049 $author_2 = self::factory()->user->create( 1050 array( 1051 'user_login' => 'author2', 1052 'role' => 'author', 1053 ) 1054 ); 1065 $author_2 = self::$author_id_2; 1055 1066 $post_2 = self::factory()->post->create( 1056 1067 array( -
trunk/tests/phpunit/tests/post/getPostsByAuthorSql.php
r51566 r60253 5 5 */ 6 6 class Tests_Post_GetPostsByAuthorSql extends WP_UnitTestCase { 7 8 /** 9 * ID of the first user. 10 * 11 * @var int 12 */ 13 public static $user_id_1; 14 15 /** 16 * ID of the second user. 17 * 18 * @var int 19 */ 20 public static $user_id_2; 21 22 /** 23 * Set up the shared fixture. 24 * 25 * @param WP_UnitTest_Factory $factory Factory instance. 26 */ 27 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 28 self::$user_id_1 = $factory->user->create(); 29 self::$user_id_2 = $factory->user->create(); 30 } 7 31 8 32 public function test_post_type_post() { … … 60 84 public function test_public_only_true_should_not_allow_any_private_posts_for_loggedin_user() { 61 85 $current_user = get_current_user_id(); 62 $u = self:: factory()->user->create();86 $u = self::$user_id_1; 63 87 wp_set_current_user( $u ); 64 88 … … 71 95 public function test_public_only_should_default_to_false() { 72 96 $current_user = get_current_user_id(); 73 $u = self:: factory()->user->create();97 $u = self::$user_id_1; 74 98 wp_set_current_user( $u ); 75 99 … … 81 105 public function test_public_only_false_should_allow_current_user_access_to_own_private_posts_when_current_user_matches_post_author() { 82 106 $current_user = get_current_user_id(); 83 $u = self:: factory()->user->create();107 $u = self::$user_id_1; 84 108 wp_set_current_user( $u ); 85 109 … … 92 116 public function test_public_only_false_should_not_allow_access_to_private_posts_if_current_user_is_not_post_author() { 93 117 $current_user = get_current_user_id(); 94 $u1 = self:: factory()->user->create();95 $u2 = self:: factory()->user->create();118 $u1 = self::$user_id_1; 119 $u2 = self::$user_id_2; 96 120 wp_set_current_user( $u1 ); 97 121 … … 104 128 public function test_public_only_false_should_allow_current_user_access_to_own_private_posts_when_post_author_is_not_provided() { 105 129 $current_user = get_current_user_id(); 106 $u = self:: factory()->user->create();130 $u = self::$user_id_1; 107 131 wp_set_current_user( $u ); 108 132 -
trunk/tests/phpunit/tests/query/conditionals.php
r56559 r60253 15 15 protected $post_ids; 16 16 17 /** 18 * ID of the user-a. 19 * 20 * @var int 21 */ 22 public static $user_a_id; 23 24 /** 25 * Set up the shared fixture. 26 * 27 * @param WP_UnitTest_Factory $factory Factory instance. 28 */ 29 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 30 self::$user_a_id = $factory->user->create( array( 'user_login' => 'user-a' ) ); 31 } 32 17 33 public function set_up() { 18 34 parent::set_up(); … … 589 605 // 'author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?author_name=$matches[1]&feed=$matches[2]', 590 606 public function test_author_feed() { 591 self::factory()->user->create( array( 'user_login' => 'user-a' ) );592 607 // Check the long form. 593 608 $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); … … 608 623 public function test_author_paged() { 609 624 update_option( 'posts_per_page', 2 ); 610 $user_id = self:: factory()->user->create( array( 'user_login' => 'user-a' ) );625 $user_id = self::$user_a_id; 611 626 self::factory()->post->create_many( 3, array( 'post_author' => $user_id ) ); 612 627 $this->go_to( '/author/user-a/page/2/' ); … … 616 631 // 'author/([^/]+)/?$' => 'index.php?author_name=$matches[1]', 617 632 public function test_author() { 618 $user_id = self:: factory()->user->create( array( 'user_login' => 'user-a' ) );633 $user_id = self::$user_a_id; 619 634 self::factory()->post->create( array( 'post_author' => $user_id ) ); 620 635 $this->go_to( '/author/user-a/' ); … … 623 638 624 639 public function test_author_with_no_posts() { 625 $user_id = self::factory()->user->create( array( 'user_login' => 'user-a' ) );626 640 $this->go_to( '/author/user-a/' ); 627 641 $this->assertQueryTrue( 'is_archive', 'is_author' ); … … 1123 1137 */ 1124 1138 public function test_is_author_with_nicename_that_begins_with_a_number_that_clashes_with_another_author_id() { 1125 $u1 = self:: factory()->user->create();1139 $u1 = self::$user_a_id; 1126 1140 1127 1141 $u2_name = $u1 . '_user'; … … 1280 1294 1281 1295 // We need a non-post that shares an ID with a post assigned a template. 1282 $user_id = self:: factory()->user->create();1296 $user_id = self::$user_a_id; 1283 1297 if ( ! get_post( $user_id ) ) { 1284 1298 $post_id = self::factory()->post->create( array( 'post_type' => 'post' ) ); … … 1353 1367 */ 1354 1368 public function test_is_author_should_not_match_numeric_id_to_nickname_beginning_with_id() { 1355 $u1 = self::factory()->user->create( 1356 array( 1357 'nickname' => 'Foo', 1358 'user_nicename' => 'foo', 1359 ) 1360 ); 1369 $u1 = self::$user_a_id; 1361 1370 $u2 = self::factory()->user->create( 1362 1371 array( … … 1376 1385 */ 1377 1386 public function test_is_author_should_not_match_numeric_id_to_user_nicename_beginning_with_id() { 1378 $u1 = self::factory()->user->create( 1379 array( 1380 'nickname' => 'Foo', 1381 'user_nicename' => 'foo', 1382 ) 1383 ); 1387 $u1 = self::$user_a_id; 1384 1388 $u2 = self::factory()->user->create( 1385 1389 array( -
trunk/tests/phpunit/tests/taxonomy.php
r60251 r60253 5 5 */ 6 6 class Tests_Taxonomy extends WP_UnitTestCase { 7 8 /** 9 * Editor user ID. 10 * 11 * @var int $editor_id 12 */ 13 public static $editor_id; 14 15 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 16 self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) ); 17 } 18 7 19 public function test_get_post_taxonomies() { 8 20 $this->assertSame( array( 'category', 'post_tag', 'post_format' ), get_object_taxonomies( 'post' ) ); … … 1011 1023 ); 1012 1024 1013 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'editor' ) ));1025 wp_set_current_user( self::$editor_id ); 1014 1026 $updated_post_id = edit_post( 1015 1027 array( … … 1037 1049 public function test_default_term_for_custom_taxonomy() { 1038 1050 1039 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'editor' ) ));1051 wp_set_current_user( self::$editor_id ); 1040 1052 1041 1053 $tax = 'custom-tax'; -
trunk/tests/phpunit/tests/url.php
r56549 r60253 8 8 class Tests_URL extends WP_UnitTestCase { 9 9 10 /** 11 * Author user ID. 12 * 13 * @var int $author_id 14 */ 15 public static $author_id; 16 17 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 18 self::$author_id = $factory->user->create( array( 'role' => 'author' ) ); 19 } 20 10 21 public function set_up() { 11 22 parent::set_up(); … … 387 398 */ 388 399 public function test_get_adjacent_post_should_return_private_posts_belonging_to_the_current_user() { 389 $u = self:: factory()->user->create( array( 'role' => 'author' ) );400 $u = self::$author_id; 390 401 $old_uid = get_current_user_id(); 391 402 wp_set_current_user( $u ); … … 426 437 */ 427 438 public function test_get_adjacent_post_should_return_private_posts_belonging_to_other_users_if_the_current_user_can_read_private_posts() { 428 $u1 = self:: factory()->user->create( array( 'role' => 'author' ) );439 $u1 = self::$author_id; 429 440 $u2 = self::factory()->user->create( array( 'role' => 'administrator' ) ); 430 441 $old_uid = get_current_user_id(); … … 466 477 */ 467 478 public function test_get_adjacent_post_should_not_return_private_posts_belonging_to_other_users_if_the_current_user_cannot_read_private_posts() { 468 $u1 = self:: factory()->user->create( array( 'role' => 'author' ) );479 $u1 = self::$author_id; 469 480 $u2 = self::factory()->user->create( array( 'role' => 'author' ) ); 470 481 $old_uid = get_current_user_id(); -
trunk/tests/phpunit/tests/user.php
r60250 r60253 1084 1084 */ 1085 1085 public function test_wp_update_user_should_delete_userslugs_cache() { 1086 $u = self:: factory()->user->create();1086 $u = self::$sub_id; 1087 1087 $user = get_userdata( $u ); 1088 1088 … … 1940 1940 $_REQUEST = array(); 1941 1941 1942 $administrator = self::factory()->user->create( 1943 array( 1944 'role' => 'administrator', 1945 ) 1946 ); 1942 $administrator = self::$admin_id; 1947 1943 1948 1944 wp_set_current_user( $administrator ); … … 1958 1954 1959 1955 // Promote an editor to an administrator. 1960 $editor = self::factory()->user->create( 1961 array( 1962 'role' => 'editor', 1963 ) 1964 ); 1956 $editor = self::$editor_id; 1965 1957 1966 1958 $_POST['role'] = 'administrator';
Note: See TracChangeset
for help on using the changeset viewer.