summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-09-25 14:32:32 +0200
committerVincent Petry <pvince81@owncloud.com>2014-09-25 14:32:32 +0200
commit9fc23e1967371d3765f24d74339704df77e29606 (patch)
tree842624b0581fa98958cff530b65b06c05acb0cbe /tests
parentf46e49529fed8cb60ff846bb959b2f564b14bea6 (diff)
parent6ff29f3874cac3c263c255b2c36cda5b8a1c67f1 (diff)
downloadnextcloud-server-9fc23e1967371d3765f24d74339704df77e29606.tar.gz
nextcloud-server-9fc23e1967371d3765f24d74339704df77e29606.zip
Merge pull request #10934 from owncloud/datadir-write-setup
Don't complain about non-writable datadirs before we're installed
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/utilcheckserver.php91
1 files changed, 72 insertions, 19 deletions
diff --git a/tests/lib/utilcheckserver.php b/tests/lib/utilcheckserver.php
index 155d617c4ad..be5596c1900 100644
--- a/tests/lib/utilcheckserver.php
+++ b/tests/lib/utilcheckserver.php
@@ -13,10 +13,30 @@ class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
private $datadir;
+ /**
+ * @param array $systemOptions
+ * @return \OCP\IConfig | PHPUnit_Framework_MockObject_MockObject
+ */
+ protected function getConfig($systemOptions) {
+ $systemOptions['datadirectory'] = $this->datadir;
+ $systemOptions['appstoreenabled'] = false; //it's likely that there is no app folder we can write in
+ $config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $config->expects($this->any())
+ ->method('getSystemValue')
+ ->will($this->returnCallback(function ($key, $default) use ($systemOptions) {
+ return isset($systemOptions[$key]) ? $systemOptions[$key] : $default;
+ }));
+ return $config;
+ }
+
public function setUp() {
- $this->datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data');
+ $this->datadir = \OC_Helper::tmpFolder();
file_put_contents($this->datadir . '/.ocdata', '');
+ \OC::$server->getSession()->set('checkServer_succeeded', false);
}
public function tearDown() {
@@ -28,7 +48,9 @@ class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
* Test that checkServer() returns no errors in the regular case.
*/
public function testCheckServer() {
- $result = \OC_Util::checkServer();
+ $result = \OC_Util::checkServer($this->getConfig(array(
+ 'installed' => true
+ )));
$this->assertEmpty($result);
}
@@ -41,19 +63,12 @@ class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
// 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();
+ $result = \OC_Util::checkServer($this->getConfig(array(
+ 'installed' => false
+ )));
$this->assertEmpty($result);
-
- // restore config
- \OC_Config::setValue('installed', $oldInstalled);
}
/**
@@ -67,20 +82,20 @@ class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
$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();
+ $result = \OC_Util::checkServer($this->getConfig(array(
+ 'installed' => true,
+ 'version' => '6.0.0.1'
+ )));
$this->assertEmpty($result);
// restore versions
$session->set('OC_Version', $oldCurrentVersion);
- \OC_Config::setValue('version', $oldInstallVersion);
}
/**
@@ -93,7 +108,7 @@ class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
}
/**
- * Test that checkDataDirectoryValidity and checkServer
+ * Test that checkDataDirectoryValidity and checkServer
* both return an error when ".ocdata" is missing.
*/
public function testCheckDataDirValidityWhenFileMissing() {
@@ -101,8 +116,46 @@ class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
$result = \OC_Util::checkDataDirectoryValidity($this->datadir);
$this->assertEquals(1, count($result));
- $result = \OC_Util::checkServer();
- $this->assertEquals(1, count($result));
+ $result = \OC_Util::checkServer($this->getConfig(array(
+ 'installed' => true,
+ 'version' => implode('.', OC_Util::getVersion())
+ )));
+ $this->assertCount(1, $result);
+ }
+
+ /**
+ * Tests that no error is given when the datadir is writable
+ */
+ public function testDataDirWritable() {
+ $result = \OC_Util::checkServer($this->getConfig(array(
+ 'installed' => true,
+ 'version' => implode('.', OC_Util::getVersion())
+ )));
+ $this->assertEmpty($result);
}
+ /**
+ * Tests an error is given when the datadir is not writable
+ */
+ public function testDataDirNotWritable() {
+ chmod($this->datadir, 0300);
+ $result = \OC_Util::checkServer($this->getConfig(array(
+ 'installed' => true,
+ 'version' => implode('.', OC_Util::getVersion())
+ )));
+ $this->assertCount(1, $result);
+ }
+
+ /**
+ * Tests no error is given when the datadir is not writable during setup
+ */
+ public function testDataDirNotWritableSetup() {
+ chmod($this->datadir, 0300);
+ $result = \OC_Util::checkServer($this->getConfig(array(
+ 'installed' => false,
+ 'version' => implode('.', OC_Util::getVersion())
+ )));
+ chmod($this->datadir, 0700); //needed for cleanup
+ $this->assertEmpty($result);
+ }
}