Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable23] Handle non existing settings again #32658

Merged
merged 2 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/private/Settings/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
42 changes: 30 additions & 12 deletions tests/lib/Settings/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
*/

namespace OCA\Settings\Tests\AppInfo;
namespace OC\Settings\Tests\AppInfo;

use OC\Settings\AuthorizedGroupMapper;
use OC\Settings\Manager;
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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');

Expand All @@ -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());
}
}