|
| 1 | +<?php |
| 2 | + |
| 3 | +use WP_CLI\Tests\TestCase; |
| 4 | + |
| 5 | +class UpdateMixedLineEndingsTest extends TestCase { |
| 6 | + private static $test_config_path; |
| 7 | + private static $test_config_lines; |
| 8 | + private static $config_transformer; |
| 9 | + public static function set_up_before_class() { |
| 10 | + self::$test_config_lines = array( |
| 11 | + "<?php\n", |
| 12 | + "// this is a demo\r\n", |
| 13 | + "\r\n", |
| 14 | + "\r\n", |
| 15 | + "define( 'DB_NAME', '' );\n", |
| 16 | + "define( 'DB_HOST', '' );\r\n", |
| 17 | + "define( 'DB_USER', '' );\n\r", |
| 18 | + "\r\n", |
| 19 | + "\n\r", |
| 20 | + "\r", |
| 21 | + "\r", |
| 22 | + "\r\n", |
| 23 | + "define( 'DB_COLLATE', '');\n", |
| 24 | + "\n\r", |
| 25 | + "\n\r", |
| 26 | + "\r", |
| 27 | + "\r", |
| 28 | + ); |
| 29 | + self::$test_config_path = tempnam( sys_get_temp_dir(), 'wp-config' ); |
| 30 | + file_put_contents( self::$test_config_path, implode( '', self::$test_config_lines ) ); |
| 31 | + self::$config_transformer = new WPConfigTransformer( self::$test_config_path ); |
| 32 | + } |
| 33 | + public static function tear_down_after_class() { |
| 34 | + unlink( self::$test_config_path ); |
| 35 | + } |
| 36 | + public function testMixedLineEndingsAreNormalized() { |
| 37 | + $this->assertTrue( self::$config_transformer->update( 'constant', 'DB_HOST', 'demo' ) ); |
| 38 | + $this->assertTrue( self::$config_transformer->update( 'constant', 'DB_HOST', '' ) ); |
| 39 | + |
| 40 | + $modified_config_lines = file( self::$test_config_path ); |
| 41 | + $this->assertSame( array_map( 'trim', self::$test_config_lines ), array_map( 'trim', $modified_config_lines ) ); |
| 42 | + } |
| 43 | +} |
0 commit comments