From 46ac4d1102a7f32e7543a831ce8a999a0f7d5bfe Mon Sep 17 00:00:00 2001 From: sualko Date: Wed, 2 Sep 2020 10:33:32 +0200 Subject: [PATCH] test: add RestrictionService test --- .../Service/RestrictionServiceTest.php | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 tests/Integration/Service/RestrictionServiceTest.php diff --git a/tests/Integration/Service/RestrictionServiceTest.php b/tests/Integration/Service/RestrictionServiceTest.php new file mode 100644 index 0000000..b49cd44 --- /dev/null +++ b/tests/Integration/Service/RestrictionServiceTest.php @@ -0,0 +1,78 @@ +db = OC::$server->getDatabaseConnection(); + $mapper = new RestrictionMapper($this->db); + $this->service = new RestrictionService($mapper); + + $this->groupId = $this->getRandomString(); + } + + public function testCreate() { + $restriction = $this->service->create($this->groupId); + + $this->assertEquals($this->groupId, $restriction->getGroupId()); + + $this->service->delete($restriction->getId()); + } + + /** + * @depends testCreate + */ + public function testExistsByGroupId() { + $restriction = $this->service->create($this->groupId); + + $this->assertTrue($this->service->existsByGroupId($this->groupId)); + + $this->assertFalse($this->service->existsByGroupId($this->getRandomString())); + + $this->service->delete($restriction->getId()); + + $this->assertFalse($this->service->existsByGroupId($this->groupId)); + } + + /** + * @depends testCreate + */ + public function testUpdate() { + $restriction = $this->service->create($this->groupId); + $updatedRestriction = $this->service->update( + $restriction->getId(), + $this->groupId, + 10, + ['public'], + 15, + false + ); + + $this->assertEquals(10, $updatedRestriction->getMaxRooms()); + $this->assertEquals(15, $updatedRestriction->getMaxParticipants()); + $this->assertEquals(false, $updatedRestriction->getAllowRecording()); + + $this->service->delete($restriction->getId()); + } + + + private function getRandomString(): string { + return \OC::$server->getSecureRandom()->generate(18, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE); + } +}