2020-06-15 17:23:53 +02:00
|
|
|
<?php
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
namespace OCA\BigBlueButton\Tests\Controller;
|
2020-06-15 17:23:53 +02:00
|
|
|
|
2020-09-23 12:33:09 +02:00
|
|
|
use OCA\BigBlueButton\CircleHelper;
|
2020-06-15 17:23:53 +02:00
|
|
|
use OCA\BigBlueButton\Controller\RoomShareController;
|
|
|
|
use OCA\BigBlueButton\Db\Room;
|
|
|
|
use OCA\BigBlueButton\Db\RoomShare;
|
2020-09-23 12:33:09 +02:00
|
|
|
use OCA\BigBlueButton\Service\RoomService;
|
2020-06-15 17:23:53 +02:00
|
|
|
use OCA\BigBlueButton\Service\RoomShareService;
|
|
|
|
use OCP\AppFramework\Http;
|
2020-09-23 12:33:09 +02:00
|
|
|
use OCP\IRequest;
|
2020-06-15 17:23:53 +02:00
|
|
|
use OCP\IUserManager;
|
2020-09-23 12:33:09 +02:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2020-06-15 17:23:53 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
class RoomShareControllerTest extends TestCase {
|
2020-06-15 17:23:53 +02:00
|
|
|
private $request;
|
|
|
|
private $service;
|
|
|
|
private $roomService;
|
2020-08-29 13:20:28 +02:00
|
|
|
private $circleHelper;
|
2020-06-15 17:23:53 +02:00
|
|
|
private $userManager;
|
|
|
|
private $controller;
|
|
|
|
|
2020-06-17 10:56:28 +02:00
|
|
|
private $userId = 'user_foo';
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function setUp(): void {
|
2020-06-15 17:23:53 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->request = $this->createMock(IRequest::class);
|
|
|
|
$this->service = $this->createMock(RoomShareService::class);
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
|
|
$this->roomService = $this->createMock(RoomService::class);
|
2020-08-29 13:20:28 +02:00
|
|
|
$this->circleHelper = $this->createMock(CircleHelper::class);
|
2020-06-15 17:23:53 +02:00
|
|
|
|
|
|
|
$this->controller = new RoomShareController(
|
|
|
|
'bbb',
|
|
|
|
$this->request,
|
|
|
|
$this->service,
|
|
|
|
$this->userManager,
|
|
|
|
$this->roomService,
|
2020-08-29 13:20:28 +02:00
|
|
|
$this->circleHelper,
|
2020-06-17 10:56:28 +02:00
|
|
|
$this->userId
|
2020-06-15 17:23:53 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function testIndexWithoutRoomId() {
|
2020-06-15 17:23:53 +02:00
|
|
|
$response = $this->controller->index();
|
|
|
|
|
|
|
|
$this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus());
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function testIndexWithoutPermission() {
|
2020-06-15 17:23:53 +02:00
|
|
|
$this->request
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getParam')
|
|
|
|
->with('id')
|
|
|
|
->willReturn(1234);
|
|
|
|
|
2020-06-17 10:56:28 +02:00
|
|
|
$room = new Room();
|
|
|
|
$room->setUserId('user_bar');
|
|
|
|
|
2020-06-15 17:23:53 +02:00
|
|
|
$this->roomService
|
|
|
|
->expects($this->once())
|
|
|
|
->method('find')
|
2020-06-17 10:56:28 +02:00
|
|
|
->with(1234)
|
|
|
|
->willReturn($room);
|
2020-06-15 17:23:53 +02:00
|
|
|
|
|
|
|
$response = $this->controller->index();
|
|
|
|
|
|
|
|
$this->assertEquals(Http::STATUS_FORBIDDEN, $response->getStatus());
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function testIndexWithoutShares() {
|
2020-06-15 17:23:53 +02:00
|
|
|
$roomId = 1234;
|
|
|
|
$this->request
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getParam')
|
|
|
|
->with('id')
|
|
|
|
->willReturn($roomId);
|
|
|
|
|
2020-06-17 10:56:28 +02:00
|
|
|
$room = new Room();
|
|
|
|
$room->setUserId($this->userId);
|
|
|
|
|
2020-06-15 17:23:53 +02:00
|
|
|
$this->roomService
|
|
|
|
->expects($this->once())
|
|
|
|
->method('find')
|
2020-06-17 10:56:28 +02:00
|
|
|
->willReturn($room);
|
2020-06-15 17:23:53 +02:00
|
|
|
|
|
|
|
$this->service
|
|
|
|
->expects($this->once())
|
|
|
|
->method('findAll')
|
|
|
|
->with($roomId)
|
|
|
|
->willReturn([]);
|
|
|
|
|
|
|
|
$response = $this->controller->index();
|
|
|
|
|
|
|
|
$this->assertEquals(Http::STATUS_OK, $response->getStatus());
|
|
|
|
$this->assertEquals([], $response->getData());
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function testIndexWithShares() {
|
2020-06-15 17:23:53 +02:00
|
|
|
$roomId = 1234;
|
|
|
|
$this->request
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getParam')
|
|
|
|
->with('id')
|
|
|
|
->willReturn($roomId);
|
|
|
|
|
2020-06-17 10:56:28 +02:00
|
|
|
$room = new Room();
|
|
|
|
$room->setUserId($this->userId);
|
|
|
|
|
2020-06-15 17:23:53 +02:00
|
|
|
$this->roomService
|
|
|
|
->expects($this->once())
|
|
|
|
->method('find')
|
2020-06-17 10:56:28 +02:00
|
|
|
->willReturn($room);
|
2020-06-15 17:23:53 +02:00
|
|
|
|
|
|
|
$this->service
|
|
|
|
->expects($this->once())
|
|
|
|
->method('findAll')
|
|
|
|
->with($roomId)
|
|
|
|
->willReturn([
|
|
|
|
new RoomShare()
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response = $this->controller->index();
|
|
|
|
|
|
|
|
$this->assertEquals(Http::STATUS_OK, $response->getStatus());
|
|
|
|
$this->assertCount(1, $response->getData());
|
|
|
|
}
|
|
|
|
}
|