Changeset 9760 for trunk/tests/phpunit/testcases/core/avatars.php
- Timestamp:
- 04/16/2015 11:09:33 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/testcases/core/avatars.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/core/avatars.php
r9576 r9760 205 205 $this->assertSame( $expected, array_intersect_key( $expected, $classes ) ); 206 206 } 207 208 /** 209 * @group bp_core_check_avatar_type 210 */ 211 public function test_bp_core_check_avatar_type() { 212 $plugin_dir = trailingslashit( buddypress()->plugin_dir ); 213 214 $file = array( 215 'file' => array( 216 'name' => 'humans.txt', 217 'type' => 'text/plain', 218 'tmp_name' => $plugin_dir . 'humans.txt', 219 ) 220 ); 221 222 $this->assertFalse( bp_core_check_avatar_type( $file ) ); 223 224 $file = array( 225 'file' => array( 226 'name' => 'mystery-man.jpg', 227 'type' => 'image/jpeg', 228 'tmp_name' => $plugin_dir . 'bp-core/images/mystery-man.jpg', 229 ) 230 ); 231 232 $this->assertTrue( bp_core_check_avatar_type( $file ) ); 233 234 $file = array( 235 'file' => array( 236 'name' => 'mystery-man.jpg', 237 'type' => 'application/octet-stream', 238 'tmp_name' => $plugin_dir . 'bp-core/images/mystery-man.jpg', 239 ) 240 ); 241 242 $this->assertTrue( bp_core_check_avatar_type( $file ), 'flash is using application/octet-stream for image uploads' ); 243 } 244 245 /** 246 * @group bp_core_check_avatar_type 247 * @group bp_core_get_allowed_avatar_types 248 */ 249 public function test_bp_core_get_allowed_avatar_types_filter() { 250 add_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_add_type' ) ); 251 252 $this->assertEquals( array( 'jpeg', 'gif', 'png' ), bp_core_get_allowed_avatar_types() ); 253 254 remove_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_add_type' ) ); 255 256 add_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_remove_type' ) ); 257 258 $this->assertEquals( array( 'gif', 'png' ), bp_core_get_allowed_avatar_types() ); 259 260 remove_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_remove_type' ) ); 261 262 add_filter( 'bp_core_get_allowed_avatar_types', '__return_empty_array' ); 263 264 $this->assertEquals( array( 'jpeg', 'gif', 'png' ), bp_core_get_allowed_avatar_types() ); 265 266 remove_filter( 'bp_core_get_allowed_avatar_types', '__return_empty_array' ); 267 } 268 269 /** 270 * @group bp_core_check_avatar_type 271 * @group bp_core_get_allowed_avatar_mimes 272 */ 273 public function test_bp_core_get_allowed_avatar_mimes() { 274 $mimes = bp_core_get_allowed_avatar_mimes(); 275 276 $this->assertEquals( array( 'jpeg', 'gif', 'png', 'jpg' ), array_keys( $mimes ) ); 277 $this->assertEquals( array( 'image/jpeg', 'image/gif', 'image/png', 'image/jpeg' ), array_values( $mimes ) ); 278 279 add_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_add_type' ) ); 280 281 $this->assertEquals( array( 'image/jpeg', 'image/gif', 'image/png', 'image/jpeg' ), array_values( bp_core_get_allowed_avatar_mimes() ) ); 282 283 remove_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_add_type' ) ); 284 285 add_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_remove_type' ) ); 286 287 $this->assertEquals( array( 'image/gif', 'image/png' ), array_values( bp_core_get_allowed_avatar_mimes() ) ); 288 289 remove_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_remove_type' ) ); 290 291 add_filter( 'bp_core_get_allowed_avatar_types', '__return_empty_array' ); 292 293 $this->assertEquals( array( 'image/jpeg', 'image/gif', 'image/png', 'image/jpeg' ), array_values( bp_core_get_allowed_avatar_mimes() ) ); 294 295 remove_filter( 'bp_core_get_allowed_avatar_types', '__return_empty_array' ); 296 } 297 298 public function avatar_types_filter_add_type( $types ) { 299 $types[] = 'bmp'; 300 301 return $types; 302 } 303 304 public function avatar_types_filter_remove_type( $types ) { 305 $jpeg = array_shift( $types ); 306 307 return $types; 308 } 207 309 }
Note: See TracChangeset
for help on using the changeset viewer.