| | 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 | } |