Skip to content

Commit

Permalink
Remove inline functions to make tests compatible w/ php 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Sep 18, 2017
1 parent cd83084 commit 3bfb55b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
24 changes: 13 additions & 11 deletions tests/test-cmb-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,22 +911,14 @@ public function test_group_wrap_attributes() {

$this->assertEquals( implode( ' ', $expected ), $cmb->group_wrap_attributes( $field_group ) );

$json = '{"glossary": {"title": "example glossary","GlossDiv": {"title": "S","GlossList": {"GlossEntry": {"ID": "SGML","SortAs": "SGML","GlossTerm": "Standard Generalized Markup Language","Acronym": "SGML","Abbrev": "ISO 8879:1986","GlossDef": {"para": "A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso": ["GML", "XML"]},"GlossSee": "<script>xss</script><a href="http://xssattackexamples.com/">Click to Download</a>"}}}}}';
$this->json = '{"glossary": {"title": "example glossary","GlossDiv": {"title": "S","GlossList": {"GlossEntry": {"ID": "SGML","SortAs": "SGML","GlossTerm": "Standard Generalized Markup Language","Acronym": "SGML","Abbrev": "ISO 8879:1986","GlossDef": {"para": "A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso": ["GML", "XML"]},"GlossSee": "<script>xss</script><a href="http://xssattackexamples.com/">Click to Download</a>"}}}}}';

add_filter( 'cmb2_group_wrap_attributes', function( $group_wrap_atts, $field_group ) use ( $json ) {
$group_wrap_atts['heyo'] = "it's Zao";
$group_wrap_atts['data-json'] = $json;

$group_wrap_atts['"><script>xss</script><a href="http://xssattackexamples.com/">Click to Download</a>'] = 'hackers';
$group_wrap_atts['hackers'] = '"><script>xss</script><a href="http://xssattackexamples.com/">Click to Download</a>';

return $group_wrap_atts;
}, 10, 2 );
add_filter( 'cmb2_group_wrap_attributes', array( $this, 'for_testing_cmb2_group_wrap_attributes' ) , 10, 2 );

$clean_json = str_replace(
'<script>xss</script><a href="http://xssattackexamples.com/">Click to Download</a>',
'xssClick to Download',
$json
$this->json
);

$expected[] = 'heyo="it\'s Zao"';
Expand All @@ -937,6 +929,16 @@ public function test_group_wrap_attributes() {
$this->assertHTMLstringsAreEqual( implode( ' ', $expected ), $cmb->group_wrap_attributes( $field_group ) );
}

public function for_testing_cmb2_group_wrap_attributes( $group_wrap_atts, $field_group ) {
$group_wrap_atts['heyo'] = "it's Zao";
$group_wrap_atts['data-json'] = $this->json;

$group_wrap_atts['"><script>xss</script><a href="http://xssattackexamples.com/">Click to Download</a>'] = 'hackers';
$group_wrap_atts['hackers'] = '"><script>xss</script><a href="http://xssattackexamples.com/">Click to Download</a>';

return $group_wrap_atts;
}

public static function overloading_test( $cmb2, $noun = '' ) {
$cmb2->fabulous_noun = $noun;
return 'Fabulous ' . $noun;
Expand Down
17 changes: 11 additions & 6 deletions tests/test-cmb-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -1171,9 +1171,7 @@ public function test_maybe_custom_field_object() {
),
) );

add_action( 'cmb2_render_test_custom', function() {
echo 'hey macarena!';
} );
add_action( 'cmb2_render_test_custom', array( __CLASS__, 'hey_macarena' ) );

$field = cmb2_get_field( 'field_test', 'field_test_field_custom', $this->post_id );

Expand All @@ -1183,14 +1181,21 @@ public function test_maybe_custom_field_object() {

$this->assertSame( 'hey macarena!', $this->capture_render( array( $types, 'render' ) ) );

add_filter( 'cmb2_render_class_test_custom', function() {
return 'CMB2_Type_Title';
} );
add_filter( 'cmb2_render_class_test_custom', array( __CLASS__, 'return_cmb2_type_title' ) );

$this->assertInstanceOf( 'CMB2_Type_Title', $types->maybe_custom_field_object( 'test_custom' ) );

$expected = '<h5 class="cmb2-metabox-title" id="field-test-field-custom">Name</h5><p class="cmb2-metabox-description">This is a description</p>';

$this->assertHTMLstringsAreEqual( $expected, $this->capture_render( array( $types, 'render' ) ) );
}

public static function hey_macarena() {
echo 'hey macarena!';
}

public static function return_cmb2_type_title() {
return 'CMB2_Type_Title';
}

}

0 comments on commit 3bfb55b

Please sign in to comment.