| | 1 | <?php |
| | 2 | |
| | 3 | class TestIncludesMedia extends WPTestCase { |
| | 4 | |
| | 5 | function setUp() { |
| | 6 | $this->caption = 'A simple caption.'; |
| | 7 | $this->html_content = <<<CAP |
| | 8 | A <strong class='classy'>bolded</strong> <em>caption</em> with a <a href="#">link</a>. |
| | 9 | CAP; |
| | 10 | $this->img_content = <<<CAP |
| | 11 | <img src="pic.jpg" id='anId' alt="pic"/> |
| | 12 | CAP; |
| | 13 | } |
| | 14 | |
| | 15 | function test_img_caption_shortcode_added() { |
| | 16 | global $shortcode_tags; |
| | 17 | $this->assertEquals( 'img_caption_shortcode', $shortcode_tags['caption'] ); |
| | 18 | $this->assertEquals( 'img_caption_shortcode', $shortcode_tags['wp_caption'] ); |
| | 19 | } |
| | 20 | |
| | 21 | function test_img_caption_shortcode_with_empty_params() { |
| | 22 | $result = img_caption_shortcode( array() ); |
| | 23 | $this->assertNull( $result ); |
| | 24 | } |
| | 25 | |
| | 26 | function test_img_caption_shortcode_with_bad_attr() { |
| | 27 | $result = img_caption_shortcode( array(), 'content' ); |
| | 28 | $this->assertEquals( 'content', 'content' ); |
| | 29 | } |
| | 30 | |
| | 31 | function test_img_caption_shortcode_with_old_format() { |
| | 32 | $result = img_caption_shortcode( |
| | 33 | array( 'width' => 20, 'caption' => $this->caption ) |
| | 34 | ); |
| | 35 | $this->assertEquals( 2, preg_match_all( '/wp-caption/', $result, $_r ) ); |
| | 36 | $this->assertEquals( 1, preg_match_all( '/alignnone/', $result, $_r ) ); |
| | 37 | $this->assertEquals( 1, preg_match_all( "/{$this->caption}/", $result, $_r ) ); |
| | 38 | $this->assertEquals( 1, preg_match_all( "/width: 30/", $result, $_r ) ); |
| | 39 | } |
| | 40 | |
| | 41 | function test_img_caption_shortcode_with_old_format_id_and_align() { |
| | 42 | $result = img_caption_shortcode( |
| | 43 | array( |
| | 44 | 'width' => 20, |
| | 45 | 'caption' => $this->caption, |
| | 46 | 'id' => '"myId', |
| | 47 | 'align' => '&myAlignment' |
| | 48 | ) |
| | 49 | ); |
| | 50 | $this->assertEquals( 1, preg_match_all( '/wp-caption &myAlignment/', $result, $_r ) ); |
| | 51 | $this->assertEquals( 1, preg_match_all( '/id=""myId"/', $result, $_r ) ); |
| | 52 | $this->assertEquals( 1, preg_match_all( "/{$this->caption}/", $result, $_r ) ); |
| | 53 | } |
| | 54 | |
| | 55 | function test_new_img_caption_shortcode_with_html_caption() { |
| | 56 | $result = img_caption_shortcode( |
| | 57 | array( 'width' => 20, 'caption' => $this->html_content ) |
| | 58 | ); |
| | 59 | $our_preg = preg_quote( $this->html_content ); |
| | 60 | |
| | 61 | $this->assertEquals( 1, preg_match_all( "~{$our_preg}~", $result, $_r ) ); |
| | 62 | } |
| | 63 | |
| | 64 | function test_new_img_caption_shortcode_new_format() { |
| | 65 | $result = img_caption_shortcode( |
| | 66 | array( 'width' => 20 ), |
| | 67 | $this->img_content . $this->html_content |
| | 68 | ); |
| | 69 | $img_preg = preg_quote( $this->img_content ); |
| | 70 | $content_preg = preg_quote( $this->html_content ); |
| | 71 | |
| | 72 | $this->assertEquals( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) ); |
| | 73 | $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) ); |
| | 74 | } |
| | 75 | |
| | 76 | function test_new_img_caption_shortcode_new_format_and_linked_image() { |
| | 77 | $linked_image = "<a href='#'>{$this->img_content}</a>"; |
| | 78 | $result = img_caption_shortcode( |
| | 79 | array( 'width' => 20 ), |
| | 80 | $linked_image . $this->html_content |
| | 81 | ); |
| | 82 | $img_preg = preg_quote( $linked_image ); |
| | 83 | $content_preg = preg_quote( $this->html_content ); |
| | 84 | |
| | 85 | $this->assertEquals( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) ); |
| | 86 | $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) ); |
| | 87 | } |
| | 88 | |
| | 89 | function test_new_img_caption_shortcode_new_format_and_linked_image_with_newline() { |
| | 90 | $linked_image = "<a href='#'>{$this->img_content}</a>"; |
| | 91 | $result = img_caption_shortcode( |
| | 92 | array( 'width' => 20 ), |
| | 93 | $linked_image . "\n\n" . $this->html_content |
| | 94 | ); |
| | 95 | $img_preg = preg_quote( $linked_image ); |
| | 96 | $content_preg = preg_quote( $this->html_content ); |
| | 97 | |
| | 98 | $this->assertEquals( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) ); |
| | 99 | $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) ); |
| | 100 | } |
| | 101 | |
| | 102 | } |
| | 103 | ?> |