Changeset 48937 for trunk/tests/phpunit/tests/shortcode.php
- Timestamp:
- 09/02/2020 12:35:36 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/shortcode.php
r47198 r48937 98 98 function test_noatts() { 99 99 do_shortcode( '[test-shortcode-tag /]' ); 100 $this->assert Equals( '', $this->atts );101 $this->assert Equals( 'test-shortcode-tag', $this->tagname );100 $this->assertSame( '', $this->atts ); 101 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 102 102 } 103 103 104 104 function test_one_att() { 105 105 do_shortcode( '[test-shortcode-tag foo="asdf" /]' ); 106 $this->assert Equals( array( 'foo' => 'asdf' ), $this->atts );107 $this->assert Equals( 'test-shortcode-tag', $this->tagname );106 $this->assertSame( array( 'foo' => 'asdf' ), $this->atts ); 107 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 108 108 } 109 109 110 110 function test_not_a_tag() { 111 111 $out = do_shortcode( '[not-a-shortcode-tag]' ); 112 $this->assert Equals( '[not-a-shortcode-tag]', $out );112 $this->assertSame( '[not-a-shortcode-tag]', $out ); 113 113 } 114 114 … … 118 118 function test_tag_hyphen_not_tag() { 119 119 $out = do_shortcode( '[dumptag-notreal]' ); 120 $this->assert Equals( '[dumptag-notreal]', $out );120 $this->assertSame( '[dumptag-notreal]', $out ); 121 121 } 122 122 123 123 function test_tag_underscore_not_tag() { 124 124 $out = do_shortcode( '[dumptag_notreal]' ); 125 $this->assert Equals( '[dumptag_notreal]', $out );125 $this->assertSame( '[dumptag_notreal]', $out ); 126 126 } 127 127 128 128 function test_tag_not_tag() { 129 129 $out = do_shortcode( '[dumptagnotreal]' ); 130 $this->assert Equals( '[dumptagnotreal]', $out );130 $this->assertSame( '[dumptagnotreal]', $out ); 131 131 } 132 132 … … 135 135 */ 136 136 function test_tag_hyphen() { 137 $this->assert Equals( '_shortcode_hyphen', do_shortcode( '[hyphen]' ) );138 $this->assert Equals( '_shortcode_hyphen_foo', do_shortcode( '[hyphen-foo]' ) );139 $this->assert Equals( '_shortcode_hyphen_foo_bar', do_shortcode( '[hyphen-foo-bar]' ) );140 $this->assert Equals( '[hyphen-baz]', do_shortcode( '[hyphen-baz]' ) );141 $this->assert Equals( '[hyphen-foo-bar-baz]', do_shortcode( '[hyphen-foo-bar-baz]' ) );137 $this->assertSame( '_shortcode_hyphen', do_shortcode( '[hyphen]' ) ); 138 $this->assertSame( '_shortcode_hyphen_foo', do_shortcode( '[hyphen-foo]' ) ); 139 $this->assertSame( '_shortcode_hyphen_foo_bar', do_shortcode( '[hyphen-foo-bar]' ) ); 140 $this->assertSame( '[hyphen-baz]', do_shortcode( '[hyphen-baz]' ) ); 141 $this->assertSame( '[hyphen-foo-bar-baz]', do_shortcode( '[hyphen-foo-bar-baz]' ) ); 142 142 } 143 143 … … 157 157 'foo--bar' => 'foo--bar', 158 158 ); 159 $this->assert Equals( $expected_attrs, $this->atts );159 $this->assertSame( $expected_attrs, $this->atts ); 160 160 } 161 161 162 162 function test_two_atts() { 163 163 do_shortcode( '[test-shortcode-tag foo="asdf" bar="bing" /]' ); 164 $this->assert Equals(164 $this->assertSame( 165 165 array( 166 166 'foo' => 'asdf', … … 169 169 $this->atts 170 170 ); 171 $this->assert Equals( 'test-shortcode-tag', $this->tagname );171 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 172 172 } 173 173 174 174 function test_noatts_enclosing() { 175 175 do_shortcode( '[test-shortcode-tag]content[/test-shortcode-tag]' ); 176 $this->assert Equals( '', $this->atts );177 $this->assert Equals( 'content', $this->content );178 $this->assert Equals( 'test-shortcode-tag', $this->tagname );176 $this->assertSame( '', $this->atts ); 177 $this->assertSame( 'content', $this->content ); 178 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 179 179 } 180 180 181 181 function test_one_att_enclosing() { 182 182 do_shortcode( '[test-shortcode-tag foo="bar"]content[/test-shortcode-tag]' ); 183 $this->assert Equals( array( 'foo' => 'bar' ), $this->atts );184 $this->assert Equals( 'content', $this->content );185 $this->assert Equals( 'test-shortcode-tag', $this->tagname );183 $this->assertSame( array( 'foo' => 'bar' ), $this->atts ); 184 $this->assertSame( 'content', $this->content ); 185 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 186 186 } 187 187 188 188 function test_two_atts_enclosing() { 189 189 do_shortcode( '[test-shortcode-tag foo="bar" baz="bing"]content[/test-shortcode-tag]' ); 190 $this->assert Equals(190 $this->assertSame( 191 191 array( 192 192 'foo' => 'bar', … … 195 195 $this->atts 196 196 ); 197 $this->assert Equals( 'content', $this->content );198 $this->assert Equals( 'test-shortcode-tag', $this->tagname );197 $this->assertSame( 'content', $this->content ); 198 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 199 199 } 200 200 201 201 function test_unclosed() { 202 202 $out = do_shortcode( '[test-shortcode-tag]' ); 203 $this->assert Equals( '', $out );204 $this->assert Equals( '', $this->atts );205 $this->assert Equals( 'test-shortcode-tag', $this->tagname );203 $this->assertSame( '', $out ); 204 $this->assertSame( '', $this->atts ); 205 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 206 206 } 207 207 208 208 function test_positional_atts_num() { 209 209 $out = do_shortcode( '[test-shortcode-tag 123]' ); 210 $this->assert Equals( '', $out );211 $this->assert Equals( array( 0 => '123' ), $this->atts );212 $this->assert Equals( 'test-shortcode-tag', $this->tagname );210 $this->assertSame( '', $out ); 211 $this->assertSame( array( 0 => '123' ), $this->atts ); 212 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 213 213 } 214 214 215 215 function test_positional_atts_url() { 216 216 $out = do_shortcode( '[test-shortcode-tag http://www.youtube.com/watch?v=eBGIQ7ZuuiU]' ); 217 $this->assert Equals( '', $out );218 $this->assert Equals( array( 0 => 'http://www.youtube.com/watch?v=eBGIQ7ZuuiU' ), $this->atts );219 $this->assert Equals( 'test-shortcode-tag', $this->tagname );217 $this->assertSame( '', $out ); 218 $this->assertSame( array( 0 => 'http://www.youtube.com/watch?v=eBGIQ7ZuuiU' ), $this->atts ); 219 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 220 220 } 221 221 222 222 function test_positional_atts_quotes() { 223 223 $out = do_shortcode( '[test-shortcode-tag "something in quotes" "something else"]' ); 224 $this->assert Equals( '', $out );225 $this->assert Equals(224 $this->assertSame( '', $out ); 225 $this->assertSame( 226 226 array( 227 227 0 => 'something in quotes', … … 230 230 $this->atts 231 231 ); 232 $this->assert Equals( 'test-shortcode-tag', $this->tagname );232 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 233 233 } 234 234 235 235 function test_positional_atts_mixed() { 236 236 $out = do_shortcode( '[test-shortcode-tag 123 https://wordpress.org/ 0 "foo" bar]' ); 237 $this->assert Equals( '', $out );238 $this->assert Equals(237 $this->assertSame( '', $out ); 238 $this->assertSame( 239 239 array( 240 240 0 => '123', … … 246 246 $this->atts 247 247 ); 248 $this->assert Equals( 'test-shortcode-tag', $this->tagname );248 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 249 249 } 250 250 251 251 function test_positional_and_named_atts() { 252 252 $out = do_shortcode( '[test-shortcode-tag 123 url=https://wordpress.org/ foo bar="baz"]' ); 253 $this->assert Equals( '', $out );254 $this->assert Equals(253 $this->assertSame( '', $out ); 254 $this->assertSame( 255 255 array( 256 256 0 => '123', … … 261 261 $this->atts 262 262 ); 263 $this->assert Equals( 'test-shortcode-tag', $this->tagname );263 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 264 264 } 265 265 266 266 function test_footag_default() { 267 267 $out = do_shortcode( '[footag]' ); 268 $this->assert Equals( 'foo = ', $out );268 $this->assertSame( 'foo = ', $out ); 269 269 } 270 270 … … 272 272 $val = rand_str(); 273 273 $out = do_shortcode( '[footag foo="' . $val . '"]' ); 274 $this->assert Equals( 'foo = ' . $val, $out );274 $this->assertSame( 'foo = ' . $val, $out ); 275 275 } 276 276 … … 278 278 $out = do_shortcode( '[baztag][dumptag abc="foo" def=123 https://wordpress.org/][/baztag]' ); 279 279 $expected = "content = abc = foo\ndef = 123\n0 = https://wordpress.org\n"; 280 $this->assert Equals( $expected, $out );280 $this->assertSame( $expected, $out ); 281 281 } 282 282 … … 286 286 function test_tag_escaped() { 287 287 $out = do_shortcode( '[[footag]] [[bartag foo="bar"]]' ); 288 $this->assert Equals( '[footag] [bartag foo="bar"]', $out );288 $this->assertSame( '[footag] [bartag foo="bar"]', $out ); 289 289 290 290 $out = do_shortcode( '[[footag /]] [[bartag foo="bar" /]]' ); 291 $this->assert Equals( '[footag /] [bartag foo="bar" /]', $out );291 $this->assertSame( '[footag /] [bartag foo="bar" /]', $out ); 292 292 293 293 $out = do_shortcode( '[[baztag foo="bar"]the content[/baztag]]' ); 294 $this->assert Equals( '[baztag foo="bar"]the content[/baztag]', $out );294 $this->assertSame( '[baztag foo="bar"]the content[/baztag]', $out ); 295 295 296 296 // Double escaped. 297 297 $out = do_shortcode( '[[[footag]]] [[[bartag foo="bar"]]]' ); 298 $this->assert Equals( '[[footag]] [[bartag foo="bar"]]', $out );298 $this->assertSame( '[[footag]] [[bartag foo="bar"]]', $out ); 299 299 } 300 300 … … 302 302 // These have square brackets on either end but aren't actually escaped. 303 303 $out = do_shortcode( '[[footag] [bartag foo="bar"]]' ); 304 $this->assert Equals( '[foo = foo = bar]', $out );304 $this->assertSame( '[foo = foo = bar]', $out ); 305 305 306 306 $out = do_shortcode( '[[footag /] [bartag foo="bar" /]]' ); 307 $this->assert Equals( '[foo = foo = bar]', $out );307 $this->assertSame( '[foo = foo = bar]', $out ); 308 308 309 309 $out = do_shortcode( '[[baztag foo="bar"]the content[/baztag]' ); 310 $this->assert Equals( '[content = the content', $out );310 $this->assertSame( '[content = the content', $out ); 311 311 312 312 $out = do_shortcode( '[[not-a-tag]]' ); 313 $this->assert Equals( '[[not-a-tag]]', $out );313 $this->assertSame( '[[not-a-tag]]', $out ); 314 314 315 315 $out = do_shortcode( '[[[footag] [bartag foo="bar"]]]' ); 316 $this->assert Equals( '[[foo = foo = bar]]', $out );316 $this->assertSame( '[[foo = foo = bar]]', $out ); 317 317 } 318 318 … … 351 351 EOF; 352 352 $out = do_shortcode( $in ); 353 $this->assert Equals( strip_ws( $expected ), strip_ws( $out ) );353 $this->assertSame( strip_ws( $expected ), strip_ws( $out ) ); 354 354 } 355 355 … … 360 360 // NO-BREAK SPACE: U+00A0. 361 361 do_shortcode( "[test-shortcode-tag foo=\"bar\" \xC2\xA0baz=\"123\"]" ); 362 $this->assert Equals(362 $this->assertSame( 363 363 array( 364 364 'foo' => 'bar', … … 367 367 $this->atts 368 368 ); 369 $this->assert Equals( '', $this->content );369 $this->assertSame( '', $this->content ); 370 370 } 371 371 … … 376 376 // ZERO WIDTH SPACE: U+200B. 377 377 do_shortcode( "[test-shortcode-tag foo=\"bar\" \xE2\x80\x8Babc=\"def\"]" ); 378 $this->assert Equals(378 $this->assertSame( 379 379 array( 380 380 'foo' => 'bar', … … 383 383 $this->atts 384 384 ); 385 $this->assert Equals( '', $this->content );385 $this->assertSame( '', $this->content ); 386 386 } 387 387 … … 392 392 // A blank line is added at the end, so test with it already there. 393 393 $test_string = "[footag]\n"; 394 $this->assert Equals( $test_string, shortcode_unautop( wpautop( $test_string ) ) );394 $this->assertSame( $test_string, shortcode_unautop( wpautop( $test_string ) ) ); 395 395 } 396 396 … … 419 419 */ 420 420 function test_strip_shortcodes( $expected, $content ) { 421 $this->assert Equals( $expected, strip_shortcodes( $content ) );421 $this->assertSame( $expected, strip_shortcodes( $content ) ); 422 422 } 423 423 … … 427 427 function test_strip_shortcodes_filter() { 428 428 add_filter( 'strip_shortcodes_tagnames', array( $this, '_filter_strip_shortcodes_tagnames' ) ); 429 $this->assert Equals( 'beforemiddle [footag]after', strip_shortcodes( 'before[gallery]middle [footag]after' ) );429 $this->assertSame( 'beforemiddle [footag]after', strip_shortcodes( 'before[gallery]middle [footag]after' ) ); 430 430 remove_filter( 'strip_shortcodes_tagnames', array( $this, '_filter_strip_shortcodes_tagnames' ) ); 431 431 } … … 463 463 464 464 do_shortcode( '[bartag foo="foo1" /]' ); 465 $this->assert Equals(465 $this->assertSame( 466 466 array( 467 467 'foo' => 'foo1', … … 470 470 $this->filter_atts_out 471 471 ); 472 $this->assert Equals(472 $this->assertSame( 473 473 array( 474 474 'foo' => 'no foo', … … 477 477 $this->filter_atts_pairs 478 478 ); 479 $this->assert Equals( array( 'foo' => 'foo1' ), $this->filter_atts_atts );479 $this->assertSame( array( 'foo' => 'foo1' ), $this->filter_atts_atts ); 480 480 481 481 remove_filter( 'shortcode_atts_bartag', array( $this, '_filter_atts' ), 10, 3 ); … … 486 486 487 487 $out = do_shortcode( '[bartag foo="foo1" baz="baz1" /]' ); 488 $this->assert Equals( array( 'foo' => 'no foo' ), $this->filter_atts_out );489 $this->assert Equals( 'foo = no foo', $out );488 $this->assertSame( array( 'foo' => 'no foo' ), $this->filter_atts_out ); 489 $this->assertSame( 'foo = no foo', $out ); 490 490 491 491 $out = do_shortcode( '[bartag foo="foo2" /]' ); 492 $this->assert Equals( 'foo = foo2', $out );492 $this->assertSame( 'foo = foo2', $out ); 493 493 494 494 remove_filter( 'shortcode_atts_bartag', array( $this, '_filter_atts2' ), 10, 3 ); … … 513 513 514 514 foreach ( $input as $in ) { 515 $this->assert Equals( $output, shortcode_unautop( $in ) );515 $this->assertSame( $output, shortcode_unautop( $in ) ); 516 516 } 517 517 } … … 523 523 */ 524 524 function test_escaping( $input, $output ) { 525 return $this->assert Equals( $output, do_shortcode( $input ) );525 return $this->assertSame( $output, do_shortcode( $input ) ); 526 526 } 527 527 … … 601 601 */ 602 602 function test_escaping2( $input, $output ) { 603 return $this->assert Equals( $output, strip_shortcodes( $input ) );603 return $this->assertSame( $output, strip_shortcodes( $input ) ); 604 604 } 605 605 … … 672 672 add_shortcode( $input, '' ); 673 673 $actual = shortcode_exists( $input ); 674 $test = $this->assert Equals( $expected, $actual );674 $test = $this->assertSame( $expected, $actual ); 675 675 if ( $actual ) { 676 676 remove_shortcode( $input ); … … 766 766 $out = do_shortcode( '[dumptag=https://wordpress.org/]' ); 767 767 $expected = "0 = =https://wordpress.org\n"; 768 $this->assert Equals( $expected, $out );768 $this->assertSame( $expected, $out ); 769 769 } 770 770 … … 775 775 $out = apply_filters( 'the_content', '[img alt="Hello :-) World"]' ); 776 776 $expected = "<img alt=\"Hello :-) World\" />\n"; 777 $this->assert Equals( $expected, $out );777 $this->assertSame( $expected, $out ); 778 778 } 779 779 … … 925 925 function test_empty_single_quote_attribute() { 926 926 $out = do_shortcode( '[test-shortcode-tag a="foo" b=\'bar\' c=baz foo \'bar\' "baz" ]test empty atts[/test-shortcode-tag]' ); 927 $this->assert Equals(927 $this->assertSame( 928 928 array( 929 929 'a' => 'foo', … … 943 943 function test_positional_atts_single_quotes() { 944 944 $out = do_shortcode( "[test-shortcode-tag 'something in quotes' 'something else']" ); 945 $this->assert Equals( '', $out );946 $this->assert Equals(945 $this->assertSame( '', $out ); 946 $this->assertSame( 947 947 array( 948 948 0 => 'something in quotes', … … 951 951 $this->atts 952 952 ); 953 $this->assert Equals( 'test-shortcode-tag', $this->tagname );953 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 954 954 } 955 955 … … 959 959 function test_positional_atts_mixed_quotes() { 960 960 $out = do_shortcode( "[test-shortcode-tag 'something in quotes' \"something else\" 123 foo bar='baz' example=\"test\" ]" ); 961 $this->assert Equals( '', $out );962 $this->assert Equals(961 $this->assertSame( '', $out ); 962 $this->assertSame( 963 963 array( 964 964 0 => 'something in quotes', … … 971 971 $this->atts 972 972 ); 973 $this->assert Equals( 'test-shortcode-tag', $this->tagname );973 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 974 974 } 975 975 }
Note: See TracChangeset
for help on using the changeset viewer.