Skip to content

Commit 985396b

Browse files
committed
test: Reset the correct mount provider collection instance and add back the files_sharing mount provider
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 838e9bd commit 985396b

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎lib/private/Server.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,8 @@ public function __construct(
836836
return $manager;
837837
});
838838

839+
$this->registerAlias(MountProviderCollection::class, IMountProviderCollection::class);
840+
839841
$this->registerService(IBus::class, function (ContainerInterface $c) {
840842
$busClass = $c->get(IConfig::class)->getSystemValueString('commandbus');
841843
if ($busClass) {

‎tests/lib/TestCase.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use OC\Installer;
2525
use OC\Updater;
2626
use OC\User\Session;
27+
use OCA\Files_Sharing\MountProvider;
2728
use OCP\Command\IBus;
2829
use OCP\DB\QueryBuilder\IQueryBuilder;
2930
use OCP\Files\IRootFolder;
@@ -374,13 +375,13 @@ public static function tearDownAfterClass(): void {
374375
$setupManager = Server::get(SetupManager::class);
375376
$setupManager->tearDown();
376377

377-
/** @var MountProviderCollection $mountProviderCollection */
378378
$mountProviderCollection = Server::get(MountProviderCollection::class);
379379
$mountProviderCollection->clearProviders();
380380

381381
/** @var IConfig $config */
382382
$config = Server::get(IConfig::class);
383383
$mountProviderCollection->registerProvider(new CacheMountProvider($config));
384+
$mountProviderCollection->registerProvider(Server::get(MountProvider::class));
384385
$mountProviderCollection->registerHomeProvider(new LocalHomeMountProvider());
385386
$objectStoreConfig = Server::get(PrimaryObjectStoreConfig::class);
386387
$mountProviderCollection->registerRootProvider(new RootMountProvider($objectStoreConfig, $config));

‎tests/lib/TestCaseTest.php‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,23 @@
88

99
namespace Test;
1010

11+
use OCP\Constants;
12+
use OCP\Files\Folder;
13+
use OCP\Files\IRootFolder;
1114
use OCP\IConfig;
1215
use OCP\Server;
16+
use OCP\Share\IManager;
17+
use OCP\Share\IShare;
18+
use Test\Traits\UserTrait;
1319

1420
/**
1521
* Tests for TestCase::overwriteSystemConfig(). System config is persisted to
1622
* config.php, so a value leaked by a test outlives the run and the next one.
1723
*/
1824
#[\PHPUnit\Framework\Attributes\Group('DB')]
1925
class TestCaseTest extends TestCase {
26+
use UserTrait;
27+
2028
private const KEY = 'testcase_overwrite_system_config';
2129

2230
private IConfig $config;
@@ -88,4 +96,30 @@ public function testRestoreReturnsAPreviousFalseValue(): void {
8896

8997
$this->assertFalse($this->config->getSystemValue(self::KEY, 'fallback'));
9098
}
99+
100+
// This test cannot fail if this suite is run standalone.
101+
// It will only fail if the mount provider collection wasn't correctly reset after a different test suite was executed before this one.
102+
public function testMountProviderCollectionReset(): void {
103+
$owner = $this->createUser('owner', 'password');
104+
$receiver = $this->createUser('receiver', 'password');
105+
106+
$ownerUserFolder = Server::get(IRootFolder::class)->getUserFolder($owner->getUID());
107+
$ownerNode = $ownerUserFolder->newFolder('foo');
108+
$this->assertInstanceOf(Folder::class, $ownerNode);
109+
110+
$manager = Server::get(IManager::class);
111+
$manager->createShare(
112+
$manager->newShare()
113+
->setShareType(IShare::TYPE_USER)
114+
->setShareOwner($owner->getUID())
115+
->setSharedBy($owner->getUID())
116+
->setSharedWith($receiver->getUID())
117+
->setNode($ownerNode)
118+
->setPermissions(Constants::PERMISSION_ALL)
119+
);
120+
121+
$receiverUserFolder = Server::get(IRootFolder::class)->getUserFolder($receiver->getUID());
122+
$receiverNode = $receiverUserFolder->get($ownerNode->getName());
123+
$this->assertInstanceOf(Folder::class, $receiverNode);
124+
}
91125
}

0 commit comments

Comments
 (0)