Skip to content

Commit

Permalink
add test files for apps/settings changes #40490
Browse files Browse the repository at this point in the history
Signed-off-by: Private Maker <[email protected]>
  • Loading branch information
privatemaker committed Sep 21, 2023
1 parent 2b488d8 commit bb2353a
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 12 deletions.
4 changes: 2 additions & 2 deletions apps/settings/composer/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => '__root__',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'b1797842784b250fb01ed5e3bf130705eb94751b',
'reference' => '1b774d74ea236e5c276211ee4916484f931eedba',
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'__root__' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'b1797842784b250fb01ed5e3bf130705eb94751b',
'reference' => '1b774d74ea236e5c276211ee4916484f931eedba',
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
Expand Down
4 changes: 0 additions & 4 deletions apps/settings/lib/Controller/PersonalSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,11 @@ public function __construct(
INavigationManager $navigationManager,
ISettingsManager $settingsManager,
IUserSession $userSession,
IGroupManager $groupManager,
ISubAdmin $subAdmin
) {
parent::__construct($appName, $request);
$this->navigationManager = $navigationManager;
$this->settingsManager = $settingsManager;
$this->userSession = $userSession;
$this->subAdmin = $subAdmin;
$this->groupManager = $groupManager;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions apps/settings/templates/settings/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
*/

use OCP\IURLGenerator;

style('settings', 'settings');
script('settings', 'settings');
\OCP\Util::addScript('settings', 'legacy-admin');
Expand All @@ -33,9 +35,10 @@
<ul tabindex="0">
<li class="app-navigation-caption"><?php p($l->t('Administration')); ?></li>
<?php foreach ($_['forms']['admin'] as $form):
if (isset($form['anchor'])):
$anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]);
$class = 'nav-icon-' . $form['anchor'];
if (isset($form['anchor'])):
$urlGenerator = \OC::$server->get(IURLGenerator::class);
$anchor = $urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]);
$class = 'nav-icon-' . $form['anchor'];
$sectionName = $form['section-name']; ?>
<li <?php print_unescaped($form['active'] ? ' class="active"' : ''); ?> data-section-id="<?php print_unescaped($form['anchor']); ?>" data-section-type="admin">
<a href="<?php p($anchor); ?>"<?php print_unescaped($form['active'] ? ' aria-current="page"' : ''); ?>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
namespace OCA\Settings\Tests\Controller;

use OCA\Settings\Controller\AdminSettingsController;
use OCA\Settings\Settings\Personal\ServerDevNotice;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Group\ISubAdmin;
use OCP\IGroupManager;
Expand Down Expand Up @@ -126,8 +125,8 @@ public function testIndex() {

$idx = $this->adminSettingsController->index('test');

$expected = new TemplateResponse('settings', 'settings/frame', [
'forms' => ['personal' => [], 'admin' => []],
$expected = new TemplateResponse('settings', 'settings/admin', [
'forms' => ['admin' => []],
'content' => ''
]);
$this->assertEquals($expected, $idx);
Expand Down
110 changes: 110 additions & 0 deletions apps/settings/tests/Controller/PersonalSettingsControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <[email protected]>
*
* @author Arthur Schiwon <[email protected]>
* @author Christoph Wurst <[email protected]>
* @author Jan C. Borchardt <[email protected]>
* @author Lukas Reschke <[email protected]>
* @author Roeland Jago Douma <[email protected]>
* @author Private Maker <[email protected]>
*
* @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 OCA\Settings\Tests\Controller;

use OCA\Settings\Controller\PersonalSettingsController;
use OCA\Settings\Settings\Personal\ServerDevNotice;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Group\ISubAdmin;
use OCP\IGroupManager;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Settings\IManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

/**
* Class PersonalSettingsControllerTest
*
* @group DB
*
* @package Tests\Settings\Controller
*/
class PersonalSettingsControllerTest extends TestCase {

/** @var PersonalSettingsController */
private $personalSettingsController;
/** @var IRequest|MockObject */
private $request;
/** @var INavigationManager|MockObject */
private $navigationManager;
/** @var IManager|MockObject */
private $settingsManager;
/** @var IUserSession|MockObject */
private $userSession;
/** @var IGroupManager|MockObject */

protected function setUp(): void {
parent::setUp();

$this->request = $this->createMock(IRequest::class);
$this->navigationManager = $this->createMock(INavigationManager::class);
$this->settingsManager = $this->createMock(IManager::class);
$this->userSession = $this->createMock(IUserSession::class);

$this->personalSettingsController = new PersonalSettingsController(
'settings',
$this->request,
$this->navigationManager,
$this->settingsManager,
$this->userSession,
);

$user = \OC::$server->getUserManager()->createUser($this->adminUid, 'mylongrandompassword');
\OC_User::setUserId($user->getUID());
// \OC::$server->getGroupManager()->createGroup('admin')->addUser($user);
}

protected function tearDown(): void {
// \OC::$server->getUserManager()->get($this->adminUid)->delete();

parent::tearDown();
}

public function testIndex() {
$user = $this->createMock(IUser::class);
$this->userSession
->method('getUser')
->willReturn($user);
$user->method('getUID')->willReturn('user123');
$this->settingsManager
->expects($this->once())
->method('getPersonalSections')
->willReturn([]);

$idx = $this->personalSettingsController->index('test');

$expected = new TemplateResponse('settings', 'settings/personal', [
'forms' => ['personal' => []],
'content' => ''
]);
$this->assertEquals($expected, $idx);
}
}

0 comments on commit bb2353a

Please sign in to comment.