From 626ae0c1bb87ee1d0fffee21b73aaa75be4c6cf7 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 30 May 2022 10:50:21 +0200 Subject: [PATCH 1/2] Handle non existing settings again See https://github.com/nextcloud/server/pull/28189#issuecomment-1140874991 Signed-off-by: Carl Schwan --- lib/private/Settings/Manager.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 84fbf9426b094..05a286e4758ab 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -126,8 +126,13 @@ protected function getSections(string $type): array { } foreach (array_unique($this->sectionClasses[$type]) as $index => $class) { - /** @var IIconSection $section */ - $section = \OC::$server->get($class); + try { + /** @var IIconSection $section */ + $section = $this->container->get($class); + } catch (QueryException $e) { + $this->log->info($e->getMessage(), ['exception' => $e]); + continue; + } $sectionID = $section->getID(); From c49b255b018b15e8445cd85456ef096640b5c4ea Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 31 May 2022 10:23:52 +0200 Subject: [PATCH 2/2] Fix unit tests Signed-off-by: Joas Schilling --- tests/lib/Settings/ManagerTest.php | 42 +++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php index 96711e75cabb9..29ae33c3c93be 100644 --- a/tests/lib/Settings/ManagerTest.php +++ b/tests/lib/Settings/ManagerTest.php @@ -21,7 +21,7 @@ * */ -namespace OCA\Settings\Tests\AppInfo; +namespace OC\Settings\Tests\AppInfo; use OC\Settings\AuthorizedGroupMapper; use OC\Settings\Manager; @@ -82,16 +82,26 @@ protected function setUp(): void { public function testGetAdminSections() { $this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class); + $section = \OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class); + $this->container->method('get') + ->with(\OCA\WorkflowEngine\Settings\Section::class) + ->willReturn($section); + $this->assertEquals([ - 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], + 55 => [$section], ], $this->manager->getAdminSections()); } public function testGetPersonalSections() { $this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class); + $section = \OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class); + $this->container->method('get') + ->with(\OCA\WorkflowEngine\Settings\Section::class) + ->willReturn($section); + $this->assertEquals([ - 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], + 55 => [$section], ], $this->manager->getPersonalSections()); } @@ -181,14 +191,16 @@ public function testGetPersonalSettings() { $this->manager->registerSetting('personal', 'section1'); $this->manager->registerSetting('personal', 'section2'); - $this->container->expects($this->at(0)) + $this->container->expects($this->exactly(2)) ->method('get') - ->with('section1') - ->willReturn($section); - $this->container->expects($this->at(1)) - ->method('get') - ->with('section2') - ->willReturn($section2); + ->withConsecutive( + ['section1'], + ['section2'] + ) + ->willReturnMap([ + ['section1', $section], + ['section2', $section2], + ]); $settings = $this->manager->getPersonalSettings('security'); @@ -212,12 +224,18 @@ public function testSameSectionAsPersonalAndAdmin() { $this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class); $this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class); + + $section = \OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class); + $this->container->method('get') + ->with(\OCA\WorkflowEngine\Settings\Section::class) + ->willReturn($section); + $this->assertEquals([ - 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], + 55 => [$section], ], $this->manager->getPersonalSections()); $this->assertEquals([ - 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], + 55 => [$section], ], $this->manager->getAdminSections()); } }