return array(
'shipped' => $shipped,
'response' => new OC_OCS_Result($data, $code, $message),
- 'app' => uniqid('testapp_', true),
+ 'app' => $this->getUniqueID('testapp_'),
);
}
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) {
$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() {
}
$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'))");
}
}
$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)");
}
$this->originalStorage = Filesystem::getStorage('/');
Filesystem::tearDown();
if (!self::$user) {
- self::$user = uniqid();
+ self::$user = $this->getUniqueID();
}
\OC_User::createUser(self::$user, 'password');
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');
*/
public function testLocalMountWhenUserDoesNotExist() {
$datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
- $userId = uniqid('user_');
+ $userId = $this->getUniqueID('user_');
\OC\Files\Filesystem::initMountPoints($userId);
* 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);
*/
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
* 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', '');
* 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
\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);
$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');
$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());
}
}
$this->markTestSkipped('The APCu extension is not available.');
return;
}
- $this->instance=new \OC\Memcache\APCu(uniqid());
+ $this->instance=new \OC\Memcache\APCu($this->getUniqueID());
}
}
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());
}
}
$this->markTestSkipped('The xcache extension is not available.');
return;
}
- $this->instance = new \OC\Memcache\XCache(uniqid());
+ $this->instance = new \OC\Memcache\XCache($this->getUniqueID());
}
}
protected function setUp() {
parent::setUp();
\OC::$server->getSession()->set('user_id', 'user1');
- $this->appKey = uniqid('app');
+ $this->appKey = $this->getUniqueID('app');
}
public function testGetEmptyOne() {
}
$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);
}
$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();
*/
class TestRepairLegacyStorages extends \Test\TestCase {
+ private $connection;
+ private $config;
private $user;
private $repair;
// 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(
$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));
class Memory extends Session {
protected function setUp() {
parent::setUp();
- $this->instance = new \OC\Session\Memory(uniqid());
+ $this->instance = new \OC\Session\Memory($this->getUniqueID());
}
}
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());
$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);
namespace Test;
+use OCP\Security\ISecureRandom;
+
abstract class TestCase extends \PHPUnit_Framework_TestCase {
/**
* Returns a unique identifier as uniqid() is not reliable sometimes
* @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
);
}
* 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);
* 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);
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());