Changeset 35246 for trunk/tests/phpunit/tests/adminbar.php
- Timestamp:
- 10/17/2015 08:48:33 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/adminbar.php
r35242 r35246 7 7 */ 8 8 class Tests_AdminBar extends WP_UnitTestCase { 9 protected static $editor_id; 10 protected static $admin_id; 11 protected static $no_role_id; 12 protected static $post_id; 13 protected static $blog_id; 14 15 protected static $user_ids = array(); 9 16 10 17 public static function setUpBeforeClass() { 11 18 require_once( ABSPATH . WPINC . '/class-wp-admin-bar.php' ); 19 20 parent::setUpBeforeClass(); 21 } 22 23 public static function wpSetUpBeforeClass( $factory ) { 24 self::$user_ids[] = self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) ); 25 self::$user_ids[] = self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) ); 26 self::$user_ids[] = self::$no_role_id = $factory->user->create( array( 'role' => '' ) ); 27 } 28 29 public static function wpTearDownAfterClass() { 30 foreach ( self::$user_ids as $id ) { 31 self::delete_user( $id ); 32 } 12 33 } 13 34 … … 16 37 */ 17 38 function test_content_post_type() { 18 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'editor' ) ));39 wp_set_current_user( self::$editor_id ); 19 40 20 41 register_post_type( 'content', array( 'show_in_admin_bar' => true ) ); … … 35 56 */ 36 57 function test_merging_existing_meta_values() { 37 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'editor' ) ));58 wp_set_current_user( self::$editor_id ); 38 59 39 60 $admin_bar = new WP_Admin_Bar; … … 43 64 'meta' => array( 'class' => 'test-class' ), 44 65 ) ); 45 $node = $admin_bar->get_node( 'test-node' ); 46 $this->assertEquals( array( 'class' => 'test-class' ), $node->meta ); 66 67 $node1 = $admin_bar->get_node( 'test-node' ); 68 $this->assertEquals( array( 'class' => 'test-class' ), $node1->meta ); 47 69 48 70 $admin_bar->add_node( array( … … 51 73 ) ); 52 74 53 $node = $admin_bar->get_node( 'test-node' );54 $this->assertEquals( array( 'class' => 'test-class', 'some-meta' => 'value' ), $node ->meta );75 $node2 = $admin_bar->get_node( 'test-node' ); 76 $this->assertEquals( array( 'class' => 'test-class', 'some-meta' => 'value' ), $node2->meta ); 55 77 } 56 78 … … 63 85 } 64 86 65 $nobody = self::factory()->user->create( array( 'role' => '' ) ); 66 $this->assertFalse( user_can( $nobody, 'read' ) ); 67 68 wp_set_current_user( $nobody ); 87 $this->assertFalse( user_can( self::$no_role_id, 'read' ) ); 88 89 wp_set_current_user( self::$no_role_id ); 69 90 70 91 $wp_admin_bar = $this->get_standard_admin_bar(); … … 82 103 $this->assertFalse( $node_user_info->href ); 83 104 $this->assertNull( $node_edit_profile ); 84 85 105 } 86 106 … … 93 113 } 94 114 95 $editor = self::factory()->user->create( array( 'role' => 'editor' ) ); 96 $this->assertTrue( user_can( $editor, 'read' ) ); 97 98 wp_set_current_user( $editor ); 115 $this->assertTrue( user_can( self::$editor_id, 'read' ) ); 116 117 wp_set_current_user( self::$editor_id ); 99 118 100 119 $wp_admin_bar = $this->get_standard_admin_bar(); … … 126 145 } 127 146 128 $admin = self::factory()->user->create( array( 'role' => 'administrator' ) ); 129 $editor = self::factory()->user->create( array( 'role' => 'editor' ) ); 130 131 $this->assertTrue( user_can( $admin, 'read' ) ); 132 $this->assertTrue( user_can( $editor, 'read' ) ); 133 134 $new_blog_id = self::factory()->blog->create( array( 135 'user_id' => $admin, 136 ) ); 137 138 $this->assertTrue( is_user_member_of_blog( $admin, $new_blog_id ) ); 139 $this->assertFalse( is_user_member_of_blog( $editor, $new_blog_id ) ); 140 141 wp_set_current_user( $editor ); 142 143 switch_to_blog( $new_blog_id ); 147 $blog_id = self::factory()->blog->create( array( 148 'user_id' => self::$admin_id, 149 ) ); 150 151 $this->assertTrue( user_can( self::$admin_id, 'read' ) ); 152 $this->assertTrue( user_can( self::$editor_id, 'read' ) ); 153 154 $this->assertTrue( is_user_member_of_blog( self::$admin_id, $blog_id ) ); 155 $this->assertFalse( is_user_member_of_blog( self::$editor_id, $blog_id ) ); 156 157 wp_set_current_user( self::$editor_id ); 158 159 switch_to_blog( $blog_id ); 144 160 145 161 $wp_admin_bar = $this->get_standard_admin_bar(); … … 151 167 152 168 // get primary blog 153 $primary = get_active_blog_for_user( $editor);169 $primary = get_active_blog_for_user( self::$editor_id ); 154 170 $this->assertInternalType( 'object', $primary ); 155 171 … … 168 184 169 185 restore_current_blog(); 170 171 186 } 172 187 … … 180 195 } 181 196 182 $admin = self::factory()->user->create( array( 'role' => 'administrator' ) ); 183 $nobody = self::factory()->user->create( array( 'role' => '' ) ); 184 185 $this->assertTrue( user_can( $admin, 'read' ) ); 186 $this->assertFalse( user_can( $nobody, 'read' ) ); 187 188 $new_blog_id = self::factory()->blog->create( array( 189 'user_id' => $admin, 190 ) ); 191 192 $this->assertTrue( is_user_member_of_blog( $admin, $new_blog_id ) ); 193 $this->assertFalse( is_user_member_of_blog( $nobody, $new_blog_id ) ); 194 $this->assertTrue( is_user_member_of_blog( $nobody, get_current_blog_id() ) ); 197 $this->assertTrue( user_can( self::$admin_id, 'read' ) ); 198 $this->assertFalse( user_can( self::$no_role_id, 'read' ) ); 199 200 $blog_id = self::factory()->blog->create( array( 201 'user_id' => self::$admin_id, 202 ) ); 203 204 $this->assertTrue( is_user_member_of_blog( self::$admin_id, $blog_id ) ); 205 $this->assertFalse( is_user_member_of_blog( self::$no_role_id, $blog_id ) ); 206 $this->assertTrue( is_user_member_of_blog( self::$no_role_id, get_current_blog_id() ) ); 195 207 196 208 // Remove `$nobody` from the current blog, so they're not a member of any blog 197 $removed = remove_user_from_blog( $nobody, get_current_blog_id() );209 $removed = remove_user_from_blog( self::$no_role_id, get_current_blog_id() ); 198 210 199 211 $this->assertTrue( $removed ); 200 $this->assertFalse( is_user_member_of_blog( $nobody, get_current_blog_id() ) );201 202 wp_set_current_user( $nobody);203 204 switch_to_blog( $ new_blog_id );212 $this->assertFalse( is_user_member_of_blog( self::$no_role_id, get_current_blog_id() ) ); 213 214 wp_set_current_user( self::$no_role_id ); 215 216 switch_to_blog( $blog_id ); 205 217 206 218 $wp_admin_bar = $this->get_standard_admin_bar(); … … 212 224 213 225 // get primary blog 214 $primary = get_active_blog_for_user( $nobody);226 $primary = get_active_blog_for_user( self::$no_role_id ); 215 227 $this->assertNull( $primary ); 216 228 … … 228 240 229 241 restore_current_blog(); 230 231 242 } 232 243
Note: See TracChangeset
for help on using the changeset viewer.