Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / conpherence / __tests__ / ConpherenceRoomTestCase.php
blob7ef908c315bd958352ff20116bdf230389902a6c
1 <?php
3 final class ConpherenceRoomTestCase extends ConpherenceTestCase {
5 protected function getPhabricatorTestCaseConfiguration() {
6 return array(
7 self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
8 );
11 public function testOneUserRoomCreate() {
12 $creator = $this->generateNewTestUser();
13 $participant_phids = array($creator->getPHID());
15 $conpherence = $this->createRoom($creator, $participant_phids);
17 $this->assertTrue((bool)$conpherence->getID());
18 $this->assertEqual(1, count($conpherence->getParticipants()));
21 public function testNUserRoomCreate() {
22 $creator = $this->generateNewTestUser();
23 $friend_1 = $this->generateNewTestUser();
24 $friend_2 = $this->generateNewTestUser();
25 $friend_3 = $this->generateNewTestUser();
27 $participant_phids = array(
28 $creator->getPHID(),
29 $friend_1->getPHID(),
30 $friend_2->getPHID(),
31 $friend_3->getPHID(),
34 $conpherence = $this->createRoom($creator, $participant_phids);
36 $this->assertTrue((bool)$conpherence->getID());
37 $this->assertEqual(4, count($conpherence->getParticipants()));
40 public function testRoomParticipantAddition() {
41 $creator = $this->generateNewTestUser();
42 $friend_1 = $this->generateNewTestUser();
43 $friend_2 = $this->generateNewTestUser();
44 $friend_3 = $this->generateNewTestUser();
46 $participant_phids = array(
47 $creator->getPHID(),
48 $friend_1->getPHID(),
51 $conpherence = $this->createRoom($creator, $participant_phids);
53 $this->assertTrue((bool)$conpherence->getID());
54 $this->assertEqual(2, count($conpherence->getParticipants()));
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()));
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
69 $this->addParticipants(
70 $friend_2,
71 $conpherence,
72 array($friend_3->getPHID()));
73 $this->assertEqual(4, count($conpherence->getParticipants()));
76 public function testRoomParticipantDeletion() {
77 $creator = $this->generateNewTestUser();
78 $friend_1 = $this->generateNewTestUser();
79 $friend_2 = $this->generateNewTestUser();
80 $friend_3 = $this->generateNewTestUser();
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,
89 $conpherence = $this->createRoom(
90 $creator,
91 array_keys($participant_map));
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()));
102 private function createRoom(
103 PhabricatorUser $creator,
104 array $participant_phids) {
106 $conpherence = ConpherenceThread::initializeNewRoom($creator);
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'));
118 id(new ConpherenceEditor())
119 ->setActor($creator)
120 ->setContentSource($this->newContentSource())
121 ->setContinueOnNoEffect(true)
122 ->applyTransactions($conpherence, $xactions);
124 return $conpherence;
127 private function changeEditPolicy(
128 PhabricatorUser $actor,
129 ConpherenceThread $room,
130 $policy) {
132 $xactions = array();
133 $xactions[] = id(new ConpherenceTransaction())
134 ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
135 ->setNewValue($policy);
137 id(new ConpherenceEditor())
138 ->setActor($actor)
139 ->setContentSource($this->newContentSource())
140 ->setContinueOnNoEffect(true)
141 ->applyTransactions($room, $xactions);