-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from silinternational/develop
Ensure alias is created when primary email address is changed
- Loading branch information
Showing
2 changed files
with
86 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,26 +18,28 @@ class DirectoryTest extends TestCase | |
|
||
public function getProperties($object, $propKeys = null): array | ||
{ | ||
if ($propKeys === null) { | ||
$propKeys = [ | ||
"changePasswordAtNextLogin", | ||
"hashFunction", | ||
"id", | ||
"password", | ||
"primaryEmail", | ||
"suspended", | ||
"isEnforcedIn2Sv", | ||
"isEnrolledIn2Sv", | ||
"aliases", | ||
]; | ||
} | ||
|
||
$outArray = []; | ||
|
||
foreach ($propKeys as $key) { | ||
$outArray[$key] = $object->$key; | ||
if ($object !== null) { | ||
if ($propKeys === null) { | ||
$propKeys = [ | ||
"changePasswordAtNextLogin", | ||
"hashFunction", | ||
"id", | ||
"password", | ||
"primaryEmail", | ||
"suspended", | ||
"isEnforcedIn2Sv", | ||
"isEnrolledIn2Sv", | ||
"aliases", | ||
]; | ||
} | ||
|
||
|
||
foreach ($propKeys as $key) { | ||
$outArray[$key] = $object->$key; | ||
} | ||
} | ||
|
||
return $outArray; | ||
} | ||
|
||
|
@@ -396,6 +398,50 @@ public function testUsersUpdate_ById() | |
$this->assertEquals($expected, $results, $msg); | ||
} | ||
|
||
public function testUsersUpdate_ById_ChangeEmail() | ||
{ | ||
$fixturesClass = new GoogleFixtures($this->dataFile); | ||
$fixturesClass->removeAllFixtures(); | ||
|
||
$userId = '999991'; | ||
$oldEmailAddress = '[email protected]'; | ||
$newEmailAddress = '[email protected]'; | ||
|
||
$userData = [ | ||
"changePasswordAtNextLogin" => false, | ||
"hashFunction" => "SHA-1", | ||
"id" => $userId, | ||
"password" => "testP4ss", | ||
"primaryEmail" => $newEmailAddress, | ||
"suspended" => false, | ||
"isEnforcedIn2Sv" => false, | ||
"isEnrolledIn2Sv" => true, | ||
"aliases" => [], | ||
]; | ||
|
||
$fixtures = $this->getFixtures(); | ||
$fixturesClass->addFixtures($fixtures); | ||
|
||
$newUser = new Google_Service_Directory_User(); | ||
ObjectUtils::initialize($newUser, $userData); | ||
|
||
$newDir = new Directory('anyclient', $this->dataFile); | ||
$newDir->users->update($userId, $newUser); | ||
$newUser = $newDir->users->get($userId); | ||
|
||
$results = $this->getProperties($newUser); | ||
$expected = $userData; | ||
$expected['aliases'][] = $oldEmailAddress; | ||
$msg = " *** Bad user data returned"; | ||
$this->assertEquals($expected, $results, $msg); | ||
|
||
// Attempt to get the user by the alias, after updating the primary email address | ||
$newUser = $newDir->users->get($oldEmailAddress); | ||
$results = $this->getProperties($newUser); | ||
$msg = " *** Bad user data returned"; | ||
$this->assertEquals($expected, $results, $msg); | ||
} | ||
|
||
public function testUsersUpdate_WithAlias() | ||
{ | ||
$fixturesClass = new GoogleFixtures($this->dataFile); | ||
|