Resources
5 years ago
AzureTest.php
1 year ago
ContactTest.php
5 years ago
DeltaQueryTest.php
1 year ago
EventTest.php
5 years ago
ExcelTest.php
1 year ago
GraphTestBase.php
1 year ago
MailTest.php
1 year ago
OnedriveTest.php
1 year ago
OnenoteTest.php
1 year ago
OpenTypeTest.php
1 year ago
PlannerTest.php
1 year ago
SharepointTest.php
1 year ago
TermStoreTest.php
1 year ago
TestConstants.php
1 year ago
UserTest.php
1 year ago
WebhooksTest.php
1 year ago
UserTest.php
150 lines
| 1 | <?php |
| 2 | use PHPUnit\Framework\TestCase; |
| 3 | use Microsoft\Graph\Test\GraphTestBase; |
| 4 | use Microsoft\Graph\Model; |
| 5 | use Beta\Microsoft\Graph\Model\User as BetaUser; |
| 6 | use Beta\Microsoft\Graph\Model as BetaModel; |
| 7 | |
| 8 | class UserTest extends TestCase |
| 9 | { |
| 10 | private $_client; |
| 11 | |
| 12 | protected function setUp(): void |
| 13 | { |
| 14 | $graphTestBase = new GraphTestBase(); |
| 15 | $this->_client = $graphTestBase->graphClient; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * @group functional |
| 20 | */ |
| 21 | public function testFilterByStartsWith() |
| 22 | { |
| 23 | $users = $this->_client->createRequest("GET", "/users?\$filter=startswith(displayName, 'A')") |
| 24 | ->setReturnType(Model\User::class) |
| 25 | ->execute(); |
| 26 | foreach ($users as $user) |
| 27 | { |
| 28 | $this->assertEquals("A", substr($user->getDisplayName(), 0,1)); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @group functional |
| 34 | */ |
| 35 | public function testGetPhoto() |
| 36 | { |
| 37 | $photo = $this->_client->createRequest("GET", "/me/photo/\$value") |
| 38 | ->execute(); |
| 39 | $this->assertNotNull($photo->getRawBody()); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @group functional |
| 44 | */ |
| 45 | public function testGetUser() |
| 46 | { |
| 47 | $user = $this->_client->createRequest("GET", "/me") |
| 48 | ->setReturnType(Model\User::class) |
| 49 | ->execute(); |
| 50 | $this->assertNotNull($user->getUserPrincipalName()); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @group functional |
| 55 | */ |
| 56 | public function testBetaGetUser() |
| 57 | { |
| 58 | $user = $this->_client->setApiVersion("beta") |
| 59 | ->createRequest("GET", "/me") |
| 60 | ->setReturnType(BetaUser::class) |
| 61 | ->execute(); |
| 62 | $this->assertNotNull($user->getUserPrincipalName()); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @group functional |
| 67 | */ |
| 68 | public function testGetManager() |
| 69 | { |
| 70 | $manager = $this->_client->createRequest("GET", "/me/manager") |
| 71 | ->setReturnType(Model\User::class) |
| 72 | ->execute(); |
| 73 | $this->assertNotNull($manager->getDisplayName()); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @group functional |
| 78 | */ |
| 79 | public function testBetaGetManager() |
| 80 | { |
| 81 | $manager = $this->_client->setApiVersion("beta") |
| 82 | ->createRequest("GET", "/me/manager") |
| 83 | ->setReturnType(BetaModel\User::class) |
| 84 | ->execute(); |
| 85 | $this->assertNotNull($manager->getDisplayName()); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @group functional |
| 90 | */ |
| 91 | public function testUpdateManager() |
| 92 | { |
| 93 | $manager = $this->_client->createRequest("GET", "/me/manager") |
| 94 | ->setReturnType(Model\User::class) |
| 95 | ->execute(); |
| 96 | |
| 97 | $this->_client->createRequest("PUT", "/me/manager/\$ref") |
| 98 | ->attachBody('{"@odata.id": "https://graph.microsoft.com/v1.0/users/'.$manager->getId().'"}') |
| 99 | ->execute(); |
| 100 | $newManager = $this->_client->createRequest("GET", "/me/manager") |
| 101 | ->setReturnType(Model\User::class) |
| 102 | ->execute(); |
| 103 | $this->assertEquals($manager, $newManager); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @group functional |
| 108 | */ |
| 109 | public function testGetMemberGroupsWithSecurityEnabled() |
| 110 | { |
| 111 | $groups = $this->_client->createRequest("POST", "/me/getMemberGroups") |
| 112 | ->attachBody("{securityEnabledOnly: true}") |
| 113 | ->setReturnType(Model\Group::class) |
| 114 | ->execute(); |
| 115 | $this->assertNotNull($groups); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @group functional |
| 120 | */ |
| 121 | public function testUpdateUser() |
| 122 | { |
| 123 | $user = $this->getCurrentUser(); |
| 124 | |
| 125 | $newUser = new Model\User(); |
| 126 | $newUser->setGivenName("Katherine"); |
| 127 | |
| 128 | $this->_client->createRequest("PATCH", "/me") |
| 129 | ->attachBody($newUser) |
| 130 | ->execute(); |
| 131 | $updatedUser = $this->getCurrentUser(); |
| 132 | |
| 133 | $this->assertEquals("Katherine", $updatedUser->getGivenName()); |
| 134 | $this->assertEquals($user->getMail(), $updatedUser->getMail()); |
| 135 | |
| 136 | $this->_client->createRequest("PATCH", "/me") |
| 137 | ->attachBody($user) |
| 138 | ->setReturnType(Model\User::class) |
| 139 | ->execute(); |
| 140 | $restoredUser = $this->getCurrentUser(); |
| 141 | $this->assertEquals($user->getGivenName(), $restoredUser->getGivenName()); |
| 142 | } |
| 143 | |
| 144 | private function getCurrentUser() |
| 145 | { |
| 146 | return $this->_client->createRequest("GET", "/me") |
| 147 | ->setReturnType(Model\User::class) |
| 148 | ->execute(); |
| 149 | } |
| 150 | } |