Coding Standards: Add visibility to methods in tests/phpunit/tests/.

Adds a `public` visibility to test fixtures, tests, data providers, and callbacks methods.

Adds a `private` visibility to helper methods within test classes.

Renames callbacks and helpers that previously started with a `_` prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit.

Props costdev, jrf, hellofromTonya.
Fixes #54177.

git-svn-id: https://develop.svn.wordpress.org/trunk@52010 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Tonya Mork
2021-11-04 15:22:47 +00:00
parent 80380cd374
commit 40ac5de838
327 changed files with 3656 additions and 3969 deletions

View File

@@ -6,11 +6,11 @@ class Tests_Shortcode extends WP_UnitTestCase {
protected $shortcodes = array( 'test-shortcode-tag', 'footag', 'bartag', 'baztag', 'dumptag', 'hyphen', 'hyphen-foo', 'hyphen-foo-bar', 'url', 'img' );
function set_up() {
public function set_up() {
parent::set_up();
foreach ( $this->shortcodes as $shortcode ) {
add_shortcode( $shortcode, array( $this, '_shortcode_' . str_replace( '-', '_', $shortcode ) ) );
add_shortcode( $shortcode, array( $this, 'shortcode_' . str_replace( '-', '_', $shortcode ) ) );
}
$this->atts = null;
@@ -19,7 +19,7 @@ class Tests_Shortcode extends WP_UnitTestCase {
}
function tear_down() {
public function tear_down() {
global $shortcode_tags;
foreach ( $this->shortcodes as $shortcode ) {
unset( $shortcode_tags[ $shortcode ] );
@@ -27,7 +27,7 @@ class Tests_Shortcode extends WP_UnitTestCase {
parent::tear_down();
}
function _shortcode_test_shortcode_tag( $atts, $content = null, $tagname = null ) {
public function shortcode_test_shortcode_tag( $atts, $content = null, $tagname = null ) {
$this->atts = $atts;
$this->content = $content;
$this->tagname = $tagname;
@@ -37,13 +37,13 @@ class Tests_Shortcode extends WP_UnitTestCase {
}
// [footag foo="bar"]
function _shortcode_footag( $atts ) {
public function shortcode_footag( $atts ) {
$foo = isset( $atts['foo'] ) ? $atts['foo'] : '';
return "foo = $foo";
}
// [bartag foo="bar"]
function _shortcode_bartag( $atts ) {
public function shortcode_bartag( $atts ) {
$processed_atts = shortcode_atts(
array(
'foo' => 'no foo',
@@ -57,11 +57,11 @@ class Tests_Shortcode extends WP_UnitTestCase {
}
// [baztag]content[/baztag]
function _shortcode_baztag( $atts, $content = '' ) {
public function shortcode_baztag( $atts, $content = '' ) {
return 'content = ' . do_shortcode( $content );
}
function _shortcode_dumptag( $atts ) {
public function shortcode_dumptag( $atts ) {
$out = '';
foreach ( $atts as $k => $v ) {
$out .= "$k = $v\n";
@@ -69,23 +69,23 @@ class Tests_Shortcode extends WP_UnitTestCase {
return $out;
}
function _shortcode_hyphen() {
public function shortcode_hyphen() {
return __FUNCTION__;
}
function _shortcode_hyphen_foo() {
public function shortcode_hyphen_foo() {
return __FUNCTION__;
}
function _shortcode_hyphen_foo_bar() {
public function shortcode_hyphen_foo_bar() {
return __FUNCTION__;
}
function _shortcode_url() {
public function shortcode_url() {
return 'http://www.wordpress.org/';
}
function _shortcode_img( $atts ) {
public function shortcode_img( $atts ) {
$out = '<img';
foreach ( $atts as $k => $v ) {
$out .= " $k=\"$v\"";
@@ -95,19 +95,19 @@ class Tests_Shortcode extends WP_UnitTestCase {
return $out;
}
function test_noatts() {
public function test_noatts() {
do_shortcode( '[test-shortcode-tag /]' );
$this->assertSame( '', $this->atts );
$this->assertSame( 'test-shortcode-tag', $this->tagname );
}
function test_one_att() {
public function test_one_att() {
do_shortcode( '[test-shortcode-tag foo="asdf" /]' );
$this->assertSame( array( 'foo' => 'asdf' ), $this->atts );
$this->assertSame( 'test-shortcode-tag', $this->tagname );
}
function test_not_a_tag() {
public function test_not_a_tag() {
$out = do_shortcode( '[not-a-shortcode-tag]' );
$this->assertSame( '[not-a-shortcode-tag]', $out );
}
@@ -115,17 +115,17 @@ class Tests_Shortcode extends WP_UnitTestCase {
/**
* @ticket 17657
*/
function test_tag_hyphen_not_tag() {
public function test_tag_hyphen_not_tag() {
$out = do_shortcode( '[dumptag-notreal]' );
$this->assertSame( '[dumptag-notreal]', $out );
}
function test_tag_underscore_not_tag() {
public function test_tag_underscore_not_tag() {
$out = do_shortcode( '[dumptag_notreal]' );
$this->assertSame( '[dumptag_notreal]', $out );
}
function test_tag_not_tag() {
public function test_tag_not_tag() {
$out = do_shortcode( '[dumptagnotreal]' );
$this->assertSame( '[dumptagnotreal]', $out );
}
@@ -133,10 +133,10 @@ class Tests_Shortcode extends WP_UnitTestCase {
/**
* @ticket 17657
*/
function test_tag_hyphen() {
$this->assertSame( '_shortcode_hyphen', do_shortcode( '[hyphen]' ) );
$this->assertSame( '_shortcode_hyphen_foo', do_shortcode( '[hyphen-foo]' ) );
$this->assertSame( '_shortcode_hyphen_foo_bar', do_shortcode( '[hyphen-foo-bar]' ) );
public function test_tag_hyphen() {
$this->assertSame( 'shortcode_hyphen', do_shortcode( '[hyphen]' ) );
$this->assertSame( 'shortcode_hyphen_foo', do_shortcode( '[hyphen-foo]' ) );
$this->assertSame( 'shortcode_hyphen_foo_bar', do_shortcode( '[hyphen-foo-bar]' ) );
$this->assertSame( '[hyphen-baz]', do_shortcode( '[hyphen-baz]' ) );
$this->assertSame( '[hyphen-foo-bar-baz]', do_shortcode( '[hyphen-foo-bar-baz]' ) );
}
@@ -144,7 +144,7 @@ class Tests_Shortcode extends WP_UnitTestCase {
/**
* @ticket 9405
*/
function test_attr_hyphen() {
public function test_attr_hyphen() {
do_shortcode( '[test-shortcode-tag foo="foo" foo-bar="foo-bar" foo-bar-="foo-bar-" -foo-bar="-foo-bar" -foo-bar-="-foo-bar-" foo-bar-baz="foo-bar-baz" -foo-bar-baz="-foo-bar-baz" foo--bar="foo--bar" /]' );
$expected_attrs = array(
'foo' => 'foo',
@@ -159,7 +159,7 @@ class Tests_Shortcode extends WP_UnitTestCase {
$this->assertSame( $expected_attrs, $this->atts );
}
function test_two_atts() {
public function test_two_atts() {
do_shortcode( '[test-shortcode-tag foo="asdf" bar="bing" /]' );
$this->assertSame(
array(
@@ -171,21 +171,21 @@ class Tests_Shortcode extends WP_UnitTestCase {
$this->assertSame( 'test-shortcode-tag', $this->tagname );
}
function test_noatts_enclosing() {
public function test_noatts_enclosing() {
do_shortcode( '[test-shortcode-tag]content[/test-shortcode-tag]' );
$this->assertSame( '', $this->atts );
$this->assertSame( 'content', $this->content );
$this->assertSame( 'test-shortcode-tag', $this->tagname );
}
function test_one_att_enclosing() {
public function test_one_att_enclosing() {
do_shortcode( '[test-shortcode-tag foo="bar"]content[/test-shortcode-tag]' );
$this->assertSame( array( 'foo' => 'bar' ), $this->atts );
$this->assertSame( 'content', $this->content );
$this->assertSame( 'test-shortcode-tag', $this->tagname );
}
function test_two_atts_enclosing() {
public function test_two_atts_enclosing() {
do_shortcode( '[test-shortcode-tag foo="bar" baz="bing"]content[/test-shortcode-tag]' );
$this->assertSame(
array(
@@ -198,28 +198,28 @@ class Tests_Shortcode extends WP_UnitTestCase {
$this->assertSame( 'test-shortcode-tag', $this->tagname );
}
function test_unclosed() {
public function test_unclosed() {
$out = do_shortcode( '[test-shortcode-tag]' );
$this->assertSame( '', $out );
$this->assertSame( '', $this->atts );
$this->assertSame( 'test-shortcode-tag', $this->tagname );
}
function test_positional_atts_num() {
public function test_positional_atts_num() {
$out = do_shortcode( '[test-shortcode-tag 123]' );
$this->assertSame( '', $out );
$this->assertSame( array( 0 => '123' ), $this->atts );
$this->assertSame( 'test-shortcode-tag', $this->tagname );
}
function test_positional_atts_url() {
public function test_positional_atts_url() {
$out = do_shortcode( '[test-shortcode-tag https://www.youtube.com/watch?v=72xdCU__XCk]' );
$this->assertSame( '', $out );
$this->assertSame( array( 0 => 'https://www.youtube.com/watch?v=72xdCU__XCk' ), $this->atts );
$this->assertSame( 'test-shortcode-tag', $this->tagname );
}
function test_positional_atts_quotes() {
public function test_positional_atts_quotes() {
$out = do_shortcode( '[test-shortcode-tag "something in quotes" "something else"]' );
$this->assertSame( '', $out );
$this->assertSame(
@@ -232,7 +232,7 @@ class Tests_Shortcode extends WP_UnitTestCase {
$this->assertSame( 'test-shortcode-tag', $this->tagname );
}
function test_positional_atts_mixed() {
public function test_positional_atts_mixed() {
$out = do_shortcode( '[test-shortcode-tag 123 https://wordpress.org/ 0 "foo" bar]' );
$this->assertSame( '', $out );
$this->assertSame(
@@ -248,7 +248,7 @@ class Tests_Shortcode extends WP_UnitTestCase {
$this->assertSame( 'test-shortcode-tag', $this->tagname );
}
function test_positional_and_named_atts() {
public function test_positional_and_named_atts() {
$out = do_shortcode( '[test-shortcode-tag 123 url=https://wordpress.org/ foo bar="baz"]' );
$this->assertSame( '', $out );
$this->assertSame(
@@ -263,18 +263,18 @@ class Tests_Shortcode extends WP_UnitTestCase {
$this->assertSame( 'test-shortcode-tag', $this->tagname );
}
function test_footag_default() {
public function test_footag_default() {
$out = do_shortcode( '[footag]' );
$this->assertSame( 'foo = ', $out );
}
function test_footag_val() {
public function test_footag_val() {
$val = rand_str();
$out = do_shortcode( '[footag foo="' . $val . '"]' );
$this->assertSame( 'foo = ' . $val, $out );
}
function test_nested_tags() {
public function test_nested_tags() {
$out = do_shortcode( '[baztag][dumptag abc="foo" def=123 https://wordpress.org/][/baztag]' );
$expected = "content = abc = foo\ndef = 123\n0 = https://wordpress.org\n";
$this->assertSame( $expected, $out );
@@ -283,7 +283,7 @@ class Tests_Shortcode extends WP_UnitTestCase {
/**
* @ticket 6518
*/
function test_tag_escaped() {
public function test_tag_escaped() {
$out = do_shortcode( '[[footag]] [[bartag foo="bar"]]' );
$this->assertSame( '[footag] [bartag foo="bar"]', $out );
@@ -298,7 +298,7 @@ class Tests_Shortcode extends WP_UnitTestCase {
$this->assertSame( '[[footag]] [[bartag foo="bar"]]', $out );
}
function test_tag_not_escaped() {
public function test_tag_not_escaped() {
// These have square brackets on either end but aren't actually escaped.
$out = do_shortcode( '[[footag] [bartag foo="bar"]]' );
$this->assertSame( '[foo = foo = bar]', $out );
@@ -316,7 +316,7 @@ class Tests_Shortcode extends WP_UnitTestCase {
$this->assertSame( '[[foo = foo = bar]]', $out );
}
function test_mixed_tags() {
public function test_mixed_tags() {
$in = <<<EOF
So this is a post with [footag foo="some stuff"] and a bunch of tags.
@@ -356,7 +356,7 @@ EOF;
/**
* @ticket 6562
*/
function test_utf8_whitespace_1() {
public function test_utf8_whitespace_1() {
// NO-BREAK SPACE: U+00A0.
do_shortcode( "[test-shortcode-tag foo=\"bar\" \xC2\xA0baz=\"123\"]" );
$this->assertSame(
@@ -372,7 +372,7 @@ EOF;
/**
* @ticket 6562
*/
function test_utf8_whitespace_2() {
public function test_utf8_whitespace_2() {
// ZERO WIDTH SPACE: U+200B.
do_shortcode( "[test-shortcode-tag foo=\"bar\" \xE2\x80\x8Babc=\"def\"]" );
$this->assertSame(
@@ -388,13 +388,13 @@ EOF;
/**
* @ticket 14050
*/
function test_shortcode_unautop() {
public function test_shortcode_unautop() {
// A blank line is added at the end, so test with it already there.
$test_string = "[footag]\n";
$this->assertSame( $test_string, shortcode_unautop( wpautop( $test_string ) ) );
}
function data_test_strip_shortcodes() {
public function data_test_strip_shortcodes() {
return array(
array( 'before', 'before[gallery]' ),
array( 'after', '[gallery]after' ),
@@ -417,25 +417,25 @@ EOF;
* @param string $expected Expected output.
* @param string $content Content to run strip_shortcodes() on.
*/
function test_strip_shortcodes( $expected, $content ) {
public function test_strip_shortcodes( $expected, $content ) {
$this->assertSame( $expected, strip_shortcodes( $content ) );
}
/**
* @ticket 37767
*/
function test_strip_shortcodes_filter() {
add_filter( 'strip_shortcodes_tagnames', array( $this, '_filter_strip_shortcodes_tagnames' ) );
public function test_strip_shortcodes_filter() {
add_filter( 'strip_shortcodes_tagnames', array( $this, 'filter_strip_shortcodes_tagnames' ) );
$this->assertSame( 'beforemiddle [footag]after', strip_shortcodes( 'before[gallery]middle [footag]after' ) );
remove_filter( 'strip_shortcodes_tagnames', array( $this, '_filter_strip_shortcodes_tagnames' ) );
remove_filter( 'strip_shortcodes_tagnames', array( $this, 'filter_strip_shortcodes_tagnames' ) );
}
function _filter_strip_shortcodes_tagnames() {
public function filter_strip_shortcodes_tagnames() {
return array( 'gallery' );
}
// Store passed in shortcode_atts_{$shortcode} args.
function _filter_atts( $out, $pairs, $atts ) {
public function filter_atts( $out, $pairs, $atts ) {
$this->filter_atts_out = $out;
$this->filter_atts_pairs = $pairs;
$this->filter_atts_atts = $atts;
@@ -443,7 +443,7 @@ EOF;
}
// Filter shortcode atts in various ways.
function _filter_atts2( $out, $pairs, $atts ) {
public function filter_atts2( $out, $pairs, $atts ) {
// If foo attribute equals "foo1", change it to be default value.
if ( isset( $out['foo'] ) && 'foo1' === $out['foo'] ) {
$out['foo'] = $pairs['foo'];
@@ -458,8 +458,8 @@ EOF;
return $out;
}
function test_shortcode_atts_filter_passes_original_arguments() {
add_filter( 'shortcode_atts_bartag', array( $this, '_filter_atts' ), 10, 3 );
public function test_shortcode_atts_filter_passes_original_arguments() {
add_filter( 'shortcode_atts_bartag', array( $this, 'filter_atts' ), 10, 3 );
do_shortcode( '[bartag foo="foo1" /]' );
$this->assertSame(
@@ -478,11 +478,11 @@ EOF;
);
$this->assertSame( array( 'foo' => 'foo1' ), $this->filter_atts_atts );
remove_filter( 'shortcode_atts_bartag', array( $this, '_filter_atts' ), 10, 3 );
remove_filter( 'shortcode_atts_bartag', array( $this, 'filter_atts' ), 10, 3 );
}
function test_shortcode_atts_filtering() {
add_filter( 'shortcode_atts_bartag', array( $this, '_filter_atts2' ), 10, 3 );
public function test_shortcode_atts_filtering() {
add_filter( 'shortcode_atts_bartag', array( $this, 'filter_atts2' ), 10, 3 );
$out = do_shortcode( '[bartag foo="foo1" baz="baz1" /]' );
$this->assertSame( array( 'foo' => 'no foo' ), $this->filter_atts_out );
@@ -491,7 +491,7 @@ EOF;
$out = do_shortcode( '[bartag foo="foo2" /]' );
$this->assertSame( 'foo = foo2', $out );
remove_filter( 'shortcode_atts_bartag', array( $this, '_filter_atts2' ), 10, 3 );
remove_filter( 'shortcode_atts_bartag', array( $this, 'filter_atts2' ), 10, 3 );
}
/**
@@ -499,7 +499,7 @@ EOF;
*
* @ticket 22692
*/
function test_spaces_around_shortcodes() {
public function test_spaces_around_shortcodes() {
$nbsp = "\xC2\xA0";
$input = array();
@@ -521,11 +521,11 @@ EOF;
*
* @dataProvider data_escaping
*/
function test_escaping( $input, $output ) {
public function test_escaping( $input, $output ) {
return $this->assertSame( $output, do_shortcode( $input ) );
}
function data_escaping() {
public function data_escaping() {
return array(
array(
'<!--[if lt IE 7]>',
@@ -599,11 +599,11 @@ EOF;
*
* @dataProvider data_escaping2
*/
function test_escaping2( $input, $output ) {
public function test_escaping2( $input, $output ) {
return $this->assertSame( $output, strip_shortcodes( $input ) );
}
function data_escaping2() {
public function data_escaping2() {
return array(
array(
'<!--[if lt IE 7]>',
@@ -639,7 +639,7 @@ EOF;
/**
* @ticket 26343
*/
function test_has_shortcode() {
public function test_has_shortcode() {
$content = 'This is a blob with [gallery] in it';
$this->assertTrue( has_shortcode( $content, 'gallery' ) );
@@ -655,8 +655,8 @@ EOF;
* @dataProvider data_registration_bad
* @expectedIncorrectUsage add_shortcode
*/
function test_registration_bad( $input, $expected ) {
return $this->sub_registration( $input, $expected );
public function test_registration_bad( $input, $expected ) {
$this->sub_registration( $input, $expected );
}
/**
@@ -664,21 +664,20 @@ EOF;
*
* @dataProvider data_registration_good
*/
function test_registration_good( $input, $expected ) {
return $this->sub_registration( $input, $expected );
public function test_registration_good( $input, $expected ) {
$this->sub_registration( $input, $expected );
}
function sub_registration( $input, $expected ) {
private function sub_registration( $input, $expected ) {
add_shortcode( $input, '' );
$actual = shortcode_exists( $input );
$test = $this->assertSame( $expected, $actual );
$this->assertSame( $expected, $actual );
if ( $actual ) {
remove_shortcode( $input );
}
return $test;
}
function data_registration_bad() {
public function data_registration_bad() {
return array(
array(
'<html>',
@@ -711,7 +710,7 @@ EOF;
);
}
function data_registration_good() {
public function data_registration_good() {
return array(
array(
'good!',
@@ -733,13 +732,13 @@ EOF;
*
* @dataProvider data_whole_posts
*/
function test_pcre_performance( $input ) {
public function test_pcre_performance( $input ) {
$regex = '/' . get_shortcode_regex() . '/';
$result = benchmark_pcre_backtracking( $regex, $input, 'match_all' );
return $this->assertLessThan( 200, $result );
}
function data_whole_posts() {
public function data_whole_posts() {
require_once DIR_TESTDATA . '/formatting/whole-posts.php';
return data_whole_posts();
}
@@ -750,7 +749,7 @@ EOF;
* @ticket 34191
* @ticket 51734
*/
function test_php_and_js_shortcode_attribute_regexes_match() {
public function test_php_and_js_shortcode_attribute_regexes_match() {
// This test uses the source file by default but will use the built file if it exists.
// This allows the test to run using either the src or build directory.
$file_src = ABSPATH . 'js/_enqueues/wp/shortcode.js';
@@ -780,7 +779,7 @@ EOF;
*
* Test the (not recommended) [shortcode=XXX] format
*/
function test_unnamed_attribute() {
public function test_unnamed_attribute() {
$out = do_shortcode( '[dumptag=https://wordpress.org/]' );
$expected = "0 = =https://wordpress.org\n";
$this->assertSame( $expected, $out );
@@ -789,7 +788,7 @@ EOF;
/**
* @ticket 36306
*/
function test_smilies_arent_converted() {
public function test_smilies_arent_converted() {
$out = apply_filters( 'the_content', '[img alt="Hello :-) World"]' );
$expected = "<img alt=\"Hello :-) World\" />\n";
$this->assertSame( $expected, $out );
@@ -801,17 +800,17 @@ EOF;
public function test_pre_do_shortcode_tag() {
// Does nothing if no filters are set up.
$str = 'pre_do_shortcode_tag';
add_shortcode( $str, array( $this, '_shortcode_pre_do_shortcode_tag' ) );
add_shortcode( $str, array( $this, 'shortcode_pre_do_shortcode_tag' ) );
$result_nofilter = do_shortcode( "[{$str}]" );
$this->assertSame( 'foo', $result_nofilter );
// Short-circuit with filter.
add_filter( 'pre_do_shortcode_tag', array( $this, '_filter_pre_do_shortcode_tag_bar' ) );
add_filter( 'pre_do_shortcode_tag', array( $this, 'filter_pre_do_shortcode_tag_bar' ) );
$result_filter = do_shortcode( "[{$str}]" );
$this->assertSame( 'bar', $result_filter );
// Respect priority.
add_filter( 'pre_do_shortcode_tag', array( $this, '_filter_pre_do_shortcode_tag_p11' ), 11 );
add_filter( 'pre_do_shortcode_tag', array( $this, 'filter_pre_do_shortcode_tag_p11' ), 11 );
$result_priority = do_shortcode( "[{$str}]" );
$this->assertSame( 'p11', $result_priority );
@@ -833,29 +832,29 @@ EOF;
'',
),
);
add_filter( 'pre_do_shortcode_tag', array( $this, '_filter_pre_do_shortcode_tag_attr' ), 12, 4 );
add_filter( 'pre_do_shortcode_tag', array( $this, 'filter_pre_do_shortcode_tag_attr' ), 12, 4 );
$result_atts = do_shortcode( "[{$str} a='b' c='d']" );
$this->assertSame( wp_json_encode( $arr ), $result_atts );
remove_filter( 'pre_do_shortcode_tag', array( $this, '_filter_pre_do_shortcode_tag_attr' ), 12, 4 );
remove_filter( 'pre_do_shortcode_tag', array( $this, '_filter_pre_do_shortcode_tag_p11' ), 11 );
remove_filter( 'pre_do_shortcode_tag', array( $this, '_filter_pre_do_shortcode_tag_bar' ) );
remove_filter( 'pre_do_shortcode_tag', array( $this, 'filter_pre_do_shortcode_tag_attr' ), 12, 4 );
remove_filter( 'pre_do_shortcode_tag', array( $this, 'filter_pre_do_shortcode_tag_p11' ), 11 );
remove_filter( 'pre_do_shortcode_tag', array( $this, 'filter_pre_do_shortcode_tag_bar' ) );
remove_shortcode( $str );
}
public function _shortcode_pre_do_shortcode_tag( $atts = array(), $content = '' ) {
public function shortcode_pre_do_shortcode_tag( $atts = array(), $content = '' ) {
return 'foo';
}
public function _filter_pre_do_shortcode_tag_bar() {
public function filter_pre_do_shortcode_tag_bar() {
return 'bar';
}
public function _filter_pre_do_shortcode_tag_p11() {
public function filter_pre_do_shortcode_tag_p11() {
return 'p11';
}
public function _filter_pre_do_shortcode_tag_attr( $return, $key, $atts, $m ) {
public function filter_pre_do_shortcode_tag_attr( $return, $key, $atts, $m ) {
$arr = array(
'return' => $return,
'key' => $key,
@@ -871,17 +870,17 @@ EOF;
public function test_do_shortcode_tag_filter() {
// Does nothing if no filters are set up.
$str = 'do_shortcode_tag';
add_shortcode( $str, array( $this, '_shortcode_do_shortcode_tag' ) );
add_shortcode( $str, array( $this, 'shortcode_do_shortcode_tag' ) );
$result_nofilter = do_shortcode( "[{$str}]" );
$this->assertSame( 'foo', $result_nofilter );
// Modify output with filter.
add_filter( 'do_shortcode_tag', array( $this, '_filter_do_shortcode_tag_replace' ) );
add_filter( 'do_shortcode_tag', array( $this, 'filter_do_shortcode_tag_replace' ) );
$result_filter = do_shortcode( "[{$str}]" );
$this->assertSame( 'fee', $result_filter );
// Respect priority.
add_filter( 'do_shortcode_tag', array( $this, '_filter_do_shortcode_tag_generate' ), 11 );
add_filter( 'do_shortcode_tag', array( $this, 'filter_do_shortcode_tag_generate' ), 11 );
$result_priority = do_shortcode( "[{$str}]" );
$this->assertSame( 'foobar', $result_priority );
@@ -903,29 +902,29 @@ EOF;
'',
),
);
add_filter( 'do_shortcode_tag', array( $this, '_filter_do_shortcode_tag_attr' ), 12, 4 );
add_filter( 'do_shortcode_tag', array( $this, 'filter_do_shortcode_tag_attr' ), 12, 4 );
$result_atts = do_shortcode( "[{$str} a='b' c='d']" );
$this->assertSame( wp_json_encode( $arr ), $result_atts );
remove_filter( 'do_shortcode_tag', array( $this, '_filter_do_shortcode_tag_attr' ), 12 );
remove_filter( 'do_shortcode_tag', array( $this, '_filter_do_shortcode_tag_generate' ), 11 );
remove_filter( 'do_shortcode_tag', array( $this, '_filter_do_shortcode_tag_replace' ) );
remove_filter( 'do_shortcode_tag', array( $this, 'filter_do_shortcode_tag_attr' ), 12 );
remove_filter( 'do_shortcode_tag', array( $this, 'filter_do_shortcode_tag_generate' ), 11 );
remove_filter( 'do_shortcode_tag', array( $this, 'filter_do_shortcode_tag_replace' ) );
remove_shortcode( $str );
}
public function _shortcode_do_shortcode_tag( $atts = array(), $content = '' ) {
public function shortcode_do_shortcode_tag( $atts = array(), $content = '' ) {
return 'foo';
}
public function _filter_do_shortcode_tag_replace( $return ) {
public function filter_do_shortcode_tag_replace( $return ) {
return str_replace( 'oo', 'ee', $return );
}
public function _filter_do_shortcode_tag_generate( $return ) {
public function filter_do_shortcode_tag_generate( $return ) {
return 'foobar';
}
public function _filter_do_shortcode_tag_attr( $return, $key, $atts, $m ) {
public function filter_do_shortcode_tag_attr( $return, $key, $atts, $m ) {
$arr = array(
'return' => $return,
'key' => $key,
@@ -940,7 +939,7 @@ EOF;
*
* Test 'value' syntax for empty attributes
*/
function test_empty_single_quote_attribute() {
public function test_empty_single_quote_attribute() {
$out = do_shortcode( '[test-shortcode-tag a="foo" b=\'bar\' c=baz foo \'bar\' "baz" ]test empty atts[/test-shortcode-tag]' );
$this->assertSame(
array(
@@ -958,7 +957,7 @@ EOF;
/**
* @ticket 37304
*/
function test_positional_atts_single_quotes() {
public function test_positional_atts_single_quotes() {
$out = do_shortcode( "[test-shortcode-tag 'something in quotes' 'something else']" );
$this->assertSame( '', $out );
$this->assertSame(
@@ -974,7 +973,7 @@ EOF;
/**
* @ticket 37304
*/
function test_positional_atts_mixed_quotes() {
public function test_positional_atts_mixed_quotes() {
$out = do_shortcode( "[test-shortcode-tag 'something in quotes' \"something else\" 123 foo bar='baz' example=\"test\" ]" );
$this->assertSame( '', $out );
$this->assertSame(