enlist only registered sections that also have settings registered to

This commit is contained in:
Arthur Schiwon 2016-08-19 17:52:33 +02:00 committed by Joas Schilling
parent cb3c1eee97
commit 7972fa5527
No known key found for this signature in database
GPG key ID: E166FD8976B3BAC8
2 changed files with 29 additions and 7 deletions

View file

@ -327,10 +327,6 @@ class Manager implements IManager {
* @inheritdoc
*/
public function getAdminSections() {
$query = $this->dbc->getQueryBuilder();
$query->select(['class', 'priority'])
->from(self::TABLE_ADMIN_SECTIONS);
// built-in sections
$sections = [
0 => [new Section('server', $this->l->t('Server settings'), 0)],
@ -341,7 +337,15 @@ class Manager implements IManager {
99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0)],
];
$query = $this->dbc->getQueryBuilder();
$query->selectDistinct('s.class')
->addSelect('s.priority')
->from(self::TABLE_ADMIN_SECTIONS, 's')
->from(self::TABLE_ADMIN_SETTINGS, 'f')
->where($query->expr()->eq('s.id', 'f.section'))
;
$result = $query->execute();
while($row = $result->fetch()) {
if(!isset($sections[$row['priority']])) {
$sections[$row['priority']] = [];

View file

@ -136,15 +136,33 @@ class ManagerTest extends TestCase {
public function testGetAdminSections() {
$qb = $this->getMockBuilder('\OCP\DB\QueryBuilder\IQueryBuilder')->getMock();
$expr = $this->getMockBuilder('OCP\DB\QueryBuilder\IExpressionBuilder')->getMock();
$qb
->expects($this->once())
->method('select')
->with(['class', 'priority'])
->with(['s.class', 's.priority'])
->willReturn($qb);
$qb
->expects($this->exactly(2))
->method('from')
->willReturn($qb);
$qb
->expects($this->at(1))
->method('from')
->with('admin_sections', 's')
->willReturn($qb);
$qb
->expects($this->at(2))
->method('from')
->with('admin_settings', 'f')
->willReturn($qb);
$qb
->expects($this->once())
->method('from')
->with('admin_sections')
->method('expr')
->willReturn($expr);
$qb
->expects($this->once())
->method('where')
->willReturn($qb);
$stmt = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement')->getMock();
$qb