Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/maniphest/constants/__tests__/ManiphestTaskStatusTestCase.php
12262 views
1
<?php
2
3
final class ManiphestTaskStatusTestCase extends PhabricatorTestCase {
4
5
public function testManiphestStatusConstants() {
6
$map = array(
7
'y' => true,
8
'closed' => true,
9
'longlonglong' => true,
10
'duplicate2' => true,
11
12
'' => false,
13
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' =>
14
false,
15
'.' => false,
16
' ' => false,
17
'ABCD' => true,
18
'a b c ' => false,
19
'1' => false,
20
'111' => false,
21
'11a' => true,
22
);
23
24
foreach ($map as $input => $expect) {
25
$this->assertEqual(
26
$expect,
27
ManiphestTaskStatus::isValidStatusConstant($input),
28
pht('Validate "%s"', $input));
29
}
30
}
31
32
public function testManiphestStatusConfigValidation() {
33
$this->assertConfigValid(
34
false,
35
pht('Empty'),
36
array());
37
38
// This is a minimal, valid configuration.
39
40
$valid = array(
41
'open' => array(
42
'name' => pht('Open'),
43
'special' => 'default',
44
),
45
'closed' => array(
46
'name' => pht('Closed'),
47
'special' => 'closed',
48
'closed' => true,
49
),
50
'duplicate' => array(
51
'name' => pht('Duplicate'),
52
'special' => 'duplicate',
53
'closed' => true,
54
),
55
);
56
$this->assertConfigValid(true, pht('Minimal Valid Config'), $valid);
57
58
// We should raise on a bad key.
59
$bad_key = $valid;
60
$bad_key['!'] = array('name' => pht('Exclaim'));
61
$this->assertConfigValid(false, pht('Bad Key'), $bad_key);
62
63
// We should raise on a value type.
64
$bad_type = $valid;
65
$bad_type['other'] = 'other';
66
$this->assertConfigValid(false, pht('Bad Value Type'), $bad_type);
67
68
// We should raise on an unknown configuration key.
69
$invalid_key = $valid;
70
$invalid_key['open']['imaginary'] = 'unicorn';
71
$this->assertConfigValid(false, pht('Invalid Key'), $invalid_key);
72
73
// We should raise on two statuses with the same special.
74
$double_close = $valid;
75
$double_close['finished'] = array(
76
'name' => pht('Finished'),
77
'special' => 'closed',
78
'closed' => true,
79
);
80
$this->assertConfigValid(false, pht('Duplicate Special'), $double_close);
81
82
// We should raise if any of the special statuses are missing.
83
foreach ($valid as $key => $config) {
84
$missing = $valid;
85
unset($missing[$key]);
86
$this->assertConfigValid(false, pht('Missing Special'), $missing);
87
}
88
89
// The "default" special should be an open status.
90
$closed_default = $valid;
91
$closed_default['open']['closed'] = true;
92
$this->assertConfigValid(false, pht('Closed Default'), $closed_default);
93
94
// The "closed" special should be a closed status.
95
$open_closed = $valid;
96
$open_closed['closed']['closed'] = false;
97
$this->assertConfigValid(false, pht('Open Closed'), $open_closed);
98
99
// The "duplicate" special should be a closed status.
100
$open_duplicate = $valid;
101
$open_duplicate['duplicate']['closed'] = false;
102
$this->assertConfigValid(false, pht('Open Duplicate'), $open_duplicate);
103
}
104
105
private function assertConfigValid($expect, $name, array $config) {
106
$caught = null;
107
try {
108
ManiphestTaskStatus::validateConfiguration($config);
109
} catch (Exception $ex) {
110
$caught = $ex;
111
}
112
113
$this->assertEqual(
114
$expect,
115
!($caught instanceof Exception),
116
pht('Validation of "%s"', $name));
117
}
118
119
}
120
121