You are here

public function BlockFieldPluginTest::testBlockCache in Display Suite 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/BlockFieldPluginTest.php \Drupal\Tests\ds\Functional\BlockFieldPluginTest::testBlockCache()

Tests cache properties on blocks.

Cache contexts, tags and max-age on the block should get merged into the field build array.

File

tests/src/Functional/BlockFieldPluginTest.php, line 144

Class

BlockFieldPluginTest
Tests for managing custom code, and block fields.

Namespace

Drupal\Tests\ds\Functional

Code

public function testBlockCache() {
  $block_field_id = mb_strtolower($this
    ->randomMachineName());
  $entity_type = 'node';
  $edit = [
    'name' => $this
      ->randomString(),
    'id' => $block_field_id,
    'entities[' . $entity_type . ']' => TRUE,
    'block' => 'ds_cache_test_block',
  ];
  $this
    ->dsCreateBlockField($edit);
  $fields['fields[dynamic_block_field:' . $entity_type . '-' . $block_field_id . '][region]'] = 'left';
  $this
    ->dsSelectLayout();
  $this
    ->dsConfigureUI($fields);
  $settings['type'] = 'article';
  $node = $this
    ->drupalCreateNode($settings);

  // Check for query parameters.
  $this
    ->drupalGet($node
    ->toUrl(), [
    'query' => [
      'cached' => 1,
    ],
  ]);
  $this
    ->assertSession()
    ->responseContains('cached=1');

  // Check for query parameters.
  $this
    ->drupalGet($node
    ->toUrl(), [
    'query' => [
      'cached' => 2,
    ],
  ]);
  $this
    ->assertSession()
    ->responseContains('cached=2');
}