You are here

public function EntityListBuilderTest::testCacheSettings in Apigee Edge 8

Tests configurable cache max-age for entity list builders.

Throws

\Drupal\Core\Entity\EntityStorageException

File

tests/src/Kernel/Entity/ListBuilder/EntityListBuilderTest.php, line 175

Class

EntityListBuilderTest
Tests for EntityListBuilder.

Namespace

Drupal\Tests\apigee_edge\Kernel\Entity\ListBuilder

Code

public function testCacheSettings() {
  $this->app = $this
    ->createDeveloperApp();
  $this
    ->setCurrentUser($this->account);
  $url = Url::fromRoute('entity.developer_app.collection_by_developer', [
    'user' => $this->account
      ->id(),
  ]);
  $request = Request::create($url
    ->toString(), 'GET');
  $this->stack
    ->queueMockResponse([
    'get_developer_apps_names' => [
      'apps' => [
        $this->app,
      ],
    ],
  ]);
  $this
    ->queueDeveloperResponse($this->account);

  /** @var \Drupal\Core\Render\HtmlResponse $response */
  $response = $this->container
    ->get('http_kernel')
    ->handle($request);
  $this
    ->assertEqual($response
    ->getCacheableMetadata()
    ->getCacheMaxAge(), 900);

  // Update the config.
  $config = $this
    ->config('apigee_edge.' . static::ENTITY_TYPE . '_settings');
  $config
    ->set('cache_expiration', 100)
    ->save();
  $this->stack
    ->queueMockResponse([
    'get_developer_apps_names' => [
      'apps' => [
        $this->app,
      ],
    ],
  ]);
  $this
    ->queueDeveloperResponse($this->account);

  /** @var \Drupal\Core\Render\HtmlResponse $response */
  $response = $this->container
    ->get('http_kernel')
    ->handle($request);
  $this
    ->assertEqual($response
    ->getCacheableMetadata()
    ->getCacheMaxAge(), 100);
}