Make WordPress Core

Ticket #18311: 0001-Added-tests-for-new-image-shortcode-handler.patch

File 0001-Added-tests-for-new-image-shortcode-handler.patch, 4.6 KB (added by sushkov, 12 years ago)
  • new file wp-testcase/test_includes_media.php

    From 8f71b248b06b19ccac4e51d62f291cbc58e2c690 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Stas=20SU=C8=98COV?= <stas@net.utcluj.ro>
    Date: Fri, 27 Apr 2012 02:46:02 +0300
    Subject: [PATCH] Added tests for new image shortcode handler.
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    
    Signed-off-by: Stas SUȘCOV <stas@net.utcluj.ro>
    ---
     wp-testcase/test_includes_media.php |  103 +++++++++++++++++++++++++++++++++++
     1 files changed, 103 insertions(+), 0 deletions(-)
     create mode 100644 wp-testcase/test_includes_media.php
    
    diff --git wp-testcase/test_includes_media.php wp-testcase/test_includes_media.php
    new file mode 100644
    index 0000000..13e21b2
    - +  
     1<?php
     2
     3class TestIncludesMedia extends WPTestCase {
     4
     5  function setUp() {
     6    $this->caption = 'A simple caption.';
     7    $this->html_content = <<<CAP
     8A <strong class='classy'>bolded</strong> <em>caption</em> with a <a href="#">link</a>.
     9CAP;
     10    $this->img_content = <<<CAP
     11<img src="pic.jpg" id='anId' alt="pic"/>
     12CAP;
     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 &amp;myAlignment/', $result, $_r ) );
     51    $this->assertEquals( 1, preg_match_all( '/id="&quot;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?>