-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathOutlookContactTest.php
69 lines (57 loc) · 1.94 KB
/
OutlookContactTest.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
<?php
namespace Office365;
use Office365\Outlook\Contacts\Contact;
use Office365\Outlook\EmailAddress;
use Office365\Runtime\Http\RequestException;
class OutlookContactTest extends GraphTestCase
{
public function testCreateMyContact()
{
/** @var Contact $contact */
$contact = self::$graphClient->getMe()->getContacts()->add();
$contact->setGivenName("Pavel");
$contact->setSurname("Bansky");
$contact->getBusinessPhones()[] = "+1 732 555 0102";
$contact->setEmailAddresses([new EmailAddress("Pavel Bansky","[email protected]")]);
self::$graphClient->executeQuery();
self::assertNotNull($contact->getId());
return $contact;
}
/**
* @depends testCreateMyContact
* @param Contact $contact
*/
public function testFindMyContact(Contact $contact)
{
$id = $contact->getId();
$foundContact = self::$graphClient->getMe()->getContacts()->getById($id)->get()->executeQuery();
self::assertNotNull($foundContact);
}
/**
* @depends testCreateMyContact
* @param Contact $contact
*/
public function testUpdateMyContact(Contact $contact)
{
$surnameValue = "Jr.";
$contact->setSurname($surnameValue)->update()->executeQuery();
//load updated contact
$existingContact = $contact->get()->executeQuery();
self::assertEquals($surnameValue,$existingContact->getSurname());
}
/**
* @depends testCreateMyContact
* @param Contact $contact
*/
public function testDeleteMyContact(Contact $contact)
{
$contactIdToDelete = $contact->getId();
$contact->deleteObject()->executeQuery();
try {
self::$graphClient->getMe()->getContacts()->getById($contactIdToDelete)->get()->executeQuery();
}
catch (RequestException $ex){
self::assertEquals(404, $ex->getCode());
}
}
}