-
Notifications
You must be signed in to change notification settings - Fork 8
/
PersonRequestTest.php
120 lines (94 loc) · 3.67 KB
/
PersonRequestTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace Tests\Unit\Docs;
use CTApi\Models\Person;
use CTApi\Requests\PersonRequest;
use Tests\Unit\TestCaseHttpMocked;
class PersonRequestTest extends TestCaseHttpMocked
{
public function testExampleCode()
{
// logged in user
$myself = PersonRequest::whoami();
$this->assertEquals("Logged in Person: Matthew Evangelist", "Logged in Person: " . $myself->getFirstName() . " " . $myself->getLastName());
// Get specific Person
$personA = PersonRequest::find(21); // returns "null" if id is invalid
$personB = PersonRequest::findOrFail(22); // throws exception if id is invalid
// request all users
$allPersons = PersonRequest::all();
$personList = "";
foreach ($allPersons as $person) {
$personList .= $person->getFirstName() . " / ";
}
$this->assertEquals("Matthew / Mark / Luke / John / ", $personList);
// filter user
$teenager = PersonRequest::where('birthday_before', '2007-01-01')
->where('birthday_after', '2003-01-01')
->orderBy('birthday')
->get();
// Request Event of Person
$personA = PersonRequest::whoami();
$events = $personA->requestEvents()?->get();
}
/**
* @doesNotPerformAssertions
*/
public function testCreatePerson()
{
$newPerson = new Person();
$newPerson->setFirstName("John")
->setLastName("Doe")
->setBirthName("Smith");
//add further attributes
PersonRequest::create($newPerson);
}
/**
* @doesNotPerformAssertions
*/
public function testUpdatePerson()
{
$person = PersonRequest::findOrFail(21);
$person->setEmail('new-mail@example.com');
PersonRequest::update($person);
}
/**
* @doesNotPerformAssertions
*/
public function testUpdatePersonSingleAttrbute()
{
$person = PersonRequest::findOrFail(21);
$person->setEmail('new-mail@example.com');
$person->setJob('This should not be persisted!');
PersonRequest::update($person, ['email']);
}
public function testUpdatePersonModifiableAttributes()
{
$person = PersonRequest::findOrFail(21);
// Attributes that can be updated in ChurchTools-API
$listOfModifiableAttributes = implode("; ", $person->getModifiableAttributes());
$this->assertEquals("addressAddition; birthday; birthName; birthplace; campusId; city; country; departmentIds; email; fax; firstName; job; lastName; mobile; nickname; phonePrivate; phoneWork; sexId; statusId; street; zip", $listOfModifiableAttributes);
}
/**
* @doesNotPerformAssertions
*/
public function testDeletePerson()
{
$person = PersonRequest::findOrFail(21);
// delete person on churchtools
PersonRequest::delete($person);
}
public function testBirthdayRequest()
{
$birthdayPersons = PersonRequest::birthdays()
->where("start_date", "2022-01-01")
->where("end_date", "2022-12-31")
->where("my_groups", true)
->get();
$lastBirthdayPerson = end($birthdayPersons);
$this->assertEquals("21", $lastBirthdayPerson->getPerson()?->getId());
$this->assertEquals("John", $lastBirthdayPerson->getPerson()?->getFirstName());
$this->assertEquals("Snow", $lastBirthdayPerson->getPerson()?->getLastName());
$this->assertEquals("1997-03-01", $lastBirthdayPerson->getAnniversaryInitialDate());
$this->assertEquals("2022-03-01", $lastBirthdayPerson->getAnniversary());
$this->assertEquals("25", $lastBirthdayPerson->getAge());
}
}