Merge pull request #3151 from nextcloud/navigation-icons

add icons to navigation of personal & admin settings
This commit is contained in:
Morris Jobke 2017-01-24 10:56:31 -06:00 committed by GitHub
commit e09bba5e36
28 changed files with 310 additions and 62 deletions

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="32" width="32" viewBox="0 0 32 32"><path d="M14.903 3.237l4.76 4.515-7.14 6.772 4.76 4.514 7.142-6.772 4.762 4.515V3.237H14.904zM5.38 5.495C4.063 5.495 3 6.5 3 7.752V25.81c0 1.25 1.062 2.257 2.38 2.257h19.045c1.318 0 2.38-1.007 2.38-2.257v-6.772l-2.38-2.257v9.03H5.38V7.752h9.523l-2.38-2.258H5.38z" fill="#000"/></svg>

After

Width:  |  Height:  |  Size: 367 B

View File

@ -24,13 +24,21 @@
namespace OCA\Files_External\Settings;
use OCP\IL10N;
use OCP\Settings\ISection;
use OCP\IURLGenerator;
use OCP\Settings\IIconSection;
class Section implements ISection {
class Section implements IIconSection {
/** @var IL10N */
private $l;
/** @var IURLGenerator */
private $url;
public function __construct(IL10N $l) {
/**
* @param IURLGenerator $url
* @param IL10N $l
*/
public function __construct(IURLGenerator $url, IL10N $l) {
$this->url = $url;
$this->l = $l;
}
@ -64,4 +72,11 @@ class Section implements ISection {
public function getPriority() {
return 10;
}
/**
* {@inheritdoc}
*/
public function getIcon() {
return $this->url->imagePath('files_external', 'app-dark.svg');
}
}

View File

@ -25,19 +25,24 @@ namespace OCA\Files_External\Tests\Settings;
use OCA\Files_External\Settings\Section;
use OCP\IL10N;
use OCP\IURLGenerator;
use Test\TestCase;
class SectionTest extends TestCase {
/** @var IL10N */
private $l;
/** @var IURLGenerator */
private $urlGenerator;
/** @var Section */
private $section;
public function setUp() {
parent::setUp();
$this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')->disableOriginalConstructor()->getMock();
$this->l = $this->getMockBuilder('\OCP\IL10N')->disableOriginalConstructor()->getMock();
$this->section = new Section(
$this->urlGenerator,
$this->l
);
}

View File

@ -0,0 +1 @@
<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M10.707 11.412l-.587-.587-.03-.03a.513.513 0 0 1-.074-.526L13.07 3.4l-1.5-1.498-.15.15-.708-.706.505-.505a.538.538 0 0 1 .224-.128c.04-.01.05-.01.087-.016h.087c.04.006.05.006.086.016.072.02.134.055.192.1.74.676 1.42 1.415 2.127 2.124a.503.503 0 0 1 .103.556l-3.053 6.87.344.343.49-.49 3.01 3.01a1.192 1.192 0 0 1-1.685 1.686l-3.012-3.01.49-.488zm-.533-10.217a.986.986 0 0 0-1.396 0l-7.582 7.58a.99.99 0 0 0 0 1.398l1.397 1.396a.986.986 0 0 0 1.396 0l7.58-7.583a.988.988 0 0 0 0-1.396l-1.396-1.395z" fill="#000"/></svg>

After

Width:  |  Height:  |  Size: 611 B

View File

@ -24,13 +24,21 @@
namespace OCA\Theming\Settings;
use OCP\IL10N;
use OCP\Settings\ISection;
use OCP\IURLGenerator;
use OCP\Settings\IIconSection;
class Section implements ISection {
class Section implements IIconSection {
/** @var IL10N */
private $l;
/** @var IURLGenerator */
private $url;
public function __construct(IL10N $l) {
/**
* @param IURLGenerator $url
* @param IL10N $l
*/
public function __construct(IURLGenerator $url, IL10N $l) {
$this->url = $url;
$this->l = $l;
}
@ -64,4 +72,11 @@ class Section implements ISection {
public function getPriority() {
return 30;
}
/**
* {@inheritdoc}
*/
public function getIcon() {
return $this->url->imagePath('theming', 'app-dark.svg');
}
}

View File

@ -25,19 +25,24 @@ namespace OCA\Theming\Tests\Settings;
use OCA\Theming\Settings\Section;
use OCP\IL10N;
use OCP\IURLGenerator;
use Test\TestCase;
class SectionTest extends TestCase {
/** @var IL10N */
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
private $url;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l;
/** @var Section */
private $section;
public function setUp() {
parent::setUp();
$this->l = $this->getMockBuilder('\OCP\IL10N')->getMock();
$this->url = $this->createMock(IURLGenerator::class);
$this->l = $this->createMock(IL10N::class);
$this->section = new Section(
$this->url,
$this->l
);
}
@ -59,4 +64,13 @@ class SectionTest extends TestCase {
public function testGetPriority() {
$this->assertSame(30, $this->section->getPriority());
}
public function testGetIcon() {
$this->url->expects($this->once())
->method('imagePath')
->with('theming', 'app-dark.svg')
->willReturn('icon');
$this->assertSame('icon', $this->section->getIcon());
}
}

View File

@ -24,13 +24,21 @@
namespace OCA\User_LDAP\Settings;
use OCP\IL10N;
use OCP\Settings\ISection;
use OCP\IURLGenerator;
use OCP\Settings\IIconSection;
class Section implements ISection {
class Section implements IIconSection {
/** @var IL10N */
private $l;
/** @var IURLGenerator */
private $url;
public function __construct(IL10N $l) {
/**
* @param IURLGenerator $url
* @param IL10N $l
*/
public function __construct(IURLGenerator $url, IL10N $l) {
$this->url = $url;
$this->l = $l;
}
@ -64,4 +72,11 @@ class Section implements ISection {
public function getPriority() {
return 25;
}
/**
* {@inheritdoc}
*/
public function getIcon() {
return $this->url->imagePath('user_ldap', 'app.svg');
}
}

View File

@ -25,19 +25,24 @@ namespace OCA\User_LDAP\Tests\Settings;
use OCA\User_LDAP\Settings\Section;
use OCP\IL10N;
use OCP\IURLGenerator;
use Test\TestCase;
class SectionTest extends TestCase {
/** @var IL10N */
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
private $url;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l;
/** @var Section */
private $section;
public function setUp() {
parent::setUp();
$this->l = $this->getMockBuilder('\OCP\IL10N')->getMock();
$this->url = $this->createMock(IURLGenerator::class);
$this->l = $this->createMock(IL10N::class);
$this->section = new Section(
$this->url,
$this->l
);
}
@ -59,4 +64,13 @@ class SectionTest extends TestCase {
public function testGetPriority() {
$this->assertSame(25, $this->section->getPriority());
}
public function testGetIcon() {
$this->url->expects($this->once())
->method('imagePath')
->with('user_ldap', 'app.svg')
->willReturn('icon');
$this->assertSame('icon', $this->section->getIcon());
}
}

View File

@ -24,13 +24,21 @@
namespace OCA\WorkflowEngine\Settings;
use OCP\IL10N;
use OCP\Settings\ISection;
use OCP\IURLGenerator;
use OCP\Settings\IIconSection;
class Section implements ISection {
class Section implements IIconSection {
/** @var IL10N */
private $l;
/** @var IURLGenerator */
private $url;
public function __construct(IL10N $l) {
/**
* @param IURLGenerator $url
* @param IL10N $l
*/
public function __construct(IURLGenerator $url, IL10N $l) {
$this->url = $url;
$this->l = $l;
}
@ -54,4 +62,11 @@ class Section implements ISection {
public function getPriority() {
return 55;
}
/**
* {@inheritdoc}
*/
public function getIcon() {
return $this->url->imagePath('core', 'actions/tag.svg');
}
}

View File

@ -104,6 +104,12 @@ em {
opacity: 1;
box-shadow: inset 2px 0 #0082c9;
}
li > a:first-child img {
margin-bottom: -3px;
margin-right: 11px;
width: 16px;
margin-left: 2px;
}
.collapse {
display: none;
/* hide collapse button initially */

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1"><path d="M6.938 0A.43.43 0 0 0 6.5.438v1.25a5.818 5.818 0 0 0-1.53.656l-.907-.906a.436.436 0 0 0-.625 0l-1.5 1.5a.436.436 0 0 0 0 .624l.906.907c-.285.48-.514.976-.656 1.53H.938a.43.43 0 0 0-.438.438v2.125C.5 8.81.69 9 .938 9h1.25a5.82 5.82 0 0 0 .656 1.53l-.907.908a.436.436 0 0 0 0 .625l1.5 1.5c.176.176.45.176.625 0l.907-.907c.48.285.976.514 1.53.656v1.25c0 .25.19.438.437.438h2.125a.43.43 0 0 0 .438-.438v-1.25a5.82 5.82 0 0 0 1.53-.657l.907.907c.176.175.45.175.625 0l1.5-1.5a.436.436 0 0 0 0-.625l-.906-.906A5.79 5.79 0 0 0 13.812 9h1.25a.43.43 0 0 0 .438-.438V6.437A.43.43 0 0 0 15.062 6h-1.25a5.79 5.79 0 0 0-.656-1.532l.906-.906a.436.436 0 0 0 0-.625l-1.5-1.5a.436.436 0 0 0-.625 0l-.906.906a5.816 5.816 0 0 0-1.53-.656V.437A.43.43 0 0 0 9.063 0zM8 4.157a3.344 3.344 0 0 1 0 6.686 3.344 3.344 0 0 1 0-6.686z" display="block"/></svg>

After

Width:  |  Height:  |  Size: 915 B

View File

@ -225,6 +225,7 @@ return array(
'OCP\\Security\\ISecureRandom' => $baseDir . '/lib/public/Security/ISecureRandom.php',
'OCP\\Security\\StringUtils' => $baseDir . '/lib/public/Security/StringUtils.php',
'OCP\\Session\\Exceptions\\SessionNotAvailableException' => $baseDir . '/lib/public/Session/Exceptions/SessionNotAvailableException.php',
'OCP\\Settings\\IIconSection' => $baseDir . '/lib/public/Settings/IIconSection.php',
'OCP\\Settings\\IManager' => $baseDir . '/lib/public/Settings/IManager.php',
'OCP\\Settings\\ISection' => $baseDir . '/lib/public/Settings/ISection.php',
'OCP\\Settings\\ISettings' => $baseDir . '/lib/public/Settings/ISettings.php',

View File

@ -255,6 +255,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Security\\ISecureRandom' => __DIR__ . '/../../..' . '/lib/public/Security/ISecureRandom.php',
'OCP\\Security\\StringUtils' => __DIR__ . '/../../..' . '/lib/public/Security/StringUtils.php',
'OCP\\Session\\Exceptions\\SessionNotAvailableException' => __DIR__ . '/../../..' . '/lib/public/Session/Exceptions/SessionNotAvailableException.php',
'OCP\\Settings\\IIconSection' => __DIR__ . '/../../..' . '/lib/public/Settings/IIconSection.php',
'OCP\\Settings\\IManager' => __DIR__ . '/../../..' . '/lib/public/Settings/IManager.php',
'OCP\\Settings\\ISection' => __DIR__ . '/../../..' . '/lib/public/Settings/ISection.php',
'OCP\\Settings\\ISettings' => __DIR__ . '/../../..' . '/lib/public/Settings/ISettings.php',

View File

@ -792,7 +792,8 @@ class Server extends ServerContainer implements IServerContainer {
$c->getEncryptionManager(),
$c->getUserManager(),
$c->getLockingProvider(),
new \OC\Settings\Mapper($c->getDatabaseConnection())
new \OC\Settings\Mapper($c->getDatabaseConnection()),
$c->getURLGenerator()
);
return $manager;
});

View File

@ -29,6 +29,7 @@ use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
use OCP\Settings\ISettings;
@ -55,6 +56,8 @@ class Manager implements IManager {
private $userManager;
/** @var ILockingProvider */
private $lockingProvider;
/** @var IURLGenerator */
private $url;
/**
* @param ILogger $log
@ -65,7 +68,7 @@ class Manager implements IManager {
* @param IUserManager $userManager
* @param ILockingProvider $lockingProvider
* @param Mapper $mapper
* @internal param IDBConnection $dbc
* @param IURLGenerator $url
*/
public function __construct(
ILogger $log,
@ -75,7 +78,8 @@ class Manager implements IManager {
EncryptionManager $encryptionManager,
IUserManager $userManager,
ILockingProvider $lockingProvider,
Mapper $mapper
Mapper $mapper,
IURLGenerator $url
) {
$this->log = $log;
$this->dbc = $dbc;
@ -85,6 +89,7 @@ class Manager implements IManager {
$this->encryptionManager = $encryptionManager;
$this->userManager = $userManager;
$this->lockingProvider = $lockingProvider;
$this->url = $url;
}
/**
@ -260,11 +265,11 @@ class Manager implements IManager {
public function getAdminSections() {
// built-in sections
$sections = [
0 => [new Section('server', $this->l->t('Server settings'), 0)],
5 => [new Section('sharing', $this->l->t('Sharing'), 0)],
45 => [new Section('encryption', $this->l->t('Encryption'), 0)],
98 => [new Section('additional', $this->l->t('Additional settings'), 0)],
99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0)],
0 => [new Section('server', $this->l->t('Server settings'), 0, $this->url->imagePath('settings', 'admin.svg'))],
5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))],
45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))],
];
$rows = $this->mapper->getAdminSectionsFromDB();

View File

@ -23,25 +23,29 @@
namespace OC\Settings;
use OCP\Settings\ISection;
use OCP\Settings\IIconSection;
class Section implements ISection {
class Section implements IIconSection {
/** @var string */
private $id;
/** @var string */
private $name;
/** @var int */
private $priority;
/** @var string */
private $icon;
/**
* @param string $id
* @param string $name
* @param int $priority
* @param string $icon
*/
public function __construct($id, $name, $priority) {
public function __construct($id, $name, $priority, $icon = '') {
$this->id = $id;
$this->name = $name;
$this->priority = $priority;
$this->icon = $icon;
}
/**
@ -74,4 +78,15 @@ class Section implements ISection {
public function getPriority() {
return $this->priority;
}
/**
* returns the relative path to an 16*16 icon describing the section.
* e.g. '/core/img/places/files.svg'
*
* @returns string
* @since 12
*/
public function getIcon() {
return $this->icon;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* @copyright Copyright (c) 2017, Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCP\Settings;
/**
* @since 12
*/
interface IIconSection extends ISection {
/**
* returns the relative path to an 16*16 icon describing the section.
* e.g. '/core/img/places/files.svg'
*
* @returns string
* @since 12
*/
public function getIcon();
}

View File

@ -24,6 +24,7 @@
namespace OCP\Settings;
/**
* @deprecated 12 Use IIconSection instead
* @since 9.1
*/
interface ISection {

View File

@ -28,7 +28,9 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\Settings\IIconSection;
use OCP\Settings\IManager as ISettingsManager;
use OCP\Settings\ISection;
use OCP\Template;
/**
@ -133,10 +135,16 @@ class AdminSettingsController extends Controller {
/** @var \OC\Settings\Section[] $prioritizedSections */
foreach($sections as $prioritizedSections) {
foreach ($prioritizedSections as $section) {
$icon = '';
if ($section instanceof IIconSection) {
$icon = $section->getIcon();
}
$templateParameters[] = [
'anchor' => $section->getID(),
'section-name' => $section->getName(),
'active' => $section->getID() === $currentSection,
'icon' => $icon,
];
}
}

View File

@ -7,6 +7,29 @@ input#openid, input#webdav { width:20em; }
/* PERSONAL */
/* icons for sidebar */
.nav-icon-personal-settings {
background-image: url('../img/personal.svg?v=1');
}
.nav-icon-sessions {
background-image: url('../img/toggle-filelist.svg?v=1');
}
.nav-icon-apppasswords {
background-image: url('../img/password.svg?v=1');
}
.nav-icon-clientsbox {
background-image: url('../img/change.svg?v=1');
}
.nav-icon-activity {
background-image: url('../img/activity-dark.svg?v=1');
}
.nav-icon-federated-cloud {
background-image: url('../img/share.svg?v=1');
}
.nav-icon-second-factor-backup-codes {
background-image: url('../img/password.svg?v=1');
}
#avatarform {
width: 160px;
padding-right: 0;
@ -713,6 +736,17 @@ table.grid td.date{
}
/* ADMIN */
/* Navigation icons */
#app-navigation img {
margin-bottom: -3px;
margin-right: 6px;
width: 16px;
}
#app-navigation li span.no-icon {
padding-left: 25px;
}
#security-warning li {
list-style: initial;
margin: 10px 0;

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" height="32" width="32" version="1.0">
<path d="m16 1-10 18h11l-1 12 10-18h-11z"/>
</svg>

After

Width:  |  Height:  |  Size: 185 B

5
settings/img/change.svg Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1">
<path d="m7.9375 0c-3.1175 0.023214-6.0756 1.876-7.3438 4.9375l2.7812 1.1563c1.0568-2.5513 3.98-3.7756 6.5312-2.7188 0.8628 0.3573 1.5738 0.9274 2.0938 1.625l-2 2h6v-6l-1.875 1.875c-0.802-0.9616-1.825-1.7688-3.063-2.2812-1.02-0.4227-2.0853-0.60149-3.1245-0.59375z"/>
<path d="m0 9.5v6l2.0938-2.094c0.7676 0.843 1.7205 1.535 2.8437 2 4.082 1.691 8.7775-0.262 10.468-4.344l-2.781-1.1558c-1.057 2.5508-3.98 3.7758-6.5312 2.7188-0.7435-0.308-1.3509-0.805-1.8438-1.375l1.75-1.75h-6z"/>
</svg>

After

Width:  |  Height:  |  Size: 623 B

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 71 100"><path d="M35.5 6.25c-13.807 0-25 11.193-25 25v12.5H4.25V87.5h62.5V43.75H60.5v-12.5c0-13.807-11.194-25-25-25zm0 12.5c6.904 0 12.5 5.596 12.5 12.5v12.5H23v-12.5c0-6.904 5.596-12.5 12.5-12.5z"/></svg>

After

Width:  |  Height:  |  Size: 281 B

1
settings/img/share.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 16 16"><path d="M12.228 1a2.457 2.457 0 0 0-2.46 2.454c0 .075.01.15.016.224L5.05 6.092a2.445 2.445 0 0 0-1.596-.586A2.453 2.453 0 0 0 1 7.96a2.453 2.453 0 0 0 2.454 2.455 2.45 2.45 0 0 0 1.46-.477l4.865 2.474c-.004.044-.01.09-.01.134a2.457 2.457 0 1 0 .804-1.818l-4.696-2.4c.02-.123.035-.25.035-.378 0-.072-.01-.144-.015-.214l4.74-2.414A2.457 2.457 0 1 0 12.228.99z"/></svg>

After

Width:  |  Height:  |  Size: 450 B

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 16 16" version="1"><rect rx=".5" ry=".5" height="4" width="4" y="1" x="1"/><rect rx=".5" ry=".5" height="1" width="9" y="2" x="6"/><rect rx=".5" ry=".5" height="4" width="4" y="6" x="1"/><rect rx=".5" ry=".5" height="1" width="9" y="7" x="6"/><rect rx=".5" ry=".5" height="4" width="4" y="11" x="1"/><rect rx=".5" ry=".5" height="1" width="9" y="12" x="6"/></svg>

After

Width:  |  Height:  |  Size: 439 B

View File

@ -30,14 +30,28 @@ script('files', 'jquery.fileupload');
<div id="app-navigation">
<ul>
<?php foreach($_['forms'] as $form) {
<?php
foreach($_['forms'] as $form) {
if (isset($form['anchor'])) {
$anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]);
$class = 'nav-icon-' . $form['anchor'];
$sectionName = $form['section-name'];
$active = $form['active'] ? ' class="active"' : '';
print_unescaped(sprintf("<li%s><a href='%s'>%s</a></li>", $active, \OCP\Util::sanitizeHTML($anchor), \OCP\Util::sanitizeHTML($sectionName)));
?>
<li <?php print_unescaped($form['active'] ? ' class="active"' : ''); ?>>
<a href="<?php p($anchor); ?>">
<?php if (!empty($form['icon'])) { ?>
<img alt="" src="<?php print_unescaped($form['icon']); ?>">
<span><?php p($form['section-name']); ?></span>
<?php } else { ?>
<span class="no-icon"><?php p($form['section-name']); ?></span>
<?php } ?>
</a>
</li>
<?php
}
}?>
}
?>
</ul>
</div>

View File

@ -9,12 +9,14 @@
?>
<div id="app-navigation">
<ul>
<ul class="with-icon">
<?php foreach($_['forms'] as $form) {
if (isset($form['anchor'])) {
$anchor = '#' . $form['anchor'];
$class = 'nav-icon-' . $form['anchor'];
$sectionName = $form['section-name'];
print_unescaped(sprintf("<li><a href='%s'>%s</a></li>", \OCP\Util::sanitizeHTML($anchor), \OCP\Util::sanitizeHTML($sectionName)));
print_unescaped(sprintf("<li><a href='%s' class='%s'>%s</a></li>", \OCP\Util::sanitizeHTML($anchor),
\OCP\Util::sanitizeHTML($class), \OCP\Util::sanitizeHTML($sectionName)));
}
}?>
</ul>

View File

@ -32,6 +32,7 @@ use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
use Test\TestCase;
@ -55,18 +56,21 @@ class ManagerTest extends TestCase {
private $lockingProvider;
/** @var Mapper|\PHPUnit_Framework_MockObject_MockObject */
private $mapper;
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
private $url;
public function setUp() {
parent::setUp();
$this->logger = $this->getMockBuilder('\OCP\ILogger')->getMock();
$this->dbConnection = $this->getMockBuilder('\OCP\IDBConnection')->getMock();
$this->l10n = $this->getMockBuilder('\OCP\IL10N')->getMock();
$this->config = $this->getMockBuilder('\OCP\IConfig')->getMock();
$this->encryptionManager = $this->getMockBuilder('\OCP\Encryption\IManager')->getMock();
$this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock();
$this->lockingProvider = $this->getMockBuilder('\OCP\Lock\ILockingProvider')->getMock();
$this->mapper = $this->getMockBuilder(Mapper::class)->disableOriginalConstructor()->getMock();
$this->logger = $this->createMock(ILogger::class);
$this->dbConnection = $this->createMock(IDBConnection::class);
$this->l10n = $this->createMock(IL10N::class);
$this->config = $this->createMock(IConfig::class);
$this->encryptionManager = $this->createMock(IManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->lockingProvider = $this->createMock(ILockingProvider::class);
$this->mapper = $this->createMock(Mapper::class);
$this->url = $this->createMock(IURLGenerator::class);
$this->manager = new Manager(
$this->logger,
@ -76,7 +80,8 @@ class ManagerTest extends TestCase {
$this->encryptionManager,
$this->userManager,
$this->lockingProvider,
$this->mapper
$this->mapper,
$this->url
);
}
@ -133,22 +138,26 @@ class ManagerTest extends TestCase {
$this->mapper->expects($this->once())
->method('getAdminSectionsFromDB')
->will($this->returnValue([
['class' => '\OCA\LogReader\Settings\Section', 'priority' => 90]
['class' => \OCA\WorkflowEngine\Settings\Section::class, 'priority' => 90]
]));
$this->mapper->expects($this->once())
->method('getAdminSettingsCountFromDB')
->will($this->returnValue([
'logging' => 1
]));
$this->url->expects($this->exactly(5))
->method('imagePath')
->willReturnMap([
['settings', 'admin.svg', '1'],
['core', 'actions/share.svg', '2'],
['core', 'actions/password.svg', '3'],
['core', 'actions/settings-dark.svg', '4'],
['settings', 'help.svg', '5'],
]);
$this->assertEquals([
0 => [new Section('server', 'Server settings', 0)],
5 => [new Section('sharing', 'Sharing', 0)],
45 => [new Section('encryption', 'Encryption', 0)],
90 => [new \OCA\LogReader\Settings\Section(\OC::$server->getL10N('logreader'))],
98 => [new Section('additional', 'Additional settings', 0)],
99 => [new Section('tips-tricks', 'Tips & tricks', 0)],
0 => [new Section('server', 'Server settings', 0, '1')],
5 => [new Section('sharing', 'Sharing', 0, '2')],
45 => [new Section('encryption', 'Encryption', 0, '3')],
90 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
98 => [new Section('additional', 'Additional settings', 0, '4')],
99 => [new Section('tips-tricks', 'Tips & tricks', 0, '5')],
], $this->manager->getAdminSections());
}
@ -161,19 +170,24 @@ class ManagerTest extends TestCase {
$this->mapper->expects($this->once())
->method('getAdminSectionsFromDB')
->will($this->returnValue([
['class' => '\OCA\LogReader\Settings\Section', 'priority' => 90]
]));
$this->mapper->expects($this->once())
->method('getAdminSettingsCountFromDB')
->will($this->returnValue([]));
$this->url->expects($this->exactly(5))
->method('imagePath')
->willReturnMap([
['settings', 'admin.svg', '1'],
['core', 'actions/share.svg', '2'],
['core', 'actions/password.svg', '3'],
['core', 'actions/settings-dark.svg', '4'],
['settings', 'help.svg', '5'],
]);
$this->assertEquals([
0 => [new Section('server', 'Server settings', 0)],
5 => [new Section('sharing', 'Sharing', 0)],
45 => [new Section('encryption', 'Encryption', 0)],
98 => [new Section('additional', 'Additional settings', 0)],
99 => [new Section('tips-tricks', 'Tips & tricks', 0)],
0 => [new Section('server', 'Server settings', 0, '1')],
5 => [new Section('sharing', 'Sharing', 0, '2')],
45 => [new Section('encryption', 'Encryption', 0, '3')],
98 => [new Section('additional', 'Additional settings', 0, '4')],
99 => [new Section('tips-tricks', 'Tips & tricks', 0, '5')],
], $this->manager->getAdminSections());
}