You are here

public function EntityControllerCacheTest::testTeamEntityControllerCache in Apigee Edge 8

Tests team entity controller cache.

File

modules/apigee_edge_teams/tests/src/Kernel/EntityControllerCacheTest.php, line 51

Class

EntityControllerCacheTest
Apigee Edge Teams entity controller cache tests.

Namespace

Drupal\Tests\apigee_edge_teams\Kernel

Code

public function testTeamEntityControllerCache() {
  $team_cache = $this->container
    ->get('apigee_edge_teams.controller.cache.team');

  /** @var \Drupal\apigee_edge\Entity\Controller\Cache\EntityIdCacheInterface $team_id_cache */
  $team_id_cache = $this->container
    ->get('apigee_edge_teams.controller.cache.team_ids');

  // Generate team entities with random data.
  $teams = [];
  for ($i = 0; $i < 3; $i++) {
    $id = $this
      ->getRandomUniqueId();
    $teams[$id] = new Company([
      'name' => $id,
    ]);
  }
  $this
    ->saveAllEntitiesAndValidate($teams, $team_cache, $team_id_cache);

  /** @var \Apigee\Edge\Api\Management\Entity\CompanyInterface $team */
  foreach ($teams as $team) {

    // Load team by name.
    $this
      ->assertSame($team, $team_cache
      ->getEntity($team
      ->getName()));
    $this
      ->assertContains($team
      ->getName(), $team_id_cache
      ->getIds());

    // Pass an invalid entity id to ensure it does not cause any trouble
    // anymore.
    // @see \Drupal\apigee_edge\Entity\Controller\Cache\EntityCache::removeEntities()
    // @see https://www.drupal.org/project/drupal/issues/3017753
    $team_cache
      ->removeEntities([
      $team
        ->getName(),
      $this
        ->getRandomGenerator()
        ->string(),
    ]);
    $this
      ->assertNull($team_cache
      ->getEntity($team
      ->getName()));
    $this
      ->assertNotContains($team
      ->getName(), $team_id_cache
      ->getIds());
  }
  $this
    ->assertEmptyCaches($team_cache, $team_id_cache);
}