Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Admin settings #207

Merged
merged 1 commit into from
Jan 12, 2017
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
61 changes: 30 additions & 31 deletions lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,51 +21,50 @@

namespace OCA\Spreed\Settings;


use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\Settings\ISettings;

use OCA\Spreed\Util;

class Admin implements ISettings {

/** @var IConfig */
private $config;
/** @var IConfig */
private $config;

public function __construct(IConfig $config) {
$this->config = $config;
}
public function __construct(IConfig $config) {
$this->config = $config;
}

/**
* @return TemplateResponse
*/
public function getForm() {
$parameters = [
/**
* @return TemplateResponse
*/
public function getForm() {
$parameters = [
'stunServer' => $this->config->getAppValue('spreed', 'stun_server', 'stun.nextcloud.com:443'),
'turnServer' => $this->config->getAppValue('spreed', 'turn_server', ''),
'turnServerSecret' => $this->config->getAppValue('spreed', 'turn_server_secret', ''),
'turnServerProtocols' => $this->config->getAppValue('spreed', 'turn_server_protocols', ''),
];
];

return new TemplateResponse('spreed', 'settings-admin', $parameters, '');
}
return new TemplateResponse('spreed', 'settings-admin', $parameters, '');
}

/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection() {
return 'additional';
}
/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection() {
return 'additional';
}

/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/
public function getPriority() {
return 30;
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/
public function getPriority() {
return 30;
}

}
64 changes: 64 additions & 0 deletions tests/php/Settings/AdminTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* @copyright Copyright (c) 2017 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 OCA\Spreed\Tests\php\Settings;

use OCA\Spreed\Settings\Admin;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;

class AdminTest extends \Test\TestCase {

/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $config;
/** @var Admin */
protected $admin;

public function setUp() {
parent::setUp();

$this->config = $this->createMock(IConfig::class);

$this->admin = new Admin($this->config);
}

public function testGetSection() {
$this->assertInternalType('string', $this->admin->getSection());
$this->assertNotEmpty($this->admin->getSection());
}

public function testGetPriority() {
$this->assertInternalType('int', $this->admin->getPriority());
$this->assertGreaterThan(0, $this->admin->getPriority());
}

public function testGetForm() {
$form = $this->admin->getForm();
$this->assertInstanceOf(TemplateResponse::class, $form);
$this->assertSame('', $form->getRenderAs());

$params = $form->getParams();
$this->assertArrayHasKey('stunServer', $params);
$this->assertArrayHasKey('turnServer', $params);
$this->assertArrayHasKey('turnServerSecret', $params);
$this->assertArrayHasKey('turnServerProtocols', $params);
}
}