]> source.dussan.org Git - nextcloud-server.git/commitdiff
Replace uniqid calls with $this->getUniqueID so tests pass again on windows
authorJoas Schilling <nickvergessen@gmx.de>
Tue, 2 Dec 2014 12:51:36 +0000 (13:51 +0100)
committerJoas Schilling <nickvergessen@gmx.de>
Wed, 3 Dec 2014 11:10:55 +0000 (12:10 +0100)
21 files changed:
tests/lib/api.php
tests/lib/db.php
tests/lib/db/migrator.php
tests/lib/db/mysqlmigration.php
tests/lib/db/sqlitemigration.php
tests/lib/files/cache/updaterlegacy.php
tests/lib/files/filesystem.php
tests/lib/files/node/integration.php
tests/lib/files/view.php
tests/lib/memcache/apc.php
tests/lib/memcache/apcu.php
tests/lib/memcache/memcached.php
tests/lib/memcache/xcache.php
tests/lib/ocs/privatedata.php
tests/lib/repair/repaircollation.php
tests/lib/repair/repairinnodb.php
tests/lib/repair/repairlegacystorage.php
tests/lib/session/memory.php
tests/lib/tags.php
tests/lib/testcase.php
tests/lib/util.php

index bf9748a60400b0016f98fe63d9b71944dd6df5b2..3b925a639605d1fc186ce370e0d49cc1864351a5 100644 (file)
@@ -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_'),
                        );
        }
 
index a401aded62a0e33bc7e83d011eead4ced4e82f8a..aefbb3624eda5bf79cb6bc79068b33ea2edaca8c 100644 (file)
@@ -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) {
index 7acd3382fe290ea7d2664815270d1a0796094300..1a1d530f1d2a45ff32496870317c88d90ee4c84e 100644 (file)
@@ -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() {
index 70199147760600535fa599f984549597aa59c774..6c283e6c59cb6a9ab0a768ba4b24ab8f132279f2 100644 (file)
@@ -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'))");
        }
 
index e3d0e386ab538ad4f81a4c12115429ef34549df6..9206381ff711f74e7226ffc8fb1349e006634909 100644 (file)
@@ -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)");
        }
 
index 7c05800cd6ba3f528549a71dc7985256e4c4d23a..7cf4dc6df5f59acd92e41f728bf2458aeb5e732e 100644 (file)
@@ -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');
index 746600c7d15f2defbed56aff6f2e1729b8e099cf..1b84db0fc0da95196e73ddcf7550a4cc1b41c799 100644 (file)
@@ -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
index fd777460ec6cfd47e06a3f5bf4269146c610f103..d8c180cc84466a08df92d1bf49a81b74337dc982 100644 (file)
@@ -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);
index d6dd176bba955d3c2c50582aed4b9ae6011babc6..8bb4e0ac2cca6bed448b4ea6579792187edabd1b 100644 (file)
@@ -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');
index 550d5068dc1fe9854421c5aaa9f64438608f20a4..fdb785b9dc5ab126d94e2347564db31687731872 100644 (file)
@@ -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());
        }
 }
index 1b849e1c54d5eb17ab37b1383166164548c6cf07..afcaa99bfbeccb05deb1cb093462baaa657ab46c 100644 (file)
@@ -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());
        }
 }
index a94b809a7b558d88c094f05159172b5b3ecb2407..51a78996dd462c3bf51949a9cb4847ae47f0b38f 100644 (file)
@@ -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());
        }
 }
index b97d5545c6e412e490692175e707ceca5ac32944..36efe0b220a51abe0e38cf421cd594627a2a9c8a 100644 (file)
@@ -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());
        }
 }
index 20f1dd3836282176d67ea9aa7dbe4923631dc6cd..a9300f5beac15730c10ecae04ca667c04d051010 100644 (file)
@@ -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() {
index e711fcd9d831cc4bdfe888ac339e3c44f7f1ab36..29dad19000876588ae3f25019c722217a080cb08 100644 (file)
@@ -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);
index 21d7d97882139e6458b8d0988e9d7fcd2b6243b2..d4039472a6bbdf81223ad3e171c619ab316e9acf 100644 (file)
@@ -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();
index ac845657cd94ea926b9be5867d243112662e657f..f08393300e141cf2c6b1850ad93c97bb0d80e897 100644 (file)
@@ -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));
index 84dee548a1e7631226a1ad7e6353beea47eb0c6a..1ca4956c6ea497e093a36b7457c4b6cfdecb6c91 100644 (file)
@@ -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());
        }
 }
index 3f0c52d19ea0c35e93b7e03c9d7873394237c29c..533e6a19add1d0e715f895e3efe4b1ab5e9337ca 100644 (file)
@@ -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);
index 934bc5fa8f3bf7f8688e6f6e79400d9211992c2c..27c283295350bfe2e7b7cc228b4fa913b3a11562 100644 (file)
@@ -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
                );
        }
 
index 6de599b070ede1c190d9ccd9de4c5658d195c0a0..1ddbd2aba2b86d176a261455a72e0400ff8d95b7 100644 (file)
@@ -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());