public function AppWarningsCheckerTest::testGetWarnings in Apigee Edge 8
Test app warnings.
@covers \Drupal\apigee_edge\Entity\AppWarningsChecker::getWarnings
File
- tests/
src/ Kernel/ Entity/ AppWarningsCheckerTest.php, line 271
Class
- AppWarningsCheckerTest
- Tests the AppWarningsChecker.
Namespace
Drupal\Tests\apigee_edge\Kernel\EntityCode
public function testGetWarnings() {
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager = $this->container
->get('entity_type.manager');
/** @var \Drupal\apigee_edge\Entity\AppWarningsCheckerInterface $app_warnings_checker */
$app_warnings_checker = $this->container
->get('apigee_edge.entity.app_warnings_checker');
if ($this->integration_enabled) {
$this->apiProduct = ApiProduct::create([
'name' => $this
->randomMachineName(),
'displayName' => $this
->randomMachineName(),
'approvalType' => ApiProduct::APPROVAL_TYPE_AUTO,
]);
$this->apiProduct
->save();
// Revoke old credential and create a new valid one.
$this
->operationOnCredential($this->approvedAppWithOneRevokedCredential, 'revoke', 0);
$this
->operationOnCredential($this->approvedAppWithOneRevokedCredential, 'generate');
// Revoke old credential.
$this
->operationOnCredential($this->approvedAppWithAllRevokedCredential, 'revoke', 0);
// Revoke old credential.
$this
->operationOnCredential($this->revokedAppWithRevokedCredential, 'revoke', 0);
$this
->operationOnCredential($this->revokedAppWithRevokedCredential, 'generate');
// Create a new cred that will expire in 5 seconds, delete old.
$this
->operationOnCredential($this->approvedAppWithExpiredCredential, 'delete', 0);
$this
->operationOnCredential($this->approvedAppWithExpiredCredential, 'generate', 0, 5 * 1000);
// Create a new cred that will expire in 5 seconds, delete old.
$this
->operationOnCredential($this->revokedAppWithExpiredCredential, 'delete', 0);
$this
->operationOnCredential($this->revokedAppWithExpiredCredential, 'generate', 0, 5 * 1000);
// Wait a bit and reset "request time" to make sure credentials
// are considered expired.
sleep(6);
$request = Request::create('/', 'GET');
$this->container
->get('http_kernel')
->handle($request);
}
else {
$approved_credential = [
"consumerKey" => $this
->randomMachineName(),
"consumerSecret" => $this
->randomMachineName(),
"status" => AppCredentialInterface::STATUS_APPROVED,
'expiresAt' => ($this->container
->get('datetime.time')
->getRequestTime() + 24 * 60 * 60) * 1000,
];
$revoked_credential = [
"consumerKey" => $this
->randomMachineName(),
"consumerSecret" => $this
->randomMachineName(),
"status" => AppCredentialInterface::STATUS_REVOKED,
'expiresAt' => ($this->container
->get('datetime.time')
->getRequestTime() + 24 * 60 * 60) * 1000,
];
$expired_credential = [
"consumerKey" => $this
->randomMachineName(),
"consumerSecret" => $this
->randomMachineName(),
"status" => AppCredentialInterface::STATUS_APPROVED,
'expiresAt' => ($this->container
->get('datetime.time')
->getRequestTime() - 24 * 60 * 60) * 1000,
];
$this->stack
->queueMockResponse([
'get_developer_apps_with_credentials' => [
'apps' => [
$this->approvedAppWithApprovedCredential,
$this->approvedAppWithOneRevokedCredential,
$this->revokedAppWithRevokedCredential,
$this->approvedAppWithExpiredCredential,
$this->revokedAppWithExpiredCredential,
],
'credentials' => [
$this->approvedAppWithApprovedCredential
->id() => [
$approved_credential,
],
$this->approvedAppWithOneRevokedCredential
->id() => [
$approved_credential,
$revoked_credential,
],
$this->approvedAppWithAllRevokedCredential
->id() => [
$revoked_credential,
],
$this->revokedAppWithRevokedCredential
->id() => [
$approved_credential,
$revoked_credential,
],
$this->approvedAppWithExpiredCredential
->id() => [
$expired_credential,
],
$this->revokedAppWithExpiredCredential
->id() => [
$expired_credential,
],
],
],
]);
$entity_type_manager
->getStorage('developer_app')
->loadMultiple();
}
// No warnings for approved app.
$this
->assertEmpty(array_filter($app_warnings_checker
->getWarnings($this->approvedAppWithApprovedCredential)));
// No warnings to approved app with one revoked credentials.
$this
->assertEmpty(array_filter($app_warnings_checker
->getWarnings($this->approvedAppWithOneRevokedCredential)));
// One warning for approved app with all credentials revoked.
$warnings = array_filter($app_warnings_checker
->getWarnings($this->approvedAppWithAllRevokedCredential));
$this
->assertCount(1, $warnings);
$this
->assertEqual('No valid credentials associated with this app.', (string) $warnings['revokedCred']);
// No warnings to revoked app with revoked credentials.
$this
->assertEmpty(array_filter($app_warnings_checker
->getWarnings($this->revokedAppWithRevokedCredential)));
// One warning for approved app with expired credentials.
$warnings = array_filter($app_warnings_checker
->getWarnings($this->approvedAppWithExpiredCredential));
$this
->assertCount(1, $warnings);
$this
->assertEqual('At least one of the credentials associated with this app is expired.', (string) $warnings['expiredCred']);
// One warning for revoked app with expired credentials.
$warnings = array_filter($app_warnings_checker
->getWarnings($this->revokedAppWithExpiredCredential));
$this
->assertCount(1, $warnings);
$this
->assertEqual('At least one of the credentials associated with this app is expired.', (string) $warnings['expiredCred']);
}