From c63767719b40bdb7e37fcf6b616e4b961f27cc11 Mon Sep 17 00:00:00 2001 From: sualko Date: Wed, 10 Jun 2020 13:55:21 +0200 Subject: [PATCH] test: add first unit tests --- phpunit.xml | 12 ++ tests/Unit/Controller/JoinControllerTest.php | 130 +++++++++++++++++++ tests/bootstrap.php | 10 ++ 3 files changed, 152 insertions(+) create mode 100644 phpunit.xml create mode 100644 tests/Unit/Controller/JoinControllerTest.php create mode 100644 tests/bootstrap.php diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..f544afa --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,12 @@ + + + + tests/Unit + + + + + lib + + + diff --git a/tests/Unit/Controller/JoinControllerTest.php b/tests/Unit/Controller/JoinControllerTest.php new file mode 100644 index 0000000..8cf27d0 --- /dev/null +++ b/tests/Unit/Controller/JoinControllerTest.php @@ -0,0 +1,130 @@ +request = $this->createMock(IRequest::class); + $this->session = $this->createMock(ISession::class); + $this->service = $this->createMock(RoomService::class); + $this->userSession = $this->createMock(IUserSession::class); + $this->config = $this->createMock(IConfig::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->api = $this->createMock(API::class); + + $this->controller = new JoinController( + 'bbb', + $this->request, + $this->session, + $this->service, + $this->urlGenerator, + $this->userSession, + $this->config, + $this->api + ); + + $this->room = new Room(); + $this->room->uid = 'uid_foo'; + $this->room->userId = 'user_foo'; + $this->room->access = Room::ACCESS_PUBLIC; + $this->room->name = 'name_foo'; + $this->room->password = 'password_foo'; + } + + public function testNonExistingRoom() + { + $this->expectException(NotFoundException::class); + $this->service + ->expects($this->once()) + ->method('findByUID') + ->willReturn(null); + + $this->controller->index(null); + } + + public function testUserIsLoggedIn() + { + $this->controller->setToken($this->room->uid); + $this->service + ->expects($this->once()) + ->method('findByUID') + ->willReturn($this->room); + + $this->userSession + ->expects($this->once()) + ->method('isLoggedIn') + ->willReturn(true); + + $user = $this->createMock(IUser::class); + $user->method('getDisplayName')->willReturn('User Bar'); + $user->method('getUID')->willReturn('user_bar'); + + $this->userSession + ->expects($this->once()) + ->method('getUser') + ->willReturn($user); + + $this->api + ->expects($this->once()) + ->method('createMeeting') + ->willReturn(12345); + + $url = 'https://foobar'; + $this->api + ->expects($this->once()) + ->method('createJoinUrl') + ->willReturn($url); + + $result = $this->controller->index(null); + + $this->assertInstanceOf(RedirectResponse::class, $result); + $this->assertEquals($url, $result->getRedirectURL()); + } + + public function testUserNeedsToAuthenticate() + { + $this->markTestIncomplete(); + } + + public function testInvalidDisplayname() + { + $this->markTestIncomplete(); + } + + public function testPasswordRequired() + { + $this->markTestIncomplete(); + } + + public function testFormActionAllowed() + { + $this->markTestIncomplete(); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..4020143 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,10 @@ +