public function TextimageFieldFormatterTest::testTextimageCaching in Textimage 8.4
Same name and namespace in other branches
- 8.3 tests/src/Functional/TextimageFieldFormatterTest.php \Drupal\Tests\textimage\Functional\TextimageFieldFormatterTest::testTextimageCaching()
Test Textimage caching.
File
- tests/
src/ Functional/ TextimageFieldFormatterTest.php, line 313
Class
- TextimageFieldFormatterTest
- Test Textimage formatters on node display.
Namespace
Drupal\Tests\textimage\FunctionalCode
public function testTextimageCaching() {
// Create a text field for Textimage test.
$field_name = 'test_caching';
$this
->createTextField($field_name, 'article');
// Create a new node.
$field_value = 'test for caching';
$nid = $this
->createTextimageNode('text', $field_name, $field_value, 'article', 'test');
$node = Node::load($nid);
// Set textimage formatter - no link.
$display = $this->entityDisplayRepository
->getViewDisplay('node', $node
->getType(), 'default');
$display_options['type'] = 'textimage_text_field_formatter';
$display_options['settings']['image_style'] = 'textimage_test';
$display_options['settings']['image_link'] = '';
$display_options['settings']['image_build_deferred'] = FALSE;
$display
->setComponent($field_name, $display_options)
->save();
$this
->drupalGet('node/' . $nid);
// From previous get, Textimage was built.
$this
->assertSession()
->pageTextContains('Built Textimage');
// Invalidate the rendered objects cache. Textimage should find the image
// in its cache.
Cache::invalidateTags([
'rendered',
]);
$this
->drupalGet('node/' . $nid);
$this
->assertSession()
->pageTextContains('Cached Textimage');
// Invalidate the rendered objects cache, and delete the Textimage cache.
// Textimage should still find a built image in the store.
Cache::invalidateTags([
'rendered',
]);
\Drupal::cache('textimage')
->deleteAll();
$this
->drupalGet('node/' . $nid);
$this
->assertSession()
->pageTextContains('Stored Textimage');
// Invalidate 'rendered' again, Textimage should find the image in its
// cache.
Cache::invalidateTags([
'rendered',
]);
$this
->drupalGet('node/' . $nid);
$this
->assertSession()
->pageTextContains('Cached Textimage');
}