Make WordPress Core

Ticket #48955: 48955.test.diff

File 48955.test.diff, 1.1 KB (added by jnylen0, 5 years ago)

Test for wp_kses + array

  • tests/phpunit/tests/kses.php

    diff --git a/tests/phpunit/tests/kses.php b/tests/phpunit/tests/kses.php
    index 916e1adf73..6d079df8f5 100644
    a b EOF; 
    755755
    756756                $this->assertEquals( "<{$element}>", wp_kses_attr( $element, $attribute, array( 'foo' => false ), array() ) );
    757757        }
     758
     759        function test_wp_kses_array() {
     760                global $allowedposttags;
     761
     762                $attributes = array(
     763                        'class'  => 'classname',
     764                        'id'     => 'id',
     765                        'style'  => 'color: red;',
     766                        'title'  => 'title',
     767                        'href'   => 'http://example.com',
     768                        'rel'    => 'related',
     769                        'rev'    => 'revision',
     770                        'name'   => 'name',
     771                        'target' => '_blank',
     772                );
     773
     774                $input           = [];
     775                $output_expected = [];
     776                $output_actual   = [];
     777
     778                foreach ( $attributes as $name => $value ) {
     779                        $input[]           = "<a $name='$value'>I link this</a>";
     780                        $output_expected[] = "<a $name='" . trim( $value, ';' ) . "'>I link this</a>";
     781                }
     782
     783                $output_actual = wp_kses( $input, $allowedposttags );
     784                $this->assertEquals( $output_expected, $output_actual );
     785        }
    758786}