Make WordPress Core

Ticket #26829: 26829.tests.refreshed.diff

File 26829.tests.refreshed.diff, 3.0 KB (added by chesio, 6 years ago)

Tests for refreshed patch (also covering new function)

  • tests/phpunit/data/formatting/markers.txt

     
     1
     2# BEGIN Empty
     3# END Empty
     4
     5# BEGIN FooBar
     6FooBar line
     7# END FooBar
     8
     9# BEGIN Foo Bar
     10Foo Bar line
     11# END Foo Bar
     12
     13# BEGIN Foo
     14Foo line
     15# END Foo
     16
     17# BEGIN Multiline
     18
     19Multiline 2
     20Multiline 3
     21
     22Multiline 5
     23
     24# END Multiline
  • tests/phpunit/tests/admin/includesMisc.php

     
    2222                foreach ( $tests as $k => $v )
    2323                        $this->assertEquals( $v, url_shorten( $k ) );
    2424        }
     25
     26        function test_extract_from_markers() {
     27                $filename = DIR_TESTDATA . '/formatting/markers.txt';
     28
     29                // Assert that section marked with marker that is prefix of another marker is extracted correctly.
     30                $test_foo = array(
     31                        'Foo line',
     32                );
     33                $this->assertEquals( $test_foo, extract_from_markers( $filename, 'Foo' ) );
     34
     35                // Assert that section marked by marker with spaces is extracted correctly.
     36                $test_foo_bar = array(
     37                        'Foo Bar line',
     38                );
     39                $this->assertEquals( $test_foo_bar, extract_from_markers( $filename, 'Foo Bar' ) );
     40
     41                // Assert that section with multiple lines (including empty lines) is extracted correctly.
     42                $test_wordpress = array(
     43                        '',
     44                        'Multiline 2',
     45                        'Multiline 3',
     46                        '',
     47                        'Multiline 5',
     48                        '',
     49                );
     50                $this->assertEquals( $test_wordpress, extract_from_markers( $filename, 'Multiline' ) );
     51
     52                // Assert that empty array is returned for empty section.
     53                $this->assertEquals( array(), extract_from_markers( $filename, 'Empty' ) );
     54
     55                // Assert that empty array is returned for non-existing section.
     56                $this->assertEquals( array(), extract_from_markers( $filename, 'Null' ) );
     57
     58                // Assert that empty array is returned if file does not exists.
     59                $this->assertEquals( array(), extract_from_markers( rand_str(), 'Foo' ) );
     60        }
     61
     62        /**
     63         * @ticket 26829
     64         */
     65        function test_split_by_markers() {
     66                // Test data
     67                $pre = array(
     68                        '# BEGIN FooPre',
     69                        'Line before',
     70                        '# END FooPre',
     71                );
     72                $in = array(
     73                        '# BEGIN Foo',
     74                        'Line in',
     75                        '# END Foo',
     76                );
     77                $post = array (
     78                        '# BEGIN FooPost',
     79                        'Line after',
     80                        '# END FooPost',
     81                );
     82
     83                $lines = array_merge($pre, $in, $post);
     84
     85                // Assert correct results when splitting by FooPre
     86                $this->assertEquals(
     87                        array( array(), array( 'Line before' ), array_merge( $in, $post ) ),
     88                        split_by_markers( $lines, 'FooPre' )
     89                );
     90                // Assert correct results when splitting by Foo
     91                $this->assertEquals(
     92                        array( $pre, array( 'Line in' ), $post ),
     93                        split_by_markers( $lines, 'Foo' )
     94                );
     95                // Assert correct results when splitting by FooPost
     96                $this->assertEquals(
     97                        array( array_merge($pre, $in), array( 'Line after' ), array() ),
     98                        split_by_markers( $lines, 'FooPost' )
     99                );
     100        }
    25101}