Skip to:
Content

BuddyPress.org

Changeset 13316


Ignore:
Timestamp:
08/13/2022 12:59:52 PM (4 years ago)
Author:
imath
Message:

Media: adjust avatar/cover image unit tests for the WP v5.7 context

As the .webp image file type will only be available if WP version >= 5.8, we need to only check for it using the same requirement.

Fixes #8643

Location:
trunk/tests/phpunit/testcases/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/avatars.php

    r13315 r13316  
    66class BP_Tests_Avatars extends BP_UnitTestCase {
    77        private $params = array();
     8        protected $allowed_image_types = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
     9        protected $allowed_image_mimes = array( 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/png' );
     10
     11        public function set_up() {
     12                parent::set_up();
     13
     14                if ( bp_is_running_wp( '5.8.0', '>=' ) ) {
     15                        $this->allowed_image_types[] = 'webp';
     16                        $this->allowed_image_mimes[] = 'image/webp';
     17                }
     18        }
    819
    920        private function clean_existing_avatars( $type = 'user' ) {
     
    256267         */
    257268        public function test_bp_core_get_allowed_avatar_types_filter() {
     269                $allowed_image_types = $this->allowed_image_types;
    258270                add_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_add_type' ) );
    259271
    260                 $this->assertEquals( array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' ), bp_core_get_allowed_avatar_types() );
     272                $this->assertEquals( $allowed_image_types, bp_core_get_allowed_avatar_types() );
    261273
    262274                remove_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_add_type' ) );
    263275
    264276                add_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_remove_type' ) );
    265 
    266                 $this->assertEquals( array( 'jpeg', 'jpe', 'gif', 'png', 'webp' ), bp_core_get_allowed_avatar_types() );
     277                array_shift( $allowed_image_types );
     278
     279                $this->assertEquals( $allowed_image_types, bp_core_get_allowed_avatar_types() );
    267280
    268281                remove_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_remove_type' ) );
     
    270283                add_filter( 'bp_core_get_allowed_avatar_types', '__return_empty_array' );
    271284
    272                 $this->assertEquals( array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' ), bp_core_get_allowed_avatar_types() );
     285                $this->assertEquals( $this->allowed_image_types, bp_core_get_allowed_avatar_types() );
    273286
    274287                remove_filter( 'bp_core_get_allowed_avatar_types', '__return_empty_array' );
     
    280293         */
    281294        public function test_bp_core_get_allowed_avatar_mimes() {
    282                 $mimes = bp_core_get_allowed_avatar_mimes();
    283 
    284                 $this->assertEqualSets( array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' ), array_keys( $mimes ) );
    285                 $this->assertEqualSets( array( 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/png', 'image/webp' ), array_values( $mimes ) );
     295                $mimes               = bp_core_get_allowed_avatar_mimes();
     296                $allowed_image_mimes = $this->allowed_image_mimes;
     297
     298                $this->assertEqualSets( $this->allowed_image_types, array_keys( $mimes ) );
     299                $this->assertEqualSets( $allowed_image_mimes, array_values( $mimes ) );
    286300
    287301                add_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_add_type' ) );
    288302
    289                 $this->assertEqualSets( array( 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/png', 'image/webp' ), array_values( bp_core_get_allowed_avatar_mimes() ) );
     303                $this->assertEqualSets( $allowed_image_mimes, array_values( bp_core_get_allowed_avatar_mimes() ) );
    290304
    291305                remove_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_add_type' ) );
    292306
    293307                add_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_remove_type' ) );
    294 
    295                 $this->assertEqualSets( array( 'image/jpeg', 'image/jpeg', 'image/gif', 'image/png', 'image/webp', 'image/jpeg' ), array_values( bp_core_get_allowed_avatar_mimes() ) );
     308                array_shift( $allowed_image_mimes );
     309
     310                $this->assertEqualSets( array_merge( $allowed_image_mimes, array( 'image/jpeg' ) ), array_values( bp_core_get_allowed_avatar_mimes() ) );
    296311
    297312                remove_filter( 'bp_core_get_allowed_avatar_types', array( $this, 'avatar_types_filter_remove_type' ) );
     
    299314                add_filter( 'bp_core_get_allowed_avatar_types', '__return_empty_array' );
    300315
    301                 $this->assertEqualSets( array( 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/png', 'image/webp' ), array_values( bp_core_get_allowed_avatar_mimes() ) );
     316                $this->assertEqualSets( $this->allowed_image_mimes, array_values( bp_core_get_allowed_avatar_mimes() ) );
    302317
    303318                remove_filter( 'bp_core_get_allowed_avatar_types', '__return_empty_array' );
  • trunk/tests/phpunit/testcases/core/functions.php

    r13315 r13316  
    785785         */
    786786        public function test_bp_attachments_get_allowed_types() {
    787                 $supported = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' );
     787                $supported = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
     788                if ( bp_is_running_wp( '5.8.0', '>=' ) ) {
     789                        $supported[] = 'webp';
     790                }
    788791
    789792                $avatar = bp_attachments_get_allowed_types( 'avatar' );
Note: See TracChangeset for help on using the changeset viewer.