2020-06-18 15:07:19 +02:00
|
|
|
<?php
|
2020-06-19 09:28:58 +02:00
|
|
|
|
2020-06-18 15:07:19 +02:00
|
|
|
namespace OCA\BigBlueButton\Tests\Integration\Db;
|
|
|
|
|
|
|
|
use OC;
|
|
|
|
use OCA\BigBlueButton\Db\Room;
|
|
|
|
use OCA\BigBlueButton\Db\RoomMapper;
|
|
|
|
use OCA\BigBlueButton\Db\RoomShare;
|
|
|
|
use OCA\BigBlueButton\Db\RoomShareMapper;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
|
|
|
class RoomMapperTest extends TestCase {
|
2020-06-19 09:28:58 +02:00
|
|
|
/** @var IDBConnection */
|
|
|
|
private $db;
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
/** @var RoomMapper */
|
|
|
|
private $mapper;
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
/** @var RoomShareMapper */
|
|
|
|
private $shareMapper;
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
/** @var string */
|
|
|
|
private $userId;
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
/** @var string */
|
|
|
|
private $uid;
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function setUp(): void {
|
2020-06-18 15:07:19 +02:00
|
|
|
parent::setUp();
|
|
|
|
$this->db = OC::$server->getDatabaseConnection();
|
2020-06-19 09:28:58 +02:00
|
|
|
$this->mapper = new RoomMapper($this->db);
|
|
|
|
$this->shareMapper = new RoomShareMapper($this->db);
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
$this->userId = $this->getRandomString();
|
|
|
|
$this->uid = $this->getRandomString();
|
|
|
|
}
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function testInsert() {
|
|
|
|
$room = $this->insert($this->uid, $this->userId);
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
$this->assertEquals($this->uid, $room->getUid());
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
$this->mapper->delete($room);
|
|
|
|
}
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
/**
|
|
|
|
* @depends testInsert
|
|
|
|
*/
|
|
|
|
public function testFind() {
|
|
|
|
$newRoom = $this->insert($this->uid, $this->userId);
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
$room = $this->mapper->find($newRoom->getId());
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
$this->assertEquals($this->uid, $room->getUid());
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
$this->mapper->delete($room);
|
|
|
|
}
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
/**
|
|
|
|
* @depends testInsert
|
|
|
|
*/
|
|
|
|
public function testFindByUid() {
|
|
|
|
$newRoom = $this->insert($this->uid, $this->userId);
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
$room = $this->mapper->findByUid($this->uid);
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
$this->assertEquals($newRoom->getId(), $room->getId());
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
$this->mapper->delete($room);
|
|
|
|
}
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
/**
|
|
|
|
* @depends testInsert
|
|
|
|
*/
|
|
|
|
public function testFindAll() {
|
|
|
|
$room = $this->insert($this->uid, $this->userId);
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
$foreignRoom1 = $this->insert($this->getRandomString(), $this->getRandomString());
|
|
|
|
$foreignRoom2 = $this->insert($this->getRandomString(), $this->getRandomString());
|
|
|
|
$foreignRoom3 = $this->insert($this->getRandomString(), $this->getRandomString());
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-08-29 13:20:28 +02:00
|
|
|
$this->assertCount(1, $this->mapper->findAll($this->userId, [], []));
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
$shares = [];
|
|
|
|
$shares[] = $this->insertShare($foreignRoom1->getId(), RoomShare::SHARE_TYPE_USER, $this->userId);
|
|
|
|
$shares[] = $this->insertShare($foreignRoom1->getId(), RoomShare::SHARE_TYPE_GROUP, 'foo bar');
|
|
|
|
$shares[] = $this->insertShare($foreignRoom2->getId(), RoomShare::SHARE_TYPE_GROUP, 'foo bar');
|
|
|
|
$shares[] = $this->insertShare($foreignRoom3->getId(), RoomShare::SHARE_TYPE_USER, $this->getRandomString());
|
2020-08-29 13:20:28 +02:00
|
|
|
$shares[] = $this->insertShare($foreignRoom3->getId(), RoomShare::SHARE_TYPE_CIRCLE, 'c1');
|
|
|
|
$shares[] = $this->insertShare($foreignRoom3->getId(), RoomShare::SHARE_TYPE_CIRCLE, 'c2');
|
2020-06-19 09:28:58 +02:00
|
|
|
$shares[] = $this->insertShare($foreignRoom3->getId(), RoomShare::SHARE_TYPE_USER, $this->userId, RoomShare::PERMISSION_MODERATOR);
|
|
|
|
$shares[] = $this->insertShare($foreignRoom3->getId(), RoomShare::SHARE_TYPE_GROUP, 'foo bar', RoomShare::PERMISSION_USER);
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-08-29 13:20:28 +02:00
|
|
|
$rooms = $this->mapper->findAll($this->userId, ['foo bar'], ['c1']);
|
|
|
|
$this->assertCount(4, $rooms);
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
$this->mapper->delete($room);
|
|
|
|
$this->mapper->delete($foreignRoom1);
|
|
|
|
$this->mapper->delete($foreignRoom2);
|
|
|
|
$this->mapper->delete($foreignRoom3);
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
foreach ($shares as $share) {
|
|
|
|
$this->shareMapper->delete($share);
|
|
|
|
}
|
|
|
|
}
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
private function getRandomString(): string {
|
|
|
|
return \OC::$server->getSecureRandom()->generate(18, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE);
|
|
|
|
}
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
private function insert($uid, $userId): Room {
|
|
|
|
$room = new Room();
|
|
|
|
$room->setUid($uid);
|
2020-06-18 15:07:19 +02:00
|
|
|
$room->setName('random name');
|
|
|
|
$room->setWelcome('');
|
|
|
|
$room->setMaxParticipants(0);
|
|
|
|
$room->setAttendeePassword('1');
|
|
|
|
$room->setModeratorPassword('2');
|
|
|
|
$room->setRecord(false);
|
2020-06-19 09:28:58 +02:00
|
|
|
$room->setUserId($userId);
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
return $this->mapper->insert($room);
|
|
|
|
}
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
private function insertShare($id, $type, $with, $permission = RoomShare::PERMISSION_ADMIN): RoomShare {
|
|
|
|
$roomShare = new RoomShare();
|
2020-06-18 15:07:19 +02:00
|
|
|
|
|
|
|
$roomShare->setRoomId($id);
|
|
|
|
$roomShare->setShareType($type);
|
|
|
|
$roomShare->setShareWith($with);
|
2020-06-19 09:28:58 +02:00
|
|
|
$roomShare->setPermission($permission);
|
2020-06-18 15:07:19 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
return $this->shareMapper->insert($roomShare);
|
|
|
|
}
|
|
|
|
}
|