Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/conpherence/__tests__/ConpherenceRoomTestCase.php
12256 views
1
<?php
2
3
final class ConpherenceRoomTestCase extends ConpherenceTestCase {
4
5
protected function getPhabricatorTestCaseConfiguration() {
6
return array(
7
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
8
);
9
}
10
11
public function testOneUserRoomCreate() {
12
$creator = $this->generateNewTestUser();
13
$participant_phids = array($creator->getPHID());
14
15
$conpherence = $this->createRoom($creator, $participant_phids);
16
17
$this->assertTrue((bool)$conpherence->getID());
18
$this->assertEqual(1, count($conpherence->getParticipants()));
19
}
20
21
public function testNUserRoomCreate() {
22
$creator = $this->generateNewTestUser();
23
$friend_1 = $this->generateNewTestUser();
24
$friend_2 = $this->generateNewTestUser();
25
$friend_3 = $this->generateNewTestUser();
26
27
$participant_phids = array(
28
$creator->getPHID(),
29
$friend_1->getPHID(),
30
$friend_2->getPHID(),
31
$friend_3->getPHID(),
32
);
33
34
$conpherence = $this->createRoom($creator, $participant_phids);
35
36
$this->assertTrue((bool)$conpherence->getID());
37
$this->assertEqual(4, count($conpherence->getParticipants()));
38
}
39
40
public function testRoomParticipantAddition() {
41
$creator = $this->generateNewTestUser();
42
$friend_1 = $this->generateNewTestUser();
43
$friend_2 = $this->generateNewTestUser();
44
$friend_3 = $this->generateNewTestUser();
45
46
$participant_phids = array(
47
$creator->getPHID(),
48
$friend_1->getPHID(),
49
);
50
51
$conpherence = $this->createRoom($creator, $participant_phids);
52
53
$this->assertTrue((bool)$conpherence->getID());
54
$this->assertEqual(2, count($conpherence->getParticipants()));
55
56
// test add by creator
57
$participant_phids[] = $friend_2->getPHID();
58
$this->addParticipants($creator, $conpherence, array($friend_2->getPHID()));
59
$this->assertEqual(3, count($conpherence->getParticipants()));
60
61
// test add by other participant, so recent participation should
62
// meaningfully change
63
$participant_phids = array(
64
$friend_2->getPHID(), // actor
65
$creator->getPHID(), // last actor
66
$friend_1->getPHID(),
67
$friend_3->getPHID(), // new addition
68
);
69
$this->addParticipants(
70
$friend_2,
71
$conpherence,
72
array($friend_3->getPHID()));
73
$this->assertEqual(4, count($conpherence->getParticipants()));
74
}
75
76
public function testRoomParticipantDeletion() {
77
$creator = $this->generateNewTestUser();
78
$friend_1 = $this->generateNewTestUser();
79
$friend_2 = $this->generateNewTestUser();
80
$friend_3 = $this->generateNewTestUser();
81
82
$participant_map = array(
83
$creator->getPHID() => $creator,
84
$friend_1->getPHID() => $friend_1,
85
$friend_2->getPHID() => $friend_2,
86
$friend_3->getPHID() => $friend_3,
87
);
88
89
$conpherence = $this->createRoom(
90
$creator,
91
array_keys($participant_map));
92
93
foreach ($participant_map as $phid => $user) {
94
$this->removeParticipants($user, $conpherence, array($phid));
95
unset($participant_map[$phid]);
96
$this->assertEqual(
97
count($participant_map),
98
count($conpherence->getParticipants()));
99
}
100
}
101
102
private function createRoom(
103
PhabricatorUser $creator,
104
array $participant_phids) {
105
106
$conpherence = ConpherenceThread::initializeNewRoom($creator);
107
108
$xactions = array();
109
$xactions[] = id(new ConpherenceTransaction())
110
->setTransactionType(
111
ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
112
->setNewValue(array('+' => $participant_phids));
113
$xactions[] = id(new ConpherenceTransaction())
114
->setTransactionType(
115
ConpherenceThreadTitleTransaction::TRANSACTIONTYPE)
116
->setNewValue(pht('Test'));
117
118
id(new ConpherenceEditor())
119
->setActor($creator)
120
->setContentSource($this->newContentSource())
121
->setContinueOnNoEffect(true)
122
->applyTransactions($conpherence, $xactions);
123
124
return $conpherence;
125
}
126
127
private function changeEditPolicy(
128
PhabricatorUser $actor,
129
ConpherenceThread $room,
130
$policy) {
131
132
$xactions = array();
133
$xactions[] = id(new ConpherenceTransaction())
134
->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
135
->setNewValue($policy);
136
137
id(new ConpherenceEditor())
138
->setActor($actor)
139
->setContentSource($this->newContentSource())
140
->setContinueOnNoEffect(true)
141
->applyTransactions($room, $xactions);
142
}
143
144
145
}
146
147