Changeset 9125 for trunk/tests/phpunit/testcases/core/avatars.php
- Timestamp:
- 11/05/2014 03:22:56 PM (12 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/testcases/core/avatars.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/core/avatars.php
r8958 r9125 6 6 class BP_Tests_Avatars extends BP_UnitTestCase { 7 7 protected $old_current_user = 0; 8 9 private $params = array(); 8 10 9 11 public function setUp() { … … 111 113 return 'foo'; 112 114 } 115 116 /** 117 * @group bp_core_fetch_avatar 118 */ 119 public function test_bp_core_fetch_avatar_parameter_conservation() { 120 // First, run the check with custom parameters, specifying no gravatar. 121 $this->params = array( 122 'item_id' => 1406, 123 'object' => 'custom_object', 124 'type' => 'full', 125 'avatar_dir' => 'custom-dir', 126 'width' => 48, 127 'height' => 54, 128 'class' => 'custom-class', 129 'css_id' => 'custom-css-id', 130 'alt' => 'custom alt', 131 'email' => 'avatar@avatar.org', 132 'no_grav' => true, 133 'html' => true, 134 'title' => 'custom-title', 135 ); 136 137 // Check to make sure the custom parameters survived the function all the way up to output 138 add_filter( 'bp_core_fetch_avatar', array( $this, 'bp_core_fetch_avatar_filter_check' ), 12, 2 ); 139 $avatar = bp_core_fetch_avatar( $this->params ); 140 141 // Re-run check, allowing gravatars. 142 $this->params['no_grav'] = false; 143 $avatar = bp_core_fetch_avatar( $this->params ); 144 145 remove_filter( 'bp_core_fetch_avatar', array( $this, 'bp_core_fetch_avatar_filter_check' ), 12, 2 ); 146 147 unset( $this->params ); 148 } 149 150 public function bp_core_fetch_avatar_filter_check( $html, $params ) { 151 // Check that the passed parameters match the original custom parameters. 152 $this->assertEmpty( array_merge( array_diff( $params, $this->params ), array_diff( $this->params, $params ) ) ); 153 154 // Check the returned html to see that it matches an expected value. 155 // Get the correct default avatar, based on whether gravatars are allowed. 156 if ( $params['no_grav'] ) { 157 $avatar_url = bp_core_avatar_default( 'local' ); 158 } else { 159 // This test has the slight odor of hokum since it recreates so much code that could be changed at any time. 160 $bp = buddypress(); 161 // Set host based on if using ssl 162 $host = 'http://gravatar.com/avatar/'; 163 if ( is_ssl() ) { 164 $host = 'https://secure.gravatar.com/avatar/'; 165 } 166 // Set expected gravatar type 167 if ( empty( $bp->grav_default->{$this->params['object']} ) ) { 168 $default_grav = 'wavatar'; 169 } else if ( 'mystery' == $bp->grav_default->{$this->params['object']} ) { 170 $default_grav = apply_filters( 'bp_core_mysteryman_src', 'mm', $this->params['width'] ); 171 } else { 172 $default_grav = $bp->grav_default->{$this->params['object']}; 173 } 174 175 $avatar_url = $host . md5( strtolower( $this->params['email'] ) ) . '?d=' . $default_grav . '&s=' . $this->params['width']; 176 177 // Gravatar rating; http://bit.ly/89QxZA 178 $rating = get_option( 'avatar_rating' ); 179 if ( ! empty( $rating ) ) { 180 $avatar_url .= "&r={$rating}"; 181 } 182 } 183 184 $expected_html = '<img src="' . $avatar_url . '" id="' . $this->params['css_id'] . '" class="' . $this->params['class'] . ' ' . $this->params['object'] . '-' . $this->params['item_id'] . '-avatar avatar-' . $this->params['width'] . ' photo" width="' . $this->params['width'] . '" height="' . $this->params['height'] . '" alt="' . $this->params['alt'] . '" title="' . $this->params['title'] . '" />'; 185 186 $this->assertEquals( $html, $expected_html ); 187 } 113 188 }
Note: See TracChangeset
for help on using the changeset viewer.