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

Fixes #26514.
Props jorbin.



git-svn-id: https://develop.svn.wordpress.org/trunk@26976 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-01-17 18:01:34 +00:00
parent 5d8627f6c9
commit 1a4a017923
1 changed files with 34 additions and 5 deletions

View File

@ -4,7 +4,7 @@ jQuery( function() {
test( 'next() should find the shortcode', function() {
var result;
// Basic
result = wp.shortcode.next( 'foo', 'this has the [foo] shortcode' );
equal( result.index, 13, 'foo shortcode found at index 13' );
@ -26,7 +26,7 @@ jQuery( function() {
test( 'next() should find the shortcode when told to start looking beyond the start of the string', function() {
var result;
// Starting at indices
result = wp.shortcode.next( 'foo', 'this has the [foo] shortcode', 12 );
equal( result.index, 13, 'foo shortcode found before index 13' );
@ -78,11 +78,11 @@ jQuery( function() {
test( 'replace() should replace the shortcode', function() {
var result;
// Basic
result = wp.shortcode.replace( 'foo', 'this has the [foo] shortcode', shortcodeReplaceCallback );
equal( result, 'this has the bar shortcode', 'foo replaced with bar' );
result = wp.shortcode.replace( 'foo', 'this has the [foo param="foo"] shortcode', shortcodeReplaceCallback );
equal( result, 'this has the bar shortcode', 'foo and params replaced with bar' );
});
@ -111,7 +111,7 @@ jQuery( function() {
test( 'replace() should not replace the escaped shortcodes', function() {
var result;
// Escaped
result = wp.shortcode.replace( 'foo', 'this has the [[foo]] shortcode', shortcodeReplaceCallback );
equal( result, 'this has the [[foo]] shortcode', 'escaped foo not replaced' );
@ -134,7 +134,36 @@ jQuery( function() {
equal( result, 'this has the [foo] shortcode', 'stub not replaced' );
});
// A callback function for the replace tests
function shortcodeReplaceCallback( ) {
return 'bar';
}
test( 'attrs() should return named attributes created with single, double, and no quotes', function() {
var expected = {
'named': {
'param': 'foo',
'another': 'bar',
'andagain': 'baz'
}, 'numeric' : []
};
deepEqual( wp.shortcode.attrs('param="foo" another=\'bar\' andagain=baz'), expected, 'attr parsed all three named types');
});
test( 'attrs() should return numeric attributes in the order they are used', function() {
var expected = {
'named': {}, 'numeric' : ['foo', 'bar', 'baz']
};
deepEqual( wp.shortcode.attrs('foo bar baz'), expected, 'attr parsed numeric attributes');
});
test( 'attrs() should return numeric attributes in the order they are used when they have named attributes in between', function() {
var expected = {
'named': { 'not': 'a blocker' }, 'numeric' : ['foo', 'bar', 'baz']
};
deepEqual( wp.shortcode.attrs('foo not="a blocker" bar baz'), expected, 'attr parsed numeric attributes');
});
});