Skip to content

Commit

Permalink
Merge pull request #27885 from owncloud/allow-multiple-settings-panel…
Browse files Browse the repository at this point in the history
…s-per-app

Allow app to register multiple settings panels of same type
  • Loading branch information
Vincent Petry authored May 15, 2017
2 parents 81d2f35 + fa2900a commit aaba0b5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/private/Settings/SettingsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,12 @@ protected function findRegisteredPanels($type) {
$panels = [];
foreach($this->appManager->getEnabledAppsForUser($this->userSession->getUser()) as $app) {
if(isset($this->appManager->getAppInfo($app)['settings'])) {
foreach($this->appManager->getAppInfo($app)['settings'] as $t => $panel) {
foreach($this->appManager->getAppInfo($app)['settings'] as $t => $detected) {
if($t === $type)
{
$panels[] = (string) $panel;
// Allow app to register multiple panels of the same type
$detected = is_array($detected) ? $detected : [$detected];
$panels = array_merge($panels, $detected);
}
}
}
Expand Down
46 changes: 46 additions & 0 deletions tests/lib/Settings/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,52 @@ public function testGetPanelsList() {
$this->assertContains('OC\Settings\Panels\Personal\Profile', $list);
}

public function testFindRegisteredPanelsAdmin() {
// Return a mock user
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$this->userSession->expects($this->any())->method('getUser')->willReturn($user);
// Return encryption as example app with
$this->appManager->expects($this->exactly(1))->method('getEnabledAppsForUser')->with($user)->willReturn(['encryption']);
$settingsInfo = [
'settings' =>
['admin' => 'OCA\Encryption\TestPanel']
];
$this->appManager->expects($this->exactly(2))->method('getAppInfo')->with('encryption')->willReturn($settingsInfo);
$panels = $this->invokePrivate($this->settingsManager, 'findRegisteredPanels', ['admin']);
$this->assertCount(1, $panels);
}

public function testFindRegisteredPanelsPersonal() {
// Return a mock user
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$this->userSession->expects($this->any())->method('getUser')->willReturn($user);
// Return encryption as example app with
$this->appManager->expects($this->exactly(1))->method('getEnabledAppsForUser')->with($user)->willReturn(['encryption']);
$settingsInfo = [
'settings' =>
['personal' => 'OCA\Encryption\TestPanel']
];
$this->appManager->expects($this->exactly(2))->method('getAppInfo')->with('encryption')->willReturn($settingsInfo);
$panels = $this->invokePrivate($this->settingsManager, 'findRegisteredPanels', ['personal']);
$this->assertCount(1, $panels);
$this->assertEquals('OCA\Encryption\TestPanel', array_shift($panels));
}

public function testFindRegisteredPanelsPersonalMultiple() {
// Return a mock user
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$this->userSession->expects($this->any())->method('getUser')->willReturn($user);
// Return encryption as example app with
$this->appManager->expects($this->exactly(1))->method('getEnabledAppsForUser')->with($user)->willReturn(['encryption']);
$settingsInfo = [
'settings' =>
['personal' => ['OCA\Encryption\TestPanel', 'OCA\Encryption\TestPanel2']]
];
$this->appManager->expects($this->exactly(2))->method('getAppInfo')->with('encryption')->willReturn($settingsInfo);
$panels = $this->invokePrivate($this->settingsManager, 'findRegisteredPanels', ['personal']);
$this->assertCount(2, $panels);
}

public function testLoadPersonalPanels() {
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$this->userSession->expects($this->any())->method('getUser')->willReturn($user);
Expand Down

0 comments on commit aaba0b5

Please sign in to comment.