1<?php
2/**
3 * Test the modification-date attribute handler.
4 *
5 * PHP version 5
6 *
7 * @category   Kolab
8 * @package    Kolab_Format
9 * @subpackage UnitTests
10 * @author     Gunnar Wrobel <wrobel@pardus.de>
11 * @license    http://www.horde.org/licenses/lgpl21 LGPL
12 * @link       http://www.horde.org/libraries/Horde_Kolab_Format
13 */
14
15/**
16 * Test the modification-date attribute handler.
17 *
18 * Copyright 2011-2016 Horde LLC (http://www.horde.org/)
19 *
20 * See the enclosed file COPYING for license information (LGPL). If you
21 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
22 *
23 * @category   Kolab
24 * @package    Kolab_Format
25 * @subpackage UnitTests
26 * @author     Gunnar Wrobel <wrobel@pardus.de>
27 * @license    http://www.horde.org/licenses/lgpl21 LGPL
28 * @link       http://www.horde.org/libraries/Horde_Kolab_Format
29 */
30class Horde_Kolab_Format_Unit_Xml_Type_ModificationDateTest
31extends Horde_Kolab_Format_TestCase
32{
33    public function testLoadModificationDate()
34    {
35        $attributes = $this->load(
36            '<?xml version="1.0" encoding="UTF-8"?>
37<kolab version="1.0" a="b"><modification-date>2011-06-28T08:42:11Z</modification-date>c</kolab>',
38            array('element' => 'modification-date')
39        );
40        $this->assertInstanceOf('DateTime', $attributes['modification-date']);
41    }
42
43    public function testLoadModificationDateValue()
44    {
45        $attributes = $this->load(
46            '<?xml version="1.0" encoding="UTF-8"?>
47<kolab version="1.0" a="b"><modification-date>2011-06-28T08:42:11Z</modification-date>c</kolab>',
48            array('element' => 'modification-date')
49        );
50        $this->assertEquals(
51            1309250531,
52            $attributes['modification-date']->format('U')
53        );
54    }
55
56    public function testLoadStrangeModificationDate()
57    {
58        $attributes = $this->load(
59            '<?xml version="1.0" encoding="UTF-8"?>
60<kolab version="1.0" a="b"><modification-date type="strange"><b/>1970-01-01T00:00:00Z<a/></modification-date>c</kolab>',
61            array('element' => 'modification-date')
62        );
63        $this->assertEquals(0, $attributes['modification-date']->format('U'));
64    }
65
66    public function testLoadMissingModificationDate()
67    {
68        $attributes = $this->load(
69            '<?xml version="1.0" encoding="UTF-8"?>
70<kolab version="1.0"/>',
71            array('element' => 'modification-date')
72        );
73        $this->assertInstanceOf('DateTime', $attributes['modification-date']);
74    }
75
76    public function testSave()
77    {
78        $this->assertInstanceOf(
79            'DOMNode',
80            $this->saveToReturn()
81        );
82    }
83
84    public function testSaveXml()
85    {
86        $this->assertRegexp(
87            '#<modification-date>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z</modification-date>#',
88            $this->saveToXml(
89                null,
90                array(),
91                array('element' => 'modification-date')
92            )
93        );
94    }
95
96    public function testSaveOverwritesOldValue()
97    {
98        $this->assertRegexp(
99            '#<modification-date type="strange">\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z<b/><a/></modification-date>#',
100            $this->saveToXml(
101                '<?xml version="1.0" encoding="UTF-8"?>
102<kolab version="1.0" a="b"><modification-date type="strange"><b/>1970-01-01T00:00:00Z<a/></modification-date>c</kolab>',
103                array(),
104                array('element' => 'modification-date')
105            )
106        );
107    }
108
109
110    protected function getTypeClass()
111    {
112        return 'Horde_Kolab_Format_Xml_Type_ModificationDate';
113    }
114}
115