Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-09-29 11:56:22 +02:00
Родитель c26d958b98
Коммит fb766fb1a5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E166FD8976B3BAC8
5 изменённых файлов: 187 добавлений и 34 удалений

Просмотреть файл

@ -47,8 +47,8 @@ class Config {
* @return string
*/
public function getStunServer() {
$config = $this->config->getAppValue('spreed', 'stun_servers', 'stun.nextcloud.com:443');
$servers = json_decode($config);
$config = $this->config->getAppValue('spreed', 'stun_servers', json_encode(['stun.nextcloud.com:443']));
$servers = json_decode($config, true);
if ($servers === null) {
return $config ?: 'stun.nextcloud.com:443';
@ -69,9 +69,9 @@ class Config {
*/
public function getTurnSettings() {
$config = $this->config->getAppValue('spreed', 'turn_servers');
$servers = json_decode($config);
$servers = json_decode($config, true);
if ($servers === null || !empty($servers) || !is_array($servers)) {
if ($servers === null || empty($servers) || !is_array($servers)) {
return [
'server' => '',
'username' => '',

Просмотреть файл

@ -28,6 +28,11 @@ use Test\TestCase;
class ConfigTest extends TestCase {
public function testGetStunServer() {
$servers = [
'stun1.example.com:443',
'stun2.example.com:129',
];
/** @var \PHPUnit_Framework_MockObject_MockObject|ITimeFactory $timeFactory */
$timeFactory = $this->createMock(ITimeFactory::class);
/** @var \PHPUnit_Framework_MockObject_MockObject|IConfig $config */
@ -35,31 +40,35 @@ class ConfigTest extends TestCase {
$config
->expects($this->once())
->method('getAppValue')
->with('spreed', 'stun_server', 'stun.nextcloud.com:443')
->willReturn('88.198.160.129');
->with('spreed', 'stun_servers', json_encode(['stun.nextcloud.com:443']))
->willReturn(json_encode($servers));
$helper = new Config($config, $timeFactory);
$this->assertSame('88.198.160.129', $helper->getStunServer());
$this->assertTrue(in_array($helper->getStunServer(), $servers, true));
}
public function testGenerateTurnSettings() {
/** @var \PHPUnit_Framework_MockObject_MockObject|IConfig $config */
$config = $this->createMock(IConfig::class);
$config
->expects($this->at(0))
->expects($this->once())
->method('getAppValue')
->with('spreed', 'turn_server', '')
->willReturn('turn.example.org');
$config
->expects($this->at(1))
->method('getAppValue')
->with('spreed', 'turn_server_secret', '')
->willReturn('thisisasupersecretsecret');
$config
->expects($this->at(2))
->method('getAppValue')
->with('spreed', 'turn_server_protocols', '')
->willReturn('udp,tcp');
->with('spreed', 'turn_servers', '')
->willReturn(json_encode([
[
'server' => 'turn.example.org',
'secret' => 'thisisasupersecretsecret',
'protocols' => 'udp,tcp',
],
[
'server' => 'turn2.example.com',
'secret' => 'ThisIsAlsoSuperSecret',
'protocols' => 'tcp',
],
]));
/** @var \PHPUnit_Framework_MockObject_MockObject|ITimeFactory $timeFactory */
$timeFactory = $this->createMock(ITimeFactory::class);
$timeFactory
@ -69,11 +78,22 @@ class ConfigTest extends TestCase {
$helper = new Config($config, $timeFactory);
$this->assertSame(array(
'server' => 'turn.example.org',
'username' => '1479829425',
'password' => 'ZY8fZQxAw/24gT0XYnMlcepUFlI=',
'protocols' => 'udp,tcp',
), $helper->getTurnSettings());
//
$server = $helper->getTurnSettings();
if ($server['server'] === 'turn.example.org') {
$this->assertSame([
'server' => 'turn.example.org',
'username' => '1479829425',
'password' => 'ZY8fZQxAw/24gT0XYnMlcepUFlI=',
'protocols' => 'udp,tcp',
], $server);
} else {
$this->assertSame([
'server' => 'turn2.example.com',
'username' => '1479829425',
'password' => 'VoqRpE4ktQ85TqFps8Qt+scEEvE=',
'protocols' => 'tcp',
], $server);
}
}
}

Просмотреть файл

@ -0,0 +1,75 @@
<?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\Admin;
use OCA\Spreed\Settings\Admin\Section;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
class SectionTest extends \Test\TestCase {
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
protected $url;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
protected $l;
/** @var Section */
protected $admin;
public function setUp() {
parent::setUp();
$this->url = $this->createMock(IURLGenerator::class);
$this->l = $this->createMock(IL10N::class);
$this->admin = new Section($this->url, $this->l);
}
public function testGetID() {
$this->assertInternalType('string', $this->admin->getID());
$this->assertNotEmpty($this->admin->getID());
}
public function testGetName() {
$this->l->expects($this->exactly(2))
->method('t')
->with('Video calls')
->willReturnArgument(0);
$this->assertInternalType('string', $this->admin->getName());
$this->assertNotEmpty($this->admin->getName());
}
public function testGetIcon() {
$this->url->expects($this->exactly(2))
->method('imagePath')
->with('spreed', 'app-dark.svg')
->willReturn('apps/spreed/img/app-dark.svg');
$this->assertInternalType('string', $this->admin->getIcon());
$this->assertNotEmpty($this->admin->getIcon());
}
public function testGetPriority() {
$this->assertInternalType('int', $this->admin->getPriority());
$this->assertGreaterThan(0, $this->admin->getPriority());
}
}

Просмотреть файл

@ -19,17 +19,17 @@
*
*/
namespace OCA\Spreed\Tests\php\Settings;
namespace OCA\Spreed\Tests\php\Settings\Admin;
use OCA\Spreed\Settings\Admin;
use OCA\Spreed\Settings\Admin\StunServer;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
class AdminTest extends \Test\TestCase {
class StunServerTest extends \Test\TestCase {
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $config;
/** @var Admin */
/** @var StunServer */
protected $admin;
public function setUp() {
@ -37,7 +37,7 @@ class AdminTest extends \Test\TestCase {
$this->config = $this->createMock(IConfig::class);
$this->admin = new Admin($this->config);
$this->admin = new StunServer($this->config);
}
public function testGetSection() {
@ -57,8 +57,5 @@ class AdminTest extends \Test\TestCase {
$params = $form->getParams();
$this->assertArrayHasKey('stunServer', $params);
$this->assertArrayHasKey('turnServer', $params);
$this->assertArrayHasKey('turnServerSecret', $params);
$this->assertArrayHasKey('turnServerProtocols', $params);
}
}

Просмотреть файл

@ -0,0 +1,61 @@
<?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\Admin;
use OCA\Spreed\Settings\Admin\TurnServer;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
class TurnServerTest extends \Test\TestCase {
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $config;
/** @var TurnServer */
protected $admin;
public function setUp() {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
$this->admin = new TurnServer($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('turnServer', $params);
}
}