Make WordPress Core

Changeset 26976


Ignore:
Timestamp:
01/17/2014 06:01:34 PM (11 years ago)
Author:
wonderboymusic
Message:

Add (Q)Unit Tests for the wp.shortcode JS class.

Fixes #26514.
Props jorbin.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/qunit/wp-includes/js/shortcode.js

    r26222 r26976  
    55    test( 'next() should find the shortcode', function() {
    66        var result;
    7        
     7
    88        // Basic
    99        result = wp.shortcode.next( 'foo', 'this has the [foo] shortcode' );
     
    2727    test( 'next() should find the shortcode when told to start looking beyond the start of the string', function() {
    2828        var result;
    29        
     29
    3030        // Starting at indices
    3131        result = wp.shortcode.next( 'foo', 'this has the [foo] shortcode', 12 );
     
    7979    test( 'replace() should replace the shortcode', function() {
    8080        var result;
    81        
     81
    8282        // Basic
    8383        result = wp.shortcode.replace( 'foo', 'this has the [foo] shortcode', shortcodeReplaceCallback );
    8484        equal( result, 'this has the bar shortcode', 'foo replaced with bar' );
    85        
     85
    8686        result = wp.shortcode.replace( 'foo', 'this has the [foo param="foo"] shortcode', shortcodeReplaceCallback );
    8787        equal( result, 'this has the bar shortcode', 'foo and params replaced with bar' );
     
    112112    test( 'replace() should not replace the escaped shortcodes', function() {
    113113        var result;
    114        
     114
    115115        // Escaped
    116116        result = wp.shortcode.replace( 'foo', 'this has the [[foo]] shortcode', shortcodeReplaceCallback );
     
    135135    });
    136136
     137    // A callback function for the replace tests
    137138    function shortcodeReplaceCallback( ) {
    138139        return 'bar';
    139140    }
     141
     142    test( 'attrs() should return named attributes created with single, double, and no quotes', function() {
     143        var expected = {
     144            'named': {
     145                'param': 'foo',
     146                'another': 'bar',
     147                'andagain': 'baz'
     148            }, 'numeric' : []
     149        };
     150
     151        deepEqual( wp.shortcode.attrs('param="foo" another=\'bar\' andagain=baz'), expected, 'attr parsed all three named types');
     152    });
     153
     154    test( 'attrs() should return numeric attributes in the order they are used', function() {
     155        var expected = {
     156            'named': {}, 'numeric' : ['foo', 'bar', 'baz']
     157        };
     158
     159        deepEqual( wp.shortcode.attrs('foo bar baz'), expected, 'attr parsed numeric attributes');
     160    });
     161
     162    test( 'attrs() should return numeric attributes in the order they are used when they have named attributes in between', function() {
     163        var expected = {
     164            'named': { 'not': 'a blocker'  }, 'numeric' : ['foo', 'bar', 'baz']
     165        };
     166
     167        deepEqual( wp.shortcode.attrs('foo not="a blocker" bar baz'), expected, 'attr parsed numeric attributes');
     168    });
    140169});
Note: See TracChangeset for help on using the changeset viewer.