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
--- /dev/null
+++ wp-testcase/test_includes_media.php
@@ -0,0 +1,103 @@
+<?php
+
+class TestIncludesMedia extends WPTestCase {
+
+  function setUp() {
+    $this->caption = 'A simple caption.';
+    $this->html_content = <<<CAP
+A <strong class='classy'>bolded</strong> <em>caption</em> with a <a href="#">link</a>.
+CAP;
+    $this->img_content = <<<CAP
+<img src="pic.jpg" id='anId' alt="pic"/>
+CAP;
+  }
+
+  function test_img_caption_shortcode_added() {
+    global $shortcode_tags;
+    $this->assertEquals( 'img_caption_shortcode', $shortcode_tags['caption'] );
+    $this->assertEquals( 'img_caption_shortcode', $shortcode_tags['wp_caption'] );
+  }
+
+  function test_img_caption_shortcode_with_empty_params() {
+    $result = img_caption_shortcode( array() );
+    $this->assertNull( $result );
+  }
+
+  function test_img_caption_shortcode_with_bad_attr() {
+    $result = img_caption_shortcode( array(), 'content' );
+    $this->assertEquals( 'content', 'content' );
+  }
+
+  function test_img_caption_shortcode_with_old_format() {
+    $result = img_caption_shortcode( 
+      array( 'width' => 20, 'caption' => $this->caption ) 
+    );
+    $this->assertEquals( 2, preg_match_all( '/wp-caption/', $result, $_r ) );
+    $this->assertEquals( 1, preg_match_all( '/alignnone/', $result, $_r ) );
+    $this->assertEquals( 1, preg_match_all( "/{$this->caption}/", $result, $_r ) );
+    $this->assertEquals( 1, preg_match_all( "/width: 30/", $result, $_r ) );
+  }
+
+  function test_img_caption_shortcode_with_old_format_id_and_align() {
+    $result = img_caption_shortcode( 
+      array( 
+        'width' => 20,
+        'caption' => $this->caption,
+        'id' => '"myId',
+        'align' => '&myAlignment'
+      )
+    );
+    $this->assertEquals( 1, preg_match_all( '/wp-caption &amp;myAlignment/', $result, $_r ) );
+    $this->assertEquals( 1, preg_match_all( '/id="&quot;myId"/', $result, $_r ) );
+    $this->assertEquals( 1, preg_match_all( "/{$this->caption}/", $result, $_r ) );
+  }
+
+  function test_new_img_caption_shortcode_with_html_caption() {
+    $result = img_caption_shortcode( 
+      array( 'width' => 20, 'caption' => $this->html_content ) 
+    );
+    $our_preg = preg_quote( $this->html_content );
+
+    $this->assertEquals( 1, preg_match_all( "~{$our_preg}~", $result, $_r ) );
+  }
+
+  function test_new_img_caption_shortcode_new_format() {
+    $result = img_caption_shortcode( 
+      array( 'width' => 20 ),
+      $this->img_content . $this->html_content
+    );
+    $img_preg = preg_quote( $this->img_content );
+    $content_preg = preg_quote( $this->html_content );
+
+    $this->assertEquals( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) );
+    $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) );
+  }
+
+  function test_new_img_caption_shortcode_new_format_and_linked_image() {
+    $linked_image = "<a href='#'>{$this->img_content}</a>";
+    $result = img_caption_shortcode( 
+      array( 'width' => 20 ),
+      $linked_image . $this->html_content
+    );
+    $img_preg = preg_quote( $linked_image );
+    $content_preg = preg_quote( $this->html_content );
+
+    $this->assertEquals( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) );
+    $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) );
+  }
+
+  function test_new_img_caption_shortcode_new_format_and_linked_image_with_newline() {
+    $linked_image = "<a href='#'>{$this->img_content}</a>";
+    $result = img_caption_shortcode( 
+      array( 'width' => 20 ),
+      $linked_image . "\n\n" . $this->html_content
+    );
+    $img_preg = preg_quote( $linked_image );
+    $content_preg = preg_quote( $this->html_content );
+
+    $this->assertEquals( 1, preg_match_all( "~{$img_preg}.*wp-caption-text~", $result, $_r ) );
+    $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) );
+  }
+
+}
+?>
-- 
1.7.5.4

