Skip to content
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
23 changes: 19 additions & 4 deletions lib/private/Settings/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ public function __construct(
* @return void
*/
public function registerSection(string $type, string $section) {
$this->sectionClasses[$section] = $type;
if (!isset($this->sectionClasses[$type])) {
$this->sectionClasses[$type] = [];
}

$this->sectionClasses[$type][] = $section;
}

/**
Expand All @@ -145,7 +149,11 @@ protected function getSections(string $type): array {
$this->sections[$type] = [];
}

foreach ($this->sectionClasses as $class => $sectionType) {
if (!isset($this->sectionClasses[$type])) {
return $this->sections[$type];
}

foreach ($this->sectionClasses[$type] as $index => $class) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foreach ($this->sectionClasses[$type] as $class) { works in php

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but I need the index a couple of lines below

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah in the unset.

try {
/** @var ISection $section */
$section = \OC::$server->query($class);
Expand All @@ -159,9 +167,16 @@ protected function getSections(string $type): array {
continue;
}

$this->sections[$sectionType][$section->getID()] = $section;
$sectionID = $section->getID();

if (isset($this->sections[$type][$sectionID])) {
$this->log->logException(new \InvalidArgumentException('Section with the same ID already registered'), ['level' => ILogger::INFO]);
continue;
}

$this->sections[$type][$sectionID] = $section;

unset($this->sectionClasses[$class]);
unset($this->sectionClasses[$type][$index]);
}

return $this->sections[$type];
Expand Down
41 changes: 41 additions & 0 deletions tests/lib/Settings/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,45 @@ public function testGetPersonalSettings() {
10 => [new Security($this->userManager)],
], $this->manager->getPersonalSettings('security'));
}

public function testSameSectionAsPersonalAndAdmin() {
$this->l10n
->expects($this->any())
->method('t')
->will($this->returnArgument(0));

$this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class);
$this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class);

$this->url->expects($this->exactly(9))
->method('imagePath')
->willReturnMap([
['core', 'actions/info.svg', '1'],
['settings', 'password.svg', '2'],
['core', 'clients/phone.svg', '3'],
['settings', 'admin.svg', '0'],
['core', 'actions/settings-dark.svg', '1'],
['core', 'actions/share.svg', '2'],
['core', 'actions/password.svg', '3'],
['core', 'places/contacts.svg', '5'],
['settings', 'help.svg', '4'],
]);

$this->assertEquals([
0 => [new Section('personal-info', 'Personal info', 0, '1')],
5 => [new Section('security', 'Security', 0, '2')],
15 => [new Section('sync-clients', 'Mobile & desktop', 0, '3')],
55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
], $this->manager->getPersonalSections());

$this->assertEquals([
0 => [new Section('overview', 'Overview', 0, '0')],
1 => [new Section('server', 'Basic settings', 0, '1')],
5 => [new Section('sharing', 'Sharing', 0, '2')],
10 => [new Section('security', 'Security', 0, '3')],
50 => [new Section('groupware', 'Groupware', 0, '5')],
55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
98 => [new Section('additional', 'Additional settings', 0, '1')],
], $this->manager->getAdminSections());
}
}