You are here

protected function AreaDisplayLinkTest::assertWarningMessages in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php \Drupal\Tests\views\Kernel\Handler\AreaDisplayLinkTest::assertWarningMessages()
  2. 9 core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php \Drupal\Tests\views\Kernel\Handler\AreaDisplayLinkTest::assertWarningMessages()

Assert the warning messages are shown after changing the page_1 display.

@internal

Parameters

\Drupal\views\ViewExecutable $view: The view to check.

array $unequal_options: An array of options that should be unequal.

Throws

\Exception

File

core/modules/views/tests/src/Kernel/Handler/AreaDisplayLinkTest.php, line 397

Class

AreaDisplayLinkTest
Tests the core views_handler_area_display_link handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

protected function assertWarningMessages(ViewExecutable $view, array $unequal_options) : void {
  $messenger = $this->container
    ->get('messenger');

  // Create a list of options to check.
  // @see \Drupal\views\Plugin\views\area\DisplayLink::validate()
  $options = [
    'filters' => 'Filter criteria',
    'sorts' => 'Sort criteria',
    'pager' => 'Pager',
    'arguments' => 'Contextual filters',
  ];

  // Create a list of options to check.
  // @see \Drupal\views\Plugin\views\area\DisplayLink::validate()
  $unequal_options_text = implode(', ', array_intersect_key($options, array_flip($unequal_options)));
  $errors = $view
    ->validate();
  $messages = $messenger
    ->messagesByType(MessengerInterface::TYPE_WARNING);
  $this
    ->assertCount(0, $errors);
  $this
    ->assertCount(3, $messages);
  $this
    ->assertSame('<em class="placeholder">Block 1</em>: The link in the <em class="placeholder">header</em> area points to the <em class="placeholder">Page 1</em> display which uses different settings than the <em class="placeholder">Block 1</em> display for: <em class="placeholder">' . $unequal_options_text . '</em>. To make sure users see the exact same result when clicking the link, please check that the settings are the same.', $messages[0]
    ->__toString());
  $this
    ->assertSame('<em class="placeholder">Page 1</em>: The link in the <em class="placeholder">header</em> area points to the <em class="placeholder">Page 2</em> display which uses different settings than the <em class="placeholder">Page 1</em> display for: <em class="placeholder">' . $unequal_options_text . '</em>. To make sure users see the exact same result when clicking the link, please check that the settings are the same.', $messages[1]
    ->__toString());
  $this
    ->assertSame('<em class="placeholder">Page 2</em>: The link in the <em class="placeholder">header</em> area points to the <em class="placeholder">Page 1</em> display which uses different settings than the <em class="placeholder">Page 2</em> display for: <em class="placeholder">' . $unequal_options_text . '</em>. To make sure users see the exact same result when clicking the link, please check that the settings are the same.', $messages[2]
    ->__toString());
  $messenger
    ->deleteAll();

  // If the default display is shown in the UI, warnings should be shown for
  // this display as well.
  $this
    ->config('views.settings')
    ->set('ui.show.default_display', TRUE)
    ->save();
  $errors = $view
    ->validate();
  $messages = $messenger
    ->messagesByType(MessengerInterface::TYPE_WARNING);
  $this
    ->assertCount(0, $errors);
  $this
    ->assertCount(4, $messages);
  $this
    ->assertSame('<em class="placeholder">Default</em>: The link in the <em class="placeholder">header</em> area points to the <em class="placeholder">Page 1</em> display which uses different settings than the <em class="placeholder">Default</em> display for: <em class="placeholder">' . $unequal_options_text . '</em>. To make sure users see the exact same result when clicking the link, please check that the settings are the same.', $messages[0]
    ->__toString());
  $this
    ->assertSame('<em class="placeholder">Block 1</em>: The link in the <em class="placeholder">header</em> area points to the <em class="placeholder">Page 1</em> display which uses different settings than the <em class="placeholder">Block 1</em> display for: <em class="placeholder">' . $unequal_options_text . '</em>. To make sure users see the exact same result when clicking the link, please check that the settings are the same.', $messages[1]
    ->__toString());
  $this
    ->assertSame('<em class="placeholder">Page 1</em>: The link in the <em class="placeholder">header</em> area points to the <em class="placeholder">Page 2</em> display which uses different settings than the <em class="placeholder">Page 1</em> display for: <em class="placeholder">' . $unequal_options_text . '</em>. To make sure users see the exact same result when clicking the link, please check that the settings are the same.', $messages[2]
    ->__toString());
  $this
    ->assertSame('<em class="placeholder">Page 2</em>: The link in the <em class="placeholder">header</em> area points to the <em class="placeholder">Page 1</em> display which uses different settings than the <em class="placeholder">Page 2</em> display for: <em class="placeholder">' . $unequal_options_text . '</em>. To make sure users see the exact same result when clicking the link, please check that the settings are the same.', $messages[3]
    ->__toString());
  $messenger
    ->deleteAll();
  $this
    ->config('views.settings')
    ->set('ui.show.default_display', FALSE)
    ->save();
}