Changeset 218 in tests
- Timestamp:
- 02/27/2009 12:15:57 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wp-testcase/test_shortcode.php
r204 r218 32 32 add_shortcode('dumptag', 'dumptag_func'); 33 33 34 // suggested by markj for testing p-wrapping of shortcode output 35 function paragraph_func($atts, $content='') { 36 extract(shortcode_atts(array( 37 'class' => 'graf', 38 ), $atts)); 39 return "<p class='$class'>$content</p>\n"; 40 } 41 add_shortcode('paragraph', 'paragraph_func'); 42 34 43 class TestShortcode extends WPTestCase { 35 44 … … 39 48 #error_reporting(E_ALL); 40 49 #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) { 45 57 $this->atts = $atts; 46 58 $this->content = $content; 59 $this->tagname = $tagname; 47 60 } 48 61 … … 50 63 do_shortcode('[test-shortcode-tag /]'); 51 64 $this->assertEquals( '', $this->atts ); 65 $this->assertEquals( 'test-shortcode-tag', $this->tagname ); 52 66 } 53 67 … … 55 69 do_shortcode('[test-shortcode-tag foo="asdf" /]'); 56 70 $this->assertEquals( array('foo' => 'asdf'), $this->atts ); 71 $this->assertEquals( 'test-shortcode-tag', $this->tagname ); 57 72 } 58 73 … … 65 80 do_shortcode('[test-shortcode-tag foo="asdf" bar="bing" /]'); 66 81 $this->assertEquals( array('foo' => 'asdf', 'bar' => 'bing'), $this->atts ); 82 $this->assertEquals( 'test-shortcode-tag', $this->tagname ); 67 83 } 68 84 … … 71 87 $this->assertEquals( '', $this->atts ); 72 88 $this->assertEquals( 'content', $this->content ); 89 $this->assertEquals( 'test-shortcode-tag', $this->tagname ); 73 90 } 74 91 … … 77 94 $this->assertEquals( array('foo' => 'bar'), $this->atts ); 78 95 $this->assertEquals( 'content', $this->content ); 96 $this->assertEquals( 'test-shortcode-tag', $this->tagname ); 79 97 } 80 98 … … 83 101 $this->assertEquals( array('foo' => 'bar', 'baz' => 'bing'), $this->atts ); 84 102 $this->assertEquals( 'content', $this->content ); 103 $this->assertEquals( 'test-shortcode-tag', $this->tagname ); 85 104 } 86 105 … … 89 108 $this->assertEquals( '', $out ); 90 109 $this->assertEquals( '', $this->atts ); 110 $this->assertEquals( 'test-shortcode-tag', $this->tagname ); 91 111 } 92 112 … … 95 115 $this->assertEquals( '', $out ); 96 116 $this->assertEquals( array(0=>'123'), $this->atts ); 117 $this->assertEquals( 'test-shortcode-tag', $this->tagname ); 97 118 } 98 119 … … 101 122 $this->assertEquals( '', $out ); 102 123 $this->assertEquals( array(0=>'http://www.youtube.com/watch?v=eBGIQ7ZuuiU'), $this->atts ); 124 $this->assertEquals( 'test-shortcode-tag', $this->tagname ); 103 125 } 104 126 … … 107 129 $this->assertEquals( '', $out ); 108 130 $this->assertEquals( array(0=>'something in quotes', 1=>'something else'), $this->atts ); 131 $this->assertEquals( 'test-shortcode-tag', $this->tagname ); 109 132 } 110 133 … … 113 136 $this->assertEquals( '', $out ); 114 137 $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 ); 115 139 } 116 140 … … 119 143 $this->assertEquals( '', $out ); 120 144 $this->assertEquals( array(0=>'123', 'url' => 'http://wordpress.com/', 1=>'foo', 'bar' => 'baz'), $this->atts ); 145 $this->assertEquals( 'test-shortcode-tag', $this->tagname ); 121 146 } 122 147 … … 217 242 function test_utf8_whitespace_1() { 218 243 // see http://trac.wordpress.org/ticket/6562 244 $this->knownWPBug(6562); 219 245 do_shortcode("[test-shortcode-tag foo=\"bar\" \x00\xA0baz=\"123\"]"); 220 246 $this->assertEquals( array('foo' => 'bar', 'baz' => '123'), $this->atts ); … … 224 250 function test_utf8_whitespace_2() { 225 251 // see http://trac.wordpress.org/ticket/6562 252 $this->knownWPBug(6562); 226 253 do_shortcode("[test-shortcode-tag foo=\"bar\" \x20\x0babc=\"def\"]"); 227 254 $this->assertEquals( array('foo' => 'bar', 'abc' => 'def'), $this->atts ); 228 255 $this->assertEquals( '', $this->content ); 229 256 } 257 258 /* 259 enabled = the shortcode works as normal (default) 260 strip = the shortcode will be parsed and removed. e.g. '[shortcode foo="bar"]' produces ''. '[shortcode]foo[/shortcode]' produces 'foo'. 261 faux = the shortcode will be abbreviated. e.g. '[shortcode foo="bar"]' products '[shortcode]'. '[shortocde]foo[/shortcode]' produces '[shortcode]' 262 disabled = 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 } 230 300 231 301 }
Note: See TracChangeset
for help on using the changeset viewer.