Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/util/__tests__/AlmanacNamesTestCase.php
12262 views
1
<?php
2
3
final class AlmanacNamesTestCase extends PhabricatorTestCase {
4
5
public function testServiceOrDeviceNames() {
6
$map = array(
7
'' => false,
8
'a' => false,
9
'ab' => false,
10
'...' => false,
11
'ab.' => false,
12
'.ab' => false,
13
'A-B' => false,
14
'A!B' => false,
15
'A.B' => false,
16
'a..b' => false,
17
'1.2' => false,
18
'127.0.0.1' => false,
19
'1.b' => false,
20
'a.1' => false,
21
'a.1.b' => false,
22
'-.a' => false,
23
'-a.b' => false,
24
'a-.b' => false,
25
'a.-' => false,
26
'a.-b' => false,
27
'a.b-' => false,
28
'-.-' => false,
29
'a--b' => false,
30
31
'abc' => true,
32
'a.b' => true,
33
'db.companyname.instance' => true,
34
'web002.useast.example.com' => true,
35
'master.example-corp.com' => true,
36
37
// Maximum length is 100.
38
str_repeat('a', 100) => true,
39
str_repeat('a', 101) => false,
40
);
41
42
foreach ($map as $input => $expect) {
43
$caught = null;
44
try {
45
AlmanacNames::validateName($input);
46
} catch (Exception $ex) {
47
$caught = $ex;
48
}
49
$this->assertEqual(
50
$expect,
51
!($caught instanceof Exception),
52
$input);
53
}
54
}
55
}
56
57