Skip to content

Commit

Permalink
Windows / Linux htaccess test consistency (YOURLS#2628)
Browse files Browse the repository at this point in the history
\r\n or \r or \n ftw
  • Loading branch information
ozh authored Mar 26, 2020
1 parent 916377d commit 0d0a97a
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions tests/tests/install/htaccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function servers() {
*/
public function test_htaccess( $server, $is_apache, $file ) {
$_SERVER['SERVER_SOFTWARE'] = $server;

$this->assertSame( $is_apache, yourls_is_apache() );

if( file_exists( YOURLS_ABSPATH . '/' . $file ) )
@unlink( YOURLS_ABSPATH . '/' . $file );

$this->assertTrue( yourls_create_htaccess() );
$this->assertFileExists( YOURLS_ABSPATH . '/' . $file );
}
Expand All @@ -75,28 +75,34 @@ public function htaccess_content() {
public function test_htaccess_content( $filename ) {
$newfile = str_replace( 'original_', 'test_', $filename );
$expected = str_replace( 'original_', 'expected_', $filename );

$newfile = YOURLS_TESTDATA_DIR . '/htaccess/' . $newfile;
$filename = YOURLS_TESTDATA_DIR . '/htaccess/' . $filename;
$expected = YOURLS_TESTDATA_DIR . '/htaccess/' . $expected;

// If file exist, copy it (if file doesn't exist, it's because we're creating from scratch)
if( file_exists( $filename ) ) {
if ( !copy( $filename, $newfile ) ) {
$this->markTestSkipped( "Cannot copy file $filename" );
}
}

$marker = 'YOURLS';
$content = array(
$content = array(
'This is a test',
'Hello World',
'1,2... 1,2...',
);


// check we can create the htaccess
$this->assertTrue( yourls_insert_with_markers( $newfile, $marker, $content ) );
$this->assertFileEquals( $expected, $newfile );
@unlink( $newfile );

// check it is correctly create. First, remove line endings so tests are consistent between Windows and Linux
// For this reason, we're not using $this->assertFileEquals()
$exp = array_map( function($line) {return str_replace(array("\r", "\n"), '', $line);}, file($expected));
$new = array_map( function($line) {return str_replace(array("\r", "\n"), '', $line);}, file($newfile));
$this->assertSame($exp, $new);
unlink( $newfile );
}

}

0 comments on commit 0d0a97a

Please sign in to comment.