Changeset 25382
- Timestamp:
- 09/12/2013 04:55:24 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/media.php
r25002 r25382 7 7 class Tests_Media extends WP_UnitTestCase { 8 8 9 10 11 12 9 function setUp() { 10 parent::setUp(); 11 $this->caption = 'A simple caption.'; 12 $this->html_content = <<<CAP 13 13 A <strong class='classy'>bolded</strong> <em>caption</em> with a <a href="#">link</a>. 14 14 CAP; 15 15 $this->img_content = <<<CAP 16 16 <img src="pic.jpg" id='anId' alt="pic"/> 17 17 CAP; 18 $this->img_name = 'image.jpg'; 19 $this->img_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $this->img_name; 20 $this->img_html = '<img src="' . $this->img_url . '"/>'; 21 $this->img_dimensions = array( 'width' => 100, 'height' => 100 ); 22 } 23 24 function test_img_caption_shortcode_added() { 25 global $shortcode_tags; 26 $this->assertEquals( 'img_caption_shortcode', $shortcode_tags['caption'] ); 27 $this->assertEquals( 'img_caption_shortcode', $shortcode_tags['wp_caption'] ); 28 } 29 30 function test_img_caption_shortcode_with_empty_params() { 31 $result = img_caption_shortcode( array() ); 32 $this->assertNull( $result ); 33 } 34 35 function test_img_caption_shortcode_with_bad_attr() { 36 $result = img_caption_shortcode( array(), 'content' ); 37 $this->assertEquals( 'content', 'content' ); 38 } 39 40 function test_img_caption_shortcode_with_old_format() { 41 $result = img_caption_shortcode( 42 array( 'width' => 20, 'caption' => $this->caption ) 43 ); 44 $this->assertEquals( 2, preg_match_all( '/wp-caption/', $result, $_r ) ); 45 $this->assertEquals( 1, preg_match_all( '/alignnone/', $result, $_r ) ); 46 $this->assertEquals( 1, preg_match_all( "/{$this->caption}/", $result, $_r ) ); 47 $this->assertEquals( 1, preg_match_all( "/width: 30/", $result, $_r ) ); 48 } 49 50 function test_img_caption_shortcode_with_old_format_id_and_align() { 51 $result = img_caption_shortcode( 52 array( 53 'width' => 20, 54 'caption' => $this->caption, 55 'id' => '"myId', 56 'align' => '&myAlignment' 57 ) 58 ); 59 $this->assertEquals( 1, preg_match_all( '/wp-caption &myAlignment/', $result, $_r ) ); 60 $this->assertEquals( 1, preg_match_all( '/id=""myId"/', $result, $_r ) ); 61 $this->assertEquals( 1, preg_match_all( "/{$this->caption}/", $result, $_r ) ); 62 } 63 64 function test_new_img_caption_shortcode_with_html_caption() { 65 $result = img_caption_shortcode( 66 array( 'width' => 20, 'caption' => $this->html_content ) 67 ); 68 $our_preg = preg_quote( $this->html_content ); 69 70 $this->assertEquals( 1, preg_match_all( "~{$our_preg}~", $result, $_r ) ); 71 } 72 73 function test_new_img_caption_shortcode_new_format() { 74 $result = img_caption_shortcode( 75 array( 'width' => 20 ), 76 $this->img_content . $this->html_content 77 ); 78 $img_preg = preg_quote( $this->img_content ); 79 $content_preg = preg_quote( $this->html_content ); 80 81 $this->assertEquals( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) ); 82 $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) ); 83 } 84 85 function test_new_img_caption_shortcode_new_format_and_linked_image() { 86 $linked_image = "<a href='#'>{$this->img_content}</a>"; 87 $result = img_caption_shortcode( 88 array( 'width' => 20 ), 89 $linked_image . $this->html_content 90 ); 91 $img_preg = preg_quote( $linked_image ); 92 $content_preg = preg_quote( $this->html_content ); 93 94 $this->assertEquals( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) ); 95 $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) ); 96 } 97 98 function test_new_img_caption_shortcode_new_format_and_linked_image_with_newline() { 99 $linked_image = "<a href='#'>{$this->img_content}</a>"; 100 $result = img_caption_shortcode( 101 array( 'width' => 20 ), 102 $linked_image . "\n\n" . $this->html_content 103 ); 104 $img_preg = preg_quote( $linked_image ); 105 $content_preg = preg_quote( $this->html_content ); 106 107 $this->assertEquals( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) ); 108 $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) ); 109 } 18 $this->img_name = 'image.jpg'; 19 $this->img_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $this->img_name; 20 $this->img_html = '<img src="' . $this->img_url . '"/>'; 21 $this->img_dimensions = array( 'width' => 100, 'height' => 100 ); 22 add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) ); 23 } 24 25 function tearDown() { 26 parent::tearDown(); 27 remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) ); 28 } 29 30 function deprecated_function_run( $function ) { 31 if ( in_array( $function, array( 'wp_convert_bytes_to_hr' ) ) ) 32 add_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) ); 33 } 34 35 function deprecated_function_trigger_error() { 36 remove_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) ); 37 return false; 38 } 39 40 function test_img_caption_shortcode_added() { 41 global $shortcode_tags; 42 $this->assertEquals( 'img_caption_shortcode', $shortcode_tags['caption'] ); 43 $this->assertEquals( 'img_caption_shortcode', $shortcode_tags['wp_caption'] ); 44 } 45 46 function test_img_caption_shortcode_with_empty_params() { 47 $result = img_caption_shortcode( array() ); 48 $this->assertNull( $result ); 49 } 50 51 function test_img_caption_shortcode_with_bad_attr() { 52 $result = img_caption_shortcode( array(), 'content' ); 53 $this->assertEquals( 'content', 'content' ); 54 } 55 56 function test_img_caption_shortcode_with_old_format() { 57 $result = img_caption_shortcode( 58 array( 'width' => 20, 'caption' => $this->caption ) 59 ); 60 $this->assertEquals( 2, preg_match_all( '/wp-caption/', $result, $_r ) ); 61 $this->assertEquals( 1, preg_match_all( '/alignnone/', $result, $_r ) ); 62 $this->assertEquals( 1, preg_match_all( "/{$this->caption}/", $result, $_r ) ); 63 $this->assertEquals( 1, preg_match_all( "/width: 30/", $result, $_r ) ); 64 } 65 66 function test_img_caption_shortcode_with_old_format_id_and_align() { 67 $result = img_caption_shortcode( 68 array( 69 'width' => 20, 70 'caption' => $this->caption, 71 'id' => '"myId', 72 'align' => '&myAlignment' 73 ) 74 ); 75 $this->assertEquals( 1, preg_match_all( '/wp-caption &myAlignment/', $result, $_r ) ); 76 $this->assertEquals( 1, preg_match_all( '/id=""myId"/', $result, $_r ) ); 77 $this->assertEquals( 1, preg_match_all( "/{$this->caption}/", $result, $_r ) ); 78 } 79 80 function test_new_img_caption_shortcode_with_html_caption() { 81 $result = img_caption_shortcode( 82 array( 'width' => 20, 'caption' => $this->html_content ) 83 ); 84 $our_preg = preg_quote( $this->html_content ); 85 86 $this->assertEquals( 1, preg_match_all( "~{$our_preg}~", $result, $_r ) ); 87 } 88 89 function test_new_img_caption_shortcode_new_format() { 90 $result = img_caption_shortcode( 91 array( 'width' => 20 ), 92 $this->img_content . $this->html_content 93 ); 94 $img_preg = preg_quote( $this->img_content ); 95 $content_preg = preg_quote( $this->html_content ); 96 97 $this->assertEquals( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) ); 98 $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) ); 99 } 100 101 function test_new_img_caption_shortcode_new_format_and_linked_image() { 102 $linked_image = "<a href='#'>{$this->img_content}</a>"; 103 $result = img_caption_shortcode( 104 array( 'width' => 20 ), 105 $linked_image . $this->html_content 106 ); 107 $img_preg = preg_quote( $linked_image ); 108 $content_preg = preg_quote( $this->html_content ); 109 110 $this->assertEquals( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) ); 111 $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) ); 112 } 113 114 function test_new_img_caption_shortcode_new_format_and_linked_image_with_newline() { 115 $linked_image = "<a href='#'>{$this->img_content}</a>"; 116 $result = img_caption_shortcode( 117 array( 'width' => 20 ), 118 $linked_image . "\n\n" . $this->html_content 119 ); 120 $img_preg = preg_quote( $linked_image ); 121 $content_preg = preg_quote( $this->html_content ); 122 123 $this->assertEquals( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) ); 124 $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) ); 125 } 110 126 111 127 function test_add_remove_oembed_provider() { … … 163 179 $this->assertEquals( '1MB', wp_convert_bytes_to_hr( $mb ) ); 164 180 $this->assertEquals( '1kB', wp_convert_bytes_to_hr( $kb ) ); 181 182 $this->assertEquals( '1 TB', size_format( $tb ) ); 183 $this->assertEquals( '1 GB', size_format( $gb ) ); 184 $this->assertEquals( '1 MB', size_format( $mb ) ); 185 $this->assertEquals( '1 kB', size_format( $kb ) ); 165 186 166 187 // now some values around
Note: See TracChangeset
for help on using the changeset viewer.