diff options
author | Morris Jobke <hey@morrisjobke.de> | 2014-11-17 16:44:45 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2014-11-17 16:44:45 +0100 |
commit | 146cb920c9daba10da0bd93efab3e64df97224de (patch) | |
tree | d55b5e13f4b9903cc23b9946ce188e9ad8c62ad7 /tests | |
parent | 36528c6ef622876f9d89d3b0fbfafc8e44f569fb (diff) | |
parent | 6625d5c88f74edade459ec7e2ee0bfb79f21fedd (diff) | |
download | nextcloud-server-146cb920c9daba10da0bd93efab3e64df97224de.tar.gz nextcloud-server-146cb920c9daba10da0bd93efab3e64df97224de.zip |
Merge pull request #12218 from owncloud/issue/10991-fixes
Issue/10991 Make unit tests pass on windows
Diffstat (limited to 'tests')
32 files changed, 362 insertions, 149 deletions
diff --git a/tests/lib/app.php b/tests/lib/app.php index 5bce3b8c3e6..6ae548759ed 100644 --- a/tests/lib/app.php +++ b/tests/lib/app.php @@ -455,6 +455,9 @@ class Test_App extends PHPUnit_Framework_TestCase { \OC::$server->registerService('AppConfig', function ($c) use ($oldService){ return $oldService; }); + + // Remove the cache of the mocked apps list with a forceRefresh + \OC_App::getEnabledApps(true); } } diff --git a/tests/lib/archive/tar.php b/tests/lib/archive/tar.php index 5b9089b32e1..99f7fb30e2b 100644 --- a/tests/lib/archive/tar.php +++ b/tests/lib/archive/tar.php @@ -9,7 +9,7 @@ class Test_Archive_TAR extends Test_Archive { public function setUp() { if (OC_Util::runningOnWindows()) { - $this->markTestSkipped('tar archives are not supported on windows'); + $this->markTestSkipped('[Windows] tar archives are not supported on Windows'); } parent::setUp(); } diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php index 0e19c105cd1..8cc45c85405 100644 --- a/tests/lib/cache/file.php +++ b/tests/lib/cache/file.php @@ -23,8 +23,12 @@ namespace Test\Cache; class FileCache extends \Test_Cache { + /** @var string */ private $user; + /** @var string */ private $datadir; + /** @var \OC\Files\Storage\Storage */ + private $storage; function skip() { //$this->skipUnless(OC_User::isLoggedIn()); @@ -42,6 +46,7 @@ class FileCache extends \Test_Cache { //} //set up temporary storage + $this->storage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); $storage = new \OC\Files\Storage\Temporary(array()); \OC\Files\Filesystem::mount($storage,array(),'/'); @@ -68,5 +73,11 @@ class FileCache extends \Test_Cache { public function tearDown() { \OC_User::setUserId($this->user); \OC_Config::setValue('cachedirectory', $this->datadir); + + // Restore the original mount point + \OC\Files\Filesystem::clearMounts(); + \OC\Files\Filesystem::mount($this->storage, array(), '/'); + + parent::tearDown(); } } diff --git a/tests/lib/cache/usercache.php b/tests/lib/cache/usercache.php index a1b6af1c55d..8a23a805ebe 100644 --- a/tests/lib/cache/usercache.php +++ b/tests/lib/cache/usercache.php @@ -23,8 +23,12 @@ namespace Test\Cache; class UserCache extends \Test_Cache { + /** @var string */ private $user; + /** @var string */ private $datadir; + /** @var \OC\Files\Storage\Storage */ + private $storage; public function setUp() { //clear all proxies and hooks so we can do clean testing @@ -38,6 +42,7 @@ class UserCache extends \Test_Cache { //} //set up temporary storage + $this->storage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); $storage = new \OC\Files\Storage\Temporary(array()); \OC\Files\Filesystem::mount($storage,array(),'/'); @@ -63,5 +68,12 @@ class UserCache extends \Test_Cache { public function tearDown() { \OC_User::setUserId($this->user); + \OC_Config::setValue('cachedirectory', $this->datadir); + + // Restore the original mount point + \OC\Files\Filesystem::clearMounts(); + \OC\Files\Filesystem::mount($this->storage, array(), '/'); + + parent::tearDown(); } } diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php index 96b4207ad43..9e7330db20c 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -33,7 +33,13 @@ class Updater extends \PHPUnit_Framework_TestCase { */ protected $updater; - public function setUp() { + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + + protected function setUp() { + parent::setUp(); + + $this->originalStorage = Filesystem::getStorage('/'); $this->storage = new Temporary(array()); Filesystem::clearMounts(); Filesystem::mount($this->storage, array(), '/'); @@ -42,6 +48,13 @@ class Updater extends \PHPUnit_Framework_TestCase { $this->cache = $this->storage->getCache(); } + protected function tearDown() { + Filesystem::clearMounts(); + Filesystem::mount($this->originalStorage, array(), '/'); + + parent::tearDown(); + } + public function testNewFile() { $this->storage->file_put_contents('foo.txt', 'bar'); $this->assertFalse($this->cache->inCache('foo.txt')); diff --git a/tests/lib/files/cache/updaterlegacy.php b/tests/lib/files/cache/updaterlegacy.php index c80c3168ad6..d16a062fcca 100644 --- a/tests/lib/files/cache/updaterlegacy.php +++ b/tests/lib/files/cache/updaterlegacy.php @@ -29,6 +29,9 @@ class UpdaterLegacy extends \PHPUnit_Framework_TestCase { */ private $cache; + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + private static $user; public function setUp() { @@ -51,7 +54,8 @@ class UpdaterLegacy extends \PHPUnit_Framework_TestCase { $this->scanner->scan(''); $this->cache = $this->storage->getCache(); - \OC\Files\Filesystem::tearDown(); + $this->originalStorage = Filesystem::getStorage('/'); + Filesystem::tearDown(); if (!self::$user) { self::$user = uniqid(); } @@ -59,7 +63,7 @@ class UpdaterLegacy extends \PHPUnit_Framework_TestCase { \OC_User::createUser(self::$user, 'password'); \OC_User::setUserId(self::$user); - \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files'); + Filesystem::init(self::$user, '/' . self::$user . '/files'); Filesystem::clearMounts(); Filesystem::mount($this->storage, array(), '/' . self::$user . '/files'); @@ -74,6 +78,7 @@ class UpdaterLegacy extends \PHPUnit_Framework_TestCase { $result = \OC_User::deleteUser(self::$user); $this->assertTrue($result); Filesystem::tearDown(); + Filesystem::mount($this->originalStorage, array(), '/'); // reset app files_encryption if ($this->stateFilesEncryption) { \OC_App::enable('files_encryption'); diff --git a/tests/lib/files/cache/watcher.php b/tests/lib/files/cache/watcher.php index 22c11b9a4e0..0b04b9e7058 100644 --- a/tests/lib/files/cache/watcher.php +++ b/tests/lib/files/cache/watcher.php @@ -15,16 +15,27 @@ class Watcher extends \PHPUnit_Framework_TestCase { */ private $storages = array(); - public function setUp() { + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + + protected function setUp() { + parent::setUp(); + + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); } - public function tearDown() { + protected function tearDown() { foreach ($this->storages as $storage) { $cache = $storage->getCache(); $ids = $cache->getAll(); $cache->clear(); } + + \OC\Files\Filesystem::clearMounts(); + \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + + parent::tearDown(); } /** diff --git a/tests/lib/files/etagtest.php b/tests/lib/files/etagtest.php index b5dec107e79..8f29ed0bc63 100644 --- a/tests/lib/files/etagtest.php +++ b/tests/lib/files/etagtest.php @@ -11,7 +11,7 @@ namespace Test\Files; use OC\Files\Filesystem; use OCP\Share; -class EtagTest extends \PHPUnit_Framework_TestCase { +class EtagTest extends \Test\TestCase { private $datadir; private $tmpDir; @@ -23,7 +23,12 @@ class EtagTest extends \PHPUnit_Framework_TestCase { */ private $userBackend; - public function setUp() { + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + + protected function setUp() { + parent::setUp(); + \OC_Hook::clear('OC_Filesystem', 'setup'); \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup'); \OCP\Share::registerBackend('file', 'OC_Share_Backend_File'); @@ -37,13 +42,17 @@ class EtagTest extends \PHPUnit_Framework_TestCase { $this->userBackend = new \OC_User_Dummy(); \OC_User::useBackend($this->userBackend); + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC_Util::tearDownFS(); } - public function tearDown() { + protected function tearDown() { \OC_Config::setValue('datadirectory', $this->datadir); \OC_User::setUserId($this->uid); \OC_Util::setupFS($this->uid); + \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + + parent::tearDown(); } public function testNewUser() { diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php index 930a252bcb2..88e98fbb8c6 100644 --- a/tests/lib/files/filesystem.php +++ b/tests/lib/files/filesystem.php @@ -22,12 +22,15 @@ namespace Test\Files; -class Filesystem extends \PHPUnit_Framework_TestCase { +class Filesystem extends \Test\TestCase { /** * @var array tmpDirs */ private $tmpDirs = array(); + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + /** * @return array */ @@ -37,19 +40,23 @@ class Filesystem extends \PHPUnit_Framework_TestCase { return array('datadir' => $dir); } - public function tearDown() { + protected function setUp() { + parent::setUp(); + + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); + \OC_User::setUserId(''); + \OC\Files\Filesystem::clearMounts(); + } + + protected function tearDown() { foreach ($this->tmpDirs as $dir) { \OC_Helper::rmdirr($dir); } \OC\Files\Filesystem::clearMounts(); + \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); \OC_User::setUserId(''); } - public function setUp() { - \OC_User::setUserId(''); - \OC\Files\Filesystem::clearMounts(); - } - public function testMount() { \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', self::getStorageData(), '/'); $this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/')); diff --git a/tests/lib/files/node/integration.php b/tests/lib/files/node/integration.php index 319f2f9f5f7..cde2eb22b7b 100644 --- a/tests/lib/files/node/integration.php +++ b/tests/lib/files/node/integration.php @@ -20,6 +20,9 @@ class IntegrationTests extends \PHPUnit_Framework_TestCase { */ private $root; + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + /** * @var \OC\Files\Storage\Storage[] */ @@ -30,7 +33,10 @@ class IntegrationTests extends \PHPUnit_Framework_TestCase { */ private $view; - public function setUp() { + protected function setUp() { + parent::setUp(); + + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::init('', ''); \OC\Files\Filesystem::clearMounts(); $manager = \OC\Files\Filesystem::getMountManager(); @@ -54,11 +60,15 @@ class IntegrationTests extends \PHPUnit_Framework_TestCase { $this->root->mount($subStorage, '/substorage/'); } - public function tearDown() { + protected function tearDown() { foreach ($this->storages as $storage) { $storage->getCache()->clear(); } \OC\Files\Filesystem::clearMounts(); + + \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + + parent::tearDown(); } public function testBasicFile() { diff --git a/tests/lib/files/storage/home.php b/tests/lib/files/storage/home.php index 953fcfc8a6a..d085efe9c1c 100644 --- a/tests/lib/files/storage/home.php +++ b/tests/lib/files/storage/home.php @@ -75,7 +75,12 @@ class Home extends Storage { * Tests that the root path matches the data dir */ public function testRoot() { - $this->assertEquals($this->tmpDir, $this->instance->getLocalFolder('')); + if (\OC_Util::runningOnWindows()) { + // Windows removes trailing slashes when returning paths + $this->assertEquals(rtrim($this->tmpDir, '/'), $this->instance->getLocalFolder('')); + } else { + $this->assertEquals($this->tmpDir, $this->instance->getLocalFolder('')); + } } /** diff --git a/tests/lib/files/storage/local.php b/tests/lib/files/storage/local.php index 37462941d0c..490086c62f2 100644 --- a/tests/lib/files/storage/local.php +++ b/tests/lib/files/storage/local.php @@ -39,7 +39,7 @@ class Local extends Storage { public function testStableEtag() { if (\OC_Util::runningOnWindows()) { - $this->markTestSkipped('On Windows platform we have no stable etag generation - yet'); + $this->markTestSkipped('[Windows] On Windows platform we have no stable etag generation - yet'); } $this->instance->file_put_contents('test.txt', 'foobar'); @@ -50,7 +50,7 @@ class Local extends Storage { public function testEtagChange() { if (\OC_Util::runningOnWindows()) { - $this->markTestSkipped('On Windows platform we have no stable etag generation - yet'); + $this->markTestSkipped('[Windows] On Windows platform we have no stable etag generation - yet'); } $this->instance->file_put_contents('test.txt', 'foo'); diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php index 27b9b8dd4f4..db6a3fa7842 100644 --- a/tests/lib/files/utils/scanner.php +++ b/tests/lib/files/utils/scanner.php @@ -38,7 +38,23 @@ class TestScanner extends \OC\Files\Utils\Scanner { } } -class Scanner extends \PHPUnit_Framework_TestCase { + +class Scanner extends \Test\TestCase { + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + + protected function setUp() { + parent::setUp(); + + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); + } + + protected function tearDown() { + \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + + parent::tearDown(); + } + public function testReuseExistingRoot() { $storage = new Temporary(array()); $mount = new Mount($storage, ''); diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 086ac873bfb..44fea65e64e 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -23,9 +23,15 @@ class View extends \PHPUnit_Framework_TestCase { private $storages = array(); private $user; + /** @var \OC\Files\Storage\Storage */ private $tempStorage; - public function setUp() { + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + + protected function setUp() { + parent::setUp(); + \OC_User::clearBackends(); \OC_User::useBackend(new \OC_User_Dummy()); @@ -34,12 +40,13 @@ class View extends \PHPUnit_Framework_TestCase { $this->user = \OC_User::getUser(); \OC_User::setUserId('test'); + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); $this->tempStorage = null; } - public function tearDown() { + protected function tearDown() { \OC_User::setUserId($this->user); foreach ($this->storages as $storage) { $cache = $storage->getCache(); @@ -50,6 +57,11 @@ class View extends \PHPUnit_Framework_TestCase { if ($this->tempStorage && !\OC_Util::runningOnWindows()) { system('rm -rf ' . escapeshellarg($this->tempStorage->getDataDir())); } + + \OC\Files\Filesystem::clearMounts(); + \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + + parent::tearDown(); } /** @@ -599,7 +611,7 @@ class View extends \PHPUnit_Framework_TestCase { $folderName = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789'; $tmpdirLength = strlen(\OC_Helper::tmpFolder()); if (\OC_Util::runningOnWindows()) { - $this->markTestSkipped(); + $this->markTestSkipped('[Windows] '); $depth = ((260 - $tmpdirLength) / 57); }elseif(\OC_Util::runningOnMac()){ $depth = ((1024 - $tmpdirLength) / 57); diff --git a/tests/lib/group.php b/tests/lib/group.php index 724e723b187..795de695513 100644 --- a/tests/lib/group.php +++ b/tests/lib/group.php @@ -22,38 +22,39 @@ * */ -class Test_Group extends PHPUnit_Framework_TestCase { - function setUp() { +class Test_Group extends \Test\TestCase { + protected function setUp() { + parent::setUp(); OC_Group::clearBackends(); OC_User::clearBackends(); } - function testSingleBackend() { + public function testSingleBackend() { $userBackend = new \OC_User_Dummy(); \OC_User::getManager()->registerBackend($userBackend); OC_Group::useBackend(new OC_Group_Dummy()); - $group1 = uniqid(); - $group2 = uniqid(); + $group1 = $this->getUniqueID(); + $group2 = $this->getUniqueID(); OC_Group::createGroup($group1); OC_Group::createGroup($group2); - $user1 = uniqid(); - $user2 = uniqid(); + $user1 = $this->getUniqueID(); + $user2 = $this->getUniqueID(); $userBackend->createUser($user1, ''); $userBackend->createUser($user2, ''); - $this->assertFalse(OC_Group::inGroup($user1, $group1)); - $this->assertFalse(OC_Group::inGroup($user2, $group1)); - $this->assertFalse(OC_Group::inGroup($user1, $group2)); - $this->assertFalse(OC_Group::inGroup($user2, $group2)); + $this->assertFalse(OC_Group::inGroup($user1, $group1), 'Asserting that user1 is not in group1'); + $this->assertFalse(OC_Group::inGroup($user2, $group1), 'Asserting that user2 is not in group1'); + $this->assertFalse(OC_Group::inGroup($user1, $group2), 'Asserting that user1 is not in group2'); + $this->assertFalse(OC_Group::inGroup($user2, $group2), 'Asserting that user2 is not in group2'); $this->assertTrue(OC_Group::addToGroup($user1, $group1)); - $this->assertTrue(OC_Group::inGroup($user1, $group1)); - $this->assertFalse(OC_Group::inGroup($user2, $group1)); - $this->assertFalse(OC_Group::inGroup($user1, $group2)); - $this->assertFalse(OC_Group::inGroup($user2, $group2)); + $this->assertTrue(OC_Group::inGroup($user1, $group1), 'Asserting that user1 is in group1'); + $this->assertFalse(OC_Group::inGroup($user2, $group1), 'Asserting that user2 is not in group1'); + $this->assertFalse(OC_Group::inGroup($user1, $group2), 'Asserting that user1 is not in group2'); + $this->assertFalse(OC_Group::inGroup($user2, $group2), 'Asserting that user2 is not in group2'); $this->assertTrue(OC_Group::addToGroup($user1, $group1)); @@ -80,7 +81,7 @@ class Test_Group extends PHPUnit_Framework_TestCase { public function testNoGroupsTwice() { OC_Group::useBackend(new OC_Group_Dummy()); - $group = uniqid(); + $group = $this->getUniqueID(); OC_Group::createGroup($group); $groupCopy = $group; @@ -103,7 +104,7 @@ class Test_Group extends PHPUnit_Framework_TestCase { public function testDontAddUserToNonexistentGroup() { OC_Group::useBackend(new OC_Group_Dummy()); $groupNonExistent = 'notExistent'; - $user = uniqid(); + $user = $this->getUniqueID(); $this->assertEquals(false, OC_Group::addToGroup($user, $groupNonExistent)); $this->assertEquals(array(), OC_Group::getGroups()); @@ -114,12 +115,12 @@ class Test_Group extends PHPUnit_Framework_TestCase { $userBackend = new \OC_User_Dummy(); \OC_User::getManager()->registerBackend($userBackend); - $group1 = uniqid(); - $group2 = uniqid(); - $group3 = uniqid(); - $user1 = uniqid(); - $user2 = uniqid(); - $user3 = uniqid(); + $group1 = $this->getUniqueID(); + $group2 = $this->getUniqueID(); + $group3 = $this->getUniqueID(); + $user1 = $this->getUniqueID(); + $user2 = $this->getUniqueID(); + $user3 = $this->getUniqueID(); OC_Group::createGroup($group1); OC_Group::createGroup($group2); OC_Group::createGroup($group3); @@ -139,8 +140,7 @@ class Test_Group extends PHPUnit_Framework_TestCase { // FIXME: needs more parameter variation } - - function testMultiBackend() { + public function testMultiBackend() { $userBackend = new \OC_User_Dummy(); \OC_User::getManager()->registerBackend($userBackend); $backend1 = new OC_Group_Dummy(); @@ -148,8 +148,8 @@ class Test_Group extends PHPUnit_Framework_TestCase { OC_Group::useBackend($backend1); OC_Group::useBackend($backend2); - $group1 = uniqid(); - $group2 = uniqid(); + $group1 = $this->getUniqueID(); + $group2 = $this->getUniqueID(); OC_Group::createGroup($group1); //groups should be added to the first registered backend @@ -166,8 +166,8 @@ class Test_Group extends PHPUnit_Framework_TestCase { $this->assertTrue(OC_Group::groupExists($group1)); $this->assertTrue(OC_Group::groupExists($group2)); - $user1 = uniqid(); - $user2 = uniqid(); + $user1 = $this->getUniqueID(); + $user2 = $this->getUniqueID(); $userBackend->createUser($user1, ''); $userBackend->createUser($user2, ''); diff --git a/tests/lib/group/backend.php b/tests/lib/group/backend.php index 95a5cf5f49c..62c189489d7 100644 --- a/tests/lib/group/backend.php +++ b/tests/lib/group/backend.php @@ -20,7 +20,7 @@ * */ -abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase { +abstract class Test_Group_Backend extends \Test\TestCase { /** * @var OC_Group_Backend $backend */ @@ -33,7 +33,7 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase { */ public function getGroupName($name = null) { if(is_null($name)) { - return uniqid('test_'); + return $this->getUniqueID('test_'); } else { return $name; } @@ -45,7 +45,7 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase { * @return string */ public function getUserName() { - return uniqid('test_'); + return $this->getUniqueID('test_'); } public function testAddRemove() { @@ -138,6 +138,4 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase { $result = $this->backend->countUsersInGroup($group, 'bar'); $this->assertSame(2, $result); } - - } diff --git a/tests/lib/group/database.php b/tests/lib/group/database.php index 9b39ac00452..10958a6ccdc 100644 --- a/tests/lib/group/database.php +++ b/tests/lib/group/database.php @@ -22,36 +22,27 @@ class Test_Group_Database extends Test_Group_Backend { private $groups=array(); - + /** * get a new unique group name * test cases can override this in order to clean up created groups * @return string */ public function getGroupName($name = null) { - if(is_null($name)) { - $name=uniqid('test_'); - } - $this->groups[]=$name; + $name = parent::getGroupName($name); + $this->groups[] = $name; return $name; } - /** - * get a new unique user name - * test cases can override this in order to clean up created user - * @return string - */ - public function getUserName() { - return uniqid('test_'); - } - - public function setUp() { + protected function setUp() { + parent::setUp(); $this->backend=new OC_Group_Database(); } - public function tearDown() { + protected function tearDown() { foreach($this->groups as $group) { $this->backend->deleteGroup($group); } + parent::tearDown(); } } diff --git a/tests/lib/group/dummy.php b/tests/lib/group/dummy.php index 287d6f1a977..b4456c8f7e1 100644 --- a/tests/lib/group/dummy.php +++ b/tests/lib/group/dummy.php @@ -21,7 +21,8 @@ */ class Test_Group_Dummy extends Test_Group_Backend { - public function setUp() { + protected function setUp() { + parent::setUp(); $this->backend=new OC_Group_Dummy(); } } diff --git a/tests/lib/helper.php b/tests/lib/helper.php index 520a3e0e669..57c72c11987 100644 --- a/tests/lib/helper.php +++ b/tests/lib/helper.php @@ -115,6 +115,10 @@ class Test_Helper extends PHPUnit_Framework_TestCase { } function testGetStringMimeType() { + if (\OC_Util::runningOnWindows()) { + $this->markTestSkipped('[Windows] Strings have mimetype application/octet-stream on Windows'); + } + $result = OC_Helper::getStringMimeType("/data/data.tar.gz"); $expected = 'text/plain; charset=us-ascii'; $this->assertEquals($result, $expected); diff --git a/tests/lib/helperstorage.php b/tests/lib/helperstorage.php index 4fdd9dd6b9b..9f3bd8824f7 100644 --- a/tests/lib/helperstorage.php +++ b/tests/lib/helperstorage.php @@ -9,14 +9,22 @@ /** * Test the storage functions of OC_Helper */ -class Test_Helper_Storage extends PHPUnit_Framework_TestCase { + +class Test_Helper_Storage extends \Test\TestCase { + /** @var string */ private $user; + /** @var \OC\Files\Storage\Storage */ private $storageMock; + /** @var \OC\Files\Storage\Storage */ + private $storage; + + protected function setUp() { + parent::setUp(); - public function setUp() { - $this->user = 'user_' . uniqid(); + $this->user = $this->getUniqueID('user_'); \OC_User::createUser($this->user, $this->user); + $this->storage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::tearDown(); \OC_User::setUserId($this->user); \OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files'); @@ -25,7 +33,7 @@ class Test_Helper_Storage extends PHPUnit_Framework_TestCase { $this->storageMock = null; } - public function tearDown() { + protected function tearDown() { $this->user = null; if ($this->storageMock) { @@ -33,10 +41,13 @@ class Test_Helper_Storage extends PHPUnit_Framework_TestCase { $this->storageMock = null; } \OC\Files\Filesystem::tearDown(); + \OC\Files\Filesystem::mount($this->storage, array(), '/'); \OC_User::setUserId(''); \OC_User::deleteUser($this->user); \OC_Preferences::deleteUser($this->user); + + parent::tearDown(); } /** diff --git a/tests/lib/image.php b/tests/lib/image.php index 795bc464159..a683c3d2c8b 100644 --- a/tests/lib/image.php +++ b/tests/lib/image.php @@ -62,14 +62,18 @@ class Test_Image extends PHPUnit_Framework_TestCase { $img = new \OC_Image(OC::$SERVERROOT.'/tests/data/testimage.png'); $this->assertEquals('image/png', $img->mimeType()); + $img = new \OC_Image(null); + $this->assertEquals('', $img->mimeType()); + + if (\OC_Util::runningOnWindows()) { + $this->markTestSkipped('[Windows] Images created with imagecreate() are pngs on windows'); + } + $img = new \OC_Image(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg')); $this->assertEquals('image/jpeg', $img->mimeType()); $img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.gif'))); $this->assertEquals('image/gif', $img->mimeType()); - - $img = new \OC_Image(null); - $this->assertEquals('', $img->mimeType()); } public function testWidth() { diff --git a/tests/lib/largefilehelpergetfilesize.php b/tests/lib/largefilehelpergetfilesize.php index 58571d641e0..90ecc3dde70 100644 --- a/tests/lib/largefilehelpergetfilesize.php +++ b/tests/lib/largefilehelpergetfilesize.php @@ -13,58 +13,77 @@ namespace Test; * Large files are not considered yet. */ class LargeFileHelperGetFileSize extends \PHPUnit_Framework_TestCase { - protected $filename; - protected $fileSize; + /** @var \OC\LargeFileHelper */ protected $helper; public function setUp() { parent::setUp(); - $ds = DIRECTORY_SEPARATOR; - $this->filename = dirname(__DIR__) . "{$ds}data{$ds}strängé filename (duplicate #2).txt"; - $this->fileSize = 446; - $this->helper = new \OC\LargeFileHelper; + $this->helper = new \OC\LargeFileHelper(); } - public function testGetFileSizeViaCurl() { + public function dataFileNameProvider() { + $path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR; + + $filePaths = array(array($path . 'lorem.txt', 446)); + if (!\OC_Util::runningOnWindows()) { + $filePaths[] = array($path . 'strängé filename (duplicate #2).txt', 446); + } + + return $filePaths; + } + + /** + * @dataProvider dataFileNameProvider + */ + public function testGetFileSizeViaCurl($filename, $fileSize) { if (!extension_loaded('curl')) { $this->markTestSkipped( 'The PHP curl extension is required for this test.' ); } $this->assertSame( - $this->fileSize, - $this->helper->getFileSizeViaCurl($this->filename) + $fileSize, + $this->helper->getFileSizeViaCurl($filename) ); } - public function testGetFileSizeViaCOM() { + /** + * @dataProvider dataFileNameProvider + */ + public function testGetFileSizeViaCOM($filename, $fileSize) { if (!extension_loaded('COM')) { $this->markTestSkipped( 'The PHP Windows COM extension is required for this test.' ); } $this->assertSame( - $this->fileSize, - $this->helper->getFileSizeViaCOM($this->filename) + $fileSize, + $this->helper->getFileSizeViaCOM($filename) ); } - public function testGetFileSizeViaExec() { + /** + * @dataProvider dataFileNameProvider + */ + public function testGetFileSizeViaExec($filename, $fileSize) { if (!\OC_Helper::is_function_enabled('exec')) { $this->markTestSkipped( 'The exec() function needs to be enabled for this test.' ); } $this->assertSame( - $this->fileSize, - $this->helper->getFileSizeViaExec($this->filename) + $fileSize, + $this->helper->getFileSizeViaExec($filename) ); } - public function testGetFileSizeNative() { + /** + * @dataProvider dataFileNameProvider + */ + public function testGetFileSizeNative($filename, $fileSize) { $this->assertSame( - $this->fileSize, - $this->helper->getFileSizeNative($this->filename) + $fileSize, + $this->helper->getFileSizeNative($filename) ); } } diff --git a/tests/lib/migrate.php b/tests/lib/migrate.php index c4442511e1f..3f87bbc1ac8 100644 --- a/tests/lib/migrate.php +++ b/tests/lib/migrate.php @@ -11,6 +11,28 @@ class Test_Migrate extends PHPUnit_Framework_TestCase { public $users; public $tmpfiles = array(); + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + + protected function setUp() { + parent::setUp(); + + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); + } + + protected function tearDown() { + $u = new OC_User(); + foreach($this->users as $user) { + $u->deleteUser($user); + } + foreach($this->tmpfiles as $file) { + \OC_Helper::rmdirr($file); + } + + \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + parent::tearDown(); + } + /** * Generates a test user and sets up their file system * @return string the test users id @@ -73,18 +95,4 @@ class Test_Migrate extends PHPUnit_Framework_TestCase { // Validate the export $this->validateUserExport($user2, $user, json_decode($export)->data); } - - public function tearDown() { - $u = new OC_User(); - foreach($this->users as $user) { - $u->deleteUser($user); - } - foreach($this->tmpfiles as $file) { - \OC_Helper::rmdirr($file); - } - } - - - - } diff --git a/tests/lib/preview.php b/tests/lib/preview.php index 2febe524cba..288dd2aa417 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -8,7 +8,7 @@ namespace Test; -class Preview extends \PHPUnit_Framework_TestCase { +class Preview extends \Test\TestCase { /** * @var string @@ -20,14 +20,34 @@ class Preview extends \PHPUnit_Framework_TestCase { */ private $rootView; - public function setUp() { - $this->user = $this->initFS(); + /** @var \OC\Files\Storage\Storage */ + private $originalStorage; + + protected function setUp() { + parent::setUp(); + + $this->originalStorage = \OC\Files\Filesystem::getStorage('/'); + + // create a new user with his own filesystem view + // this gets called by each test in this test class + $this->user = $this->getUniqueID(); + \OC_User::setUserId($this->user); + \OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files'); + + \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/'); $this->rootView = new \OC\Files\View(''); $this->rootView->mkdir('/'.$this->user); $this->rootView->mkdir('/'.$this->user.'/files'); } + protected function tearDown() { + \OC\Files\Filesystem::clearMounts(); + \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); + + parent::tearDown(); + } + public function testIsPreviewDeleted() { $sampleFile = '/'.$this->user.'/files/test.txt'; @@ -184,16 +204,4 @@ class Preview extends \PHPUnit_Framework_TestCase { $this->assertEquals($this->user . '/' . \OC\Preview::THUMBNAILS_FOLDER . '/' . $fileId . '/150-150.png', $isCached); } */ - - private function initFS() { - // create a new user with his own filesystem view - // this gets called by each test in this test class - $user=uniqid(); - \OC_User::setUserId($user); - \OC\Files\Filesystem::init($user, '/'.$user.'/files'); - - \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/'); - - return $user; - } } diff --git a/tests/lib/security/certificatemanager.php b/tests/lib/security/certificatemanager.php index 5baf9e16e81..01b3afb03ee 100644 --- a/tests/lib/security/certificatemanager.php +++ b/tests/lib/security/certificatemanager.php @@ -8,7 +8,7 @@ use \OC\Security\CertificateManager; -class CertificateManagerTest extends \PHPUnit_Framework_TestCase { +class CertificateManagerTest extends \Test\TestCase { /** @var CertificateManager */ private $certificateManager; @@ -18,8 +18,8 @@ class CertificateManagerTest extends \PHPUnit_Framework_TestCase { private $user; function setUp() { - $this->username = OC_Util::generateRandomBytes(20); - OC_User::createUser($this->username, OC_Util::generateRandomBytes(20)); + $this->username = $this->getUniqueID('', 20); + OC_User::createUser($this->username, $this->getUniqueID('', 20)); \OC_Util::tearDownFS(); \OC_User::setUserId(''); diff --git a/tests/lib/streamwrappers.php b/tests/lib/streamwrappers.php index 1b61446f4dc..6f92f487037 100644 --- a/tests/lib/streamwrappers.php +++ b/tests/lib/streamwrappers.php @@ -65,7 +65,9 @@ class Test_StreamWrappers extends PHPUnit_Framework_TestCase { } public function testOC() { + $originalStorage = \OC\Files\Filesystem::getStorage('/'); \OC\Files\Filesystem::clearMounts(); + $storage = new \OC\Files\Storage\Temporary(array()); $storage->file_put_contents('foo.txt', 'asd'); \OC\Files\Filesystem::mount($storage, array(), '/'); @@ -91,5 +93,8 @@ class Test_StreamWrappers extends PHPUnit_Framework_TestCase { unlink('oc:///foo.txt'); $this->assertEquals(array('.', '..', 'bar.txt'), scandir('oc:///')); + + \OC\Files\Filesystem::clearMounts(); + \OC\Files\Filesystem::mount($originalStorage, array(), '/'); } } diff --git a/tests/lib/tempmanager.php b/tests/lib/tempmanager.php index f16fbce2c7c..85b94094393 100644 --- a/tests/lib/tempmanager.php +++ b/tests/lib/tempmanager.php @@ -122,6 +122,10 @@ class TempManager extends \PHPUnit_Framework_TestCase { } public function testLogCantCreateFile() { + if (\OC_Util::runningOnWindows()) { + $this->markTestSkipped('[Windows] chmod() does not work as intended on Windows.'); + } + $logger = $this->getMock('\Test\NullLogger'); $manager = $this->getManager($logger); chmod($this->baseDir, 0500); @@ -132,6 +136,10 @@ class TempManager extends \PHPUnit_Framework_TestCase { } public function testLogCantCreateFolder() { + if (\OC_Util::runningOnWindows()) { + $this->markTestSkipped('[Windows] chmod() does not work as intended on Windows.'); + } + $logger = $this->getMock('\Test\NullLogger'); $manager = $this->getManager($logger); chmod($this->baseDir, 0500); diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php new file mode 100644 index 00000000000..a4b4b0103f0 --- /dev/null +++ b/tests/lib/testcase.php @@ -0,0 +1,33 @@ +<?php +/** + * ownCloud + * + * @author Joas Schilling + * @copyright 2014 Joas Schilling nickvergessen@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace Test; + +abstract class TestCase extends \PHPUnit_Framework_TestCase { + protected function getUniqueID($prefix = '', $length = 13) { + // Do not use dots and slashes as we use the value for file names + return $prefix . \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate( + $length, + '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + ); + } +} diff --git a/tests/lib/user/backend.php b/tests/lib/user/backend.php index 0d3914c7ca6..c2040f4e3be 100644 --- a/tests/lib/user/backend.php +++ b/tests/lib/user/backend.php @@ -30,7 +30,7 @@ * For an example see /tests/lib/user/dummy.php */ -abstract class Test_User_Backend extends PHPUnit_Framework_TestCase { +abstract class Test_User_Backend extends \Test\TestCase { /** * @var OC_User_Backend $backend */ @@ -42,7 +42,7 @@ abstract class Test_User_Backend extends PHPUnit_Framework_TestCase { * @return string */ public function getUser() { - return uniqid('test_'); + return $this->getUniqueID('test_'); } public function testAddRemove() { @@ -68,29 +68,29 @@ abstract class Test_User_Backend extends PHPUnit_Framework_TestCase { $this->assertTrue((array_search($name1, $this->backend->getUsers())!==false)); $this->assertFalse((array_search($name2, $this->backend->getUsers())!==false)); } - + public function testLogin() { $name1=$this->getUser(); $name2=$this->getUser(); - + $this->assertFalse($this->backend->userExists($name1)); $this->assertFalse($this->backend->userExists($name2)); - + $this->backend->createUser($name1, 'pass1'); $this->backend->createUser($name2, 'pass2'); - + $this->assertTrue($this->backend->userExists($name1)); $this->assertTrue($this->backend->userExists($name2)); - + $this->assertSame($name1, $this->backend->checkPassword($name1, 'pass1')); $this->assertSame($name2, $this->backend->checkPassword($name2, 'pass2')); - + $this->assertFalse($this->backend->checkPassword($name1, 'pass2')); $this->assertFalse($this->backend->checkPassword($name2, 'pass1')); - + $this->assertFalse($this->backend->checkPassword($name1, 'dummy')); $this->assertFalse($this->backend->checkPassword($name2, 'foobar')); - + $this->backend->setPassword($name1, 'newpass1'); $this->assertFalse($this->backend->checkPassword($name1, 'pass1')); $this->assertSame($name1, $this->backend->checkPassword($name1, 'newpass1')); @@ -112,5 +112,4 @@ abstract class Test_User_Backend extends PHPUnit_Framework_TestCase { $result = $this->backend->getDisplayNames('bar'); $this->assertSame(2, count($result)); } - } diff --git a/tests/lib/user/database.php b/tests/lib/user/database.php index a8e497720c2..3a6be1ceee5 100644 --- a/tests/lib/user/database.php +++ b/tests/lib/user/database.php @@ -21,22 +21,27 @@ */ class Test_User_Database extends Test_User_Backend { + /** @var array */ + private $users; + public function getUser() { $user = parent::getUser(); $this->users[]=$user; return $user; } - - public function setUp() { + + protected function setUp() { + parent::setUp(); $this->backend=new OC_User_Database(); } - - public function tearDown() { + + protected function tearDown() { if(!isset($this->users)) { return; } foreach($this->users as $user) { $this->backend->deleteUser($user); } + parent::tearDown(); } } diff --git a/tests/lib/user/dummy.php b/tests/lib/user/dummy.php index e417fd97603..fcc921de4b1 100644 --- a/tests/lib/user/dummy.php +++ b/tests/lib/user/dummy.php @@ -21,7 +21,8 @@ */ class Test_User_Dummy extends Test_User_Backend { - public function setUp() { + protected function setUp() { + parent::setUp(); $this->backend=new OC_User_Dummy(); } } diff --git a/tests/lib/utilcheckserver.php b/tests/lib/utilcheckserver.php index be5596c1900..73a1d0e95a6 100644 --- a/tests/lib/utilcheckserver.php +++ b/tests/lib/utilcheckserver.php @@ -138,6 +138,10 @@ class Test_Util_CheckServer extends PHPUnit_Framework_TestCase { * Tests an error is given when the datadir is not writable */ public function testDataDirNotWritable() { + if (\OC_Util::runningOnWindows()) { + $this->markTestSkipped('[Windows] chmod() does not work as intended on Windows.'); + } + chmod($this->datadir, 0300); $result = \OC_Util::checkServer($this->getConfig(array( 'installed' => true, |