| | 725 | |
| | 726 | /** |
| | 727 | * Testing the safecss_filter_attr() function. |
| | 728 | * |
| | 729 | * @ticket 42729 |
| | 730 | * @dataProvider data_test_safecss_filter_attr |
| | 731 | * |
| | 732 | * @param string $css A string of CSS rules. |
| | 733 | * @param string $expected Expected string of CSS rules |
| | 734 | */ |
| | 735 | public function test_safecss_filter_attr( $css, $expected ) { |
| | 736 | $this->assertSame( $expected, safecss_filter_attr( $css ) ); |
| | 737 | } |
| | 738 | |
| | 739 | /** |
| | 740 | * Data Provider for test_safecss_filter_attr(). |
| | 741 | * |
| | 742 | * @return array { |
| | 743 | * @type array { |
| | 744 | * @string string $css A string of CSS rules. |
| | 745 | * @string string $expected Expected string of CSS rules. |
| | 746 | * } |
| | 747 | * } |
| | 748 | */ |
| | 749 | public function data_test_safecss_filter_attr() { |
| | 750 | return array( |
| | 751 | // Empty input, empty output. |
| | 752 | array( |
| | 753 | 'css' => '', |
| | 754 | 'expected' => '', |
| | 755 | ), |
| | 756 | // An arbitrary attribute name isn't allowed. |
| | 757 | array( |
| | 758 | 'css' => 'foo:bar', |
| | 759 | 'expected' => '', |
| | 760 | ), |
| | 761 | // A single attribute name, with a single value. |
| | 762 | array( |
| | 763 | 'css' => 'margin-top: 2px', |
| | 764 | 'expected' => 'margin-top: 2px', |
| | 765 | ), |
| | 766 | // Backslash \ isn't supported. |
| | 767 | array( |
| | 768 | 'css' => 'margin-top: \2px', |
| | 769 | 'expected' => '', |
| | 770 | ), |
| | 771 | // Curly bracket } isn't supported. |
| | 772 | array( |
| | 773 | 'css' => 'margin-bottom: 2px}', |
| | 774 | 'expected' => '', |
| | 775 | ), |
| | 776 | // A single attribute name, with a single text value. |
| | 777 | array( |
| | 778 | 'css' => 'text-transform: uppercase', |
| | 779 | 'expected' => 'text-transform: uppercase', |
| | 780 | ), |
| | 781 | // Only lowercase attribute names are supported. |
| | 782 | array( |
| | 783 | 'css' => 'Text-transform: capitalize', |
| | 784 | 'expected' => '', |
| | 785 | ), |
| | 786 | // Uppercase attribute values goes through. |
| | 787 | array( |
| | 788 | 'css' => 'text-transform: None', |
| | 789 | 'expected' => 'text-transform: None', |
| | 790 | ), |
| | 791 | // A single attribute, with multiple values. |
| | 792 | array( |
| | 793 | 'css' => 'font: bold 15px arial, sans-serif', |
| | 794 | 'expected' => 'font: bold 15px arial, sans-serif', |
| | 795 | ), |
| | 796 | // Multiple attributes, with single values. |
| | 797 | array( |
| | 798 | 'css' => 'font-weight: bold;font-size: 15px', |
| | 799 | 'expected' => 'font-weight: bold;font-size: 15px', |
| | 800 | ), |
| | 801 | // Multiple attributes, separated by a space. |
| | 802 | array( |
| | 803 | 'css' => 'font-weight: bold; font-size: 15px', |
| | 804 | 'expected' => 'font-weight: bold;font-size: 15px', |
| | 805 | ), |
| | 806 | // Multiple attributes, with multiple values. |
| | 807 | array( |
| | 808 | 'css' => 'margin: 10px 20px;padding: 5px 10px', |
| | 809 | 'expected' => 'margin: 10px 20px;padding: 5px 10px', |
| | 810 | ), |
| | 811 | // Parenthesis ( isn't supported. |
| | 812 | array( |
| | 813 | 'css' => 'background: green url("foo.jpg") no-repeat fixed center', |
| | 814 | 'expected' => '', |
| | 815 | ), |
| | 816 | ); |
| | 817 | } |