protected function DeveloperAppUITestTrait::assertAppCrud in Apigee Edge 8
Goes through a typical CRUD cycle for an app.
Parameters
callable|null $beforeCreate: Alters the data that will be posted on the create form.
callable|null $afterCreate: Additional asserts after the app is created.
callable|null $beforeUpdate: Alters the data that will be posted on the update form.
callable|null $afterUpdate: Additional asserts after the app is created.
\Drupal\user\UserInterface|null $account: Owner of the app.
6 calls to DeveloperAppUITestTrait::assertAppCrud()
- DeveloperAppUITest::testAppCrudMultipleProductsAdd in tests/
src/ Functional/ DeveloperAppUITest.php - Creates an app with no products and then adds multiple ones.
- DeveloperAppUITest::testAppCrudMultiplePruductsRemove in tests/
src/ Functional/ DeveloperAppUITest.php - Creates an app with multiple products and then removes them.
- DeveloperAppUITest::testAppCrudSingleProductAdd in tests/
src/ Functional/ DeveloperAppUITest.php - Creates an app with no products and then adds one.
- DeveloperAppUITest::testAppCrudSingleProductChange in tests/
src/ Functional/ DeveloperAppUITest.php - Creates an app with a single product and then removes the product.
- DeveloperAppUITest::testAppDefaultProduct in tests/
src/ Functional/ DeveloperAppUITest.php - Creates an app with the default product.
File
- tests/
src/ Functional/ DeveloperAppUITestTrait.php, line 195
Class
- DeveloperAppUITestTrait
- Contains re-usable components for developer app UI tests.
Namespace
Drupal\Tests\apigee_edge\FunctionalCode
protected function assertAppCrud(?callable $beforeCreate = NULL, ?callable $afterCreate = NULL, ?callable $beforeUpdate = NULL, ?callable $afterUpdate = NULL, ?UserInterface $account = NULL) {
if ($account === NULL) {
$account = $this->account;
}
$name = strtolower($this
->randomMachineName());
$displayName = $this
->getRandomGenerator()
->word(16);
$callbackUrl = "http://example.com/{$this->randomMachineName()}";
$description = trim($this
->getRandomGenerator()
->paragraphs(1));
$data = [
'name' => $name,
'displayName[0][value]' => $displayName,
'callbackUrl[0][value]' => $callbackUrl,
'description[0][value]' => $description,
];
if ($beforeCreate) {
$data = $beforeCreate($data);
}
$this
->postCreateAppForm($data, $account);
/** @var \Drupal\apigee_edge\Entity\Developer $developer */
$developer = Developer::load($account
->getEmail());
$app = $this
->loadDeveloperApp($name, $developer);
$this
->assertSession()
->linkByHrefExists("/user/{$account->id()}/apps/{$app->getName()}/edit?destination=/user/{$account->id()}/apps");
$this
->assertSession()
->linkByHrefExists("/user/{$account->id()}/apps/{$app->getName()}/delete?destination=/user/{$account->id()}/apps");
$this
->clickLink($displayName);
$this
->assertSession()
->pageTextContains($displayName);
$this
->assertSession()
->pageTextContains($callbackUrl);
$this
->assertSession()
->pageTextContains($description);
if ($afterCreate) {
$afterCreate($name);
}
/** @var \Drupal\apigee_edge\Entity\Storage\DeveloperAppStorageInterface $storage */
$storage = \Drupal::entityTypeManager()
->getStorage('developer_app');
/** @var \Drupal\apigee_edge\Entity\DeveloperApp $app */
$app = $storage
->load(array_values($storage
->getQuery()
->condition('developerId', $developer
->uuid())
->condition('name', $name)
->execute())[0]);
$this
->assertNotNull($app);
/** @var \Apigee\Edge\Api\Management\Entity\AppCredential[] $credentials */
$credentials = $app
->getCredentials();
/** @var \Apigee\Edge\Api\Management\Entity\AppCredential $credential */
$credential = reset($credentials);
$credential_id = $credential
->id();
$displayName = $this
->getRandomGenerator()
->word(16);
$callbackUrl = "{$callbackUrl}/{$this->randomMachineName()}";
$description = trim($this
->getRandomGenerator()
->paragraphs(1));
$data = [
'displayName[0][value]' => $displayName,
'callbackUrl[0][value]' => $callbackUrl,
'description[0][value]' => $description,
];
if ($beforeUpdate) {
$data = $beforeUpdate($data, $credential_id);
}
$this
->postEditAppForm($data, $name, $account);
$this
->assertSession()
->pageTextContains($displayName);
$this
->assertSession()
->pageTextContains($callbackUrl);
$this
->assertSession()
->pageTextContains($description);
if ($afterUpdate) {
$afterUpdate($name);
}
$this
->clickLink('Delete');
$this
->submitForm([
'verification_code' => $name,
], 'Delete');
$this
->drupalGet("/user/{$account->id()}/apps");
$this
->assertSession()
->pageTextNotContains($displayName);
}