Changeset 55821 for trunk/tests/phpunit/tests/media.php
- Timestamp:
- 05/17/2023 06:29:41 PM (3 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/media.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/media.php
r55816 r55821 3965 3965 3966 3966 /** 3967 * Tests that `wp_get_attachment_image()` uses the correct default context. 3968 * 3969 * @ticket 58212 3970 * 3971 * @covers ::wp_get_attachment_image() 3972 */ 3973 public function test_wp_get_attachment_image_context_filter_default() { 3974 $last_context = ''; 3975 $this->track_last_attachment_image_context( $last_context ); 3976 3977 wp_get_attachment_image( self::$large_id ); 3978 $this->assertSame( 'wp_get_attachment_image', $last_context ); 3979 } 3980 3981 /** 3982 * Tests that `wp_get_attachment_image()` allows overriding the context via filter. 3983 * 3984 * @ticket 58212 3985 * 3986 * @covers ::wp_get_attachment_image() 3987 */ 3988 public function test_wp_get_attachment_image_context_filter_value_is_passed_correctly() { 3989 $last_context = ''; 3990 $this->track_last_attachment_image_context( $last_context ); 3991 3992 // Add a filter that modifies the context. 3993 add_filter( 3994 'wp_get_attachment_image_context', 3995 static function() { 3996 return 'my_custom_context'; 3997 } 3998 ); 3999 4000 wp_get_attachment_image( self::$large_id ); 4001 $this->assertSame( 'my_custom_context', $last_context ); 4002 } 4003 4004 /** 4005 * Helper method to keep track of the last context returned by the 'wp_get_attachment_image_context' filter. 4006 * 4007 * The method parameter is passed by reference and therefore will always contain the last context value. 4008 * 4009 * @param mixed $last_context Variable to track last context. Passed by reference. 4010 */ 4011 private function track_last_attachment_image_context( &$last_context ) { 4012 add_filter( 4013 'wp_get_attachment_image_context', 4014 static function( $context ) use ( &$last_context ) { 4015 $last_context = $context; 4016 return $context; 4017 }, 4018 11 4019 ); 4020 } 4021 4022 /** 3967 4023 * Add threshold to create a `-scaled` output image for testing. 3968 4024 */
Note: See TracChangeset
for help on using the changeset viewer.