зеркало из https://github.com/nextcloud/spreed.git
Fix unit tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Родитель
c26d958b98
Коммит
fb766fb1a5
|
@ -47,8 +47,8 @@ class Config {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getStunServer() {
|
public function getStunServer() {
|
||||||
$config = $this->config->getAppValue('spreed', 'stun_servers', 'stun.nextcloud.com:443');
|
$config = $this->config->getAppValue('spreed', 'stun_servers', json_encode(['stun.nextcloud.com:443']));
|
||||||
$servers = json_decode($config);
|
$servers = json_decode($config, true);
|
||||||
|
|
||||||
if ($servers === null) {
|
if ($servers === null) {
|
||||||
return $config ?: 'stun.nextcloud.com:443';
|
return $config ?: 'stun.nextcloud.com:443';
|
||||||
|
@ -69,9 +69,9 @@ class Config {
|
||||||
*/
|
*/
|
||||||
public function getTurnSettings() {
|
public function getTurnSettings() {
|
||||||
$config = $this->config->getAppValue('spreed', 'turn_servers');
|
$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 [
|
return [
|
||||||
'server' => '',
|
'server' => '',
|
||||||
'username' => '',
|
'username' => '',
|
||||||
|
|
|
@ -28,6 +28,11 @@ use Test\TestCase;
|
||||||
class ConfigTest extends TestCase {
|
class ConfigTest extends TestCase {
|
||||||
|
|
||||||
public function testGetStunServer() {
|
public function testGetStunServer() {
|
||||||
|
$servers = [
|
||||||
|
'stun1.example.com:443',
|
||||||
|
'stun2.example.com:129',
|
||||||
|
];
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject|ITimeFactory $timeFactory */
|
/** @var \PHPUnit_Framework_MockObject_MockObject|ITimeFactory $timeFactory */
|
||||||
$timeFactory = $this->createMock(ITimeFactory::class);
|
$timeFactory = $this->createMock(ITimeFactory::class);
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject|IConfig $config */
|
/** @var \PHPUnit_Framework_MockObject_MockObject|IConfig $config */
|
||||||
|
@ -35,31 +40,35 @@ class ConfigTest extends TestCase {
|
||||||
$config
|
$config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('spreed', 'stun_server', 'stun.nextcloud.com:443')
|
->with('spreed', 'stun_servers', json_encode(['stun.nextcloud.com:443']))
|
||||||
->willReturn('88.198.160.129');
|
->willReturn(json_encode($servers));
|
||||||
|
|
||||||
$helper = new Config($config, $timeFactory);
|
$helper = new Config($config, $timeFactory);
|
||||||
$this->assertSame('88.198.160.129', $helper->getStunServer());
|
|
||||||
|
$this->assertTrue(in_array($helper->getStunServer(), $servers, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGenerateTurnSettings() {
|
public function testGenerateTurnSettings() {
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject|IConfig $config */
|
/** @var \PHPUnit_Framework_MockObject_MockObject|IConfig $config */
|
||||||
$config = $this->createMock(IConfig::class);
|
$config = $this->createMock(IConfig::class);
|
||||||
$config
|
$config
|
||||||
->expects($this->at(0))
|
->expects($this->once())
|
||||||
->method('getAppValue')
|
->method('getAppValue')
|
||||||
->with('spreed', 'turn_server', '')
|
->with('spreed', 'turn_servers', '')
|
||||||
->willReturn('turn.example.org');
|
->willReturn(json_encode([
|
||||||
$config
|
[
|
||||||
->expects($this->at(1))
|
'server' => 'turn.example.org',
|
||||||
->method('getAppValue')
|
'secret' => 'thisisasupersecretsecret',
|
||||||
->with('spreed', 'turn_server_secret', '')
|
'protocols' => 'udp,tcp',
|
||||||
->willReturn('thisisasupersecretsecret');
|
],
|
||||||
$config
|
[
|
||||||
->expects($this->at(2))
|
'server' => 'turn2.example.com',
|
||||||
->method('getAppValue')
|
'secret' => 'ThisIsAlsoSuperSecret',
|
||||||
->with('spreed', 'turn_server_protocols', '')
|
'protocols' => 'tcp',
|
||||||
->willReturn('udp,tcp');
|
],
|
||||||
|
]));
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject|ITimeFactory $timeFactory */
|
/** @var \PHPUnit_Framework_MockObject_MockObject|ITimeFactory $timeFactory */
|
||||||
$timeFactory = $this->createMock(ITimeFactory::class);
|
$timeFactory = $this->createMock(ITimeFactory::class);
|
||||||
$timeFactory
|
$timeFactory
|
||||||
|
@ -69,11 +78,22 @@ class ConfigTest extends TestCase {
|
||||||
|
|
||||||
$helper = new Config($config, $timeFactory);
|
$helper = new Config($config, $timeFactory);
|
||||||
|
|
||||||
$this->assertSame(array(
|
//
|
||||||
'server' => 'turn.example.org',
|
$server = $helper->getTurnSettings();
|
||||||
'username' => '1479829425',
|
if ($server['server'] === 'turn.example.org') {
|
||||||
'password' => 'ZY8fZQxAw/24gT0XYnMlcepUFlI=',
|
$this->assertSame([
|
||||||
'protocols' => 'udp,tcp',
|
'server' => 'turn.example.org',
|
||||||
), $helper->getTurnSettings());
|
'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\AppFramework\Http\TemplateResponse;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
|
||||||
class AdminTest extends \Test\TestCase {
|
class StunServerTest extends \Test\TestCase {
|
||||||
|
|
||||||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $config;
|
protected $config;
|
||||||
/** @var Admin */
|
/** @var StunServer */
|
||||||
protected $admin;
|
protected $admin;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
|
@ -37,7 +37,7 @@ class AdminTest extends \Test\TestCase {
|
||||||
|
|
||||||
$this->config = $this->createMock(IConfig::class);
|
$this->config = $this->createMock(IConfig::class);
|
||||||
|
|
||||||
$this->admin = new Admin($this->config);
|
$this->admin = new StunServer($this->config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetSection() {
|
public function testGetSection() {
|
||||||
|
@ -57,8 +57,5 @@ class AdminTest extends \Test\TestCase {
|
||||||
|
|
||||||
$params = $form->getParams();
|
$params = $form->getParams();
|
||||||
$this->assertArrayHasKey('stunServer', $params);
|
$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);
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче