You are here

public function SmartTitleConfigTest::assertSmartTitleExpectedConfigs in Smart Title 8

Assert Smart Title expected configs.

Parameters

array $expected_settings: Settings to verify (teaser view mode).

1 call to SmartTitleConfigTest::assertSmartTitleExpectedConfigs()
SmartTitleConfigTest::testSavedConfiguration in tests/src/Functional/SmartTitleConfigTest.php
Test saved configuration.

File

tests/src/Functional/SmartTitleConfigTest.php, line 112

Class

SmartTitleConfigTest
Tests the module's title hide functionality.

Namespace

Drupal\Tests\smart_title\Functional

Code

public function assertSmartTitleExpectedConfigs(array $expected_settings) {

  // Verify saved settings.
  $teaser_display = $this->container
    ->get('entity_type.manager')
    ->getStorage('entity_view_display')
    ->load('node.' . $this->testPageNode
    ->getType() . '.teaser');
  assert($teaser_display instanceof EntityViewDisplayInterface);
  $saved_settings = $teaser_display
    ->getThirdPartySetting('smart_title', 'settings', []);
  $this
    ->assertEquals($saved_settings, [
    'smart_title__tag' => $expected_settings['smart_title__tag'],
    'smart_title__classes' => $expected_settings['smart_title__classes'],
    'smart_title__link' => $expected_settings['smart_title__link'],
  ]);

  // Verify expected field settings summary.
  $web_assert = $this
    ->assertSession();
  $web_assert
    ->elementTextContains('css', '[data-drupal-selector="edit-fields-smart-title"] .field-plugin-summary', _smart_title_defaults('', NULL, 'smart_title__tag')['label'] . ': ' . $expected_settings['smart_title__tag']);

  // Css classes.
  if ((bool) $expected_settings['smart_title__classes']) {
    $web_assert
      ->elementTextContains('css', '[data-drupal-selector="edit-fields-smart-title"] .field-plugin-summary', _smart_title_defaults('', NULL, 'smart_title__classes')['label'] . ': ' . implode(', ', $expected_settings['smart_title__classes']));
  }
  else {
    $web_assert
      ->elementTextNotContains('css', '[data-drupal-selector="edit-fields-smart-title"] .field-plugin-summary', _smart_title_defaults('', NULL, 'smart_title__classes')['label']);
  }

  // Link.
  if ((bool) $expected_settings['smart_title__link']) {
    $web_assert
      ->elementTextContains('css', '[data-drupal-selector="edit-fields-smart-title"] .field-plugin-summary', _smart_title_defaults('', NULL, 'smart_title__link')['label']);
  }
  else {
    $web_assert
      ->elementTextNotContains('css', '[data-drupal-selector="edit-fields-smart-title"] .field-plugin-summary', _smart_title_defaults('', NULL, 'smart_title__link')['label']);
  }

  // Test that Smart Title is displayed on the /node page (teaser view mode)
  // for admin user.
  $this
    ->drupalGet('node');
  $this
    ->assertSession()
    ->pageTextContains($this->testPageNode
    ->label());
  $css_selector_compontents = $expected_settings['smart_title__classes'];
  array_unshift($css_selector_compontents, $expected_settings['smart_title__tag']);
  $article_title = $this
    ->xpath($this
    ->cssSelectToXpath('article ' . implode('.', $css_selector_compontents)));
  $this
    ->assertEquals($this->testPageNode
    ->label(), $article_title[0]
    ->getText());
}