summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorkondou <kondou@ts.unde.re>2014-03-21 20:23:31 +0100
committerkondou <kondou@ts.unde.re>2014-03-21 20:23:31 +0100
commitdda7129a243c7ebdbcdf9c2b5dbf167542402bc2 (patch)
treed03dff6783ebabb6273a19ed59a6b9b3731e923e /tests
parent556c6eca2397eaa03c4503822d647c8b6cb5e70e (diff)
parent4be0b3f6cce540282c6745d6bf3d2a0fa4ac65b4 (diff)
downloadnextcloud-server-dda7129a243c7ebdbcdf9c2b5dbf167542402bc2.tar.gz
nextcloud-server-dda7129a243c7ebdbcdf9c2b5dbf167542402bc2.zip
Merge branch 'master' of https://github.com/owncloud/core into last_cron_log
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/appframework/routing/RoutingTest.php8
-rw-r--r--tests/lib/files/storage/wrapper/quota.php18
-rw-r--r--tests/lib/helper.php4
-rw-r--r--tests/lib/image.php24
-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
9 files changed, 204 insertions, 7 deletions
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/storage/wrapper/quota.php b/tests/lib/files/storage/wrapper/quota.php
index bd2c69a7396..777529fd85e 100644
--- a/tests/lib/files/storage/wrapper/quota.php
+++ b/tests/lib/files/storage/wrapper/quota.php
@@ -61,6 +61,24 @@ class Quota extends \Test\Files\Storage\Storage {
$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(
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/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/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
);