Skip to content

Commit ddac16b

Browse files
authored
Merge pull request #32657 from nextcloud/backport/32655/stable24
[stable24] Handle non existing settings again
2 parents 535b84e + 26050a4 commit ddac16b

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

lib/private/Settings/Manager.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,13 @@ protected function getSections(string $type): array {
126126
}
127127

128128
foreach (array_unique($this->sectionClasses[$type]) as $index => $class) {
129-
/** @var IIconSection $section */
130-
$section = \OC::$server->get($class);
129+
try {
130+
/** @var IIconSection $section */
131+
$section = $this->container->get($class);
132+
} catch (QueryException $e) {
133+
$this->log->info($e->getMessage(), ['exception' => $e]);
134+
continue;
135+
}
131136

132137
$sectionID = $section->getID();
133138

tests/lib/Settings/ManagerTest.php

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*/
2323

24-
namespace OCA\Settings\Tests\AppInfo;
24+
namespace OC\Settings\Tests\AppInfo;
2525

2626
use OC\Settings\AuthorizedGroupMapper;
2727
use OC\Settings\Manager;
@@ -82,16 +82,26 @@ protected function setUp(): void {
8282
public function testGetAdminSections() {
8383
$this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class);
8484

85+
$section = \OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class);
86+
$this->container->method('get')
87+
->with(\OCA\WorkflowEngine\Settings\Section::class)
88+
->willReturn($section);
89+
8590
$this->assertEquals([
86-
55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
91+
55 => [$section],
8792
], $this->manager->getAdminSections());
8893
}
8994

9095
public function testGetPersonalSections() {
9196
$this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class);
9297

98+
$section = \OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class);
99+
$this->container->method('get')
100+
->with(\OCA\WorkflowEngine\Settings\Section::class)
101+
->willReturn($section);
102+
93103
$this->assertEquals([
94-
55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
104+
55 => [$section],
95105
], $this->manager->getPersonalSections());
96106
}
97107

@@ -181,14 +191,16 @@ public function testGetPersonalSettings() {
181191
$this->manager->registerSetting('personal', 'section1');
182192
$this->manager->registerSetting('personal', 'section2');
183193

184-
$this->container->expects($this->at(0))
194+
$this->container->expects($this->exactly(2))
185195
->method('get')
186-
->with('section1')
187-
->willReturn($section);
188-
$this->container->expects($this->at(1))
189-
->method('get')
190-
->with('section2')
191-
->willReturn($section2);
196+
->withConsecutive(
197+
['section1'],
198+
['section2']
199+
)
200+
->willReturnMap([
201+
['section1', $section],
202+
['section2', $section2],
203+
]);
192204

193205
$settings = $this->manager->getPersonalSettings('security');
194206

@@ -212,12 +224,18 @@ public function testSameSectionAsPersonalAndAdmin() {
212224
$this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class);
213225
$this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class);
214226

227+
228+
$section = \OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class);
229+
$this->container->method('get')
230+
->with(\OCA\WorkflowEngine\Settings\Section::class)
231+
->willReturn($section);
232+
215233
$this->assertEquals([
216-
55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
234+
55 => [$section],
217235
], $this->manager->getPersonalSections());
218236

219237
$this->assertEquals([
220-
55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
238+
55 => [$section],
221239
], $this->manager->getAdminSections());
222240
}
223241
}

0 commit comments

Comments
 (0)