Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-11-27 18:31:44 +0300
committerJoas Schilling <coding@schilljs.com>2019-12-04 10:36:59 +0300
commit0e1d2b39b92c77d2c58ef60c525677957713e546 (patch)
tree745d723c175ff8ab2967b0e939f55a4d0d1da221 /tests
parentff7efea822e95e8927929140995ed5031bec5d80 (diff)
Typed events for Talk
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/php/Chat/ChatManagerTest.php6
-rw-r--r--tests/php/Chat/Command/ExecutorTest.php22
-rw-r--r--tests/php/Chat/Command/ShellExecutorTest.php28
-rw-r--r--tests/php/Controller/RoomControllerTest.php6
-rw-r--r--tests/php/Controller/SignalingControllerTest.php15
-rw-r--r--tests/php/RoomTest.php (renamed from tests/php/PasswordVerificationTest.php)27
-rw-r--r--tests/php/Signaling/BackendNotifierTest.php13
7 files changed, 46 insertions, 71 deletions
diff --git a/tests/php/Chat/ChatManagerTest.php b/tests/php/Chat/ChatManagerTest.php
index 647f5a317..4e20e31a6 100644
--- a/tests/php/Chat/ChatManagerTest.php
+++ b/tests/php/Chat/ChatManagerTest.php
@@ -31,16 +31,16 @@ use OCA\Talk\Room;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
class ChatManagerTest extends TestCase {
/** @var CommentsManager|ICommentsManager|MockObject */
protected $commentsManager;
- /** @var EventDispatcherInterface|MockObject */
+ /** @var IEventDispatcher|MockObject */
protected $dispatcher;
/** @var Notifier|MockObject */
protected $notifier;
@@ -53,7 +53,7 @@ class ChatManagerTest extends TestCase {
parent::setUp();
$this->commentsManager = $this->createMock(CommentsManager::class);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->notifier = $this->createMock(Notifier::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
diff --git a/tests/php/Chat/Command/ExecutorTest.php b/tests/php/Chat/Command/ExecutorTest.php
index 9b449123a..f935a46b0 100644
--- a/tests/php/Chat/Command/ExecutorTest.php
+++ b/tests/php/Chat/Command/ExecutorTest.php
@@ -25,20 +25,21 @@ namespace OCA\Talk\Tests\php\Chat\Command;
use OCA\Talk\Chat\Command\Executor;
use OCA\Talk\Chat\Command\ShellExecutor;
+use OCA\Talk\Events\CommandEvent;
use OCA\Talk\Model\Command;
use OCA\Talk\Room;
use OCA\Talk\Service\CommandService;
use OCP\Comments\IComment;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IL10N;
use OCP\ILogger;
use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;
class ExecutorTest extends TestCase {
- /** @var EventDispatcherInterface|MockObject */
+ /** @var IEventDispatcher|MockObject */
protected $dispatcher;
/** @var ShellExecutor|MockObject */
@@ -59,7 +60,7 @@ class ExecutorTest extends TestCase {
public function setUp(): void {
parent::setUp();
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->shellExecutor = $this->createMock(ShellExecutor::class);
$this->commandService = $this->createMock(CommandService::class);
$this->logger = $this->createMock(ILogger::class);
@@ -90,18 +91,9 @@ class ExecutorTest extends TestCase {
$room = $this->createMock(Room::class);
$command = Command::fromParams([]);
- $event = $this->createMock(GenericEvent::class);
+ $event = $this->createMock(CommandEvent::class);
$event->expects($this->once())
- ->method('setArguments')
- ->with([
- 'room' => $room,
- 'message' => $message,
- 'arguments' => $arguments,
- 'output' => '',
- ]);
- $event->expects($this->once())
- ->method('getArgument')
- ->with('output')
+ ->method('getOutput')
->willReturn($expected);
$executor = $this->getMockBuilder(Executor::class)
@@ -116,7 +108,7 @@ class ExecutorTest extends TestCase {
->getMock();
$executor->expects($this->once())
->method('createEvent')
- ->with($command)
+ ->with($room, $message, $command, $arguments)
->willReturn($event);
$this->dispatcher->expects($this->once())
diff --git a/tests/php/Chat/Command/ShellExecutorTest.php b/tests/php/Chat/Command/ShellExecutorTest.php
index 74c8978ce..21bf37503 100644
--- a/tests/php/Chat/Command/ShellExecutorTest.php
+++ b/tests/php/Chat/Command/ShellExecutorTest.php
@@ -23,39 +23,11 @@
namespace OCA\Talk\Tests\php\Chat\Command;
-use OCA\Talk\Chat\Command\Executor;
use OCA\Talk\Chat\Command\ShellExecutor;
-use OCA\Talk\Model\Command;
-use OCA\Talk\Room;
-use OCA\Talk\Service\CommandService;
-use OCP\Comments\IComment;
-use OCP\IL10N;
-use OCP\ILogger;
-use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;
class ShellExecutorTest extends TestCase {
- /** @var EventDispatcherInterface|MockObject */
- protected $dispatcher;
-
- /** @var ShellExecutor|MockObject */
- protected $shellExecutor;
-
- /** @var CommandService|MockObject */
- protected $commandService;
-
- /** @var ILogger|MockObject */
- protected $logger;
-
- /** @var IL10N|MockObject */
- protected $l10n;
-
- /** @var Executor */
- protected $executor;
-
public function dataExecShell(): array {
return [
['admin', 'token', '', '', '', ''],
diff --git a/tests/php/Controller/RoomControllerTest.php b/tests/php/Controller/RoomControllerTest.php
index 66a93e329..d31226bec 100644
--- a/tests/php/Controller/RoomControllerTest.php
+++ b/tests/php/Controller/RoomControllerTest.php
@@ -36,12 +36,12 @@ use OCA\Talk\TalkSession;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class RoomControllerTest extends \Test\TestCase {
@@ -59,7 +59,7 @@ class RoomControllerTest extends \Test\TestCase {
protected $chatManager;
/** @var GuestManager|MockObject */
protected $guestManager;
- /** @var EventDispatcherInterface|MockObject */
+ /** @var IEventDispatcher|MockObject */
protected $dispatcher;
/** @var MessageParser|MockObject */
protected $messageParser;
@@ -79,7 +79,7 @@ class RoomControllerTest extends \Test\TestCase {
$this->manager = $this->createMock(Manager::class);
$this->guestManager = $this->createMock(GuestManager::class);
$this->chatManager = $this->createMock(ChatManager::class);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->messageParser = $this->createMock(MessageParser::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->l = $this->createMock(IL10N::class);
diff --git a/tests/php/Controller/SignalingControllerTest.php b/tests/php/Controller/SignalingControllerTest.php
index 24cb9ffdf..fbb0103c6 100644
--- a/tests/php/Controller/SignalingControllerTest.php
+++ b/tests/php/Controller/SignalingControllerTest.php
@@ -25,6 +25,7 @@ namespace OCA\Talk\Tests\php\Controller;
use OCA\Talk\Chat\CommentsManager;
use OCA\Talk\Config;
use OCA\Talk\Controller\SignalingController;
+use OCA\Talk\Events\SignalingEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
@@ -33,6 +34,7 @@ use OCA\Talk\Room;
use OCA\Talk\Signaling\Messages;
use OCA\Talk\TalkSession;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IL10N;
@@ -41,7 +43,6 @@ use OCP\IUserManager;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class CustomInputSignalingController extends SignalingController {
@@ -81,7 +82,7 @@ class SignalingControllerTest extends \Test\TestCase {
private $userId;
/** @var ISecureRandom */
private $secureRandom;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $dispatcher;
/** @var CustomInputSignalingController */
@@ -107,7 +108,7 @@ class SignalingControllerTest extends \Test\TestCase {
$this->messages = $this->createMock(Messages::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
- $this->dispatcher = \OC::$server->getEventDispatcher();
+ $this->dispatcher = \OC::$server->query(IEventDispatcher::class);
$this->recreateSignalingController();
}
@@ -531,9 +532,9 @@ class SignalingControllerTest extends \Test\TestCase {
}
public function testBackendRoomSessionFromEvent() {
- $this->dispatcher->addListener(SignalingController::class . '::signalingBackendRoom', function(GenericEvent $event) {
- $room = $event->getSubject();
- $event->setArgument('roomSession', [
+ $this->dispatcher->addListener(SignalingController::class . '::signalingBackendRoom', static function(SignalingEvent $event) {
+ $room = $event->getRoom();
+ $event->setSession([
'foo' => 'bar',
'room' => $room->getToken(),
]);
@@ -693,7 +694,7 @@ class SignalingControllerTest extends \Test\TestCase {
// Make sure that leaving a user with an old session id doesn't remove
// the current user from the room if he re-joined in the meantime.
$dbConnection = \OC::$server->getDatabaseConnection();
- $dispatcher = \OC::$server->getEventDispatcher();
+ $dispatcher = \OC::$server->query(IEventDispatcher::class);
$this->manager = new Manager(
$dbConnection,
\OC::$server->getConfig(),
diff --git a/tests/php/PasswordVerificationTest.php b/tests/php/RoomTest.php
index 212d86242..0f2ddfb5d 100644
--- a/tests/php/PasswordVerificationTest.php
+++ b/tests/php/RoomTest.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2018 Peter Edens <petere@conceiva.com>
*
@@ -20,40 +21,46 @@
*/
namespace OCA\Talk\Tests\php;
+use OC\EventDispatcher\EventDispatcher;
+use OCA\Talk\Events\VerifyRoomPasswordEvent;
use OCA\Talk\Manager;
use OCA\Talk\Room;
use OCA\Talk\Webinary;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IDBConnection;
+use OCP\ILogger;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
-use Symfony\Component\EventDispatcher\EventDispatcher;
use Test\TestCase;
-use Symfony\Component\EventDispatcher\GenericEvent;
-class PasswordVerificationTest extends TestCase {
+class RoomTest extends TestCase {
public function testVerifyPassword() {
- $dispatcher = new EventDispatcher();
- $dispatcher->addListener(Room::class . '::verifyPassword', function(GenericEvent $event) {
- $password = $event->getArgument('password');
+ $dispatcher = new EventDispatcher(
+ new \Symfony\Component\EventDispatcher\EventDispatcher(),
+ \OC::$server,
+ $this->createMock(ILogger::class)
+ );
+ $dispatcher->addListener(Room::class . '::verifyPassword', static function(VerifyRoomPasswordEvent $event) {
+ $password = $event->getPassword();
if ($password === '1234') {
- $event->setArgument('result', [ 'result' => true, 'url' => '']);
+ $event->setIsPasswordValid(true);
+ $event->setRedirectUrl('');
}
else {
- $event->setArgument('result', [ 'result' => false, 'url' => 'https://test']);
+ $event->setIsPasswordValid(false);
+ $event->setRedirectUrl('https://test');
}
});
- $hasher = $this->createMock(IHasher::class);
$room = new Room(
$this->createMock(Manager::class),
$this->createMock(IDBConnection::class),
$this->createMock(ISecureRandom::class),
$dispatcher,
$this->createMock(ITimeFactory::class),
- $hasher,
+ $this->createMock(IHasher::class),
1,
Room::PUBLIC_CALL,
Room::READ_WRITE,
diff --git a/tests/php/Signaling/BackendNotifierTest.php b/tests/php/Signaling/BackendNotifierTest.php
index 0dcc9c61b..f73653e52 100644
--- a/tests/php/Signaling/BackendNotifierTest.php
+++ b/tests/php/Signaling/BackendNotifierTest.php
@@ -32,6 +32,7 @@ use OCA\Talk\Signaling\BackendNotifier;
use OCA\Talk\TalkSession;
use OCA\Talk\Webinary;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Http\Client\IClientService;
use OCP\IGroupManager;
use OCP\IL10N;
@@ -124,7 +125,7 @@ class BackendNotifierTest extends \Test\TestCase {
});
$dbConnection = \OC::$server->getDatabaseConnection();
- $dispatcher = \OC::$server->getEventDispatcher();
+ $dispatcher = \OC::$server->query(IEventDispatcher::class);
$this->manager = new Manager(
$dbConnection,
$config,
@@ -281,7 +282,7 @@ class BackendNotifierTest extends \Test\TestCase {
public function testRoomTypeChanged() {
$room = $this->manager->createPublicRoom();
- $room->changeType(Room::GROUP_CALL);
+ $room->setType(Room::GROUP_CALL);
$requests = $this->controller->getRequests();
$bodies = array_map(function($request) use ($room) {
@@ -370,7 +371,8 @@ class BackendNotifierTest extends \Test\TestCase {
'userId' => $this->userId,
'sessionId' => $userSession,
]);
- $room->changeInCall($userSession, Participant::FLAG_IN_CALL | Participant::FLAG_WITH_AUDIO | Participant::FLAG_WITH_VIDEO);
+ $participant = $room->getParticipantBySession($userSession);
+ $room->changeInCall($participant, Participant::FLAG_IN_CALL | Participant::FLAG_WITH_AUDIO | Participant::FLAG_WITH_VIDEO);
$requests = $this->controller->getRequests();
$bodies = array_map(function($request) use ($room) {
@@ -403,7 +405,8 @@ class BackendNotifierTest extends \Test\TestCase {
$this->controller->clearRequests();
$guestSession = $room->joinRoomGuest('');
- $room->changeInCall($guestSession, Participant::FLAG_IN_CALL);
+ $guestParticipant = $room->getParticipantBySession($guestSession);
+ $room->changeInCall($guestParticipant, Participant::FLAG_IN_CALL);
$requests = $this->controller->getRequests();
$bodies = array_map(function($request) use ($room) {
@@ -440,7 +443,7 @@ class BackendNotifierTest extends \Test\TestCase {
], $bodies);
$this->controller->clearRequests();
- $room->changeInCall($userSession, Participant::FLAG_DISCONNECTED);
+ $room->changeInCall($participant, Participant::FLAG_DISCONNECTED);
$requests = $this->controller->getRequests();
$bodies = array_map(function($request) use ($room) {