From: Joas Schilling Date: Tue, 2 Dec 2014 12:51:36 +0000 (+0100) Subject: Replace uniqid calls with $this->getUniqueID so tests pass again on windows X-Git-Tag: v8.0.0alpha1~184^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ea4c25609dd23345fa1f639479421ff318e6f6c9;p=nextcloud-server.git Replace uniqid calls with $this->getUniqueID so tests pass again on windows --- 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/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/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/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());