You are here

public function UiPatternsFieldRenderTest::testUiPatternsFieldRendering in UI Patterns 8

Tests field template settings.

File

modules/ui_patterns_ds/tests/src/FunctionalJavascript/UiPatternsFieldRenderTest.php, line 50

Class

UiPatternsFieldRenderTest
Test Display Suite field template rendering.

Namespace

Drupal\Tests\ui_patterns_ds\FunctionalJavascript

Code

public function testUiPatternsFieldRendering() {
  $assert_session = $this
    ->assertSession();
  $this
    ->enableTwigDebugMode();
  $user = $this
    ->drupalCreateUser([], NULL, TRUE);
  $this
    ->drupalLogin($user);
  $node = $this
    ->drupalCreateNode([
    'title' => 'Test article',
    'body' => 'Test body',
    'type' => 'article',
  ]);
  $this
    ->drupalGet($node
    ->toUrl());

  // Assert correct variant suggestions.
  $suggestions = [
    'pattern-field--variant-default--ds-field-template--body--node--article--full.html.twig',
    'pattern-field--variant-default--ds-field-template--body--node--full.html.twig',
    'pattern-field--variant-default--ds-field-template--body--node--article.html.twig',
    'pattern-field--variant-default--ds-field-template--body--node.html.twig',
    'pattern-field--variant-default--ds-field-template--body.html.twig',
    'pattern-field--variant-default--ds-field-template.html.twig',
    'pattern-field--ds-field-template--body--node--article--full.html.twig',
    'pattern-field--ds-field-template--body--node--full.html.twig',
    'pattern-field--ds-field-template--body--node--article.html.twig',
    'pattern-field--ds-field-template--body--node.html.twig',
    'pattern-field--ds-field-template--body.html.twig',
    'pattern-field--ds-field-template.html.twig',
    'pattern-field--variant-default.html.twig',
    'pattern-field.html.twig',
  ];
  foreach ($suggestions as $suggestion) {
    $assert_session
      ->responseContains($suggestion);
  }

  // Test content is rendered in the pattern.
  $assert_session
    ->pageTextContains('Value: Test body');
}