1 | <?php |
||
8 | class RFC2550Test extends PHPUnit_Framework_TestCase |
||
9 | { |
||
10 | public function setUp() |
||
11 | { |
||
12 | $this->converter = new RFC2550(); |
||
13 | } |
||
14 | |||
15 | public function provideTwoWaySamples() |
||
16 | { |
||
17 | // 3.1 section |
||
18 | yield [1, '0001']; |
||
19 | yield [12, '0012']; |
||
20 | yield [123, '0123']; |
||
21 | yield [1234, '1234']; |
||
22 | |||
23 | // 3.2 section |
||
24 | yield [12345, 'A12345']; |
||
25 | |||
26 | // 3.3 section |
||
27 | yield [123456, 'B123456']; |
||
28 | yield [12345678, 'D12345678']; |
||
29 | yield ['999999999999999999999999999999', 'Z999999999999999999999999999999']; |
||
30 | |||
31 | // 3.4.2.1 |
||
32 | yield ['1000000000000000000000000000000', '^A1000000000000000000000000000000']; |
||
33 | yield ['99999999999999999999999999999999999999999999999999999999', '^Z99999999999999999999999999999999999999999999999999999999']; |
||
34 | |||
35 | // 3.4.2.2 |
||
36 | yield ['100000000000000000000000000000000000000000000000000000000', '^^AA100000000000000000000000000000000000000000000000000000000']; |
||
37 | |||
38 | // 3.4.2.3 |
||
39 | $y = '1' . str_repeat('0', 732); |
||
40 | yield [$y, '^^^AAA' . $y]; |
||
41 | |||
42 | // 3.5 |
||
43 | yield [0, '/9999']; |
||
44 | yield [-1, '/9998']; |
||
45 | yield [-10000, '*Z89999']; |
||
46 | yield [-99999, '*Z00000']; |
||
47 | yield [-100000, '*Y899999']; |
||
48 | yield ['-1000000000000000000000000000000', '!Z8999999999999999999999999999999']; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @dataProvider provideTwoWaySamples |
||
53 | */ |
||
54 | public function testConverter($year, $formatted) |
||
55 | { |
||
56 | $this->assertSame($formatted, $this->converter->to($year)); |
||
57 | $this->assertSame((string)$year, $this->converter->from($formatted)); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * 3.6 implementation |
||
62 | */ |
||
63 | public function testOptionnalZeroOnY10kDates() |
||
64 | { |
||
65 | $this->assertSame('10000', $this->converter->from('A1')); |
||
66 | $this->assertSame('1000000000000000000000000000000', $this->converter->from('^A1')); |
||
67 | $this->assertSame('100000000000000000000000000000000000000000000000000000000', $this->converter->from('^^AA1')); |
||
68 | $y = '1' . str_repeat('0', 732); |
||
69 | $this->assertSame($y, $this->converter->from('^^^AAA1')); |
||
70 | } |
||
71 | } |