Make WordPress Core


Ignore:
Timestamp:
01/09/2019 05:59:49 AM (8 years ago)
Author:
pento
Message:

Comments: Add a new is_avatar_comment_type() function.

This function splits the get_avatar_comment_types filter out of get_avatar_data().

Props dshanske, birgire.
Fixes #44033.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/avatar.php

    r42343 r44499  
    241241        }
    242242
     243        /**
     244         * The `get_avatar_data()` function should return gravatar url when comment type allowed to retrieve avatars.
     245         *
     246         * @ticket 44033
     247         */
     248        public function test_get_avatar_data_should_return_gravatar_url_when_input_avatar_comment_type() {
     249                $comment_type = 'comment';
     250                $comment      = self::factory()->comment->create_and_get(
     251                        array(
     252                                'comment_author_email' => 'commenter@example.com',
     253                                'comment_type'         => $comment_type,
     254                        )
     255                );
     256
     257                $actual_data = get_avatar_data( $comment );
     258
     259                $this->assertTrue( is_avatar_comment_type( $comment_type ) );
     260                $this->assertRegexp( '|^http?://[0-9]+.gravatar.com/avatar/[0-9a-f]{32}\?|', $actual_data['url'] );
     261        }
     262
     263        /**
     264         * The `get_avatar_data()` function should return invalid url when comment type not allowed to retrieve avatars.
     265         *
     266         * @ticket 44033
     267         */
     268        public function test_get_avatar_data_should_return_invalid_url_when_input_not_avatar_comment_type() {
     269                $comment_type = 'review';
     270                $comment      = self::factory()->comment->create_and_get(
     271                        array(
     272                                'comment_author_email' => 'commenter@example.com',
     273                                'comment_type'         => $comment_type,
     274                        )
     275                );
     276
     277                $actual_data = get_avatar_data( $comment );
     278
     279                $this->assertFalse( is_avatar_comment_type( $comment_type ) );
     280                $this->assertFalse( $actual_data['url'] );
     281        }
     282
    243283}
Note: See TracChangeset for help on using the changeset viewer.