Skip to content

Commit 339702e

Browse files
committed
refactor: make share manager buildable
Signed-off-by: Robin Appelman <[email protected]>
1 parent 4a23308 commit 339702e

File tree

4 files changed

+25
-207
lines changed

4 files changed

+25
-207
lines changed

apps/files_sharing/tests/CapabilitiesTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
use OCP\IConfig;
3939
use OCP\IDateTimeZone;
4040
use OCP\IGroupManager;
41-
use OCP\IL10N;
4241
use OCP\IURLGenerator;
4342
use OCP\IUserManager;
4443
use OCP\IUserSession;
@@ -86,7 +85,6 @@ private function getResults(array $map) {
8685
$this->createMock(IHasher::class),
8786
$this->createMock(IMountManager::class),
8887
$this->createMock(IGroupManager::class),
89-
$this->createMock(IL10N::class),
9088
$this->createMock(IFactory::class),
9189
$this->createMock(IProviderFactory::class),
9290
$this->createMock(IUserManager::class),

lib/private/Server.php

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
use OC\Session\CryptoWrapper;
153153
use OC\SetupCheck\SetupCheckManager;
154154
use OC\Share20\ProviderFactory;
155-
use OC\Share20\ShareDisableChecker;
156155
use OC\Share20\ShareHelper;
157156
use OC\SpeechToText\SpeechToTextManager;
158157
use OC\SystemTag\ManagerFactory as SystemTagManagerFactory;
@@ -261,6 +260,7 @@
261260
use OCP\Security\RateLimiting\ILimiter;
262261
use OCP\Security\VerificationToken\IVerificationToken;
263262
use OCP\SetupCheck\ISetupCheckManager;
263+
use OCP\Share\IProviderFactory;
264264
use OCP\Share\IShareHelper;
265265
use OCP\SpeechToText\ISpeechToTextManager;
266266
use OCP\SystemTag\ISystemTagManager;
@@ -1247,36 +1247,14 @@ public function __construct($webRoot, \OC\Config $config) {
12471247
/** @deprecated 19.0.0 */
12481248
$this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
12491249

1250-
$this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) {
1250+
$this->registerService(IProviderFactory::class, function (ContainerInterface $c) {
12511251
$config = $c->get(\OCP\IConfig::class);
12521252
$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
12531253
/** @var \OCP\Share\IProviderFactory $factory */
1254-
$factory = new $factoryClass($this);
1255-
1256-
$manager = new \OC\Share20\Manager(
1257-
$c->get(LoggerInterface::class),
1258-
$c->get(\OCP\IConfig::class),
1259-
$c->get(ISecureRandom::class),
1260-
$c->get(IHasher::class),
1261-
$c->get(IMountManager::class),
1262-
$c->get(IGroupManager::class),
1263-
$c->getL10N('lib'),
1264-
$c->get(IFactory::class),
1265-
$factory,
1266-
$c->get(IUserManager::class),
1267-
$c->get(IRootFolder::class),
1268-
$c->get(IMailer::class),
1269-
$c->get(IURLGenerator::class),
1270-
$c->get('ThemingDefaults'),
1271-
$c->get(IEventDispatcher::class),
1272-
$c->get(IUserSession::class),
1273-
$c->get(KnownUserService::class),
1274-
$c->get(ShareDisableChecker::class),
1275-
$c->get(IDateTimeZone::class),
1276-
);
1277-
1278-
return $manager;
1254+
return new $factoryClass($this);
12791255
});
1256+
1257+
$this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class);
12801258
/** @deprecated 19.0.0 */
12811259
$this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
12821260

lib/private/Share20/Manager.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ public function __construct(
130130
IHasher $hasher,
131131
IMountManager $mountManager,
132132
IGroupManager $groupManager,
133-
IL10N $l,
134133
IFactory $l10nFactory,
135134
IProviderFactory $factory,
136135
IUserManager $userManager,
@@ -150,7 +149,7 @@ public function __construct(
150149
$this->hasher = $hasher;
151150
$this->mountManager = $mountManager;
152151
$this->groupManager = $groupManager;
153-
$this->l = $l;
152+
$this->l = $l10nFactory->get('lib');
154153
$this->l10nFactory = $l10nFactory;
155154
$this->factory = $factory;
156155
$this->userManager = $userManager;

tests/lib/Share20/ManagerTest.php

Lines changed: 19 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,27 @@ protected function setUp(): void {
151151
->willReturnCallback(function ($singular, $plural, $count, $parameters = []) {
152152
return vsprintf(str_replace('%n', $count, ($count === 1) ? $singular : $plural), $parameters);
153153
});
154+
$this->l10nFactory->method('get')->willReturn($this->l);
154155

155156
$this->factory = new DummyFactory(\OC::$server);
156157

157-
$this->manager = new Manager(
158+
$this->manager = $this->createManager($this->factory);
159+
160+
$this->defaultProvider = $this->createMock(DefaultShareProvider::class);
161+
$this->defaultProvider->method('identifier')->willReturn('default');
162+
$this->factory->setProvider($this->defaultProvider);
163+
}
164+
165+
private function createManager(IProviderFactory $factory): Manager {
166+
return new Manager(
158167
$this->logger,
159168
$this->config,
160169
$this->secureRandom,
161170
$this->hasher,
162171
$this->mountManager,
163172
$this->groupManager,
164-
$this->l,
165173
$this->l10nFactory,
166-
$this->factory,
174+
$factory,
167175
$this->userManager,
168176
$this->rootFolder,
169177
$this->mailer,
@@ -175,10 +183,6 @@ protected function setUp(): void {
175183
$this->shareDisabledChecker,
176184
$this->dateTimeZone,
177185
);
178-
179-
$this->defaultProvider = $this->createMock(DefaultShareProvider::class);
180-
$this->defaultProvider->method('identifier')->willReturn('default');
181-
$this->factory->setProvider($this->defaultProvider);
182186
}
183187

184188
/**
@@ -193,7 +197,6 @@ private function createManagerMock() {
193197
$this->hasher,
194198
$this->mountManager,
195199
$this->groupManager,
196-
$this->l,
197200
$this->l10nFactory,
198201
$this->factory,
199202
$this->userManager,
@@ -2796,27 +2799,7 @@ public function testGetShareByToken() {
27962799

27972800
$factory = $this->createMock(IProviderFactory::class);
27982801

2799-
$manager = new Manager(
2800-
$this->logger,
2801-
$this->config,
2802-
$this->secureRandom,
2803-
$this->hasher,
2804-
$this->mountManager,
2805-
$this->groupManager,
2806-
$this->l,
2807-
$this->l10nFactory,
2808-
$factory,
2809-
$this->userManager,
2810-
$this->rootFolder,
2811-
$this->mailer,
2812-
$this->urlGenerator,
2813-
$this->defaults,
2814-
$this->dispatcher,
2815-
$this->userSession,
2816-
$this->knownUserService,
2817-
$this->shareDisabledChecker,
2818-
$this->dateTimeZone,
2819-
);
2802+
$manager = $this->createManager($factory);
28202803

28212804
$share = $this->createMock(IShare::class);
28222805

@@ -2845,27 +2828,7 @@ public function testGetShareByTokenRoom() {
28452828

28462829
$factory = $this->createMock(IProviderFactory::class);
28472830

2848-
$manager = new Manager(
2849-
$this->logger,
2850-
$this->config,
2851-
$this->secureRandom,
2852-
$this->hasher,
2853-
$this->mountManager,
2854-
$this->groupManager,
2855-
$this->l,
2856-
$this->l10nFactory,
2857-
$factory,
2858-
$this->userManager,
2859-
$this->rootFolder,
2860-
$this->mailer,
2861-
$this->urlGenerator,
2862-
$this->defaults,
2863-
$this->dispatcher,
2864-
$this->userSession,
2865-
$this->knownUserService,
2866-
$this->shareDisabledChecker,
2867-
$this->dateTimeZone,
2868-
);
2831+
$manager = $this->createManager($factory);
28692832

28702833
$share = $this->createMock(IShare::class);
28712834

@@ -2901,27 +2864,7 @@ public function testGetShareByTokenWithException() {
29012864

29022865
$factory = $this->createMock(IProviderFactory::class);
29032866

2904-
$manager = new Manager(
2905-
$this->logger,
2906-
$this->config,
2907-
$this->secureRandom,
2908-
$this->hasher,
2909-
$this->mountManager,
2910-
$this->groupManager,
2911-
$this->l,
2912-
$this->l10nFactory,
2913-
$factory,
2914-
$this->userManager,
2915-
$this->rootFolder,
2916-
$this->mailer,
2917-
$this->urlGenerator,
2918-
$this->defaults,
2919-
$this->dispatcher,
2920-
$this->userSession,
2921-
$this->knownUserService,
2922-
$this->shareDisabledChecker,
2923-
$this->dateTimeZone,
2924-
);
2867+
$manager = $this->createManager($factory);
29252868

29262869
$share = $this->createMock(IShare::class);
29272870

@@ -4302,27 +4245,7 @@ public function testShareProviderExists($shareType, $expected) {
43024245
throw new Exception\ProviderException();
43034246
});
43044247

4305-
$manager = new Manager(
4306-
$this->logger,
4307-
$this->config,
4308-
$this->secureRandom,
4309-
$this->hasher,
4310-
$this->mountManager,
4311-
$this->groupManager,
4312-
$this->l,
4313-
$this->l10nFactory,
4314-
$factory,
4315-
$this->userManager,
4316-
$this->rootFolder,
4317-
$this->mailer,
4318-
$this->urlGenerator,
4319-
$this->defaults,
4320-
$this->dispatcher,
4321-
$this->userSession,
4322-
$this->knownUserService,
4323-
$this->shareDisabledChecker,
4324-
$this->dateTimeZone,
4325-
);
4248+
$manager = $this->createManager($factory);
43264249
$this->assertSame($expected,
43274250
$manager->shareProviderExists($shareType)
43284251
);
@@ -4338,27 +4261,7 @@ public function dataTestShareProviderExists() {
43384261
public function testGetSharesInFolder() {
43394262
$factory = new DummyFactory2($this->createMock(IServerContainer::class));
43404263

4341-
$manager = new Manager(
4342-
$this->logger,
4343-
$this->config,
4344-
$this->secureRandom,
4345-
$this->hasher,
4346-
$this->mountManager,
4347-
$this->groupManager,
4348-
$this->l,
4349-
$this->l10nFactory,
4350-
$factory,
4351-
$this->userManager,
4352-
$this->rootFolder,
4353-
$this->mailer,
4354-
$this->urlGenerator,
4355-
$this->defaults,
4356-
$this->dispatcher,
4357-
$this->userSession,
4358-
$this->knownUserService,
4359-
$this->shareDisabledChecker,
4360-
$this->dateTimeZone,
4361-
);
4264+
$manager = $this->createManager($factory);
43624265

43634266
$factory->setProvider($this->defaultProvider);
43644267
$extraProvider = $this->createMock(IShareProvider::class);
@@ -4405,27 +4308,7 @@ public function testGetSharesInFolder() {
44054308
public function testGetAccessList() {
44064309
$factory = new DummyFactory2($this->createMock(IServerContainer::class));
44074310

4408-
$manager = new Manager(
4409-
$this->logger,
4410-
$this->config,
4411-
$this->secureRandom,
4412-
$this->hasher,
4413-
$this->mountManager,
4414-
$this->groupManager,
4415-
$this->l,
4416-
$this->l10nFactory,
4417-
$factory,
4418-
$this->userManager,
4419-
$this->rootFolder,
4420-
$this->mailer,
4421-
$this->urlGenerator,
4422-
$this->defaults,
4423-
$this->dispatcher,
4424-
$this->userSession,
4425-
$this->knownUserService,
4426-
$this->shareDisabledChecker,
4427-
$this->dateTimeZone,
4428-
);
4311+
$manager = $this->createManager($factory);
44294312

44304313
$factory->setProvider($this->defaultProvider);
44314314
$extraProvider = $this->createMock(IShareProvider::class);
@@ -4524,27 +4407,7 @@ public function testGetAccessList() {
45244407
public function testGetAccessListWithCurrentAccess() {
45254408
$factory = new DummyFactory2($this->createMock(IServerContainer::class));
45264409

4527-
$manager = new Manager(
4528-
$this->logger,
4529-
$this->config,
4530-
$this->secureRandom,
4531-
$this->hasher,
4532-
$this->mountManager,
4533-
$this->groupManager,
4534-
$this->l,
4535-
$this->l10nFactory,
4536-
$factory,
4537-
$this->userManager,
4538-
$this->rootFolder,
4539-
$this->mailer,
4540-
$this->urlGenerator,
4541-
$this->defaults,
4542-
$this->dispatcher,
4543-
$this->userSession,
4544-
$this->knownUserService,
4545-
$this->shareDisabledChecker,
4546-
$this->dateTimeZone,
4547-
);
4410+
$manager = $this->createManager($factory);
45484411

45494412
$factory->setProvider($this->defaultProvider);
45504413
$extraProvider = $this->createMock(IShareProvider::class);
@@ -4652,27 +4515,7 @@ public function testGetAccessListWithCurrentAccess() {
46524515
public function testGetAllShares() {
46534516
$factory = new DummyFactory2($this->createMock(IServerContainer::class));
46544517

4655-
$manager = new Manager(
4656-
$this->logger,
4657-
$this->config,
4658-
$this->secureRandom,
4659-
$this->hasher,
4660-
$this->mountManager,
4661-
$this->groupManager,
4662-
$this->l,
4663-
$this->l10nFactory,
4664-
$factory,
4665-
$this->userManager,
4666-
$this->rootFolder,
4667-
$this->mailer,
4668-
$this->urlGenerator,
4669-
$this->defaults,
4670-
$this->dispatcher,
4671-
$this->userSession,
4672-
$this->knownUserService,
4673-
$this->shareDisabledChecker,
4674-
$this->dateTimeZone,
4675-
);
4518+
$manager = $this->createManager($factory);
46764519

46774520
$factory->setProvider($this->defaultProvider);
46784521
$extraProvider = $this->createMock(IShareProvider::class);

0 commit comments

Comments
 (0)