~ubuntu-branches/ubuntu/wily/phabricator/wily-proposed

« back to all changes in this revision

Viewing changes to phabricator/src/applications/conpherence/__tests__/ConpherenceThreadTestCase.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2015-08-03 23:28:35 UTC
  • mfrom: (0.39.1) (0.38.1) (0.27.3) (2.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20150803232835-qnomusa964oxnywb
Tags: 0~git20150803-1
* New snapshot release (closes: #789760)
* renamed arcanist bash-completion file (closes: #791632)
* depends on same version for libphutil (closes: #794462)
* added php5-mysqlnd alternative depends (closes: #792136)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
final class ConpherenceThreadTestCase extends ConpherenceTestCase {
4
 
 
5
 
  protected function getPhabricatorTestCaseConfiguration() {
6
 
    return array(
7
 
      self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
8
 
    );
9
 
  }
10
 
 
11
 
  public function testOneUserThreadCreate() {
12
 
    $creator = $this->generateNewTestUser();
13
 
    $participant_phids = array($creator->getPHID());
14
 
 
15
 
    $conpherence = $this->createThread($creator, $participant_phids);
16
 
 
17
 
    $this->assertTrue((bool)$conpherence->getID());
18
 
    $this->assertEqual(1, count($conpherence->getParticipants()));
19
 
    $this->assertEqual(
20
 
      $participant_phids,
21
 
      $conpherence->getRecentParticipantPHIDs());
22
 
  }
23
 
 
24
 
  public function testNUserThreadCreate() {
25
 
    $creator = $this->generateNewTestUser();
26
 
    $friend_1 = $this->generateNewTestUser();
27
 
    $friend_2 = $this->generateNewTestUser();
28
 
    $friend_3 = $this->generateNewTestUser();
29
 
 
30
 
    $participant_phids = array(
31
 
      $creator->getPHID(),
32
 
      $friend_1->getPHID(),
33
 
      $friend_2->getPHID(),
34
 
      $friend_3->getPHID(),
35
 
    );
36
 
 
37
 
    $conpherence = $this->createThread($creator, $participant_phids);
38
 
 
39
 
    $this->assertTrue((bool)$conpherence->getID());
40
 
    $this->assertEqual(4, count($conpherence->getParticipants()));
41
 
    $this->assertEqual(
42
 
      $participant_phids,
43
 
      $conpherence->getRecentParticipantPHIDs());
44
 
  }
45
 
 
46
 
  public function testThreadParticipantAddition() {
47
 
    $creator = $this->generateNewTestUser();
48
 
    $friend_1 = $this->generateNewTestUser();
49
 
    $friend_2 = $this->generateNewTestUser();
50
 
    $friend_3 = $this->generateNewTestUser();
51
 
 
52
 
    $participant_phids = array(
53
 
      $creator->getPHID(),
54
 
      $friend_1->getPHID(),
55
 
    );
56
 
 
57
 
    $conpherence = $this->createThread($creator, $participant_phids);
58
 
 
59
 
    $this->assertTrue((bool)$conpherence->getID());
60
 
    $this->assertEqual(2, count($conpherence->getParticipants()));
61
 
    $this->assertEqual(
62
 
      $participant_phids,
63
 
      $conpherence->getRecentParticipantPHIDs());
64
 
 
65
 
    // test add by creator
66
 
    $participant_phids[] = $friend_2->getPHID();
67
 
    $this->addParticipants($creator, $conpherence, array($friend_2->getPHID()));
68
 
    $this->assertEqual(
69
 
      $participant_phids,
70
 
      $conpherence->getRecentParticipantPHIDs());
71
 
 
72
 
    // test add by other participant, so recent participation should
73
 
    // meaningfully change
74
 
    $participant_phids = array(
75
 
      $friend_2->getPHID(),  // actor
76
 
      $creator->getPHID(),   // last actor
77
 
      $friend_1->getPHID(),
78
 
      $friend_3->getPHID(),  // new addition
79
 
    );
80
 
    $this->addParticipants(
81
 
      $friend_2,
82
 
      $conpherence,
83
 
      array($friend_3->getPHID()));
84
 
    $this->assertEqual(
85
 
      $participant_phids,
86
 
      $conpherence->getRecentParticipantPHIDs());
87
 
  }
88
 
 
89
 
  public function testThreadParticipantDeletion() {
90
 
    $creator = $this->generateNewTestUser();
91
 
    $friend_1 = $this->generateNewTestUser();
92
 
    $friend_2 = $this->generateNewTestUser();
93
 
    $friend_3 = $this->generateNewTestUser();
94
 
 
95
 
    $participant_map = array(
96
 
      $creator->getPHID() => $creator,
97
 
      $friend_1->getPHID() => $friend_1,
98
 
      $friend_2->getPHID() => $friend_2,
99
 
      $friend_3->getPHID() => $friend_3,
100
 
    );
101
 
 
102
 
    $conpherence = $this->createThread(
103
 
      $creator,
104
 
      array_keys($participant_map));
105
 
 
106
 
    foreach ($participant_map as $phid => $user) {
107
 
      $this->removeParticipants($user, $conpherence, array($phid));
108
 
      unset($participant_map[$phid]);
109
 
      $this->assertEqual(
110
 
        count($participant_map),
111
 
        count($conpherence->getParticipants()));
112
 
    }
113
 
  }
114
 
 
115
 
  public function testAddMessageWithFileAttachments() {
116
 
    $creator = $this->generateNewTestUser();
117
 
    $friend_1 = $this->generateNewTestUser();
118
 
    $policy_exception_user = $this->generateNewTestUser();
119
 
 
120
 
    $participant_map = array(
121
 
      $creator->getPHID() => $creator,
122
 
      $friend_1->getPHID() => $friend_1,
123
 
    );
124
 
 
125
 
    $conpherence = $this->createThread(
126
 
      $creator,
127
 
      array_keys($participant_map));
128
 
 
129
 
    foreach ($participant_map as $phid => $user) {
130
 
      $xactions = $this->addMessageWithFile($user, $conpherence);
131
 
      $this->assertEqual(2, count($xactions), pht('hi'));
132
 
    }
133
 
 
134
 
    $caught = null;
135
 
    try {
136
 
      $xactions = $this->addMessageWithFile(
137
 
        $policy_exception_user,
138
 
        $conpherence);
139
 
    } catch (PhabricatorPolicyException $ex) {
140
 
      $caught = $ex;
141
 
    }
142
 
    $this->assertTrue(
143
 
      $caught instanceof PhabricatorPolicyException,
144
 
      pht(
145
 
        'User not participating in thread should get policy exception '.
146
 
        'trying to add message.'));
147
 
    $this->assertTrue(
148
 
      $conpherence->establishConnection('w')->isReadLocking(),
149
 
      pht(
150
 
        'Conpherence object should still be read locked from policy '.
151
 
        'exception.'));
152
 
    $conpherence->endReadLocking();
153
 
    $conpherence->killTransaction();
154
 
  }
155
 
 
156
 
  private function createThread(
157
 
    PhabricatorUser $creator,
158
 
    array $participant_phids) {
159
 
 
160
 
    list($errors, $conpherence) = ConpherenceEditor::createThread(
161
 
      $creator,
162
 
      $participant_phids,
163
 
      pht('Test'),
164
 
      pht('Test'),
165
 
      PhabricatorContentSource::newConsoleSource());
166
 
    return $conpherence;
167
 
  }
168
 
 
169
 
}