forked from littleredbutton/cloud_bbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoomShareControllerTest.php
More file actions
134 lines (108 loc) · 3.04 KB
/
RoomShareControllerTest.php
File metadata and controls
134 lines (108 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
namespace OCA\BigBlueButton\Tests\Controller;
use OCA\BigBlueButton\CircleHelper;
use OCA\BigBlueButton\Controller\RoomShareController;
use OCA\BigBlueButton\Db\Room;
use OCA\BigBlueButton\Db\RoomShare;
use OCA\BigBlueButton\Service\RoomService;
use OCA\BigBlueButton\Service\RoomShareService;
use OCP\AppFramework\Http;
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IUserManager;
use PHPUnit\Framework\TestCase;
class RoomShareControllerTest extends TestCase {
private $request;
private $service;
private $roomService;
private $circleHelper;
private $userManager;
private $groupManager;
private $controller;
private $userId = 'user_foo';
public function setUp(): void {
parent::setUp();
$this->request = $this->createMock(IRequest::class);
$this->service = $this->createMock(RoomShareService::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->roomService = $this->createMock(RoomService::class);
$this->circleHelper = $this->createMock(CircleHelper::class);
$this->controller = new RoomShareController(
'bbb',
$this->request,
$this->service,
$this->userManager,
$this->groupManager,
$this->roomService,
$this->circleHelper,
$this->userId
);
}
public function testIndexWithoutRoomId() {
$response = $this->controller->index();
$this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus());
}
public function testIndexWithoutPermission() {
$this->request
->expects($this->once())
->method('getParam')
->with('id')
->willReturn(1234);
$room = new Room();
$room->setUserId('user_bar');
$this->roomService
->expects($this->once())
->method('find')
->with(1234)
->willReturn($room);
$response = $this->controller->index();
$this->assertEquals(Http::STATUS_FORBIDDEN, $response->getStatus());
}
public function testIndexWithoutShares() {
$roomId = 1234;
$this->request
->expects($this->once())
->method('getParam')
->with('id')
->willReturn($roomId);
$room = new Room();
$room->setUserId($this->userId);
$this->roomService
->expects($this->once())
->method('find')
->willReturn($room);
$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());
}
public function testIndexWithShares() {
$roomId = 1234;
$this->request
->expects($this->once())
->method('getParam')
->with('id')
->willReturn($roomId);
$room = new Room();
$room->setUserId($this->userId);
$this->roomService
->expects($this->once())
->method('find')
->willReturn($room);
$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());
}
}