Completed
Push — master ( 4b7994...32578e )
by Damian
24s
created

DBTimeTest::testFormatFromSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\ORM\Tests;
4
5
use SilverStripe\i18n\i18n;
6
use SilverStripe\ORM\FieldType\DBField;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\ORM\FieldType\DBTime;
9
use SilverStripe\Security\Member;
10
11
class DBTimeTest extends SapphireTest
12
{
13
    protected function setUp()
14
    {
15
        parent::setUp();
16
        i18n::set_locale('en_NZ');
17
    }
18
19
    public function dataTestParse()
20
    {
21
        return [
22
            // Test am-pm conversion
23
            ['11:01 pm', '23:01:00'],
24
            ['11:01 am', '11:01:00'],
25
            ['12:01 pm', '12:01:00'],
26
            ['12:01 am', '00:01:00'],
27
            // Test seconds
28
            ['11:01.01 pm', '23:01:01'],
29
            ['12:01.01', '12:01:01'],
30
        ];
31
    }
32
33
    /**
34
     * @dataProvider dataTestParse
35
     * @param string $input
36
     * @param string $expected
37
     */
38
    public function testParse($input, $expected)
39
    {
40
        $time = DBField::create_field('Time', $input);
41
        $this->assertEquals(
42
            $expected,
43
            $time->getValue(),
44
            "Date parsed from {$input} should be {$expected}"
45
        );
46
    }
47
48
    public function testNice()
49
    {
50
        $time = DBTime::create_field('Time', '17:15:55');
51
        $this->assertEquals('5:15:55 PM', $time->Nice());
52
    }
53
54
    public function testShort()
55
    {
56
        $time = DBTime::create_field('Time', '17:15:55');
57
        $this->assertEquals('5:15 PM', $time->Short());
58
    }
59
}
60