summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/api.php2
-rw-r--r--tests/lib/app/dependencyanalyzer.php109
-rw-r--r--tests/lib/app/infoparser.php20
-rw-r--r--tests/lib/appframework/controller/ControllerTest.php3
-rw-r--r--tests/lib/appframework/http/DispatcherTest.php8
-rw-r--r--tests/lib/db.php2
-rw-r--r--tests/lib/db/migrator.php2
-rw-r--r--tests/lib/db/mysqlmigration.php2
-rw-r--r--tests/lib/db/sqlitemigration.php2
-rw-r--r--tests/lib/files/cache/updaterlegacy.php2
-rw-r--r--tests/lib/files/filesystem.php12
-rw-r--r--tests/lib/files/node/file.php41
-rw-r--r--tests/lib/files/node/folder.php19
-rw-r--r--tests/lib/files/node/integration.php2
-rw-r--r--tests/lib/files/node/node.php52
-rw-r--r--tests/lib/files/node/root.php7
-rw-r--r--tests/lib/files/objectstore/swift.php6
-rw-r--r--tests/lib/files/view.php2
-rw-r--r--tests/lib/memcache/apc.php2
-rw-r--r--tests/lib/memcache/apcu.php2
-rw-r--r--tests/lib/memcache/memcached.php6
-rw-r--r--tests/lib/memcache/xcache.php2
-rw-r--r--tests/lib/ocs/privatedata.php2
-rw-r--r--tests/lib/repair/repaircollation.php2
-rw-r--r--tests/lib/repair/repairinnodb.php2
-rw-r--r--tests/lib/repair/repairlegacystorage.php8
-rw-r--r--tests/lib/session/memory.php2
-rw-r--r--tests/lib/tags.php10
-rw-r--r--tests/lib/testcase.php6
-rw-r--r--tests/lib/util.php6
30 files changed, 242 insertions, 101 deletions
diff --git a/tests/lib/api.php b/tests/lib/api.php
index bf9748a6040..3b925a63960 100644
--- a/tests/lib/api.php
+++ b/tests/lib/api.php
@@ -17,7 +17,7 @@ class Test_API extends \Test\TestCase {
return array(
'shipped' => $shipped,
'response' => new OC_OCS_Result($data, $code, $message),
- 'app' => uniqid('testapp_', true),
+ 'app' => $this->getUniqueID('testapp_'),
);
}
diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php
new file mode 100644
index 00000000000..7d06842e8ad
--- /dev/null
+++ b/tests/lib/app/dependencyanalyzer.php
@@ -0,0 +1,109 @@
+<?php
+
+/**
+ * @author Thomas Müller
+ * @copyright 2014 Thomas Müller deepdiver@owncloud.com
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\App;
+
+use OC;
+use OC\App\Platform;
+use OCP\IL10N;
+
+class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @var Platform
+ */
+ private $platformMock;
+
+ /**
+ * @var IL10N
+ */
+ private $l10nMock;
+
+ public function setUp() {
+ $this->platformMock = $this->getMockBuilder('\OC\App\Platform')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->platformMock->expects($this->any())
+ ->method('getPhpVersion')
+ ->will( $this->returnValue('5.4.3'));
+ $this->platformMock->expects($this->any())
+ ->method('getDatabase')
+ ->will( $this->returnValue('mysql'));
+ $this->l10nMock = $this->getMockBuilder('\OCP\IL10N')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->l10nMock->expects($this->any())
+ ->method('t')
+ ->will($this->returnCallback(function($text, $parameters = array()) {
+ return vsprintf($text, $parameters);
+ }));
+ }
+
+ /**
+ * @dataProvider providesPhpVersion
+ */
+ public function testPhpVersion($expectedMissing, $minVersion, $maxVersion) {
+ $app = array(
+ 'dependencies' => array(
+ 'php' => array()
+ )
+ );
+ if (!is_null($minVersion)) {
+ $app['dependencies']['php']['@attributes']['min-version'] = $minVersion;
+ }
+ if (!is_null($maxVersion)) {
+ $app['dependencies']['php']['@attributes']['max-version'] = $maxVersion;
+ }
+ $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock);
+ $missing = $analyser->analyze();
+
+ $this->assertTrue(is_array($missing));
+ $this->assertEquals(count($expectedMissing), count($missing));
+ $this->assertEquals($expectedMissing, $missing);
+ }
+
+ /**
+ * @dataProvider providesDatabases
+ */
+ public function testDatabases($expectedMissing, $databases) {
+ $app = array(
+ 'dependencies' => array(
+ )
+ );
+ if (!is_null($databases)) {
+ $app['dependencies']['database'] = $databases;
+ }
+ $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock);
+ $missing = $analyser->analyze();
+
+ $this->assertTrue(is_array($missing));
+ $this->assertEquals(count($expectedMissing), count($missing));
+ $this->assertEquals($expectedMissing, $missing);
+ }
+
+ function providesDatabases() {
+ return array(
+ // non BC - in case on databases are defined -> all are supported
+ array(array(), null),
+ array(array(), array()),
+ array(array('Following databases are supported: sqlite, postgres'), array('sqlite', array('@value' => 'postgres'))),
+ );
+ }
+
+ function providesPhpVersion() {
+ return array(
+ array(array(), null, null),
+ array(array(), '5.4', null),
+ array(array(), null, '5.5'),
+ array(array(), '5.4', '5.5'),
+ array(array('PHP 5.4.4 or higher is required.'), '5.4.4', null),
+ array(array('PHP with a version less then 5.4.2 is required.'), null, '5.4.2'),
+ );
+ }
+}
diff --git a/tests/lib/app/infoparser.php b/tests/lib/app/infoparser.php
index 277e1582e45..13c0b51e117 100644
--- a/tests/lib/app/infoparser.php
+++ b/tests/lib/app/infoparser.php
@@ -39,15 +39,23 @@ class InfoParser extends \PHPUnit_Framework_TestCase {
$this->parser = new \OC\App\InfoParser($httpHelper, $urlGenerator);
}
- public function testParsingValidXml() {
- $expectedData = json_decode(file_get_contents(OC::$SERVERROOT.'/tests/data/app/expected-info.json'), true);
- $data = $this->parser->parse(OC::$SERVERROOT.'/tests/data/app/valid-info.xml');
+ /**
+ * @dataProvider providesInfoXml
+ */
+ public function testParsingValidXml($expectedJson, $xmlFile) {
+ $expectedData = null;
+ if (!is_null($expectedJson)) {
+ $expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/$expectedJson"), true);
+ }
+ $data = $this->parser->parse(OC::$SERVERROOT. "/tests/data/app/$xmlFile");
$this->assertEquals($expectedData, $data);
}
- public function testParsingInvalidXml() {
- $data = $this->parser->parse(OC::$SERVERROOT.'/tests/data/app/invalid-info.xml');
- $this->assertNull($data);
+ function providesInfoXml() {
+ return array(
+ array('expected-info.json', 'valid-info.xml'),
+ array(null, 'invalid-info.xml'),
+ );
}
}
diff --git a/tests/lib/appframework/controller/ControllerTest.php b/tests/lib/appframework/controller/ControllerTest.php
index d186651dc23..18d47d00f6b 100644
--- a/tests/lib/appframework/controller/ControllerTest.php
+++ b/tests/lib/appframework/controller/ControllerTest.php
@@ -173,7 +173,8 @@ class ControllerTest extends \Test\TestCase {
public function testFormatDataResponseJSON() {
$expectedHeaders = array(
'test' => 'something',
- 'Cache-Control' => 'no-cache, must-revalidate'
+ 'Cache-Control' => 'no-cache, must-revalidate',
+ 'Content-Type' => 'application/json; charset=utf-8'
);
$response = $this->controller->customDataResponse(array('hi'));
diff --git a/tests/lib/appframework/http/DispatcherTest.php b/tests/lib/appframework/http/DispatcherTest.php
index 45ebd6fce96..3933e00804b 100644
--- a/tests/lib/appframework/http/DispatcherTest.php
+++ b/tests/lib/appframework/http/DispatcherTest.php
@@ -232,10 +232,6 @@ class DispatcherTest extends \Test\TestCase {
public function testExceptionCallsAfterException() {
- // TODO fails on PHP 5.3
- if (version_compare(PHP_VERSION, '5.4.0', '<')) {
- $this->markTestSkipped('Fails on PHP 5.3');
- }
$out = 'yo';
$httpHeaders = 'Http';
$responseHeaders = array('hell' => 'yeah');
@@ -251,10 +247,6 @@ class DispatcherTest extends \Test\TestCase {
public function testExceptionThrowsIfCanNotBeHandledByAfterException() {
- // TODO fails on PHP 5.3 and crashed travis (10 minute timeout)
- if (version_compare(PHP_VERSION, '5.4.0', '<')) {
- $this->markTestSkipped('Fails on PHP 5.3 and causes infinite loop - travis fails after 10 minute timeout');
- }
$out = 'yo';
$httpHeaders = 'Http';
$responseHeaders = array('hell' => 'yeah');
diff --git a/tests/lib/db.php b/tests/lib/db.php
index a401aded62a..aefbb3624ed 100644
--- a/tests/lib/db.php
+++ b/tests/lib/db.php
@@ -265,7 +265,7 @@ class Test_DB extends \Test\TestCase {
protected function insertCardData($fullname, $uri) {
$query = OC_DB::prepare("INSERT INTO `*PREFIX*{$this->table2}` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)");
- $this->assertSame(1, $query->execute(array($fullname, $uri, uniqid())));
+ $this->assertSame(1, $query->execute(array($fullname, $uri, $this->getUniqueID())));
}
protected function updateCardData($fullname, $uri) {
diff --git a/tests/lib/db/migrator.php b/tests/lib/db/migrator.php
index 7acd3382fe2..1a1d530f1d2 100644
--- a/tests/lib/db/migrator.php
+++ b/tests/lib/db/migrator.php
@@ -39,7 +39,7 @@ class Migrator extends \Test\TestCase {
$this->markTestSkipped('DB migration tests are not supported on MSSQL');
}
$this->manager = new \OC\DB\MDB2SchemaManager($this->connection);
- $this->tableName = 'test_' . uniqid();
+ $this->tableName = strtolower($this->getUniqueID('test_'));
}
protected function tearDown() {
diff --git a/tests/lib/db/mysqlmigration.php b/tests/lib/db/mysqlmigration.php
index 70199147760..6c283e6c59c 100644
--- a/tests/lib/db/mysqlmigration.php
+++ b/tests/lib/db/mysqlmigration.php
@@ -23,7 +23,7 @@ class TestMySqlMigration extends \Test\TestCase {
}
$dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
- $this->tableName = uniqid($dbPrefix . "_enum_bit_test");
+ $this->tableName = $this->getUniqueID($dbPrefix . '_enum_bit_test');
$this->connection->exec("CREATE TABLE $this->tableName(b BIT, e ENUM('1','2','3','4'))");
}
diff --git a/tests/lib/db/sqlitemigration.php b/tests/lib/db/sqlitemigration.php
index e3d0e386ab5..9206381ff71 100644
--- a/tests/lib/db/sqlitemigration.php
+++ b/tests/lib/db/sqlitemigration.php
@@ -23,7 +23,7 @@ class TestSqliteMigration extends \Test\TestCase {
}
$dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
- $this->tableName = uniqid($dbPrefix . "_enum_bit_test");
+ $this->tableName = $this->getUniqueID($dbPrefix . '_enum_bit_test');
$this->connection->exec("CREATE TABLE $this->tableName(t0 tinyint unsigned, t1 tinyint)");
}
diff --git a/tests/lib/files/cache/updaterlegacy.php b/tests/lib/files/cache/updaterlegacy.php
index 7c05800cd6b..7cf4dc6df5f 100644
--- a/tests/lib/files/cache/updaterlegacy.php
+++ b/tests/lib/files/cache/updaterlegacy.php
@@ -58,7 +58,7 @@ class UpdaterLegacy extends \Test\TestCase {
$this->originalStorage = Filesystem::getStorage('/');
Filesystem::tearDown();
if (!self::$user) {
- self::$user = uniqid();
+ self::$user = $this->getUniqueID();
}
\OC_User::createUser(self::$user, 'password');
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
index 746600c7d15..1b84db0fc0d 100644
--- a/tests/lib/files/filesystem.php
+++ b/tests/lib/files/filesystem.php
@@ -189,7 +189,7 @@ class Filesystem extends \Test\TestCase {
if (\OC\Files\Filesystem::getView()) {
$user = \OC_User::getUser();
} else {
- $user = uniqid();
+ $user = $this->getUniqueID();
\OC\Files\Filesystem::init($user, '/' . $user . '/files');
}
\OC_Hook::clear('OC_Filesystem');
@@ -217,7 +217,7 @@ class Filesystem extends \Test\TestCase {
*/
public function testLocalMountWhenUserDoesNotExist() {
$datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
- $userId = uniqid('user_');
+ $userId = $this->getUniqueID('user_');
\OC\Files\Filesystem::initMountPoints($userId);
@@ -231,7 +231,7 @@ class Filesystem extends \Test\TestCase {
* Tests that the home storage is used for the user's mount point
*/
public function testHomeMount() {
- $userId = uniqid('user_');
+ $userId = $this->getUniqueID('user_');
\OC_User::createUser($userId, $userId);
@@ -251,7 +251,7 @@ class Filesystem extends \Test\TestCase {
*/
public function testLegacyHomeMount() {
$datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
- $userId = uniqid('user_');
+ $userId = $this->getUniqueID('user_');
// insert storage into DB by constructing it
// to make initMountsPoint find its existence
@@ -281,7 +281,7 @@ class Filesystem extends \Test\TestCase {
* Test that the default cache dir is part of the user's home
*/
public function testMountDefaultCacheDir() {
- $userId = uniqid('user_');
+ $userId = $this->getUniqueID('user_');
$oldCachePath = \OC_Config::getValue('cache_path', '');
// no cache path configured
\OC_Config::setValue('cache_path', '');
@@ -306,7 +306,7 @@ class Filesystem extends \Test\TestCase {
* the user's home
*/
public function testMountExternalCacheDir() {
- $userId = uniqid('user_');
+ $userId = $this->getUniqueID('user_');
$oldCachePath = \OC_Config::getValue('cache_path', '');
// set cache path to temp dir
diff --git a/tests/lib/files/node/file.php b/tests/lib/files/node/file.php
index 1ae312ab5a8..a1d2266edf7 100644
--- a/tests/lib/files/node/file.php
+++ b/tests/lib/files/node/file.php
@@ -8,6 +8,7 @@
namespace Test\Files\Node;
+use OC\Files\FileInfo;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OC\Files\View;
@@ -20,6 +21,10 @@ class File extends \Test\TestCase {
$this->user = new \OC\User\User('', new \OC_User_Dummy);
}
+ protected function getFileInfo($data) {
+ return new FileInfo('', null, '', $data);
+ }
+
public function testDelete() {
$manager = $this->getMock('\OC\Files\Mount\Manager');
@@ -39,7 +44,7 @@ class File extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$view->expects($this->once())
->method('unlink')
@@ -89,7 +94,7 @@ class File extends \Test\TestCase {
$view->expects($this->any())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1))));
$view->expects($this->once())
->method('unlink')
@@ -124,7 +129,7 @@ class File extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$node->delete();
@@ -156,7 +161,7 @@ class File extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$this->assertEquals('bar', $node->getContent());
@@ -180,7 +185,7 @@ class File extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => 0)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => 0))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$node->getContent();
@@ -201,7 +206,7 @@ class File extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$view->expects($this->once())
->method('file_put_contents')
@@ -226,7 +231,7 @@ class File extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$node->putContent('bar');
@@ -241,9 +246,9 @@ class File extends \Test\TestCase {
$root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
$view->expects($this->once())
- ->method('getMimeType')
+ ->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue('text/plain'));
+ ->will($this->returnValue($this->getFileInfo(array('mimetype' => 'text/plain'))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$this->assertEquals('text/plain', $node->getMimeType());
@@ -279,7 +284,7 @@ class File extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$fh = $node->fopen('r');
@@ -316,7 +321,7 @@ class File extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$fh = $node->fopen('w');
@@ -348,7 +353,7 @@ class File extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => 0)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => 0))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$node->fopen('r');
@@ -375,7 +380,7 @@ class File extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_UPDATE)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_UPDATE))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$node->fopen('w');
@@ -402,7 +407,7 @@ class File extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$node->fopen('w');
@@ -425,7 +430,7 @@ class File extends \Test\TestCase {
$view->expects($this->any())
->method('getFileInfo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 3)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 3))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
@@ -469,7 +474,7 @@ class File extends \Test\TestCase {
$view->expects($this->any())
->method('getFileInfo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ, 'fileid' => 3)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ, 'fileid' => 3))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
@@ -556,7 +561,7 @@ class File extends \Test\TestCase {
$view->expects($this->any())
->method('getFileInfo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
@@ -587,7 +592,7 @@ class File extends \Test\TestCase {
$view->expects($this->any())
->method('getFileInfo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$view->expects($this->never())
->method('rename');
diff --git a/tests/lib/files/node/folder.php b/tests/lib/files/node/folder.php
index 91aa3b82db2..4aa57aa9373 100644
--- a/tests/lib/files/node/folder.php
+++ b/tests/lib/files/node/folder.php
@@ -9,6 +9,7 @@
namespace Test\Files\Node;
use OC\Files\Cache\Cache;
+use OC\Files\FileInfo;
use OC\Files\Mount\Mount;
use OC\Files\Node\Node;
use OCP\Files\NotFoundException;
@@ -23,6 +24,10 @@ class Folder extends \Test\TestCase {
$this->user = new \OC\User\User('', new \OC_User_Dummy);
}
+ protected function getFileInfo($data) {
+ return new FileInfo('', null, '', $data);
+ }
+
public function testDelete() {
$manager = $this->getMock('\OC\Files\Mount\Manager');
/**
@@ -39,7 +44,7 @@ class Folder extends \Test\TestCase {
$view->expects($this->any())
->method('getFileInfo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$view->expects($this->once())
->method('rmdir')
@@ -87,7 +92,7 @@ class Folder extends \Test\TestCase {
$view->expects($this->any())
->method('getFileInfo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1))));
$view->expects($this->once())
->method('rmdir')
@@ -121,7 +126,7 @@ class Folder extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
$node->delete();
@@ -255,7 +260,7 @@ class Folder extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$view->expects($this->once())
->method('mkdir')
@@ -285,7 +290,7 @@ class Folder extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
$node->newFolder('asd');
@@ -305,7 +310,7 @@ class Folder extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$view->expects($this->once())
->method('touch')
@@ -335,7 +340,7 @@ class Folder extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
$node->newFile('asd');
diff --git a/tests/lib/files/node/integration.php b/tests/lib/files/node/integration.php
index fd777460ec6..d8c180cc844 100644
--- a/tests/lib/files/node/integration.php
+++ b/tests/lib/files/node/integration.php
@@ -48,7 +48,7 @@ class IntegrationTests extends \Test\TestCase {
\OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook');
\OC_Hook::connect('OC_Filesystem', 'post_touch', '\OC\Files\Cache\Updater', 'touchHook');
- $user = new User(uniqid('user'), new \OC_User_Dummy);
+ $user = new User($this->getUniqueID('user'), new \OC_User_Dummy);
\OC_User::setUserId($user->getUID());
$this->view = new View();
$this->root = new Root($manager, $this->view, $user);
diff --git a/tests/lib/files/node/node.php b/tests/lib/files/node/node.php
index 8820be5b0b2..4697479ba95 100644
--- a/tests/lib/files/node/node.php
+++ b/tests/lib/files/node/node.php
@@ -8,6 +8,8 @@
namespace Test\Files\Node;
+use OC\Files\FileInfo;
+
class Node extends \Test\TestCase {
private $user;
@@ -16,6 +18,10 @@ class Node extends \Test\TestCase {
$this->user = new \OC\User\User('', new \OC_User_Dummy);
}
+ protected function getFileInfo($data) {
+ return new FileInfo('', null, '', $data);
+ }
+
public function testStat() {
$manager = $this->getMock('\OC\Files\Mount\Manager');
/**
@@ -55,12 +61,12 @@ class Node extends \Test\TestCase {
->method('getUser')
->will($this->returnValue($this->user));
- $stat = array(
+ $stat = $this->getFileInfo(array(
'fileid' => 1,
'size' => 100,
'etag' => 'qwerty',
'mtime' => 50
- );
+ ));
$view->expects($this->once())
->method('getFileInfo')
@@ -82,10 +88,18 @@ class Node extends \Test\TestCase {
->method('getUser')
->will($this->returnValue($this->user));
+
+ $stat = $this->getFileInfo(array(
+ 'fileid' => 1,
+ 'size' => 100,
+ 'etag' => 'qwerty',
+ 'mtime' => 50
+ ));
+
$view->expects($this->once())
- ->method('filesize')
+ ->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(100));
+ ->will($this->returnValue($stat));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$this->assertEquals(100, $node->getSize());
@@ -102,12 +116,12 @@ class Node extends \Test\TestCase {
->method('getUser')
->will($this->returnValue($this->user));
- $stat = array(
+ $stat = $this->getFileInfo(array(
'fileid' => 1,
'size' => 100,
'etag' => 'qwerty',
'mtime' => 50
- );
+ ));
$view->expects($this->once())
->method('getFileInfo')
@@ -128,15 +142,18 @@ class Node extends \Test\TestCase {
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
- /**
- * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage
- */
- $storage = $this->getMock('\OC\Files\Storage\Storage');
+
+ $stat = $this->getFileInfo(array(
+ 'fileid' => 1,
+ 'size' => 100,
+ 'etag' => 'qwerty',
+ 'mtime' => 50
+ ));
$view->expects($this->once())
- ->method('filemtime')
+ ->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(50));
+ ->will($this->returnValue($stat));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$this->assertEquals(50, $node->getMTime());
@@ -239,14 +256,9 @@ class Node extends \Test\TestCase {
->will($this->returnValue(true));
$view->expects($this->once())
- ->method('filemtime')
- ->with('/bar/foo')
- ->will($this->returnValue(100));
-
- $view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$node = new \OC\Files\Node\Node($root, $view, '/bar/foo');
$node->touch(100);
@@ -299,7 +311,7 @@ class Node extends \Test\TestCase {
$view->expects($this->any())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$node = new \OC\Files\Node\Node($root, $view, '/bar/foo');
$node->touch(100);
@@ -323,7 +335,7 @@ class Node extends \Test\TestCase {
$view->expects($this->any())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\Node($root, $view, '/bar/foo');
$node->touch(100);
diff --git a/tests/lib/files/node/root.php b/tests/lib/files/node/root.php
index fcce7070f5d..35bd462157e 100644
--- a/tests/lib/files/node/root.php
+++ b/tests/lib/files/node/root.php
@@ -8,6 +8,7 @@
namespace Test\Files\Node;
+use OC\Files\FileInfo;
use OCP\Files\NotPermittedException;
use OC\Files\Mount\Manager;
@@ -19,6 +20,10 @@ class Root extends \Test\TestCase {
$this->user = new \OC\User\User('', new \OC_User_Dummy);
}
+ protected function getFileInfo($data) {
+ return new FileInfo('', null, '', $data);
+ }
+
public function testGet() {
$manager = new Manager();
/**
@@ -34,7 +39,7 @@ class Root extends \Test\TestCase {
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('fileid' => 10, 'path' => 'bar/foo', 'name', 'mimetype' => 'text/plain')));
+ ->will($this->returnValue($this->getFileInfo(array('fileid' => 10, 'path' => 'bar/foo', 'name', 'mimetype' => 'text/plain'))));
$view->expects($this->once())
->method('is_dir')
diff --git a/tests/lib/files/objectstore/swift.php b/tests/lib/files/objectstore/swift.php
index f2c4a983cf2..30c60598277 100644
--- a/tests/lib/files/objectstore/swift.php
+++ b/tests/lib/files/objectstore/swift.php
@@ -34,7 +34,7 @@ class Swift extends \Test\Files\Storage\Storage {
parent::setUp();
if (!getenv('RUN_OBJECTSTORE_TESTS')) {
- $this->markTestSkipped('objectstore tests are unreliable on travis');
+ $this->markTestSkipped('objectstore tests are unreliable in some environments');
}
\OC_App::disable('files_sharing');
@@ -87,10 +87,6 @@ class Swift extends \Test\Files\Storage\Storage {
}
public function testStat() {
- // TODO travis
- if (getenv('TRAVIS')) {
- $this->markTestSkipped('Fails on travis - connection times out sometimes');
- }
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$ctimeStart = time();
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
index d6dd176bba9..8bb4e0ac2cc 100644
--- a/tests/lib/files/view.php
+++ b/tests/lib/files/view.php
@@ -71,7 +71,7 @@ class View extends \Test\TestCase {
$storage1 = $this->getTestStorage();
$storage2 = $this->getTestStorage();
$storage3 = $this->getTestStorage();
- $root = '/' . uniqid();
+ $root = $this->getUniqueID('/');
\OC\Files\Filesystem::mount($storage1, array(), $root . '/');
\OC\Files\Filesystem::mount($storage2, array(), $root . '/substorage');
\OC\Files\Filesystem::mount($storage3, array(), $root . '/folder/anotherstorage');
diff --git a/tests/lib/memcache/apc.php b/tests/lib/memcache/apc.php
index 550d5068dc1..fdb785b9dc5 100644
--- a/tests/lib/memcache/apc.php
+++ b/tests/lib/memcache/apc.php
@@ -21,6 +21,6 @@ class APC extends Cache {
$this->markTestSkipped('The apc extension is emulated by ACPu.');
return;
}
- $this->instance=new \OC\Memcache\APC(uniqid());
+ $this->instance=new \OC\Memcache\APC($this->getUniqueID());
}
}
diff --git a/tests/lib/memcache/apcu.php b/tests/lib/memcache/apcu.php
index 1b849e1c54d..afcaa99bfbe 100644
--- a/tests/lib/memcache/apcu.php
+++ b/tests/lib/memcache/apcu.php
@@ -17,6 +17,6 @@ class APCu extends Cache {
$this->markTestSkipped('The APCu extension is not available.');
return;
}
- $this->instance=new \OC\Memcache\APCu(uniqid());
+ $this->instance=new \OC\Memcache\APCu($this->getUniqueID());
}
}
diff --git a/tests/lib/memcache/memcached.php b/tests/lib/memcache/memcached.php
index a94b809a7b5..51a78996dd4 100644
--- a/tests/lib/memcache/memcached.php
+++ b/tests/lib/memcache/memcached.php
@@ -16,14 +16,14 @@ class Memcached extends Cache {
if (!\OC\Memcache\Memcached::isAvailable()) {
self::markTestSkipped('The memcached extension is not available.');
}
- $instance = new \OC\Memcache\Memcached(uniqid());
- if ($instance->set(uniqid(), uniqid()) === false) {
+ $instance = new \OC\Memcache\Memcached(self::getUniqueID());
+ if ($instance->set(self::getUniqueID(), self::getUniqueID()) === false) {
self::markTestSkipped('memcached server seems to be down.');
}
}
protected function setUp() {
parent::setUp();
- $this->instance = new \OC\Memcache\Memcached(uniqid());
+ $this->instance = new \OC\Memcache\Memcached($this->getUniqueID());
}
}
diff --git a/tests/lib/memcache/xcache.php b/tests/lib/memcache/xcache.php
index b97d5545c6e..36efe0b220a 100644
--- a/tests/lib/memcache/xcache.php
+++ b/tests/lib/memcache/xcache.php
@@ -17,6 +17,6 @@ class XCache extends Cache {
$this->markTestSkipped('The xcache extension is not available.');
return;
}
- $this->instance = new \OC\Memcache\XCache(uniqid());
+ $this->instance = new \OC\Memcache\XCache($this->getUniqueID());
}
}
diff --git a/tests/lib/ocs/privatedata.php b/tests/lib/ocs/privatedata.php
index 20f1dd38362..a9300f5beac 100644
--- a/tests/lib/ocs/privatedata.php
+++ b/tests/lib/ocs/privatedata.php
@@ -26,7 +26,7 @@ class Test_OC_OCS_Privatedata extends \Test\TestCase {
protected function setUp() {
parent::setUp();
\OC::$server->getSession()->set('user_id', 'user1');
- $this->appKey = uniqid('app');
+ $this->appKey = $this->getUniqueID('app');
}
public function testGetEmptyOne() {
diff --git a/tests/lib/repair/repaircollation.php b/tests/lib/repair/repaircollation.php
index e711fcd9d83..29dad190008 100644
--- a/tests/lib/repair/repaircollation.php
+++ b/tests/lib/repair/repaircollation.php
@@ -53,7 +53,7 @@ class TestRepairCollation extends \Test\TestCase {
}
$dbPrefix = $this->config->getSystemValue("dbtableprefix");
- $this->tableName = uniqid($dbPrefix . "_collation_test");
+ $this->tableName = $this->getUniqueID($dbPrefix . "_collation_test");
$this->connection->exec("CREATE TABLE $this->tableName(text VARCHAR(16)) COLLATE utf8_unicode_ci");
$this->repair = new TestCollationRepair($this->config, $this->connection);
diff --git a/tests/lib/repair/repairinnodb.php b/tests/lib/repair/repairinnodb.php
index 21d7d978821..d4039472a6b 100644
--- a/tests/lib/repair/repairinnodb.php
+++ b/tests/lib/repair/repairinnodb.php
@@ -31,7 +31,7 @@ class TestRepairInnoDB extends \Test\TestCase {
}
$dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
- $this->tableName = uniqid($dbPrefix . "_innodb_test");
+ $this->tableName = $this->getUniqueID($dbPrefix . "_innodb_test");
$this->connection->exec("CREATE TABLE $this->tableName(id INT) ENGINE MyISAM");
$this->repair = new \OC\Repair\InnoDB();
diff --git a/tests/lib/repair/repairlegacystorage.php b/tests/lib/repair/repairlegacystorage.php
index ac845657cd9..f08393300e1 100644
--- a/tests/lib/repair/repairlegacystorage.php
+++ b/tests/lib/repair/repairlegacystorage.php
@@ -13,6 +13,8 @@
*/
class TestRepairLegacyStorages extends \Test\TestCase {
+ private $connection;
+ private $config;
private $user;
private $repair;
@@ -247,12 +249,12 @@ class TestRepairLegacyStorages extends \Test\TestCase {
// regular data dir
array(
'/tmp/oc-autotest/datadir/',
- uniqid('user_'),
+ $this->getUniqueID('user_'),
),
// long datadir / short user
array(
'/tmp/oc-autotest/datadir01234567890123456789012345678901234567890123456789END/',
- uniqid('user_'),
+ $this->getUniqueID('user_'),
),
// short datadir / long user
array(
@@ -271,7 +273,7 @@ class TestRepairLegacyStorages extends \Test\TestCase {
$output[] = 'info: ' . $description;
});
- $this->prepareSettings('/tmp/oc-autotest/datadir', uniqid('user_'));
+ $this->prepareSettings('/tmp/oc-autotest/datadir', $this->getUniqueID('user_'));
$this->assertNotEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone'));
$this->repair->run();
$this->assertEquals(1, count($output));
diff --git a/tests/lib/session/memory.php b/tests/lib/session/memory.php
index 84dee548a1e..1ca4956c6ea 100644
--- a/tests/lib/session/memory.php
+++ b/tests/lib/session/memory.php
@@ -12,6 +12,6 @@ namespace Test\Session;
class Memory extends Session {
protected function setUp() {
parent::setUp();
- $this->instance = new \OC\Session\Memory(uniqid());
+ $this->instance = new \OC\Session\Memory($this->getUniqueID());
}
}
diff --git a/tests/lib/tags.php b/tests/lib/tags.php
index 3f0c52d19ea..533e6a19add 100644
--- a/tests/lib/tags.php
+++ b/tests/lib/tags.php
@@ -25,14 +25,18 @@ class Test_Tags extends \Test\TestCase {
protected $objectType;
protected $user;
protected $backupGlobals = FALSE;
+ /** @var \OC\Tagging\TagMapper */
+ protected $tagMapper;
+ /** @var \OC\TagManager */
+ protected $tagMgr;
protected function setUp() {
parent::setUp();
OC_User::clearBackends();
OC_User::useBackend('dummy');
- $this->user = uniqid('user_');
- $this->objectType = uniqid('type_');
+ $this->user = $this->getUniqueID('user_');
+ $this->objectType = $this->getUniqueID('type_');
OC_User::createUser($this->user, 'pass');
OC_User::setUserId($this->user);
$this->tagMapper = new OC\Tagging\TagMapper(\OC::$server->getDb());
@@ -205,7 +209,7 @@ class Test_Tags extends \Test\TestCase {
$tagger = $this->tagMgr->load('test');
$tagger->tagAs(1, $test_tag);
- $other_user = uniqid('user2_');
+ $other_user = $this->getUniqueID('user2_');
OC_User::createUser($other_user, 'pass');
OC_User::setUserId($other_user);
diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php
index 934bc5fa8f3..27c28329535 100644
--- a/tests/lib/testcase.php
+++ b/tests/lib/testcase.php
@@ -22,6 +22,8 @@
namespace Test;
+use OCP\Security\ISecureRandom;
+
abstract class TestCase extends \PHPUnit_Framework_TestCase {
/**
* Returns a unique identifier as uniqid() is not reliable sometimes
@@ -30,11 +32,11 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
* @param int $length
* @return string
*/
- protected function getUniqueID($prefix = '', $length = 13) {
+ protected static function getUniqueID($prefix = '', $length = 13) {
return $prefix . \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(
$length,
// Do not use dots and slashes as we use the value for file names
- '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+ ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER
);
}
diff --git a/tests/lib/util.php b/tests/lib/util.php
index 6de599b070e..1ddbd2aba2b 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -150,7 +150,7 @@ class Test_Util extends \Test\TestCase {
* Tests that the home storage is not wrapped when no quota exists.
*/
function testHomeStorageWrapperWithoutQuota() {
- $user1 = uniqid();
+ $user1 = $this->getUniqueID();
\OC_User::createUser($user1, 'test');
OC_Preferences::setValue($user1, 'files', 'quota', 'none');
\OC_User::setUserId($user1);
@@ -172,7 +172,7 @@ class Test_Util extends \Test\TestCase {
* Tests that the home storage is not wrapped when no quota exists.
*/
function testHomeStorageWrapperWithQuota() {
- $user1 = uniqid();
+ $user1 = $this->getUniqueID();
\OC_User::createUser($user1, 'test');
OC_Preferences::setValue($user1, 'files', 'quota', '1024');
\OC_User::setUserId($user1);
@@ -331,7 +331,7 @@ class Test_Util extends \Test\TestCase {
Dummy_OC_App::setEnabledApps($enabledApps);
// need to set a user id to make sure enabled apps are read from cache
- \OC_User::setUserId(uniqid());
+ \OC_User::setUserId($this->getUniqueID());
\OCP\Config::setSystemValue('defaultapp', $defaultAppConfig);
$this->assertEquals('http://localhost/' . $expectedPath, \OC_Util::getDefaultPageUrl());