* This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ namespace Test; use OC\Files\Storage\Temporary; use OCP\Files\Mount\IMountManager; use OCP\IConfig; use Test\Traits\UserTrait; /** * Test the storage functions of OC_Helper * * @group DB */ class HelperStorageTest extends \Test\TestCase { use UserTrait; /** @var string */ private $user; /** @var \OC\Files\Storage\Storage */ private $storageMock; /** @var \OC\Files\Storage\Storage */ private $storage; private bool $savedQuotaIncludeExternalStorage; protected function setUp(): void { parent::setUp(); $this->user = $this->getUniqueID('user_'); $this->createUser($this->user, $this->user); $this->savedQuotaIncludeExternalStorage = $this->getIncludeExternalStorage(); \OC\Files\Filesystem::tearDown(); \OC_User::setUserId($this->user); \OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files'); /** @var IMountManager $manager */ $manager = \OC::$server->get(IMountManager::class); $manager->removeMount('/' . $this->user); $this->storageMock = null; } protected function tearDown(): void { $this->setIncludeExternalStorage($this->savedQuotaIncludeExternalStorage); $this->user = null; if ($this->storageMock) { $this->storageMock->getCache()->clear(); $this->storageMock = null; } \OC\Files\Filesystem::tearDown(); \OC_User::setUserId(''); \OC::$server->getConfig()->deleteAllUserValues($this->user); parent::tearDown(); } /** * Returns a storage mock that returns the given value as * free space * * @param int $freeSpace free space value * @return \OC\Files\Storage\Storage */ private function getStorageMock($freeSpace = 12) { $this->storageMock = $this->getMockBuilder(Temporary::class) ->setMethods(['free_space']) ->setConstructorArgs(['']) ->getMock(); $this->storageMock->expects($this->once()) ->method('free_space') ->willReturn(12); return $this->storageMock; } /** * Test getting the storage info */ public function testGetStorageInfo() { $homeStorage = $this->getStorageMock(12); \OC\Files\Filesystem::mount($homeStorage, [], '/' . $this->user . '/files'); $homeStorage->file_put_contents('test.txt', '01234'); $storageInfo = \OC_Helper::getStorageInfo(''); $this->assertEquals(12, $storageInfo['free']); $this->assertEquals(5, $storageInfo['used']); $this->assertEquals(17, $storageInfo['total']); } private function getIncludeExternalStorage(): bool { $class = new \ReflectionClass(\OC_Helper::class); $prop = $class->getProperty('quotaIncludeExternalStorage'); $prop->setAccessible(true); return $prop->getValue(null) ?? false; } private function setIncludeExternalStorage(bool $include) { $class = new \ReflectionClass(\OC_Helper::class); $prop = $class->getProperty('quotaIncludeExternalStorage'); $prop->setAccessible(true); $prop->setValue(null, $include); } /** * Test getting the storage info, ignoring extra mount points */ public function testGetStorageInfoExcludingExtStorage() { $homeStorage = $this->getStorageMock(12); \OC\Files\Filesystem::mount($homeStorage, [], '/' . $this->user . '/files'); $homeStorage->file_put_contents('test.txt', '01234'); $extStorage = new \OC\Files\Storage\Temporary([]); $extStorage->file_put_contents('extfile.txt', 'abcdefghijklmnopq'); $extStorage->getScanner()->scan(''); // update root size $this->setIncludeExternalStorage(false); \OC\Files\Filesystem::mount($extStorage, [], '/' . $this->user . '/files/ext'); $storageInfo = \OC_Helper::getStorageInfo(''); $this->assertEquals(12, $storageInfo['free']); $this->assertEquals(5, $storageInfo['used']); $this->assertEquals(17, $storageInfo['total']); } /** * Test getting the storage info, including extra mount points */ public function testGetStorageInfoIncludingExtStorage() { $homeStorage = new \OC\Files\Storage\Temporary([]); \OC\Files\Filesystem::mount($homeStorage, [], '/' . $this->user . '/files'); $homeStorage->file_put_contents('test.txt', '01234'); $extStorage = new \OC\Files\Storage\Temporary([]); $extStorage->file_put_contents('extfile.txt', 'abcdefghijklmnopq'); $extStorage->getScanner()->scan(''); // update root size \OC\Files\Filesystem::mount($extStorage, [], '/' . $this->user . '/files/ext'); $this->setIncludeExternalStorage(true); $config = \OC::$server->get(IConfig::class); $config->setUserValue($this->user, 'files', 'quota', '25'); $storageInfo = \OC_Helper::getStorageInfo(''); $this->assertEquals(3, $storageInfo['free']); $this->assertEquals(22, $storageInfo['used']); $this->assertEquals(25, $storageInfo['total']); $config->setUserValue($this->user, 'files', 'quota', 'default'); } /** * Test getting the storage info excluding extra mount points * when user has no quota set, even when quota ext storage option * was set */ public function testGetStorageInfoIncludingExtStorageWithNoUserQuota() { $homeStorage = $this->getStorageMock(12); \OC\Files\Filesystem::mount($homeStorage, [], '/' . $this->user . '/files'); $homeStorage->file_put_contents('test.txt', '01234'); $extStorage = new \OC\Files\Storage\Temporary([]); $extStorage->file_put_contents('extfile.txt', 'abcdefghijklmnopq'); $extStorage->getScanner()->scan(''); // update root size \OC\Files\Filesystem::mount($extStorage, [], '/' . $this->user . '/files/ext'); $config = \OC::$server->getConfig(); $this->setIncludeExternalStorage(true); $storageInfo = \OC_Helper::getStorageInfo(''); $this->assertEquals(12, $storageInfo['free'], '12 bytes free in home storage'); $this->assertEquals(22, $storageInfo['used'], '5 bytes of home storage and 17 bytes of the temporary storage are used'); $this->assertEquals(34, $storageInfo['total'], '5 bytes used and 12 bytes free in home storage as well as 17 bytes used in temporary storage'); } /** * Test getting the storage info with quota enabled */ public function testGetStorageInfoWithQuota() { $homeStorage = $this->getStorageMock(12); $homeStorage->file_put_contents('test.txt', '01234'); $homeStorage = new \OC\Files\Storage\Wrapper\Quota( [ 'storage' => $homeStorage, 'quota' => 7 ] ); \OC\Files\Filesystem::mount($homeStorage, [], '/' . $this->user . '/files'); $storageInfo = \OC_Helper::getStorageInfo(''); $this->assertEquals(2, $storageInfo['free']); $this->assertEquals(5, $storageInfo['used']); $this->assertEquals(7, $storageInfo['total']); } /** * Test getting the storage info when data exceeds quota */ public function testGetStorageInfoWhenSizeExceedsQuota() { $homeStorage = $this->getStorageMock(12); $homeStorage->file_put_contents('test.txt', '0123456789'); $homeStorage = new \OC\Files\Storage\Wrapper\Quota( [ 'storage' => $homeStorage, 'quota' => 7 ] ); \OC\Files\Filesystem::mount($homeStorage, [], '/' . $this->user . '/files'); $storageInfo = \OC_Helper::getStorageInfo(''); $this->assertEquals(0, $storageInfo['free']); $this->assertEquals(10, $storageInfo['used']); // total = quota $this->assertEquals(7, $storageInfo['total']); } /** * Test getting the storage info when the remaining * free storage space is less than the quota */ public function testGetStorageInfoWhenFreeSpaceLessThanQuota() { $homeStorage = $this->getStorageMock(12); $homeStorage->file_put_contents('test.txt', '01234'); $homeStorage = new \OC\Files\Storage\Wrapper\Quota( [ 'storage' => $homeStorage, 'quota' => 18 ] ); \OC\Files\Filesystem::mount($homeStorage, [], '/' . $this->user . '/files'); $storageInfo = \OC_Helper::getStorageInfo(''); $this->assertEquals(12, $storageInfo['free']); $this->assertEquals(5, $storageInfo['used']); // total = free + used (because quota > total) $this->assertEquals(17, $storageInfo['total']); } } yword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Effects - toggleClass Demo</title>
<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
<script src="../../jquery-1.10.2.js"></script>
<script src="../../ui/jquery.ui.effect.js"></script>
<link rel="stylesheet" href="../demos.css">
<style>
.toggler { width: 500px; height: 200px; position: relative; }
#button { padding: .5em 1em; text-decoration: none; }
#effect {position: relative; width: 240px; padding: 1em; letter-spacing: 0; font-size: 1.2em; border: 1px solid #000; background: #eee; color: #333; }
.newClass { text-indent: 40px; letter-spacing: .4em; width: 410px; height: 100px; padding: 30px; margin: 10px; font-size: 1.6em; }
</style>
<script>
$(function() {
$( "#button" ).click(function() {
$( "#effect" ).toggleClass( "newClass", 1000 );
return false;
});
});
</script>
</head>
<body>
<div class="toggler">
<div id="effect" class="newClass ui-corner-all">
Etiam libero neque, luctus a, eleifend nec, semper at, lorem. Sed pede.
</div>
</div>
<a href="#" id="button" class="ui-state-default ui-corner-all">Run Effect</a>
<div class="demo-description">
<p>Click the button above to preview the effect.</p>
</div>
</body>
</html>