1<?php
2
3namespace Sabre\VObject;
4
5class DocumentTest extends \PHPUnit_Framework_TestCase {
6
7    function testGetDocumentType() {
8
9        $doc = new MockDocument();
10        $this->assertEquals(Document::UNKNOWN, $doc->getDocumentType());
11
12    }
13
14    function testConstruct() {
15
16        $doc = new MockDocument('VLIST');
17        $this->assertEquals('VLIST', $doc->name);
18
19    }
20
21    function testCreateComponent() {
22
23        $vcal = new Component\VCalendar([], false);
24
25        $event = $vcal->createComponent('VEVENT');
26
27        $this->assertInstanceOf('Sabre\VObject\Component\VEvent', $event);
28        $vcal->add($event);
29
30        $prop = $vcal->createProperty('X-PROP', '1234256', ['X-PARAM' => '3']);
31        $this->assertInstanceOf('Sabre\VObject\Property', $prop);
32
33        $event->add($prop);
34
35        unset(
36            $event->DTSTAMP,
37            $event->UID
38        );
39
40        $out = $vcal->serialize();
41        $this->assertEquals("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nX-PROP;X-PARAM=3:1234256\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", $out);
42
43    }
44
45    function testCreate() {
46
47        $vcal = new Component\VCalendar([], false);
48
49        $event = $vcal->create('VEVENT');
50        $this->assertInstanceOf('Sabre\VObject\Component\VEvent', $event);
51
52        $prop = $vcal->create('CALSCALE');
53        $this->assertInstanceOf('Sabre\VObject\Property\Text', $prop);
54
55    }
56
57    function testGetClassNameForPropertyValue() {
58
59        $vcal = new Component\VCalendar([], false);
60        $this->assertEquals('Sabre\\VObject\\Property\\Text', $vcal->getClassNameForPropertyValue('TEXT'));
61        $this->assertNull($vcal->getClassNameForPropertyValue('FOO'));
62
63    }
64
65    function testDestroy() {
66
67        $vcal = new Component\VCalendar([], false);
68        $event = $vcal->createComponent('VEVENT');
69
70        $this->assertInstanceOf('Sabre\VObject\Component\VEvent', $event);
71        $vcal->add($event);
72
73        $prop = $vcal->createProperty('X-PROP', '1234256', ['X-PARAM' => '3']);
74
75        $event->add($prop);
76
77        $this->assertEquals($event, $prop->parent);
78
79        $vcal->destroy();
80
81        $this->assertNull($prop->parent);
82
83
84    }
85
86}
87
88
89class MockDocument extends Document {
90
91}
92