public function EntityControllerCacheTest::testAppEntityControllerCache in Apigee Edge 8
Tests app entity controller cache.
File
- tests/
src/ Kernel/ EntityControllerCacheTest.php, line 105
Class
- EntityControllerCacheTest
- Apigee Edge entity controller cache tests.
Namespace
Drupal\Tests\apigee_edge\KernelCode
public function testAppEntityControllerCache() {
$app_cache = $this->container
->get('apigee_edge.controller.cache.apps');
$app_id_cache = $this->container
->get('apigee_edge.controller.cache.app_ids');
// Generate developer app entities with random data.
$developer_apps = [];
$parent_id = $this
->getRandomUniqueId();
for ($i = 0; $i < 2; $i++) {
$id = $this
->getRandomUniqueId();
$developer_apps[$id] = new DeveloperApp([
'appId' => $id,
'name' => $this
->getRandomGenerator()
->name(),
'developerId' => $parent_id,
]);
}
// Generate company app entities with random data.
$company_apps = [];
$parent_id = $this
->getRandomUniqueId();
for ($i = 0; $i < 2; $i++) {
$id = $this
->getRandomUniqueId();
$company_apps[$id] = new CompanyApp([
'appId' => $id,
'name' => $this
->getRandomGenerator()
->name(),
'companyName' => $parent_id,
]);
}
$apps = $developer_apps + $company_apps;
$this
->saveAllEntitiesAndValidate($apps, $app_cache, $app_id_cache);
/** @var \Apigee\Edge\Api\Management\Entity\AppInterface $app */
foreach ($apps as $app) {
// Load app by id and by owner (developer uuid or company name).
$this
->assertSame($app, $app_cache
->getEntity($app
->getAppId()));
$this
->assertContains($app, $app_cache
->getAppsByOwner($app_cache
->getAppOwner($app)));
$this
->assertContains($app
->getAppId(), $app_id_cache
->getIds());
}
// Remove apps from cache by owner.
$app_cache
->removeAppsByOwner(reset($developer_apps)
->getDeveloperId());
$app_cache
->removeAppsByOwner(reset($company_apps)
->getCompanyName());
foreach ($apps as $app) {
$this
->assertNull($app_cache
->getEntity($app
->getAppId()));
$this
->assertNull($app_cache
->getAppsByOwner($app_cache
->getAppOwner($app)));
$this
->assertNotContains($app
->getAppId(), $app_id_cache
->getIds());
}
$this
->assertEmptyCaches($app_cache, $app_id_cache);
}