Make WordPress Core

Changeset 218 in tests


Ignore:
Timestamp:
02/27/2009 12:15:57 AM (16 years ago)
Author:
tellyworth
Message:

new shortcode tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_shortcode.php

    r204 r218  
    3232add_shortcode('dumptag', 'dumptag_func');
    3333
     34// suggested by markj for testing p-wrapping of shortcode output
     35function paragraph_func($atts, $content='') {
     36    extract(shortcode_atts(array(
     37        'class' => 'graf',
     38    ), $atts));
     39    return "<p class='$class'>$content</p>\n";
     40}
     41add_shortcode('paragraph', 'paragraph_func');
     42
    3443class TestShortcode extends WPTestCase {
    3544
     
    3948#error_reporting(E_ALL);
    4049#ini_set('display_errors', '1');
    41        
    42     }
    43    
    44     function _shortcode_tag($atts, $content=NULL) {
     50        $this->atts = null;
     51        $this->content = null;
     52        $this->tagname = null;
     53       
     54    }
     55   
     56    function _shortcode_tag($atts, $content=NULL, $tagname=NULL) {
    4557        $this->atts = $atts;
    4658        $this->content = $content;
     59        $this->tagname = $tagname;
    4760    }
    4861   
     
    5063        do_shortcode('[test-shortcode-tag /]');
    5164        $this->assertEquals( '', $this->atts );
     65        $this->assertEquals( 'test-shortcode-tag', $this->tagname );
    5266    }
    5367   
     
    5569        do_shortcode('[test-shortcode-tag foo="asdf" /]');
    5670        $this->assertEquals( array('foo' => 'asdf'), $this->atts );
     71        $this->assertEquals( 'test-shortcode-tag', $this->tagname );
    5772    }
    5873   
     
    6580        do_shortcode('[test-shortcode-tag foo="asdf" bar="bing" /]');
    6681        $this->assertEquals( array('foo' => 'asdf', 'bar' => 'bing'), $this->atts );
     82        $this->assertEquals( 'test-shortcode-tag', $this->tagname );
    6783    }
    6884   
     
    7187        $this->assertEquals( '', $this->atts );
    7288        $this->assertEquals( 'content', $this->content );
     89        $this->assertEquals( 'test-shortcode-tag', $this->tagname );
    7390    }
    7491   
     
    7794        $this->assertEquals( array('foo' => 'bar'), $this->atts );
    7895        $this->assertEquals( 'content', $this->content );
     96        $this->assertEquals( 'test-shortcode-tag', $this->tagname );
    7997    }
    8098   
     
    83101        $this->assertEquals( array('foo' => 'bar', 'baz' => 'bing'), $this->atts );
    84102        $this->assertEquals( 'content', $this->content );
     103        $this->assertEquals( 'test-shortcode-tag', $this->tagname );
    85104    }
    86105
     
    89108        $this->assertEquals( '', $out );
    90109        $this->assertEquals( '', $this->atts );
     110        $this->assertEquals( 'test-shortcode-tag', $this->tagname );
    91111    }
    92112
     
    95115        $this->assertEquals( '', $out );
    96116        $this->assertEquals( array(0=>'123'), $this->atts );
     117        $this->assertEquals( 'test-shortcode-tag', $this->tagname );
    97118    }
    98119
     
    101122        $this->assertEquals( '', $out );
    102123        $this->assertEquals( array(0=>'http://www.youtube.com/watch?v=eBGIQ7ZuuiU'), $this->atts );
     124        $this->assertEquals( 'test-shortcode-tag', $this->tagname );
    103125    }
    104126
     
    107129        $this->assertEquals( '', $out );
    108130        $this->assertEquals( array(0=>'something in quotes', 1=>'something else'), $this->atts );
     131        $this->assertEquals( 'test-shortcode-tag', $this->tagname );
    109132    }
    110133
     
    113136        $this->assertEquals( '', $out );
    114137        $this->assertEquals( array(0=>'123', 1=>'http://wordpress.com/', 2=>'0', 3=>'foo', 4=>'bar'), $this->atts );
     138        $this->assertEquals( 'test-shortcode-tag', $this->tagname );
    115139    }
    116140
     
    119143        $this->assertEquals( '', $out );
    120144        $this->assertEquals( array(0=>'123', 'url' => 'http://wordpress.com/', 1=>'foo', 'bar' => 'baz'), $this->atts );
     145        $this->assertEquals( 'test-shortcode-tag', $this->tagname );
    121146    }
    122147
     
    217242    function test_utf8_whitespace_1() {
    218243        // see http://trac.wordpress.org/ticket/6562
     244        $this->knownWPBug(6562);
    219245        do_shortcode("[test-shortcode-tag foo=\"bar\" \x00\xA0baz=\"123\"]");
    220246        $this->assertEquals( array('foo' => 'bar', 'baz' => '123'), $this->atts );
     
    224250    function test_utf8_whitespace_2() {
    225251        // see http://trac.wordpress.org/ticket/6562
     252        $this->knownWPBug(6562);
    226253        do_shortcode("[test-shortcode-tag foo=\"bar\" \x20\x0babc=\"def\"]");
    227254        $this->assertEquals( array('foo' => 'bar', 'abc' => 'def'), $this->atts );
    228255        $this->assertEquals( '', $this->content );
    229256    }
     257   
     258/*
     259enabled = the shortcode works as normal (default)
     260strip = the shortcode will be parsed and removed.  e.g. '[shortcode foo="bar"]' produces ''.  '[shortcode]foo[/shortcode]' produces 'foo'.
     261faux = the shortcode will be abbreviated.  e.g. '[shortcode foo="bar"]' products '[shortcode]'.  '[shortocde]foo[/shortcode]' produces '[shortcode]'
     262disabled = the shortcode is not parsed at all.  e.g. '[shortcode foo="bar"]' products '[shortcode foo="bar"]'
     263*/
     264
     265    function test_shortcodes_enabled() {
     266        if ( !is_callable('set_all_shortcode_status') )
     267            $this->markTestSkipped();
     268        set_all_shortcode_status('enabled');
     269        $out = do_shortcode("[baztag]foo is [footag foo='bar'][/baztag]");
     270        $expected = 'content = foo is foo = bar';
     271        $this->assertEquals( $expected, $out );
     272    }
     273   
     274    function test_shortcodes_disabled() {
     275        if ( !is_callable('set_all_shortcode_status') )
     276            $this->markTestSkipped();
     277        set_all_shortcode_status('disabled');
     278        $out = do_shortcode("[baztag]foo is [footag foo='bar'][/baztag]");
     279        $expected = $out;
     280        $this->assertEquals( $expected, $out );
     281    }
     282   
     283    function test_shortcodes_strip() {
     284        if ( !is_callable('set_all_shortcode_status') )
     285            $this->markTestSkipped();
     286        set_all_shortcode_status('strip');
     287        $out = do_shortcode("[baztag]foo is [footag foo='bar'][/baztag]");
     288        $expected = 'foo is ';
     289        $this->assertEquals( $expected, $out );
     290    }
     291   
     292    function test_shortcodes_faux() {
     293        if ( !is_callable('set_all_shortcode_status') )
     294            $this->markTestSkipped();
     295        set_all_shortcode_status('faux');
     296        $out = do_shortcode("[baztag]foo is [footag foo='bar'][/baztag]");
     297        $expected = '[baztag]';
     298        $this->assertEquals( $expected, $out );
     299    }
    230300
    231301}
Note: See TracChangeset for help on using the changeset viewer.