Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/19/2015 11:41:33 PM (7 years ago)
Author:
imath
Message:

Allow multiple classes to be passed to the class argument of bp_core_fetch_avatar()

Using an array of classes or a list of classes separated by a space for the class argument of bp_core_fetch_avatar() will output each one of them into the class attribute of the image tag.

Fixes #6069

File:
1 edited

Legend:

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

    r9316 r9381  
    179179        $this->assertEquals( $html, $expected_html );
    180180    }
     181
     182    /**
     183     * @group bp_core_fetch_avatar
     184     */
     185    public function test_bp_core_fetch_avatar_class_attribute() {
     186        $u = $this->factory->user->create();
     187
     188        $hw = 100;
     189        $args = array(
     190            'item_id'    => $u,
     191            'object'     => 'user',
     192            'type'       => 'full',
     193            'width'      => $hw,
     194            'height'     => $hw,
     195            'class'      => '',
     196            'no_grav'    => true,
     197            'html'       => true,
     198        );
     199
     200        // Class attribute is empty
     201        $avatar = bp_core_fetch_avatar( $args );
     202        $expected = array( 'avatar', 'user-' . $u . '-avatar', 'avatar-' . $hw );
     203        preg_match( '/class=["\']?([^"\']*)["\' ]/is', $avatar, $matches );
     204        $classes = explode( ' ', $matches[1] );
     205        $this->assertSame( $expected, array_intersect_key( $expected, $classes ) );
     206
     207        // Class attribute is a String
     208        $args['class'] = 'custom-class class-custom';
     209        $avatar = bp_core_fetch_avatar( $args );
     210        $expected = array_merge( explode( ' ', $args['class'] ), array( 'user-' . $u . '-avatar', 'avatar-' . $hw ) );
     211        preg_match( '/class=["\']?([^"\']*)["\' ]/is', $avatar, $matches );
     212        $classes = explode( ' ', $matches[1] );
     213        $this->assertSame( $expected, array_intersect_key( $expected, $classes ) );
     214
     215        // Class attribute is an Array
     216        $args['class'] = array( 'custom-class', 'class-custom' );
     217        $avatar = bp_core_fetch_avatar( $args );
     218        $expected = array_merge( $args['class'], array( 'user-' . $u . '-avatar', 'avatar-' . $hw ) );
     219        preg_match( '/class=["\']?([^"\']*)["\' ]/is', $avatar, $matches );
     220        $classes = explode( ' ', $matches[1] );
     221        $this->assertSame( $expected, array_intersect_key( $expected, $classes ) );
     222    }
    181223}
Note: See TracChangeset for help on using the changeset viewer.