1010
1111use OC \Files \Storage \Temporary ;
1212use OCP \Files \Mount \IMountManager ;
13+ use OCP \IConfig ;
1314use Test \Traits \UserTrait ;
1415
1516/**
@@ -26,12 +27,14 @@ class HelperStorageTest extends \Test\TestCase {
2627 private $ storageMock ;
2728 /** @var \OC\Files\Storage\Storage */
2829 private $ storage ;
30+ private bool $ savedQuotaIncludeExternalStorage ;
2931
3032 protected function setUp (): void {
3133 parent ::setUp ();
3234
3335 $ this ->user = $ this ->getUniqueID ('user_ ' );
3436 $ this ->createUser ($ this ->user , $ this ->user );
37+ $ this ->savedQuotaIncludeExternalStorage = $ this ->getIncludeExternalStorage ();
3538
3639 \OC \Files \Filesystem::tearDown ();
3740 \OC_User::setUserId ($ this ->user );
@@ -45,6 +48,7 @@ protected function setUp(): void {
4548 }
4649
4750 protected function tearDown (): void {
51+ $ this ->setIncludeExternalStorage ($ this ->savedQuotaIncludeExternalStorage );
4852 $ this ->user = null ;
4953
5054 if ($ this ->storageMock ) {
@@ -91,6 +95,19 @@ public function testGetStorageInfo() {
9195 $ this ->assertEquals (5 , $ storageInfo ['used ' ]);
9296 $ this ->assertEquals (17 , $ storageInfo ['total ' ]);
9397 }
98+ private function getIncludeExternalStorage (): bool {
99+ $ class = new \ReflectionClass (\OC_Helper::class);
100+ $ prop = $ class ->getProperty ('quotaIncludeExternalStorage ' );
101+ $ prop ->setAccessible (true );
102+ return $ prop ->getValue (null ) ?? false ;
103+ }
104+
105+ private function setIncludeExternalStorage (bool $ include ) {
106+ $ class = new \ReflectionClass (\OC_Helper::class);
107+ $ prop = $ class ->getProperty ('quotaIncludeExternalStorage ' );
108+ $ prop ->setAccessible (true );
109+ $ prop ->setValue (null , $ include );
110+ }
94111
95112 /**
96113 * Test getting the storage info, ignoring extra mount points
@@ -104,8 +121,7 @@ public function testGetStorageInfoExcludingExtStorage() {
104121 $ extStorage ->file_put_contents ('extfile.txt ' , 'abcdefghijklmnopq ' );
105122 $ extStorage ->getScanner ()->scan ('' ); // update root size
106123
107- $ config = \OC ::$ server ->getConfig ();
108- $ config ->setSystemValue ('quota_include_external_storage ' , false );
124+ $ this ->setIncludeExternalStorage (false );
109125
110126 \OC \Files \Filesystem::mount ($ extStorage , [], '/ ' . $ this ->user . '/files/ext ' );
111127
@@ -129,18 +145,16 @@ public function testGetStorageInfoIncludingExtStorage() {
129145
130146 \OC \Files \Filesystem::mount ($ extStorage , [], '/ ' . $ this ->user . '/files/ext ' );
131147
132- $ config = \OC ::$ server ->getConfig ();
133- $ oldConfig = $ config ->getSystemValue ('quota_include_external_storage ' , false );
134- $ config ->setSystemValue ('quota_include_external_storage ' , 'true ' );
148+ $ this ->setIncludeExternalStorage (true );
135149
150+ $ config = \OC ::$ server ->get (IConfig::class);
136151 $ config ->setUserValue ($ this ->user , 'files ' , 'quota ' , '25 ' );
137152
138153 $ storageInfo = \OC_Helper::getStorageInfo ('' );
139154 $ this ->assertEquals (3 , $ storageInfo ['free ' ]);
140155 $ this ->assertEquals (22 , $ storageInfo ['used ' ]);
141156 $ this ->assertEquals (25 , $ storageInfo ['total ' ]);
142157
143- $ config ->setSystemValue ('quota_include_external_storage ' , $ oldConfig );
144158 $ config ->setUserValue ($ this ->user , 'files ' , 'quota ' , 'default ' );
145159 }
146160
@@ -161,15 +175,12 @@ public function testGetStorageInfoIncludingExtStorageWithNoUserQuota() {
161175 \OC \Files \Filesystem::mount ($ extStorage , [], '/ ' . $ this ->user . '/files/ext ' );
162176
163177 $ config = \OC ::$ server ->getConfig ();
164- $ oldConfig = $ config ->getSystemValue ('quota_include_external_storage ' , false );
165- $ config ->setSystemValue ('quota_include_external_storage ' , 'true ' );
178+ $ this ->setIncludeExternalStorage (true );
166179
167180 $ storageInfo = \OC_Helper::getStorageInfo ('' );
168181 $ this ->assertEquals (12 , $ storageInfo ['free ' ], '12 bytes free in home storage ' );
169182 $ this ->assertEquals (22 , $ storageInfo ['used ' ], '5 bytes of home storage and 17 bytes of the temporary storage are used ' );
170183 $ this ->assertEquals (34 , $ storageInfo ['total ' ], '5 bytes used and 12 bytes free in home storage as well as 17 bytes used in temporary storage ' );
171-
172- $ config ->setSystemValue ('quota_include_external_storage ' , $ oldConfig );
173184 }
174185
175186
0 commit comments