You are here

public function CacheTest::developerDeletedTest in Apigee Edge 8

Tests developer & developer app cache invalidation after developer removal.

Developer apps of a developer must be removed from cache even when a developer _entity_ gets deleted _programmatically_ (and not the related Drupal user).

1 call to CacheTest::developerDeletedTest()
CacheTest::testCache in tests/src/FunctionalJavascript/CacheTest.php
Tests cache of Apigee Edge entities.

File

tests/src/FunctionalJavascript/CacheTest.php, line 240

Class

CacheTest
Apigee Edge entity cache related tests.

Namespace

Drupal\Tests\apigee_edge\FunctionalJavascript

Code

public function developerDeletedTest() {
  $data = [
    'firstName' => $this
      ->randomString(),
    'lastName' => $this
      ->randomString(),
    'userName' => $this
      ->randomMachineName(),
  ];
  $data['email'] = $this
    ->randomMachineName() . ".{$data['userName']}@example.com";

  /** @var \Drupal\apigee_edge\Entity\DeveloperInterface $developer */
  $developer = Developer::create($data);
  $developer
    ->save();

  // Warm up cache.
  $developer = Developer::load($developer
    ->id());

  /** @var \Drupal\apigee_edge\Entity\DeveloperAppInterface $developerApp */
  $developerApp = DeveloperApp::create([
    'name' => $this
      ->randomMachineName(),
    'status' => DeveloperApp::STATUS_APPROVED,
    'developerId' => $developer
      ->uuid(),
  ]);
  try {
    $developerApp
      ->save();
  } catch (\Exception $e) {
    $developer
      ->delete();
    throw $e;
  }

  // Warm up cache.
  $developerApp = DeveloperApp::load($developerApp
    ->id());
  $this
    ->assertCacheInvalidation([
    "values:developer:{$developer->id()}",
    "values:developer:{$developer->uuid()}",
    // The two above should be the same, so this is just a sanity check.
    "values:developer_app:{$developerApp->id()}",
    "values:developer_app:{$developerApp->uuid()}",
    "app_names:developer_app:{$developer->uuid()}:{$developerApp->getName()}",
  ], function () use ($developer) {
    try {

      // If this fails, it would fail in the teardown as well.
      $developer
        ->delete();
    } catch (\Exception $exception) {
      $this
        ->logException($exception);
    }
  });
}