Make WordPress Core

Changeset 930 in tests for trunk/tests/shortcode.php


Ignore:
Timestamp:
07/20/2012 12:57:44 PM (12 years ago)
Author:
nacin
Message:

Add shortcode tests for shortcodes with hyphens. props aaroncampbell, kovshenin, see #WP17657.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/shortcode.php

    r904 r930  
    55class Tests_Shortcode extends WP_UnitTestCase {
    66
    7     protected $shortcodes = array( 'footag', 'bartag', 'baztag', 'dumptag' );
     7    protected $shortcodes = array( 'test-shortcode-tag', 'footag', 'bartag', 'baztag', 'dumptag', 'hyphen', 'hyphen-foo', 'hyphen-foo-bar' );
    88
    99    function setUp() {
    1010        parent::setUp();
    11         add_shortcode('test-shortcode-tag', array(&$this, '_shortcode_tag'));
    1211
    1312        foreach ( $this->shortcodes as $shortcode )
    14             add_shortcode( $shortcode, array( $this, '_shortcode_' . $shortcode ) );
     13            add_shortcode( $shortcode, array( $this, '_shortcode_' . str_replace( '-', '_', $shortcode ) ) );
    1514
    1615        $this->atts = null;
     
    2524        foreach ( $this->shortcodes as $shortcode )
    2625            unset( $shortcode_tags[ $shortcode ] );
    27         unset( $shortcode_tags['test-shortcode-tag'] );
     26    }
     27
     28    function _shortcode_test_shortcode_tag( $atts, $content = null, $tagname = null ) {
     29        $this->atts = $atts;
     30        $this->content = $content;
     31        $this->tagname = $tagname;
    2832    }
    2933
     
    5559    }
    5660
    57     function _shortcode_tag($atts, $content=NULL, $tagname=NULL) {
    58         $this->atts = $atts;
    59         $this->content = $content;
    60         $this->tagname = $tagname;
     61    function _shortcode_hyphen() {
     62        return __FUNCTION__;
     63    }
     64
     65    function _shortcode_hyphen_foo() {
     66        return __FUNCTION__;
     67    }
     68
     69    function _shortcode_hyphen_foo_bar() {
     70        return __FUNCTION__;
    6171    }
    6272
     
    7686        $out = do_shortcode('[not-a-shortcode-tag]');
    7787        $this->assertEquals( '[not-a-shortcode-tag]', $out );
     88    }
     89
     90    /**
     91     * @ticket 17657
     92     */
     93    function test_tag_hyphen_not_tag() {
     94        $out = do_shortcode( '[dumptag-notreal]' );
     95        $this->assertEquals( '[dumptag-notreal]', $out );
     96    }
     97
     98    function test_tag_underscore_not_tag() {
     99        $out = do_shortcode( '[dumptag_notreal]' );
     100        $this->assertEquals( '[dumptag_notreal]', $out );
     101    }
     102
     103    function test_tag_not_tag() {
     104        $out = do_shortcode( '[dumptagnotreal]' );
     105        $this->assertEquals( '[dumptagnotreal]', $out );
     106    }
     107
     108    /**
     109     * @ticket 17657
     110     */
     111    function test_tag_hyphen() {
     112        $this->assertEquals( '_shortcode_hyphen', do_shortcode( '[hyphen]' ) );
     113        $this->assertEquals( '_shortcode_hyphen_foo', do_shortcode( '[hyphen-foo]' ) );
     114        $this->assertEquals( '_shortcode_hyphen_foo_bar', do_shortcode( '[hyphen-foo-bar]' ) );
     115        $this->assertEquals( '[hyphen-baz]', do_shortcode( '[hyphen-baz]' ) );
     116        $this->assertEquals( '[hyphen-foo-bar-baz]', do_shortcode( '[hyphen-foo-bar-baz]' ) );
    78117    }
    79118
Note: See TracChangeset for help on using the changeset viewer.