3 final class PhabricatorUnitsTestCase
extends PhabricatorTestCase
{
5 // NOTE: Keep tests below PHP_INT_MAX on 32-bit systems, since if you write
6 // larger numeric literals they'll evaluate to nonsense.
8 public function testByteFormatting() {
12 1024 * 1024 => '1 MB',
13 10 * 1024 * 1024 => '10 MB',
14 100 * 1024 * 1024 => '100 MB',
15 1024 * 1024 * 1024 => '1 GB',
19 foreach ($tests as $input => $expect) {
22 phutil_format_bytes($input),
23 'phutil_format_bytes('.$input.')');
27 public function testByteParsing() {
36 '1GB' => 1024 * 1024 * 1024,
37 '1.5M' => (int)(1024 * 1024 * 1.5),
39 '1,234.56 KB' => (int)(1024 * 1234.56),
42 foreach ($tests as $input => $expect) {
45 phutil_parse_bytes($input),
46 'phutil_parse_bytes('.$input.')');
50 array('string' => 'string'),
52 'phutil_parse_bytes');
55 public function testDetailedDurationFormatting() {
56 $expected_zero = 'now';
59 12095939 => '19 w, 6 d',
60 -12095939 => '19 w, 6 d ago',
62 3380521 => '5 w, 4 d',
63 -3380521 => '5 w, 4 d ago',
68 foreach ($tests as $duration => $expect) {
71 phutil_format_relative_time_detailed($duration),
72 'phutil_format_relative_time_detailed('.$duration.')');
83 4 => '5 w, 4 d, 3 h, 2 m',
84 5 => '5 w, 4 d, 3 h, 2 m, 1 s',
85 6 => '5 w, 4 d, 3 h, 2 m, 1 s',
93 3 => '5 w, 4 d, 3 h ago',
94 4 => '5 w, 4 d, 3 h, 2 m ago',
95 5 => '5 w, 4 d, 3 h, 2 m, 1 s ago',
96 6 => '5 w, 4 d, 3 h, 2 m, 1 s ago',
100 -1 => $expected_zero,
111 foreach ($tests as $duration => $sub_tests) {
112 if (is_array($sub_tests)) {
113 foreach ($sub_tests as $levels => $expect) {
116 phutil_format_relative_time_detailed($duration, $levels),
117 'phutil_format_relative_time_detailed('.$duration.',
121 $expect = $sub_tests;
124 phutil_format_relative_time_detailed($duration),
125 'phutil_format_relative_time_detailed('.$duration.')');