forked from apigee/apigee-client-php
-
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.
AppGroup membership testcase 3x (apigee#304)
- Loading branch information
1 parent
f135fa1
commit 6c54545
Showing
6 changed files
with
143 additions
and
3 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
131 changes: 131 additions & 0 deletions
131
tests/Api/ApigeeX/Controller/AppGroupMembersControllerTest.php
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 |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Apigee\Edge\Tests\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\Api\ApigeeX\Controller\AppGroupMembersController; | ||
use Apigee\Edge\Api\ApigeeX\Controller\AppGroupMembersControllerInterface; | ||
use Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership; | ||
use Apigee\Edge\ClientInterface; | ||
use Apigee\Edge\Tests\Api\ApigeeX\Entity\AppGroupTestEntityProviderTrait; | ||
use Apigee\Edge\Tests\Api\Management\Controller\DeveloperControllerAwareTestTrait; | ||
use Apigee\Edge\Tests\Api\Management\Entity\DeveloperTestEntityProviderTrait; | ||
use Apigee\Edge\Tests\Test\Controller\ControllerTestBase; | ||
use Apigee\Edge\Tests\Test\Controller\DefaultAPIClientAwareTrait; | ||
use Apigee\Edge\Tests\Test\TestClientFactory; | ||
use Apigee\Edge\Tests\Test\Utility\EntityStorage; | ||
use Apigee\Edge\Tests\Test\Utility\MarkOnlineTestSkippedAwareTrait; | ||
|
||
/** | ||
* Class AppGroupMembersControllerTest. | ||
* | ||
* @group controller | ||
* @group management | ||
*/ | ||
class AppGroupMembersControllerTest extends ControllerTestBase | ||
{ | ||
use DefaultAPIClientAwareTrait; | ||
use AppGroupControllerAwareTestTrait; | ||
use DeveloperControllerAwareTestTrait; | ||
use AppGroupTestEntityProviderTrait; | ||
use DeveloperTestEntityProviderTrait; | ||
use MarkOnlineTestSkippedAwareTrait; | ||
|
||
protected const TEST_ROLE = 'simple member'; | ||
|
||
/** @var \Apigee\Edge\Api\ApigeeX\Entity\AppGroupInterface */ | ||
protected static $testAppGroup; | ||
|
||
/** @var \Apigee\Edge\Api\Management\Entity\DeveloperInterface */ | ||
protected static $testDeveloper1; | ||
|
||
/** @var \Apigee\Edge\Api\Management\Entity\DeveloperInterface */ | ||
protected static $testDeveloper2; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
parent::setUpBeforeClass(); | ||
static::$testAppGroup = static::getNewAppGroup(); | ||
static::appGroupController()->create(static::$testAppGroup); | ||
static::$testDeveloper1 = static::getNewDeveloper(); | ||
static::developerController()->create(static::$testDeveloper1); | ||
static::$testDeveloper2 = static::getNewDeveloper(); | ||
static::developerController()->create(static::$testDeveloper2); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function tearDownAfterClass(): void | ||
{ | ||
parent::tearDownAfterClass(); | ||
EntityStorage::getInstance()->purgeCreatedEntities(); | ||
} | ||
|
||
public function testCreateMembership(): void | ||
{ | ||
$members = $this->getAppGroupMembershipController()->setMembers(new AppGroupMembership([static::$testDeveloper1->getEmail() => static::TEST_ROLE])); | ||
$this->assertTrue($members->isMember(static::$testDeveloper1->getEmail())); | ||
$this->assertContains(static::TEST_ROLE, $members->getRole(static::$testDeveloper1->getEmail())); | ||
} | ||
|
||
/** | ||
* @depends testCreateMembership | ||
* | ||
* @group online | ||
*/ | ||
public function testUpdateMembership(): void | ||
{ | ||
static::markOnlineTestSkipped(__FUNCTION__); | ||
$role = 'not a simple member'; | ||
$members = $this->getAppGroupMembershipController()->setMembers(new AppGroupMembership([static::$testDeveloper1->getEmail() => $role])); | ||
$this->assertTrue($members->isMember(static::$testDeveloper1->getEmail())); | ||
$this->assertEquals($role, $members->getRole(static::$testDeveloper1->getEmail())); | ||
} | ||
|
||
/** | ||
* To make sure AppGroup has no members. | ||
* | ||
* @group online | ||
*/ | ||
public function testAddMember(): void | ||
{ | ||
$this->getAppGroupMembershipController()->setMembers(new AppGroupMembership([static::$testDeveloper1->getEmail() => ''])); | ||
// Add a new member. | ||
$this->getAppGroupMembershipController()->setMembers(new AppGroupMembership([static::$testDeveloper2->getEmail() => ''])); | ||
$members = $this->getAppGroupMembershipController()->getMembers(); | ||
$this->assertTrue($members->isMember(static::$testDeveloper1->getEmail())); | ||
$this->assertTrue($members->isMember(static::$testDeveloper2->getEmail())); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static function defaultAPIClient(): ClientInterface | ||
{ | ||
return TestClientFactory::getClient(); | ||
} | ||
|
||
protected function getAppGroupMembershipController(): AppGroupMembersControllerInterface | ||
{ | ||
return new AppGroupMembersController(static::$testAppGroup->id(), static::defaultTestOrganization(static::defaultAPIClient()), static::defaultAPIClient()); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -6,6 +6,10 @@ | |
{ | ||
"name": "foo", | ||
"value": "bar" | ||
}, | ||
{ | ||
"name": "__apigee_reserved__developer_details", | ||
"value": "[{\"developer\":\"[email protected]\",\"roles\":[\"admin\"]}, {\"developer\":\"[email protected]\",\"roles\":[\"admin\"]}]" | ||
} | ||
], | ||
"createdAt": 1691588699000, | ||
|
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 |
---|---|---|
|
@@ -11,6 +11,10 @@ | |
{ | ||
"name": "bar", | ||
"value": "baz" | ||
}, | ||
{ | ||
"name": "__apigee_reserved__developer_details", | ||
"value": "[{\"developer\":\"[email protected]\",\"roles\":[\"simple member\"]}]" | ||
} | ||
], | ||
"createdAt": 1691588699000, | ||
|