[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @group core 5 * @group BP_Button 6 */ 7 class BP_Tests_BP_Button extends BP_UnitTestCase { 8 /** 9 * @group block_self 10 */ 11 public function test_block_self_own_profile() { 12 $u = self::factory()->user->create(); 13 $this->set_current_user( $u ); 14 15 $this->go_to( bp_core_get_user_domain( $u ) ); 16 17 $b = new BP_Button( array( 18 'id' => 'foo', 19 'component' => 'members', 20 'block_self' => true, 21 ) ); 22 23 $this->assertEquals( '', $b->contents ); 24 } 25 26 /** 27 * @group block_self 28 */ 29 public function test_block_self_others_profile() { 30 $u1 = self::factory()->user->create(); 31 $this->set_current_user( $u1 ); 32 33 $u2 = self::factory()->user->create(); 34 $this->go_to( bp_core_get_user_domain( $u2 ) ); 35 36 $b = new BP_Button( array( 37 'id' => 'foo', 38 'component' => 'members', 39 'block_self' => true, 40 ) ); 41 42 $this->assertNotEmpty( $b->contents ); 43 } 44 45 /** 46 * @group block_self 47 */ 48 public function test_block_self_inside_members_loop() { 49 $now = time(); 50 $u1 = self::factory()->user->create( array( 51 'last_activity' => date( 'Y-m-d H:i:s', $now ), 52 ) ); 53 $u2 = self::factory()->user->create( array( 54 'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ), 55 ) ); 56 57 $this->set_current_user( $u1 ); 58 59 $found = array(); 60 if ( bp_has_members() ) { 61 while ( bp_members() ) { 62 bp_the_member(); 63 64 $b = new BP_Button( array( 65 'id' => 'foo', 66 'component' => 'members', 67 'block_self' => true, 68 ) ); 69 70 $found[ bp_get_member_user_id() ] = empty( $b->contents ); 71 } 72 } 73 74 $expected = array( 75 $u1 => true, 76 $u2 => false, 77 ); 78 79 $this->assertSame( $expected, $found ); 80 81 // clean up 82 $GLOBALS['members_template'] = null; 83 } 84 85 /** 86 * @group block_self 87 */ 88 public function test_block_self_false_inside_members_loop() { 89 $now = time(); 90 $u1 = self::factory()->user->create( array( 91 'last_activity' => date( 'Y-m-d H:i:s', $now ), 92 ) ); 93 $u2 = self::factory()->user->create( array( 94 'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ), 95 ) ); 96 97 $this->set_current_user( $u1 ); 98 99 $found = array(); 100 if ( bp_has_members() ) { 101 while ( bp_members() ) { 102 bp_the_member(); 103 104 $b = new BP_Button( array( 105 'id' => 'foo', 106 'component' => 'members', 107 'block_self' => false, 108 ) ); 109 110 $found[ bp_get_member_user_id() ] = empty( $b->contents ); 111 } 112 } 113 114 $expected = array( 115 $u1 => false, 116 $u2 => false, 117 ); 118 119 $this->assertSame( $expected, $found ); 120 121 // clean up 122 $GLOBALS['members_template'] = null; 123 } 124 125 /** 126 * @group block_self 127 */ 128 public function test_block_self_inside_members_loop_on_my_profile_page() { 129 $now = time(); 130 $u1 = self::factory()->user->create( array( 131 'last_activity' => date( 'Y-m-d H:i:s', $now ), 132 ) ); 133 $u2 = self::factory()->user->create( array( 134 'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ), 135 ) ); 136 137 $this->set_current_user( $u1 ); 138 $this->go_to( bp_core_get_user_domain( $u1 ) ); 139 140 $found = array(); 141 if ( bp_has_members() ) { 142 while ( bp_members() ) { 143 bp_the_member(); 144 145 $b = new BP_Button( array( 146 'id' => 'foo', 147 'component' => 'members', 148 'block_self' => true, 149 ) ); 150 151 $found[ bp_get_member_user_id() ] = empty( $b->contents ); 152 } 153 } 154 155 $expected = array( 156 $u1 => true, 157 $u2 => false, 158 ); 159 160 $this->assertSame( $expected, $found ); 161 162 // clean up 163 $GLOBALS['members_template'] = null; 164 } 165 166 /** 167 * @ticket BP7226 168 */ 169 public function test_bp_button_new_args() { 170 $b = new BP_Button( array( 171 'id' => 'foo', 172 'component' => 'members', 173 'block_self' => false, 174 'must_be_logged_in' => false, 175 'parent_element' => 'section', 176 'parent_attr' => array( 177 'class' => 'section-class', 178 'id' => 'section-id', 179 'data-parent' => 'foo', 180 ), 181 'button_element' => 'button', 182 'button_attr' => array( 183 'autofocus' => 'autofocus', 184 'type' => 'submit', 185 'name' => 'my-button' 186 ) 187 ) ); 188 189 $this->assertInternalType( 'int', strpos( $b->contents, '<section ' ) ); 190 $this->assertInternalType( 'int', strpos( $b->contents, 'class="section-class ' ) ); 191 $this->assertInternalType( 'int', strpos( $b->contents, 'id="section-id"' ) ); 192 $this->assertInternalType( 'int', strpos( $b->contents, 'data-parent="foo"' ) ); 193 $this->assertInternalType( 'int', strpos( $b->contents, '<button ' ) ); 194 $this->assertInternalType( 'int', strpos( $b->contents, 'autofocus="autofocus"' ) ); 195 $this->assertInternalType( 'int', strpos( $b->contents, 'type="submit"' ) ); 196 $this->assertInternalType( 'int', strpos( $b->contents, 'name="my-button"' ) ); 197 } 198 199 /** 200 * @ticket BP7226 201 */ 202 public function test_bp_button_deprecated_args_should_still_render() { 203 $b = new BP_Button( array( 204 'id' => 'foo', 205 'component' => 'members', 206 'block_self' => false, 207 'must_be_logged_in' => false, 208 'wrapper' => 'section', 209 'wrapper_class' => 'section-class', 210 'wrapper_id' => 'section-id', 211 'link_href' => 'http://example.com', 212 'link_class' => 'link-class', 213 'link_id' => 'link-id', 214 'link_rel' => 'nofollow', 215 'link_title' => 'link-title' 216 ) ); 217 218 $this->assertInternalType( 'int', strpos( $b->contents, '<section ' ) ); 219 $this->assertInternalType( 'int', strpos( $b->contents, 'class="section-class ' ) ); 220 $this->assertInternalType( 'int', strpos( $b->contents, 'id="section-id"' ) ); 221 $this->assertInternalType( 'int', strpos( $b->contents, 'href="http://example.com"' ) ); 222 $this->assertInternalType( 'int', strpos( $b->contents, 'class="link-class"' ) ); 223 $this->assertInternalType( 'int', strpos( $b->contents, 'id="link-id"' ) ); 224 $this->assertInternalType( 'int', strpos( $b->contents, 'rel="nofollow"' ) ); 225 $this->assertInternalType( 'int', strpos( $b->contents, 'title="link-title"' ) ); 226 } 227 228 /** 229 * @ticket BP7226 230 */ 231 public function test_bp_button_new_element_attrs_have_precedence_over_deprecated_element_attrs() { 232 $b = new BP_Button( array( 233 'id' => 'foo', 234 'component' => 'members', 235 'block_self' => false, 236 'must_be_logged_in' => false, 237 'button_element' => 'button', 238 'button_attr' => array( 239 'class' => 'new-class', 240 ), 241 'link_class' => 'old-class' 242 ) ); 243 244 $this->assertInternalType( 'int', strpos( $b->contents, '<button class="new-class"' ) ); 245 } 246 247 /** 248 * @ticket BP7226 249 */ 250 public function test_bp_button_new_element_attrs_should_not_render_for_empty_attrs() { 251 $b = new BP_Button( array( 252 'id' => 'foo', 253 'component' => 'members', 254 'block_self' => false, 255 'must_be_logged_in' => false, 256 'button_element' => 'button', 257 'button_attr' => array( 258 'class' => '', 259 ), 260 ) ); 261 262 $this->assertFalse( strpos( $b->contents, '<button class=""' ) ); 263 } 264 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |