Changeset 42343 for trunk/tests/phpunit/tests/user/countUsers.php
- Timestamp:
- 11/30/2017 11:09:33 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/user/countUsers.php
r41653 r42343 14 14 public function test_count_users_is_accurate( $strategy ) { 15 15 // Setup users 16 $admin = self::factory()->user->create( array( 17 'role' => 'administrator', 18 ) ); 19 $editor = self::factory()->user->create( array( 20 'role' => 'editor', 21 ) ); 22 $author = self::factory()->user->create( array( 23 'role' => 'author', 24 ) ); 25 $contributor = self::factory()->user->create( array( 26 'role' => 'contributor', 27 ) ); 28 $subscriber = self::factory()->user->create( array( 29 'role' => 'subscriber', 30 ) ); 31 $none = self::factory()->user->create( array( 32 'role' => '', 33 ) ); 34 $nobody = self::factory()->user->create( array( 35 'role' => '', 36 ) ); 16 $admin = self::factory()->user->create( 17 array( 18 'role' => 'administrator', 19 ) 20 ); 21 $editor = self::factory()->user->create( 22 array( 23 'role' => 'editor', 24 ) 25 ); 26 $author = self::factory()->user->create( 27 array( 28 'role' => 'author', 29 ) 30 ); 31 $contributor = self::factory()->user->create( 32 array( 33 'role' => 'contributor', 34 ) 35 ); 36 $subscriber = self::factory()->user->create( 37 array( 38 'role' => 'subscriber', 39 ) 40 ); 41 $none = self::factory()->user->create( 42 array( 43 'role' => '', 44 ) 45 ); 46 $nobody = self::factory()->user->create( 47 array( 48 'role' => '', 49 ) 50 ); 37 51 38 52 // Test user counts … … 40 54 41 55 $this->assertEquals( 8, $count['total_users'] ); 42 $this->assertEquals( array( 43 'administrator' => 2, 44 'editor' => 1, 45 'author' => 1, 46 'contributor' => 1, 47 'subscriber' => 1, 48 'none' => 2, 49 ), $count['avail_roles'] ); 56 $this->assertEquals( 57 array( 58 'administrator' => 2, 59 'editor' => 1, 60 'author' => 1, 61 'contributor' => 1, 62 'subscriber' => 1, 63 'none' => 2, 64 ), $count['avail_roles'] 65 ); 50 66 51 67 } … … 61 77 public function test_count_users_multisite_is_accurate( $strategy ) { 62 78 // Setup users 63 $admin = self::factory()->user->create( array( 64 'role' => 'administrator', 65 ) ); 66 $editor = self::factory()->user->create( array( 67 'role' => 'editor', 68 ) ); 69 $author = self::factory()->user->create( array( 70 'role' => 'author', 71 ) ); 72 $contributor = self::factory()->user->create( array( 73 'role' => 'contributor', 74 ) ); 75 $subscriber = self::factory()->user->create( array( 76 'role' => 'subscriber', 77 ) ); 78 $none = self::factory()->user->create( array( 79 'role' => '', 80 ) ); 81 $nobody = self::factory()->user->create( array( 82 'role' => '', 83 ) ); 79 $admin = self::factory()->user->create( 80 array( 81 'role' => 'administrator', 82 ) 83 ); 84 $editor = self::factory()->user->create( 85 array( 86 'role' => 'editor', 87 ) 88 ); 89 $author = self::factory()->user->create( 90 array( 91 'role' => 'author', 92 ) 93 ); 94 $contributor = self::factory()->user->create( 95 array( 96 'role' => 'contributor', 97 ) 98 ); 99 $subscriber = self::factory()->user->create( 100 array( 101 'role' => 'subscriber', 102 ) 103 ); 104 $none = self::factory()->user->create( 105 array( 106 'role' => '', 107 ) 108 ); 109 $nobody = self::factory()->user->create( 110 array( 111 'role' => '', 112 ) 113 ); 84 114 85 115 // Setup blogs 86 $blog_1 = (int) self::factory()->blog->create( array( 87 'user_id' => $editor, 88 ) ); 89 $blog_2 = (int) self::factory()->blog->create( array( 90 'user_id' => $author, 91 ) ); 116 $blog_1 = (int) self::factory()->blog->create( 117 array( 118 'user_id' => $editor, 119 ) 120 ); 121 $blog_2 = (int) self::factory()->blog->create( 122 array( 123 'user_id' => $author, 124 ) 125 ); 92 126 93 127 // Add users to blogs … … 99 133 100 134 $this->assertEquals( 8, $count['total_users'] ); 101 $this->assertEquals( array( 102 'administrator' => 2, 103 'editor' => 1, 104 'author' => 1, 105 'contributor' => 1, 106 'subscriber' => 1, 107 'none' => 2, 108 ), $count['avail_roles'] ); 135 $this->assertEquals( 136 array( 137 'administrator' => 2, 138 'editor' => 1, 139 'author' => 1, 140 'contributor' => 1, 141 'subscriber' => 1, 142 'none' => 2, 143 ), $count['avail_roles'] 144 ); 109 145 110 146 // Test users counts on blog 1 … … 114 150 115 151 $this->assertEquals( 2, $count['total_users'] ); 116 $this->assertEquals( array( 117 'administrator' => 1, 118 'editor' => 1, 119 'none' => 0, 120 ), $count['avail_roles'] ); 152 $this->assertEquals( 153 array( 154 'administrator' => 1, 155 'editor' => 1, 156 'none' => 0, 157 ), $count['avail_roles'] 158 ); 121 159 122 160 // Test users counts on blog 2 … … 126 164 127 165 $this->assertEquals( 2, $count['total_users'] ); 128 $this->assertEquals( array( 129 'administrator' => 1, 130 'contributor' => 1, 131 'none' => 0, 132 ), $count['avail_roles'] ); 166 $this->assertEquals( 167 array( 168 'administrator' => 1, 169 'contributor' => 1, 170 'none' => 0, 171 ), $count['avail_roles'] 172 ); 133 173 134 174 } … … 146 186 switch_to_blog( $site_id ); 147 187 wp_roles()->add_role( 'tester', 'Tester', array( 'test' => true ) ); 148 $user_id = self::factory()->user->create( array( 149 'role' => 'tester', 150 ) ); 188 $user_id = self::factory()->user->create( 189 array( 190 'role' => 'tester', 191 ) 192 ); 151 193 restore_current_blog(); 152 194 153 195 $count = count_users( $strategy, $site_id ); 154 $this->assertEqualSetsWithIndex( array( 155 'tester' => 1, 156 'none' => 0, 157 ), $count['avail_roles'] ); 196 $this->assertEqualSetsWithIndex( 197 array( 198 'tester' => 1, 199 'none' => 0, 200 ), $count['avail_roles'] 201 ); 158 202 } 159 203 … … 166 210 167 211 // Setup users 168 $admin = self::factory()->user->create( array( 169 'role' => 'administrator', 170 ) ); 171 $editor = self::factory()->user->create( array( 172 'role' => 'editor', 173 ) ); 212 $admin = self::factory()->user->create( 213 array( 214 'role' => 'administrator', 215 ) 216 ); 217 $editor = self::factory()->user->create( 218 array( 219 'role' => 'editor', 220 ) 221 ); 174 222 175 223 get_userdata( $editor )->add_role( 'author' ); 176 224 177 $this->assertEquals( array( 178 'editor', 179 'author' 180 ), get_userdata( $editor )->roles ); 225 $this->assertEquals( 226 array( 227 'editor', 228 'author', 229 ), get_userdata( $editor )->roles 230 ); 181 231 182 232 // Test user counts … … 184 234 185 235 $this->assertEquals( 3, $count['total_users'] ); 186 $this->assertEquals( array( 187 'administrator' => 2, 188 'editor' => 1, 189 'author' => 1, 190 'none' => 0, 191 ), $count['avail_roles'] ); 236 $this->assertEquals( 237 array( 238 'administrator' => 2, 239 'editor' => 1, 240 'author' => 1, 241 'none' => 0, 242 ), $count['avail_roles'] 243 ); 192 244 193 245 } … … 204 256 $count = count_users( $strategy ); 205 257 206 $u = self::factory()->user->create( array( 207 'role' => 'editor', 208 ) ); 258 $u = self::factory()->user->create( 259 array( 260 'role' => 'editor', 261 ) 262 ); 209 263 210 264 // Manually delete the user, but leave the capabilities usermeta. 211 $wpdb->delete( $wpdb->users, array( 212 'ID' => $u, 213 ) ); 265 $wpdb->delete( 266 $wpdb->users, array( 267 'ID' => $u, 268 ) 269 ); 214 270 215 271 $count2 = count_users( $strategy );
Note: See TracChangeset
for help on using the changeset viewer.