diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-10-22 21:31:30 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-10-22 21:31:30 -0400 |
commit | 9707c0b4c4145b9fbdab3a2ecb40c92633dacab1 (patch) | |
tree | 126918a559d09d5e1bda51f5baf520e399c3c10f | |
parent | 5d1507522366e51be79813fd5a0c80e96001a964 (diff) |
Make unit tests pass under Windows
-rw-r--r-- | app/Core/ObjectStorage/FileStorage.php | 2 | ||||
-rw-r--r-- | app/Core/Template.php | 5 | ||||
-rw-r--r-- | app/constants.php | 8 | ||||
-rw-r--r-- | config.default.php | 7 | ||||
-rw-r--r-- | tests/units/Base.php | 7 | ||||
-rw-r--r-- | tests/units/Core/TemplateTest.php | 24 | ||||
-rw-r--r-- | tests/units/Model/FileTest.php | 24 |
7 files changed, 48 insertions, 29 deletions
diff --git a/app/Core/ObjectStorage/FileStorage.php b/app/Core/ObjectStorage/FileStorage.php index 683a9e7f..dd049ca2 100644 --- a/app/Core/ObjectStorage/FileStorage.php +++ b/app/Core/ObjectStorage/FileStorage.php @@ -140,7 +140,7 @@ class FileStorage implements ObjectStorageInterface */ private function createFolder($key) { - $folder = strpos($key, '/') !== false ? $this->path.DIRECTORY_SEPARATOR.dirname($key) : $this->path; + $folder = strpos($key, DIRECTORY_SEPARATOR) !== false ? $this->path.DIRECTORY_SEPARATOR.dirname($key) : $this->path; if (! is_dir($folder) && ! mkdir($folder, 0755, true)) { throw new ObjectStorageException('Unable to create folder: '.$folder); diff --git a/app/Core/Template.php b/app/Core/Template.php index 002b20b1..ce2884a7 100644 --- a/app/Core/Template.php +++ b/app/Core/Template.php @@ -84,9 +84,10 @@ class Template extends Helper if (strpos($template_name, ':') !== false) { list($plugin, $template) = explode(':', $template_name); - $path = __DIR__.'/../../plugins/'.ucfirst($plugin).'/Template/'.$template.'.php'; + $path = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'plugins'; + $path .= DIRECTORY_SEPARATOR.ucfirst($plugin).DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.$template.'.php'; } else { - $path = __DIR__.'/../Template/'.$template_name.'.php'; + $path = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.$template_name.'.php'; } return $path; diff --git a/app/constants.php b/app/constants.php index 5010dacd..218d8f78 100644 --- a/app/constants.php +++ b/app/constants.php @@ -2,10 +2,10 @@ // Enable/disable debug defined('DEBUG') or define('DEBUG', false); -defined('DEBUG_FILE') or define('DEBUG_FILE', __DIR__.'/../data/debug.log'); +defined('DEBUG_FILE') or define('DEBUG_FILE', __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'debug.log'); // Plugin directory -defined('PLUGINS_DIR') or define('PLUGINS_DIR', __DIR__.'/../plugins'); +defined('PLUGINS_DIR') or define('PLUGINS_DIR', __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'plugins'); // Application version defined('APP_VERSION') or define('APP_VERSION', 'master'); @@ -14,7 +14,7 @@ defined('APP_VERSION') or define('APP_VERSION', 'master'); defined('DB_DRIVER') or define('DB_DRIVER', 'sqlite'); // Sqlite configuration -defined('DB_FILENAME') or define('DB_FILENAME', 'data/db.sqlite'); +defined('DB_FILENAME') or define('DB_FILENAME', 'data'.DIRECTORY_SEPARATOR.'db.sqlite'); // Mysql/Postgres configuration defined('DB_USERNAME') or define('DB_USERNAME', 'root'); @@ -93,7 +93,7 @@ defined('ENABLE_XFRAME') or define('ENABLE_XFRAME', true); defined('ENABLE_SYSLOG') or define('ENABLE_SYSLOG', true); // Default files directory -defined('FILES_DIR') or define('FILES_DIR', 'data/files/'); +defined('FILES_DIR') or define('FILES_DIR', 'data'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR); // Escape html inside markdown text defined('MARKDOWN_ESCAPE_HTML') or define('MARKDOWN_ESCAPE_HTML', true); diff --git a/config.default.php b/config.default.php index 38359d9c..90400110 100644 --- a/config.default.php +++ b/config.default.php @@ -8,13 +8,13 @@ define('DEBUG', false); // Debug file path -define('DEBUG_FILE', __DIR__.'/data/debug.log'); +define('DEBUG_FILE', __DIR__.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'debug.log'); // Plugins directory -define('PLUGINS_DIR', 'data/plugins'); +define('PLUGINS_DIR', 'data'.DIRECTORY_SEPARATOR.'plugins'); // Folder for uploaded files, don't forget the trailing slash -define('FILES_DIR', 'data/files/'); +define('FILES_DIR', 'data'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR); // E-mail address for the "From" header (notifications) define('MAIL_FROM', 'notifications@kanboard.local'); @@ -225,4 +225,3 @@ define('HTTP_PROXY_HOSTNAME', ''); define('HTTP_PROXY_PORT', '3128'); define('HTTP_PROXY_USERNAME', ''); define('HTTP_PROXY_PASSWORD', ''); - diff --git a/tests/units/Base.php b/tests/units/Base.php index 89d0e2bf..8112c954 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -84,7 +84,7 @@ abstract class Base extends PHPUnit_Framework_TestCase $this->container['db']->logQueries = true; $this->container['logger'] = new Logger; - $this->container['logger']->setLogger(new File('/dev/null')); + $this->container['logger']->setLogger(new File($this->isWindows() ? 'NUL' : '/dev/null')); $this->container['httpClient'] = new FakeHttpClient; $this->container['emailClient'] = $this->getMockBuilder('EmailClient')->setMethods(array('send'))->getMock(); @@ -99,4 +99,9 @@ abstract class Base extends PHPUnit_Framework_TestCase { $this->container['db']->closeConnection(); } + + public function isWindows() + { + return substr(PHP_OS, 0, 3) === 'WIN'; + } } diff --git a/tests/units/Core/TemplateTest.php b/tests/units/Core/TemplateTest.php index 19c0da1a..6e5ae00d 100644 --- a/tests/units/Core/TemplateTest.php +++ b/tests/units/Core/TemplateTest.php @@ -9,20 +9,34 @@ class TemplateTest extends Base public function testGetTemplateFile() { $t = new Template($this->container); - $this->assertStringEndsWith('app/Core/../Template/a/b.php', $t->getTemplateFile('a/b')); + $this->assertStringEndsWith( + 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'a'.DIRECTORY_SEPARATOR.'b.php', + $t->getTemplateFile('a'.DIRECTORY_SEPARATOR.'b') + ); } public function testGetPluginTemplateFile() { $t = new Template($this->container); - $this->assertStringEndsWith('app/Core/../../plugins/Myplugin/Template/a/b.php', $t->getTemplateFile('myplugin:a/b')); + $this->assertStringEndsWith( + 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'Myplugin'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'a'.DIRECTORY_SEPARATOR.'b.php', + $t->getTemplateFile('myplugin:a'.DIRECTORY_SEPARATOR.'b') + ); } public function testGetOverridedTemplateFile() { $t = new Template($this->container); - $t->setTemplateOverride('a/b', 'myplugin:c'); - $this->assertStringEndsWith('app/Core/../../plugins/Myplugin/Template/c.php', $t->getTemplateFile('a/b')); - $this->assertStringEndsWith('app/Core/../Template/d.php', $t->getTemplateFile('d')); + $t->setTemplateOverride('a'.DIRECTORY_SEPARATOR.'b', 'myplugin:c'); + + $this->assertStringEndsWith( + 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'Myplugin'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'c.php', + $t->getTemplateFile('a'.DIRECTORY_SEPARATOR.'b') + ); + + $this->assertStringEndsWith( + 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'d.php', + $t->getTemplateFile('d') + ); } } diff --git a/tests/units/Model/FileTest.php b/tests/units/Model/FileTest.php index e311cf75..29f6ee93 100644 --- a/tests/units/Model/FileTest.php +++ b/tests/units/Model/FileTest.php @@ -89,7 +89,7 @@ class FileTest extends Base { $f = new File($this->container); - $this->assertStringStartsWith('12/34/', $f->generatePath(12, 34, 'test.png')); + $this->assertStringStartsWith('12'.DIRECTORY_SEPARATOR.'34'.DIRECTORY_SEPARATOR, $f->generatePath(12, 34, 'test.png')); $this->assertNotEquals($f->generatePath(12, 34, 'test1.png'), $f->generatePath(12, 34, 'test2.png')); } @@ -113,7 +113,7 @@ class FileTest extends Base ->expects($this->once()) ->method('put') ->with( - $this->stringContains('1/1/'), + $this->stringContains('1'.DIRECTORY_SEPARATOR.'1'.DIRECTORY_SEPARATOR), $this->equalTo(base64_decode($data)) ) ->will($this->returnValue(true)); @@ -126,7 +126,7 @@ class FileTest extends Base $file = $f->getById(1); $this->assertNotEmpty($file); $this->assertStringStartsWith('Screenshot taken ', $file['name']); - $this->assertStringStartsWith('1/1/', $file['path']); + $this->assertStringStartsWith('1'.DIRECTORY_SEPARATOR.'1'.DIRECTORY_SEPARATOR, $file['path']); $this->assertEquals(1, $file['is_image']); $this->assertEquals(1, $file['task_id']); $this->assertEquals(time(), $file['date'], '', 2); @@ -149,7 +149,7 @@ class FileTest extends Base ->expects($this->once()) ->method('put') ->with( - $this->stringContains('1/1/'), + $this->stringContains('1'.DIRECTORY_SEPARATOR.'1'.DIRECTORY_SEPARATOR), $this->equalTo(base64_decode($data)) ) ->will($this->returnValue(true)); @@ -159,7 +159,7 @@ class FileTest extends Base $file = $f->getById(1); $this->assertNotEmpty($file); $this->assertEquals('my file.pdf', $file['name']); - $this->assertStringStartsWith('1/1/', $file['path']); + $this->assertStringStartsWith('1'.DIRECTORY_SEPARATOR.'1'.DIRECTORY_SEPARATOR, $file['path']); $this->assertEquals(0, $file['is_image']); $this->assertEquals(1, $file['task_id']); $this->assertEquals(time(), $file['date'], '', 2); @@ -211,15 +211,15 @@ class FileTest extends Base $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo1', 10)); - $this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo2', 10)); - $this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo3', 10)); + $this->assertEquals(1, $f->create(1, 'B.pdf', DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo1', 10)); + $this->assertEquals(2, $f->create(1, 'A.png', DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo2', 10)); + $this->assertEquals(3, $f->create(1, 'D.doc', DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo3', 10)); $this->container['objectStorage'] ->expects($this->at(0)) ->method('remove') ->with( - $this->equalTo('/tmp/foo2') + $this->equalTo(DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo2') ) ->will($this->returnValue(true)); @@ -227,7 +227,7 @@ class FileTest extends Base ->expects($this->at(1)) ->method('remove') ->with( - $this->equalTo('thumbnails//tmp/foo2') + $this->equalTo('thumbnails'.DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo2') ) ->will($this->returnValue(true)); @@ -235,7 +235,7 @@ class FileTest extends Base ->expects($this->at(2)) ->method('remove') ->with( - $this->equalTo('/tmp/foo1') + $this->equalTo(DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo1') ) ->will($this->returnValue(true)); @@ -243,7 +243,7 @@ class FileTest extends Base ->expects($this->at(3)) ->method('remove') ->with( - $this->equalTo('/tmp/foo3') + $this->equalTo(DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo3') ) ->will($this->returnValue(true)); |