LibCaldav_attendeeTest::testDeleteEvent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
require_once dirname(__FILE__).'/mock/functions.php';
4
require_once dirname(__FILE__).'/../programs/caldav.class.php';
5
require_once dirname(__FILE__).'/mock/calendar.php';
6
7
8
9
10
11
class LibCaldav_attendeeTest extends PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @var LibCaldav_mock
15
     */
16
    static $mock;
17
18
    public static function setUpBeforeClass()
19
    {
20
        self::$mock = bab_getInstance('LibCaldav_mock');
21
    }
22
    
23
    public function testOviWithCaldavAttendeeSaveEvent()
24
    {
25
        $oviUser = self::$mock->getOviUser();
26
        $caldavUser = self::$mock->getCaldavUser();
27
        $oviBackend = self::$mock->getOviBackend();
28
        $caldavBackend = self::$mock->getCaldavBackend();
29
        
30
        
31
        $oviCalendar = $oviBackend->PersonalCalendar($oviUser);
32
        $collection = $oviBackend->CalendarEventCollection($oviCalendar);
0 ignored issues
show
Bug introduced by
It seems like $oviCalendar defined by $oviBackend->PersonalCalendar($oviUser) on line 31 can be null; however, Func_CalendarBackend::CalendarEventCollection() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
33
        
34
        $caldavCalendar = $caldavBackend->PersonalCalendar($caldavUser);
35
        
36
        $dtstart = BAB_DateTime::fromIsoDateTime('2015-01-01 00:00:00');
37
        $dtend = BAB_DateTime::fromIsoDateTime('2015-01-02 00:00:00');
38
        
39
        $period = new bab_CalendarPeriod();
40
        $period->setCollection($collection);
41
        $period->setDates($dtstart, $dtend);
42
        $period->setProperty('UID', 'LIBCALDAV_UNITTEST_2');
43
        $period->setProperty('SUMMARY', 'Test event');
44
        $period->setProperty('STATUS', 'CONFIMED');
45
        
46
        $period->addAttendee($oviCalendar);
0 ignored issues
show
Bug introduced by
It seems like $oviCalendar defined by $oviBackend->PersonalCalendar($oviUser) on line 31 can be null; however, bab_ICalendarObject::addAttendee() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
47
        $period->addAttendee($caldavCalendar);
48
        
49
        $collection->addPeriod($period);
50
        
51
        $this->assertEquals(2, count($period->getAttendees()), 'verify number of attendees');
52
        
53
        $this->assertTrue($oviBackend->savePeriod($period));
54
        
55
        // create association with external calendars:
56
        $period->commitEvent();
57
    }
58
    
59
    
60
    
61
    
62 View Code Duplication
    public function testOviGetEvent()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        $oviUser = self::$mock->getOviUser();
65
        $oviBackend = self::$mock->getOviBackend();
66
        
67
        $calendar = $oviBackend->PersonalCalendar($oviUser);
68
        $collection = $oviBackend->CalendarEventCollection($calendar);
0 ignored issues
show
Bug introduced by
It seems like $calendar defined by $oviBackend->PersonalCalendar($oviUser) on line 67 can be null; however, Func_CalendarBackend::CalendarEventCollection() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
69
        
70
        $period = $oviBackend->getPeriod($collection, 'LIBCALDAV_UNITTEST_2');
71
        
72
        $this->assertInstanceOf('bab_CalendarPeriod', $period);
73
        $this->assertEquals('Test event', $period->getProperty('SUMMARY'));
74
    }
75
    
76
    
77 View Code Duplication
    protected function getPeriod()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $caldavUser = self::$mock->getCaldavUser();
80
        $caldavBackend = self::$mock->getCaldavBackend();
81
        
82
        $calendar = $caldavBackend->PersonalCalendar($caldavUser);
83
        $collection = $caldavBackend->CalendarEventCollection($calendar);
84
        
85
        return $caldavBackend->getPeriod($collection, 'LIBCALDAV_UNITTEST_2');
86
    }
87
    
88
    
89 View Code Duplication
    protected function getOviPeriod()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
    {
91
        $oviUser = self::$mock->getOviUser();
92
        $oviBackend = self::$mock->getOviBackend();
93
    
94
        $calendar = $oviBackend->PersonalCalendar($oviUser);
95
        $collection = $oviBackend->CalendarEventCollection($calendar);
0 ignored issues
show
Bug introduced by
It seems like $calendar defined by $oviBackend->PersonalCalendar($oviUser) on line 94 can be null; however, Func_CalendarBackend::CalendarEventCollection() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
96
    
97
        return $oviBackend->getPeriod($collection, 'LIBCALDAV_UNITTEST_2');
98
    }
99
    
100
    
101
    public function testCaldavGetEvent()
102
    {
103
        $period = $this->getPeriod();
104
    
105
        $this->assertInstanceOf('bab_CalendarPeriod', $period);
106
        $this->assertEquals('Test event', $period->getProperty('SUMMARY'));
107
    }
108
    
109
    public function testCaldavSearchEvent()
110
    {
111
        $caldavUser = self::$mock->getCaldavUser();
112
        $caldavBackend = self::$mock->getCaldavBackend();
113
        
114
        $calendar = $caldavBackend->PersonalCalendar($caldavUser);
115
        
116
        $from = BAB_DateTime::fromIsoDateTime('2015-01-01 00:00:00');
117
        $to = BAB_DateTime::fromIsoDateTime('2015-01-02 00:00:00');
118
        
119
        
120
        $query = $caldavBackend->Criteria();
121
        
122
        $criteria = $query->Begin($from)
123
            ->_AND_($query->End($to))
124
            ->_AND_($query->Calendar($calendar));
125
        
126
        $arr = $caldavBackend->selectPeriods($criteria);
127
        
128
        // can be 2 if caldav calendar has net been reset
129
        //$this->assertEquals(1, count($arr));
130
        
131
        $period = $arr[0];
132
        
133
        $this->assertInstanceOf('bab_CalendarPeriod', $period);
134
        $this->assertEquals('Test event', $period->getProperty('SUMMARY'));
135
    }
136
    
137
    
138
    public function testCancelInAllCalendars()
139
    {
140
        $caldavUser = self::$mock->getCaldavUser();
141
        $caldavBackend = self::$mock->getCaldavBackend();
142
        
143
        $calendar = $caldavBackend->PersonalCalendar($caldavUser);
144
        
145
        $period = $this->getPeriod();
146
        $this->assertTrue($period->cancelFromAllCalendars($calendar));
147
        
148
        $this->assertEquals('CANCELLED', $this->getPeriod()->getProperty('STATUS'));
149
        
150
        $oviPeriod = $this->getOviPeriod();
151
        $this->assertEquals('CANCELLED', $oviPeriod->getProperty('STATUS'));
152
    }
153
    
154
    
155
    public function testDeleteEvent()
156
    {
157
        $period = $this->getPeriod();
158
        $period->delete();
159
160
        $deletedPeriod = $this->getPeriod();
161
        
162
        $this->assertEquals(null, $deletedPeriod);
163
        
164
        // event is not deleted in ovidentia backend!
165
    }
166
}
167