1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wabel\CertainAPI\Services; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use Wabel\CertainAPI\CertainApiClient; |
8
|
|
|
use Wabel\CertainAPI\CertainApiService; |
9
|
|
|
use Wabel\CertainAPI\Ressources\AppointmentsCertain; |
10
|
|
|
|
11
|
|
|
class DetectAppointmentsChangingsServiceTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var CertainApiService |
15
|
|
|
*/ |
16
|
|
|
private $certainApiService; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var array[] |
20
|
|
|
*/ |
21
|
|
|
private $certainAppointmentsList; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var AppointmentsCertain |
25
|
|
|
*/ |
26
|
|
|
private $appointmentsCertain; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Personal Object to test |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
|
|
private function personalAppointment(){ |
33
|
|
|
return [ |
34
|
|
|
"appointmentId"=> 52, |
35
|
|
|
"startDate"=> "2015-16-07 11:00:00", |
36
|
|
|
"endDate"=> "2015-16-07 11:30:00", |
37
|
|
|
"eventCode"=> "eventCodeXYZ", |
38
|
|
|
"pkEventId"=> "pkEventIdXYZ", |
39
|
|
|
"location"=> "locationXYZ", |
40
|
|
|
"status"=> "statusXYZ", |
41
|
|
|
"appointmentType"=> "appointmentTypeXYZ", |
42
|
|
|
"appointmentRating"=> [ |
43
|
|
|
2, |
44
|
|
|
1 |
45
|
|
|
], |
46
|
|
|
"appointmentSource"=> "AME", |
47
|
|
|
"registration"=> [ |
48
|
|
|
"regCode"=> "regCodeXYZ", |
49
|
|
|
"name"=> "nameXYZ", |
50
|
|
|
"jobTitle"=> "jobTitleXYZ", |
51
|
|
|
"organization"=> "organizationXYZ", |
52
|
|
|
"attendeeType"=> "attendeeTypeXYZ", |
53
|
|
|
"city"=> "cityXYZ", |
54
|
|
|
"state"=> "stateXYZ" |
55
|
|
|
], |
56
|
|
|
"targetRegistration"=> [ |
57
|
|
|
"regCode"=> "regCodeXYZ", |
58
|
|
|
"name"=> "nameXYZ", |
59
|
|
|
"jobTitle"=> "jobTitleXYZ", |
60
|
|
|
"organization"=> "organizationXYZ", |
61
|
|
|
"attendeeType"=> "attendeeTypeXYZ", |
62
|
|
|
"city"=> "cityXYZ", |
63
|
|
|
"state"=> "stateXYZ" |
64
|
|
|
], |
65
|
|
|
"calendar"=> null |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
protected function setUp() |
70
|
|
|
{ |
71
|
|
|
$certainApiClient = new CertainApiClient(null,getenv('username'),getenv('password'),getenv('accountCode')); |
72
|
|
|
$this->certainApiService = new CertainApiService($certainApiClient); |
73
|
|
|
$this->appointmentsCertain = new AppointmentsCertain($this->certainApiService); |
74
|
|
|
$this->certainAppointmentsList = $this->appointmentsCertain->get(getenv('eventCode'),['start_index'=>0,'max_results'=>10])->getResults()->appointments; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testDetectChangings(){ |
78
|
|
|
$detectService = new DetectAppointmentsChangingsService($this->appointmentsCertain); |
|
|
|
|
79
|
|
|
$oldAppointments = $this->certainAppointmentsList; |
80
|
|
|
$currentAppoiments = $oldAppointments; |
81
|
|
|
unset($currentAppoiments[0]); |
82
|
|
|
unset($currentAppoiments[1]); |
83
|
|
|
$hasChanged = $detectService->hasChanged($oldAppointments,$currentAppoiments); |
84
|
|
|
$this->assertTrue($hasChanged); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testGetListChangings(){ |
88
|
|
|
$detectService = new DetectAppointmentsChangingsService($this->appointmentsCertain); |
|
|
|
|
89
|
|
|
$oldAppointments = $this->certainAppointmentsList; |
90
|
|
|
$currentAppoiments = $oldAppointments; |
91
|
|
|
$delete1 = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($currentAppoiments[0]); |
92
|
|
|
$delete2 = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($currentAppoiments[1]); |
93
|
|
|
$delete3 = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($currentAppoiments[4]); |
94
|
|
|
unset($currentAppoiments[0]); |
95
|
|
|
unset($currentAppoiments[1]); |
96
|
|
|
unset($currentAppoiments[4]); |
97
|
|
|
$changings = $detectService->getListChangings($oldAppointments,$currentAppoiments); |
98
|
|
|
$this->assertEquals(3,count($changings['updated_deleted'])); |
99
|
|
|
$this->assertContains($delete1,$changings['updated_deleted']); |
100
|
|
|
$this->assertContains($delete2,$changings['updated_deleted']); |
101
|
|
|
$this->assertContains($delete3,$changings['updated_deleted']); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testDetectDeleteOrUpdated(){ |
105
|
|
|
$detectService = new DetectAppointmentsChangingsService($this->appointmentsCertain); |
|
|
|
|
106
|
|
|
$oldAppointments = $this->certainAppointmentsList; |
107
|
|
|
$oldAppointments[10] = $this->personalAppointment(); |
108
|
|
|
$currentAppoiments = $oldAppointments; |
109
|
|
|
$delete1 = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($currentAppoiments[1]); |
110
|
|
|
$delete2 = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($currentAppoiments[4]); |
111
|
|
|
unset($currentAppoiments[1]); |
112
|
|
|
unset($currentAppoiments[4]); |
113
|
|
|
$update1 = $currentAppoiments[10]; |
114
|
|
|
$currentAppoiments[10]["startDate"] = "2015-17-07 12:00:00"; |
115
|
|
|
$currentAppoiments[10]["endDate"] = "2015-17-07 12:30:00"; |
116
|
|
|
$changings = $detectService->getListChangings($oldAppointments,$currentAppoiments); |
117
|
|
|
$listDetected = $detectService->detectDeleteOrUpdated($currentAppoiments,$changings['updated_deleted']); |
118
|
|
|
$this->assertEquals(3,count($changings['updated_deleted'])); |
119
|
|
|
$this->assertArrayHasKey('deleted',$listDetected); |
120
|
|
|
$this->assertArrayHasKey('updated',$listDetected); |
121
|
|
|
$this->assertEquals(2,count($listDetected['deleted'])); |
122
|
|
|
$this->assertEquals(1,count($listDetected['updated'])); |
123
|
|
|
$this->assertContains($delete1,$listDetected['deleted']); |
124
|
|
|
$this->assertContains($delete2,$listDetected['deleted']); |
125
|
|
|
$this->assertContains($update1,$listDetected['updated']); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function testDetectAppointmentsChangings(){ |
129
|
|
|
$detectService = new DetectAppointmentsChangingsService($this->appointmentsCertain); |
|
|
|
|
130
|
|
|
$oldAppointments = $this->certainAppointmentsList; |
131
|
|
|
$oldAppointments[10] = $this->personalAppointment(); |
132
|
|
|
$currentAppoiments = $oldAppointments; |
133
|
|
|
$time = time(); |
134
|
|
|
$delete1 = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($currentAppoiments[1]); |
135
|
|
|
$delete1['dateDetectChanges'] = $time; |
136
|
|
|
$delete2 = DetectAppointmentsChangingsService::recursiveArrayObjectToFullArray($currentAppoiments[4]); |
137
|
|
|
$delete2['dateDetectChanges'] = $time; |
138
|
|
|
unset($currentAppoiments[1]); |
139
|
|
|
unset($currentAppoiments[4]); |
140
|
|
|
$update1 = $currentAppoiments[10]; |
141
|
|
|
$update1['dateDetectChanges'] = $time; |
142
|
|
|
$currentAppoiments[10]["startDate"] = "2015-17-07 12:00:00"; |
143
|
|
|
$currentAppoiments[10]["endDate"] = "2015-17-07 12:30:00"; |
144
|
|
|
$listDetected = $detectService->detectAppointmentsChangings($oldAppointments,$currentAppoiments,$time); |
145
|
|
|
$this->assertContains($delete1,$listDetected['deleted']); |
146
|
|
|
$this->assertContains($delete2,$listDetected['deleted']); |
147
|
|
|
$this->assertContains($update1,$listDetected['updated']); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
} |