Replace uniqid calls with $this->getUniqueID so tests pass again on windows

This commit is contained in:
Joas Schilling 2014-12-02 13:51:36 +01:00
parent e9029f94cb
commit ea4c25609d
21 changed files with 43 additions and 35 deletions

View 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_'),
);
}

View 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) {

View 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() {

View 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'))");
}

View 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)");
}

View 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');

View 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

View 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);

View 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');

View 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());
}
}

View 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());
}
}

View 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());
}
}

View 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());
}
}

View 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() {

View 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);

View 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();

View 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));

View 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());
}
}

View 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);

View 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
);
}

View 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());