-
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.
Clarify comments, make code more readable as per review suggestions
- Loading branch information
Showing
3 changed files
with
32 additions
and
24 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
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 |
---|---|---|
|
@@ -17,28 +17,25 @@ class GroupsTest extends TestCase | |
public const GROUP_EMAIL_ADDRESS = '[email protected]'; | ||
public const GROUP_ALIAS_ADDRESS = '[email protected]'; | ||
|
||
public function testInitialSetup() | ||
protected function deleteGroupAndAliasesIfTheyExists(string $groupName) | ||
{ | ||
$mockGoogleServiceDirectory = new GoogleMock_Directory('anyclient', $this->dataFile); | ||
$group = $mockGoogleServiceDirectory->groups->get(self::GROUP_EMAIL_ADDRESS); | ||
if ($group !== null) { | ||
$mockGoogleServiceDirectory->groups->delete(self::GROUP_EMAIL_ADDRESS); | ||
} | ||
$group = $mockGoogleServiceDirectory->groups->get(self::GROUP_EMAIL_ADDRESS); | ||
self::assertNull($group, "Failed to clean up previous insert tests."); | ||
$group = $mockGoogleServiceDirectory->groups->get(self::GROUP_EMAIL_ADDRESS . 'update'); | ||
$group = $mockGoogleServiceDirectory->groups->get($groupName); | ||
if ($group !== null) { | ||
$mockGoogleServiceDirectory->groups->delete(self::GROUP_EMAIL_ADDRESS . 'update'); | ||
$mockGoogleServiceDirectory->groups->delete($groupName); | ||
} | ||
$group = $mockGoogleServiceDirectory->groups->get(self::GROUP_EMAIL_ADDRESS . 'update'); | ||
self::assertNull($group, "Failed to clean up previous update tests."); | ||
$group = $mockGoogleServiceDirectory->groups->get($groupName); | ||
self::assertNull($group, "Failed to clean up previous tests."); | ||
} | ||
|
||
public function testInsert() | ||
{ | ||
$this->deleteGroupAndAliasesIfTheyExists(self::GROUP_EMAIL_ADDRESS); | ||
$group = new GoogleDirectory_Group(); | ||
$group->setEmail(self::GROUP_EMAIL_ADDRESS); | ||
$group->setAliases([self::GROUP_ALIAS_ADDRESS]); // read-only, should not save anything | ||
// See https://developers.google.com/admin-sdk/directory/reference/rest/v1/groups#Group | ||
// setting the aliases will not add, remove, or change aliases at all. | ||
$group->setAliases([self::GROUP_ALIAS_ADDRESS]); | ||
$group->setName('Sample Group'); | ||
$group->setDescription('A Sample Group used for testing'); | ||
|
||
|
@@ -59,9 +56,12 @@ public function testInsert() | |
|
||
public function testUpdate() | ||
{ | ||
$this->deleteGroupAndAliasesIfTheyExists(self::GROUP_EMAIL_ADDRESS . 'update'); | ||
$group = new GoogleDirectory_Group(); | ||
$group->setEmail(self::GROUP_EMAIL_ADDRESS . 'update'); | ||
$group->setAliases([self::GROUP_ALIAS_ADDRESS . 'update']); // this shouldn't change aliases. | ||
// See https://developers.google.com/admin-sdk/directory/reference/rest/v1/groups#Group | ||
// setting the aliases will not add, remove, or change aliases at all. | ||
$group->setAliases([self::GROUP_ALIAS_ADDRESS . 'update']); | ||
$group->setName('Sample Group Update'); | ||
$group->setDescription('A Sample Group used for testing update'); | ||
|
||
|
@@ -79,19 +79,22 @@ public function testUpdate() | |
self::assertTrue($addedGroup instanceof GoogleDirectory_Group); | ||
self::assertEmpty($addedGroup->getAliases(), "Expecting no group aliases inserted by group.insert"); | ||
|
||
// Google group does not update aliases, but for coding simplicity the mock object does. | ||
$group->setAliases([self::GROUP_ALIAS_ADDRESS . 'update-change']); // this shouldn't change aliases. | ||
// See https://developers.google.com/admin-sdk/directory/reference/rest/v1/groups#Group | ||
// setting the aliases will not add, remove, or change aliases at all. | ||
$group->setAliases([self::GROUP_ALIAS_ADDRESS . 'update-change']); | ||
$updatedGroup = $mockGoogleServiceDirectory->groups->update($group->getEmail(), $group); | ||
self::assertTrue($updatedGroup instanceof GoogleDirectory_Group); | ||
self::assertEmpty($updatedGroup->getAliases()); // this should confirm aliases are unset | ||
self::assertEmpty($updatedGroup->getAliases(), "Expecting no group aliases changed by group.update"); | ||
} | ||
|
||
protected function deleteTestSetup() | ||
{ | ||
// Set update a deletable email address | ||
$group = new GoogleDirectory_Group(); | ||
$group->setEmail(self::GROUP_EMAIL_ADDRESS . 'delete'); | ||
$group->setAliases([self::GROUP_ALIAS_ADDRESS . 'delete']); // read-only property, should have no effect | ||
// See https://developers.google.com/admin-sdk/directory/reference/rest/v1/groups#Group | ||
// setting the aliases will not add, remove, or change aliases at all. | ||
$group->setAliases([self::GROUP_ALIAS_ADDRESS . 'delete']); | ||
$group->setName('Sample Deletable Group'); | ||
$group->setDescription('A Sample Deletable Group used for testing'); | ||
|
||
|