Make WordPress Core

Ticket #26163: NormalizeWhitespace.php

File NormalizeWhitespace.php, 991 bytes (added by mdbitz, 10 years ago)

normalize_whitespace Unit Tests

Line 
1<?php
2
3/**
4 * @group formatting
5 */
6class Tests_Formatting_NormalizeWhitespace extends WP_UnitTestCase {
7       
8        /**
9         * WhitespaceTest Content DataProvider
10         *
11         * array ( input_txt, converted_output_txt)
12         */
13        public function get_input_output() {
14                return array (
15                        array (
16                                "               ",
17                                ""
18                        ),
19                        array (
20                                "\rTEST\r",
21                                "TEST"
22                        ),
23                        array (
24                                "\r\nMY TEST CONTENT\r\n",
25                                "MY TEST CONTENT"
26                        ),
27                        array (
28                                "MY\r\nTEST\r\nCONTENT ",
29                                "MY\nTEST\nCONTENT"
30                        ),
31                        array (
32                                "\tMY\rTEST\rCONTENT ",
33                                "MY\nTEST\nCONTENT"
34                        ),
35                        array (
36                                "\tMY\t\t\tTEST\r\t\t\rCONTENT ",
37                                "MY TEST\n \nCONTENT"
38                        ),
39                        array (
40                                "\tMY TEST \t\t\t CONTENT ",
41                                "MY TEST CONTENT"
42                        ),
43                );
44        }
45
46        /**
47         * Validate the normalize_whitespace function
48         * @dataProvider get_input_output
49         */
50        function test_normalize_whitespace( $in_str, $exp_str ) {
51
52                $this->assertEquals($exp_str, normalize_whitespace( $in_str ) );
53
54        }
55}