Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests on windows #2053

Merged
merged 6 commits into from Aug 27, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 27 additions & 5 deletions _test/tests/inc/mailer.test.php
Expand Up @@ -88,27 +88,49 @@ function test_addresses(){
$mail->to('Andreas Gohr <andi@splitbrain.org>');
$mail->cleanHeaders();
$headers = $mail->prop('headers');
$this->assertEquals('Andreas Gohr <andi@splitbrain.org>', $headers['To']);

if (isWindows()) { // see FS#652
$this->assertEquals('andi@splitbrain.org', $headers['To']);
} else {
$this->assertEquals('Andreas Gohr <andi@splitbrain.org>', $headers['To']);
}

$mail->to('Andreas Gohr <andi@splitbrain.org> , foo <foo@example.com>');
$mail->cleanHeaders();
$headers = $mail->prop('headers');
$this->assertEquals('Andreas Gohr <andi@splitbrain.org>, foo <foo@example.com>', $headers['To']);
if (isWindows()) { // see FS#652
$this->assertEquals('andi@splitbrain.org, foo@example.com', $headers['To']);
} else {
$this->assertEquals('Andreas Gohr <andi@splitbrain.org>, foo <foo@example.com>', $headers['To']);
}

$mail->to('Möp <moep@example.com> , foo <foo@example.com>');
$mail->cleanHeaders();
$headers = $mail->prop('headers');
$this->assertEquals('=?UTF-8?B?TcO2cA==?= <moep@example.com>, foo <foo@example.com>', $headers['To']);

if (isWindows()) { // see FS#652
$this->assertEquals('moep@example.com, foo@example.com', $headers['To']);
} else {
$this->assertEquals('=?UTF-8?B?TcO2cA==?= <moep@example.com>, foo <foo@example.com>', $headers['To']);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for tests which's task is testing something that does not work/exist in Windows, it would make more sense to just mark the test as skipped. Eg. here the idea is to test the encoding in the name, but since the name is omitted on windows, there is nothing to test that hasn't been tested above already.


$mail->to(array('Möp <moep@example.com> ',' foo <foo@example.com>'));
$mail->cleanHeaders();
$headers = $mail->prop('headers');
$this->assertEquals('=?UTF-8?B?TcO2cA==?= <moep@example.com>, foo <foo@example.com>', $headers['To']);
if (isWindows()) { // see FS#652
$this->assertEquals('moep@example.com, foo@example.com', $headers['To']);
} else {
$this->assertEquals('=?UTF-8?B?TcO2cA==?= <moep@example.com>, foo <foo@example.com>', $headers['To']);
}

$mail->to(array('Beet, L van <lvb@example.com>',' foo <foo@example.com>'));
$mail->cleanHeaders();
$headers = $mail->prop('headers');
$this->assertEquals('=?UTF-8?B?QmVldCwgTCB2YW4=?= <lvb@example.com>, foo <foo@example.com>', $headers['To']);
if (isWindows()) { // see FS#652
$this->assertEquals('lvb@example.com, foo@example.com', $headers['To']);
} else {
$this->assertEquals('=?UTF-8?B?QmVldCwgTCB2YW4=?= <lvb@example.com>, foo <foo@example.com>', $headers['To']);
}


}
Expand Down
8 changes: 4 additions & 4 deletions _test/tests/inc/pageutils_wikiFN.test.php
Expand Up @@ -4,13 +4,13 @@ class wikifn_test extends DokuWikiTest {


function test_cache_cleaning_cleanToUnclean(){
$this->assertEquals(wikiFN('wiki:',null,false),DOKU_TMP_DATA.'pages/wiki/.txt');
$this->assertEquals(wikiFN('wiki:',null,true),DOKU_TMP_DATA.'pages/wiki.txt');
$this->assertEquals(wikiFN('wiki:',null,false), w2u(DOKU_TMP_DATA.'pages/wiki/.txt'));
$this->assertEquals(wikiFN('wiki:',null,true), w2u(DOKU_TMP_DATA.'pages/wiki.txt'));
}

function test_cache_cleaning_uncleanToClean(){
$this->assertEquals(wikiFN('wiki:',null,true),DOKU_TMP_DATA.'pages/wiki.txt');
$this->assertEquals(wikiFN('wiki:',null,false),DOKU_TMP_DATA.'pages/wiki/.txt');
$this->assertEquals(wikiFN('wiki:',null,true), w2u(DOKU_TMP_DATA.'pages/wiki.txt'));
$this->assertEquals(wikiFN('wiki:',null,false), w2u(DOKU_TMP_DATA.'pages/wiki/.txt'));
}

}
Expand Down
11 changes: 8 additions & 3 deletions _test/tests/lib/exe/css_at_import_less.test.php
Expand Up @@ -38,10 +38,15 @@ private function csstest($input, $expected_css, $expected_less) {
$this->assertEquals($expected_less, $less);
}

// make relative
private function importPath($path) {
return isWindows() ? preg_replace('#(^.*[\\\\])#','', $path) : preg_replace('#(^.*[/])#','', $path);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of the tertiary operator here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to have a proper if-then-else construct here instead of the ... ? ... : ... shortcut.

}

public function test_basic() {
$this->setUpFiles();

$import = preg_replace('#(^.*[/])#','',$this->import);
$import = $this->importPath($this->import);
$in_css = '@import "'.$import.'";';
$in_less = '@foo: "bar";
content: @foo;';
Expand All @@ -56,12 +61,12 @@ public function test_basic() {
public function test_subdirectory() {
$this->setUpFiles('/foo/bar');

$import = preg_replace('#(^.*[/])#','',$this->import);
$import = $this->importPath($this->import);
$in_css = '@import "'.$import.'";';
$in_less = '@foo: "bar";
content: @foo;';

$expected_css = '@import "/foo/bar/'.$import.'";';
$expected_css = isWindows() ? '@import "\\foo\\bar/'.$import.'";' : '@import "/foo/bar/'.$import.'";';
$expected_less = 'content: "bar";';

io_saveFile($this->import, $in_less);
Expand Down
16 changes: 11 additions & 5 deletions _test/tests/lib/exe/css_css_loadfile.test.php
Expand Up @@ -77,11 +77,17 @@ public function test_less_subdirectories() {

$this->file = tempnam($dir, 'css');

$this->csstest('@import "test.less"', '@import "/foo/bar/test.less"');
$this->csstest('@import \'test.less\'', '@import \'/foo/bar/test.less\'');
$this->csstest('@import url(test.less)', '@import url(/foo/bar/test.less)');

$this->csstest('@import "abc/test.less"', '@import "/foo/bar/abc/test.less"');
if (isWindows()) {
$this->csstest('@import "test.less"', '@import "\foo\bar/test.less"');
$this->csstest('@import \'test.less\'', '@import \'\foo\bar/test.less\'');
$this->csstest('@import url(test.less)', '@import url(\foo\bar/test.less)');
$this->csstest('@import "abc/test.less"', '@import "\foo\bar/abc/test.less"');
} else {
$this->csstest('@import "test.less"', '@import "/foo/bar/test.less"');
$this->csstest('@import \'test.less\'', '@import \'/foo/bar/test.less\'');
$this->csstest('@import url(test.less)', '@import url(/foo/bar/test.less)');
$this->csstest('@import "abc/test.less"', '@import "/foo/bar/abc/test.less"');
}
}

public function tearDown() {
Expand Down
5 changes: 1 addition & 4 deletions inc/Mailer.class.php
Expand Up @@ -331,9 +331,6 @@ public function subject($subject) {
* @return false|string the prepared header (can contain multiple lines)
*/
public function cleanAddress($addresses) {
// No named recipients for To: in Windows (see FS#652)
$names = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? false : true;

$headers = '';
if(!is_array($addresses)){
$addresses = explode(',', $addresses);
Expand Down Expand Up @@ -367,7 +364,7 @@ public function cleanAddress($addresses) {
}

// text was given
if(!empty($text) && $names) {
if(!empty($text) && !isWindows()) { // No named recipients for To: in Windows (see FS#652)
// add address quotes
$addr = "<$addr>";

Expand Down
14 changes: 14 additions & 0 deletions inc/init.php
Expand Up @@ -3,6 +3,20 @@
* Initialize some defaults needed for DokuWiki
*/

if (!function_exists('isWindows')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the function_exists check here?

// checks if it is windows OS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proper doc blocks should be used.

function isWindows() {
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false;
}
}

if (!function_exists('w2u')) {
// convert windows path to unix-like on windows OS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proper doc block should be used

function w2u($filename) {
return isWindows() ? str_replace('\\', '/', $filename) : $filename;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is needed/useful outside of tests. PHP does not care for forward or backward slashes when accessing files. So this is only ever needed when comparing files read from the file system with predefines (as done in the tests). So if this only needed for testing it could be moved to the test's utility functions.

}

/**
* timing Dokuwiki execution
*
Expand Down