summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-03-26 14:26:07 +0100
committerRobin Appelman <icewind@owncloud.com>2014-03-26 14:26:07 +0100
commit371a924c92bb751b81e2a819d8c581743be7a797 (patch)
treef0b1ec313deb42850ca754c5894737dc2a0a8fb9 /tests
parentdb6fb198fe7b8fa854050730b32d58d3787505b3 (diff)
parent028973cbea865075a32db6228b56b7d3960771d6 (diff)
downloadnextcloud-server-371a924c92bb751b81e2a819d8c581743be7a797.tar.gz
nextcloud-server-371a924c92bb751b81e2a819d8c581743be7a797.zip
merge master into webdav-injection
Diffstat (limited to 'tests')
-rw-r--r--tests/bootstrap.php9
-rw-r--r--tests/lib/appframework/routing/RoutingTest.php8
-rw-r--r--tests/lib/files/cache/homecache.php1
-rw-r--r--tests/lib/files/cache/updater.php5
-rw-r--r--tests/lib/files/storage/wrapper/quota.php34
-rw-r--r--tests/lib/helper.php4
-rw-r--r--tests/lib/helperstorage.php113
-rw-r--r--tests/lib/image.php24
-rw-r--r--tests/lib/mail.php30
-rw-r--r--tests/lib/request.php137
-rw-r--r--tests/lib/utilcheckserver.php108
-rw-r--r--tests/phpunit-autotest.xml1
-rw-r--r--tests/phpunit.xml.dist3
-rw-r--r--tests/startsessionlistener.php44
-rw-r--r--tests/testcleanuplistener.php1
15 files changed, 507 insertions, 15 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 581cfcff9f3..70de7cd1c44 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -3,9 +3,14 @@
define('PHPUNIT_RUN', 1);
-require_once __DIR__.'/../lib/base.php';
+$configDir = getenv('CONFIG_DIR');
+if ($configDir) {
+ define('PHPUNIT_CONFIG_DIR', $configDir);
+}
+
+require_once __DIR__ . '/../lib/base.php';
-if(!class_exists('PHPUnit_Framework_TestCase')) {
+if (!class_exists('PHPUnit_Framework_TestCase')) {
require_once('PHPUnit/Autoload.php');
}
diff --git a/tests/lib/appframework/routing/RoutingTest.php b/tests/lib/appframework/routing/RoutingTest.php
index d0244cf2511..9f2675bf0b4 100644
--- a/tests/lib/appframework/routing/RoutingTest.php
+++ b/tests/lib/appframework/routing/RoutingTest.php
@@ -46,7 +46,7 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase
));
// router mock
- $router = $this->getMock("\OC_Router", array('create'));
+ $router = $this->getMock("\OC\Route\Router", array('create'));
// load route configuration
$container = new DIContainer('app1');
@@ -91,7 +91,7 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase
$route = $this->mockRoute($verb, $controllerName, $actionName);
// router mock
- $router = $this->getMock("\OC_Router", array('create'));
+ $router = $this->getMock("\OC\Route\Router", array('create'));
// we expect create to be called once:
$router
@@ -116,7 +116,7 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase
private function assertResource($yaml, $resourceName, $url, $controllerName, $paramName)
{
// router mock
- $router = $this->getMock("\OC_Router", array('create'));
+ $router = $this->getMock("\OC\Route\Router", array('create'));
// route mocks
$indexRoute = $this->mockRoute('GET', $controllerName, 'index');
@@ -174,7 +174,7 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase
private function mockRoute($verb, $controllerName, $actionName)
{
$container = new DIContainer('app1');
- $route = $this->getMock("\OC_Route", array('method', 'action'), array(), '', false);
+ $route = $this->getMock("\OC\Route\Route", array('method', 'action'), array(), '', false);
$route
->expects($this->exactly(1))
->method('method')
diff --git a/tests/lib/files/cache/homecache.php b/tests/lib/files/cache/homecache.php
index dbcf6e9caa0..80dc54c9d19 100644
--- a/tests/lib/files/cache/homecache.php
+++ b/tests/lib/files/cache/homecache.php
@@ -90,7 +90,6 @@ class HomeCache extends \PHPUnit_Framework_TestCase {
// check that files and root size ignored the unknown sizes
$this->assertEquals(1000, $this->cache->calculateFolderSize('files'));
- $this->assertEquals(1000, $this->cache->calculateFolderSize(''));
// clean up
$this->cache->remove('');
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
index a6ee8c46661..e2fae0ae57f 100644
--- a/tests/lib/files/cache/updater.php
+++ b/tests/lib/files/cache/updater.php
@@ -65,11 +65,6 @@ class Updater extends \PHPUnit_Framework_TestCase {
Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
\OC_Hook::clear('OC_Filesystem');
-
- \OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Updater', 'writeHook');
- \OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Updater', 'deleteHook');
- \OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook');
- \OC_Hook::connect('OC_Filesystem', 'post_touch', '\OC\Files\Cache\Updater', 'touchHook');
}
public function tearDown() {
diff --git a/tests/lib/files/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php
index 43eae78415d..777529fd85e 100644
--- a/tests/lib/files/storage/wrapper/quota.php
+++ b/tests/lib/files/storage/wrapper/quota.php
@@ -53,6 +53,40 @@ class Quota extends \Test\Files\Storage\Storage {
$this->assertEquals(9, $instance->free_space(''));
}
+ public function testFreeSpaceWithUsedSpace() {
+ $instance = $this->getLimitedStorage(9);
+ $instance->getCache()->put(
+ '', array('size' => 3, 'unencrypted_size' => 0)
+ );
+ $this->assertEquals(6, $instance->free_space(''));
+ }
+
+ public function testFreeSpaceWithUnknownDiskSpace() {
+ $storage = $this->getMock(
+ '\OC\Files\Storage\Local',
+ array('free_space'),
+ array(array('datadir' => $this->tmpDir))
+ );
+ $storage->expects($this->any())
+ ->method('free_space')
+ ->will($this->returnValue(-2));
+ $storage->getScanner()->scan('');
+
+ $instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => 9));
+ $instance->getCache()->put(
+ '', array('size' => 3, 'unencrypted_size' => 0)
+ );
+ $this->assertEquals(6, $instance->free_space(''));
+ }
+
+ public function testFreeSpaceWithUsedSpaceAndEncryption() {
+ $instance = $this->getLimitedStorage(9);
+ $instance->getCache()->put(
+ '', array('size' => 7, 'unencrypted_size' => 3)
+ );
+ $this->assertEquals(6, $instance->free_space(''));
+ }
+
public function testFWriteNotEnoughSpace() {
$instance = $this->getLimitedStorage(9);
$stream = $instance->fopen('foo', 'w+');
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index 4311215795c..0943e6bc1b9 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -23,6 +23,7 @@ class Test_Helper extends PHPUnit_Framework_TestCase {
array('0 B', 0),
array('1 kB', 1024),
array('9.5 MB', 10000000),
+ array('1.3 GB', 1395864371),
array('465.7 GB', 500000000000),
array('454.7 TB', 500000000000000),
array('444.1 PB', 500000000000000000),
@@ -41,8 +42,9 @@ class Test_Helper extends PHPUnit_Framework_TestCase {
return array(
array(0.0, "0 B"),
array(1024.0, "1 kB"),
+ array(1395864371.0, '1.3 GB'),
array(9961472.0, "9.5 MB"),
- array(500041567436.8, "465.7 GB"),
+ array(500041567437.0, "465.7 GB"),
);
}
diff --git a/tests/lib/helperstorage.php b/tests/lib/helperstorage.php
new file mode 100644
index 00000000000..010a54e3bb0
--- /dev/null
+++ b/tests/lib/helperstorage.php
@@ -0,0 +1,113 @@
+<?php
+/**
+ * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+/**
+ * Test the storage functions of OC_Helper
+ */
+class Test_Helper_Storage extends PHPUnit_Framework_TestCase {
+ private $user;
+ private $storageMock;
+
+ public function setUp() {
+ $this->user = 'user_' . uniqid();
+ \OC\Files\Filesystem::tearDown();
+ \OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files');
+
+ $this->storageMock = $this->getMock(
+ '\OC\Files\Storage\Temporary',
+ array('free_space'),
+ array('')
+ );
+
+ \OC\Files\Filesystem::clearMounts();
+
+ $this->storageMock->expects($this->once())
+ ->method('free_space')
+ ->will($this->returnValue(12));
+ }
+
+ public function tearDown() {
+ $this->user = null;
+
+ $this->storageMock->getCache()->clear();
+ \OC\Files\Filesystem::tearDown();
+ }
+
+ /**
+ * Test getting the storage info
+ */
+ function testGetStorageInfo() {
+ \OC\Files\Filesystem::mount($this->storageMock, array(), '/' . $this->user . '/files');
+ $this->storageMock->file_put_contents('test.txt', '01234');
+
+ $storageInfo = \OC_Helper::getStorageInfo('');
+ $this->assertEquals(12, $storageInfo['free']);
+ $this->assertEquals(5, $storageInfo['used']);
+ $this->assertEquals(17, $storageInfo['total']);
+ }
+
+ /**
+ * Test getting the storage info with quota enabled
+ */
+ function testGetStorageInfoWithQuota() {
+ $this->storageMock->file_put_contents('test.txt', '01234');
+ $this->storageMock = new \OC\Files\Storage\Wrapper\Quota(
+ array(
+ 'storage' => $this->storageMock,
+ 'quota' => 7
+ )
+ );
+ \OC\Files\Filesystem::mount($this->storageMock, array(), '/' . $this->user . '/files');
+
+ $storageInfo = \OC_Helper::getStorageInfo('');
+ $this->assertEquals(2, $storageInfo['free']);
+ $this->assertEquals(5, $storageInfo['used']);
+ $this->assertEquals(7, $storageInfo['total']);
+ }
+
+ /**
+ * Test getting the storage info when data exceeds quota
+ */
+ function testGetStorageInfoWhenSizeExceedsQuota() {
+ $this->storageMock->file_put_contents('test.txt', '0123456789');
+ $this->storageMock = new \OC\Files\Storage\Wrapper\Quota(
+ array(
+ 'storage' => $this->storageMock,
+ 'quota' => 7
+ )
+ );
+ \OC\Files\Filesystem::mount($this->storageMock, array(), '/' . $this->user . '/files');
+
+ $storageInfo = \OC_Helper::getStorageInfo('');
+ $this->assertEquals(0, $storageInfo['free']);
+ $this->assertEquals(10, $storageInfo['used']);
+ // total = quota
+ $this->assertEquals(7, $storageInfo['total']);
+ }
+
+ /**
+ * Test getting the storage info when the remaining
+ * free storage space is less than the quota
+ */
+ function testGetStorageInfoWhenFreeSpaceLessThanQuota() {
+ $this->storageMock->file_put_contents('test.txt', '01234');
+ $this->storageMock = new \OC\Files\Storage\Wrapper\Quota(
+ array(
+ 'storage' => $this->storageMock,
+ 'quota' => 18
+ )
+ );
+ \OC\Files\Filesystem::mount($this->storageMock, array(), '/' . $this->user . '/files');
+
+ $storageInfo = \OC_Helper::getStorageInfo('');
+ $this->assertEquals(12, $storageInfo['free']);
+ $this->assertEquals(5, $storageInfo['used']);
+ // total = free + used (because quota > total)
+ $this->assertEquals(17, $storageInfo['total']);
+ }
+}
diff --git a/tests/lib/image.php b/tests/lib/image.php
index 4aba1b0bc61..131a9d86f3e 100644
--- a/tests/lib/image.php
+++ b/tests/lib/image.php
@@ -8,8 +8,8 @@
class Test_Image extends PHPUnit_Framework_TestCase {
public static function tearDownAfterClass() {
- unlink(OC::$SERVERROOT.'/tests/data/testimage2.png');
- unlink(OC::$SERVERROOT.'/tests/data/testimage2.jpg');
+ @unlink(OC::$SERVERROOT.'/tests/data/testimage2.png');
+ @unlink(OC::$SERVERROOT.'/tests/data/testimage2.jpg');
}
public function testGetMimeTypeForFile() {
@@ -236,4 +236,24 @@ class Test_Image extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $img->width());
$this->assertEquals(200, $img->height());
}
+
+ function convertDataProvider() {
+ return array(
+ array( 'image/gif'),
+ array( 'image/jpeg'),
+ array( 'image/png'),
+ );
+ }
+
+ /**
+ * @dataProvider convertDataProvider
+ */
+ public function testConvert($mimeType) {
+ $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png');
+ $tempFile = tempnam(sys_get_temp_dir(), 'img-test');
+
+ $img->save($tempFile, $mimeType);
+ $actualMimeType = \OC_Image::getMimeTypeForFile($tempFile);
+ $this->assertEquals($mimeType, $actualMimeType);
+ }
}
diff --git a/tests/lib/mail.php b/tests/lib/mail.php
new file mode 100644
index 00000000000..a88a9d797ae
--- /dev/null
+++ b/tests/lib/mail.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class Test_Mail extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @dataProvider buildAsciiEmailProvider
+ * @param $expected
+ * @param $address
+ */
+ public function testBuildAsciiEmail($expected, $address) {
+ $actual = \OC_Mail::buildAsciiEmail($address);
+ $this->assertEquals($expected, $actual);
+ }
+
+ function buildAsciiEmailProvider() {
+ return array(
+ array('info@example.com', 'info@example.com'),
+ array('info@xn--cjr6vy5ejyai80u.com', 'info@國際化域名.com'),
+ array('info@xn--mller-kva.de', 'info@müller.de'),
+ array('info@xn--mller-kva.xn--mller-kva.de', 'info@müller.müller.de'),
+ );
+ }
+
+}
diff --git a/tests/lib/request.php b/tests/lib/request.php
index 1d77acc70ae..bff84e1b03f 100644
--- a/tests/lib/request.php
+++ b/tests/lib/request.php
@@ -135,4 +135,141 @@ class Test_Request extends PHPUnit_Framework_TestCase {
),
);
}
+
+ public function testInsecureServerHost() {
+ unset($_SERVER['HTTP_X_FORWARDED_HOST']);
+ unset($_SERVER['HTTP_HOST']);
+ unset($_SERVER['SERVER_NAME']);
+ $_SERVER['SERVER_NAME'] = 'from.server.name:8080';
+ $host = OC_Request::insecureServerHost();
+ $this->assertEquals('from.server.name:8080', $host);
+
+ $_SERVER['HTTP_HOST'] = 'from.host.header:8080';
+ $host = OC_Request::insecureServerHost();
+ $this->assertEquals('from.host.header:8080', $host);
+
+ $_SERVER['HTTP_X_FORWARDED_HOST'] = 'from.forwarded.host:8080';
+ $host = OC_Request::insecureServerHost();
+ $this->assertEquals('from.forwarded.host:8080', $host);
+
+ $_SERVER['HTTP_X_FORWARDED_HOST'] = 'from.forwarded.host2:8080,another.one:9000';
+ $host = OC_Request::insecureServerHost();
+ $this->assertEquals('from.forwarded.host2:8080', $host);
+
+ // clean up
+ unset($_SERVER['HTTP_X_FORWARDED_HOST']);
+ unset($_SERVER['HTTP_HOST']);
+ unset($_SERVER['SERVER_NAME']);
+ }
+
+ public function testGetOverwriteHost() {
+ unset($_SERVER['REMOTE_ADDR']);
+ OC_Config::deleteKey('overwritecondaddr');
+ OC_Config::deleteKey('overwritehost');
+ $host = OC_Request::getOverwriteHost();
+ $this->assertNull($host);
+
+ OC_Config::setValue('overwritehost', '');
+ $host = OC_Request::getOverwriteHost();
+ $this->assertNull($host);
+
+ OC_Config::setValue('overwritehost', 'host.one.test:8080');
+ $host = OC_Request::getOverwriteHost();
+ $this->assertEquals('host.one.test:8080', $host);
+
+ $_SERVER['REMOTE_ADDR'] = 'somehost.test:8080';
+ OC_Config::setValue('overwritecondaddr', '^somehost\..*$');
+ $host = OC_Request::getOverwriteHost();
+ $this->assertEquals('host.one.test:8080', $host);
+
+ OC_Config::setValue('overwritecondaddr', '^somethingelse.*$');
+ $host = OC_Request::getOverwriteHost();
+ $this->assertNull($host);
+
+ // clean up
+ unset($_SERVER['REMOTE_ADDR']);
+ OC_Config::deleteKey('overwritecondaddr');
+ OC_Config::deleteKey('overwritehost');
+ }
+
+ /**
+ * @dataProvider trustedDomainDataProvider
+ */
+ public function testIsTrustedDomain($trustedDomains, $testDomain, $result) {
+ OC_Config::deleteKey('trusted_domains');
+ if ($trustedDomains !== null) {
+ OC_Config::setValue('trusted_domains', $trustedDomains);
+ }
+
+ $this->assertEquals($result, OC_Request::isTrustedDomain($testDomain));
+
+ // clean up
+ OC_Config::deleteKey('trusted_domains');
+ }
+
+ public function trustedDomainDataProvider() {
+ $trustedHostTestList = array('host.one.test:8080', 'host.two.test:8080');
+ return array(
+ // empty defaults to true
+ array(null, 'host.one.test:8080', true),
+ array('', 'host.one.test:8080', true),
+ array(array(), 'host.one.test:8080', true),
+
+ // trust list when defined
+ array($trustedHostTestList, 'host.two.test:8080', true),
+ array($trustedHostTestList, 'host.two.test:9999', false),
+ array($trustedHostTestList, 'host.three.test:8080', false),
+
+ // trust localhost regardless of trust list
+ array($trustedHostTestList, 'localhost', true),
+ array($trustedHostTestList, 'localhost:8080', true),
+ array($trustedHostTestList, '127.0.0.1', true),
+ array($trustedHostTestList, '127.0.0.1:8080', true),
+
+ // do not trust invalid localhosts
+ array($trustedHostTestList, 'localhost:1:2', false),
+ array($trustedHostTestList, 'localhost: evil.host', false),
+ );
+ }
+
+ public function testServerHost() {
+ OC_Config::deleteKey('overwritecondaddr');
+ OC_Config::setValue('overwritehost', 'overwritten.host:8080');
+ OC_Config::setValue(
+ 'trusted_domains',
+ array(
+ 'trusted.host:8080',
+ 'second.trusted.host:8080'
+ )
+ );
+ $_SERVER['HTTP_HOST'] = 'trusted.host:8080';
+
+ // CLI always gives localhost
+ $oldCLI = OC::$CLI;
+ OC::$CLI = true;
+ $host = OC_Request::serverHost();
+ $this->assertEquals('localhost', $host);
+ OC::$CLI = false;
+
+ // overwritehost overrides trusted domain
+ $host = OC_Request::serverHost();
+ $this->assertEquals('overwritten.host:8080', $host);
+
+ // trusted domain returned when used
+ OC_Config::deleteKey('overwritehost');
+ $host = OC_Request::serverHost();
+ $this->assertEquals('trusted.host:8080', $host);
+
+ // trusted domain returned when untrusted one in header
+ $_SERVER['HTTP_HOST'] = 'untrusted.host:8080';
+ OC_Config::deleteKey('overwritehost');
+ $host = OC_Request::serverHost();
+ $this->assertEquals('trusted.host:8080', $host);
+
+ // clean up
+ OC_Config::deleteKey('overwritecondaddr');
+ OC_Config::deleteKey('overwritehost');
+ unset($_SERVER['HTTP_HOST']);
+ OC::$CLI = $oldCLI;
+ }
}
diff --git a/tests/lib/utilcheckserver.php b/tests/lib/utilcheckserver.php
new file mode 100644
index 00000000000..155d617c4ad
--- /dev/null
+++ b/tests/lib/utilcheckserver.php
@@ -0,0 +1,108 @@
+<?php
+/**
+ * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+/**
+ * Tests for server check functions
+ */
+class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
+
+ private $datadir;
+
+ public function setUp() {
+ $this->datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data');
+
+ file_put_contents($this->datadir . '/.ocdata', '');
+ }
+
+ public function tearDown() {
+ // clean up
+ @unlink($this->datadir . '/.ocdata');
+ }
+
+ /**
+ * Test that checkServer() returns no errors in the regular case.
+ */
+ public function testCheckServer() {
+ $result = \OC_Util::checkServer();
+ $this->assertEmpty($result);
+ }
+
+ /**
+ * Test that checkServer() does not check the data dir validity
+ * when the server is not installed yet (else the setup cannot
+ * be run...)
+ */
+ public function testCheckServerSkipDataDirValidityOnSetup() {
+ // simulate old version that didn't have it
+ unlink($this->datadir . '/.ocdata');
+
+ $session = \OC::$server->getSession();
+ $oldInstalled = \OC_Config::getValue('installed', false);
+
+ // simulate that the server isn't setup yet
+ \OC_Config::setValue('installed', false);
+
+ // even though ".ocdata" is missing, the error isn't
+ // triggered to allow setup to run
+ $result = \OC_Util::checkServer();
+ $this->assertEmpty($result);
+
+ // restore config
+ \OC_Config::setValue('installed', $oldInstalled);
+ }
+
+ /**
+ * Test that checkServer() does not check the data dir validity
+ * when an upgrade is required (else the upgrade cannot be
+ * performed...)
+ */
+ public function testCheckServerSkipDataDirValidityOnUpgrade() {
+ // simulate old version that didn't have it
+ unlink($this->datadir . '/.ocdata');
+
+ $session = \OC::$server->getSession();
+ $oldCurrentVersion = $session->get('OC_Version');
+ $oldInstallVersion = \OC_Config::getValue('version', '0.0.0');
+
+ // upgrade condition to simulate needUpgrade() === true
+ $session->set('OC_Version', array(6, 0, 0, 2));
+ \OC_Config::setValue('version', '6.0.0.1');
+
+ // even though ".ocdata" is missing, the error isn't
+ // triggered to allow for upgrade
+ $result = \OC_Util::checkServer();
+ $this->assertEmpty($result);
+
+ // restore versions
+ $session->set('OC_Version', $oldCurrentVersion);
+ \OC_Config::setValue('version', $oldInstallVersion);
+ }
+
+ /**
+ * Test that checkDataDirectoryValidity returns no error
+ * when ".ocdata" is present.
+ */
+ public function testCheckDataDirValidity() {
+ $result = \OC_Util::checkDataDirectoryValidity($this->datadir);
+ $this->assertEmpty($result);
+ }
+
+ /**
+ * Test that checkDataDirectoryValidity and checkServer
+ * both return an error when ".ocdata" is missing.
+ */
+ public function testCheckDataDirValidityWhenFileMissing() {
+ unlink($this->datadir . '/.ocdata');
+ $result = \OC_Util::checkDataDirectoryValidity($this->datadir);
+ $this->assertEquals(1, count($result));
+
+ $result = \OC_Util::checkServer();
+ $this->assertEquals(1, count($result));
+ }
+
+}
diff --git a/tests/phpunit-autotest.xml b/tests/phpunit-autotest.xml
index 1a2ab35491b..872ff2c2596 100644
--- a/tests/phpunit-autotest.xml
+++ b/tests/phpunit-autotest.xml
@@ -36,6 +36,7 @@
</whitelist>
</filter>
<listeners>
+ <listener class="StartSessionListener" file="startsessionlistener.php" />
<listener class="TestCleanupListener" file="testcleanuplistener.php">
<arguments>
<string>detail</string>
diff --git a/tests/phpunit.xml.dist b/tests/phpunit.xml.dist
index 71a4ff2762c..21c63ea0469 100644
--- a/tests/phpunit.xml.dist
+++ b/tests/phpunit.xml.dist
@@ -29,4 +29,7 @@
</exclude>
</whitelist>
</filter>
+ <listeners>
+ <listener class="StartSessionListener" file="startsessionlistener.php" />
+ </listeners>
</phpunit>
diff --git a/tests/startsessionlistener.php b/tests/startsessionlistener.php
new file mode 100644
index 00000000000..808a2a2226f
--- /dev/null
+++ b/tests/startsessionlistener.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+/**
+ * Starts a new session before each test execution
+ */
+class StartSessionListener implements PHPUnit_Framework_TestListener {
+
+ public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
+ }
+
+ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
+ }
+
+ public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
+ }
+
+ public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
+ }
+
+ public function startTest(PHPUnit_Framework_Test $test) {
+ }
+
+ public function endTest(PHPUnit_Framework_Test $test, $time) {
+ // reopen the session - only allowed for memory session
+ if (\OC::$session instanceof \OC\Session\Memory) {
+ /** @var $session \OC\Session\Memory */
+ $session = \OC::$session;
+ $session->reopen();
+ }
+ }
+
+ public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
+ }
+
+ public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
+ }
+
+}
diff --git a/tests/testcleanuplistener.php b/tests/testcleanuplistener.php
index 299a589ef4e..2083ffce67c 100644
--- a/tests/testcleanuplistener.php
+++ b/tests/testcleanuplistener.php
@@ -83,6 +83,7 @@ class TestCleanupListener implements PHPUnit_Framework_TestListener {
$knownEntries = array(
'owncloud.log' => true,
'owncloud.db' => true,
+ '.ocdata' => true,
'..' => true,
'.' => true
);