You are here

class DisplayExtenderTest in Drupal 10

Same name in this branch
  1. 10 core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php \Drupal\Tests\views\Kernel\Plugin\DisplayExtenderTest
  2. 10 core/modules/views/tests/modules/views_test_data/src/Plugin/views/display_extender/DisplayExtenderTest.php \Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest
Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php \Drupal\Tests\views\Kernel\Plugin\DisplayExtenderTest
  2. 9 core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php \Drupal\Tests\views\Kernel\Plugin\DisplayExtenderTest

Tests the display extender plugins.

@group views

Hierarchy

  • class \Drupal\Tests\views\Kernel\Plugin\DisplayExtenderTest extends \Drupal\Tests\views\Kernel\ViewsKernelTestBase

Expanded class hierarchy of DisplayExtenderTest

See also

\Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest

File

core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php, line 16

Namespace

Drupal\Tests\views\Kernel\Plugin
View source
class DisplayExtenderTest extends ViewsKernelTestBase {

  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = [
    'test_view',
  ];

  /**
   * Tests display extenders.
   */
  public function testDisplayExtenders() {
    $this
      ->config('views.settings')
      ->set('display_extenders', [
      'display_extender_test',
    ])
      ->save();
    $this
      ->assertCount(1, Views::getEnabledDisplayExtenders(), 'Make sure that there is only one enabled display extender.');
    $view = Views::getView('test_view');
    $view
      ->initDisplay();
    $this
      ->assertCount(1, $view->display_handler
      ->getExtenders(), 'Make sure that only one extender is initialized.');
    $display_extender = $view->display_handler
      ->getExtenders()['display_extender_test'];
    $this
      ->assertInstanceOf(DisplayExtenderTestData::class, $display_extender);
    $view
      ->preExecute();
    $this
      ->assertTrue($display_extender->testState['preExecute'], 'Make sure the display extender was able to react on preExecute.');
    $view
      ->execute();
    $this
      ->assertTrue($display_extender->testState['query'], 'Make sure the display extender was able to react on query.');
  }

  /**
   * Tests display extenders validation.
   */
  public function testDisplayExtendersValidate() {
    $this
      ->config('views.settings')
      ->set('display_extenders', [
      'display_extender_test_3',
    ])
      ->save();
    $view = Views::getView('test_view');
    $errors = $view
      ->validate();
    foreach ($view->displayHandlers as $id => $display) {
      $this
        ->assertArrayHasKey($id, $errors);
      $this
        ->assertContains('Display extender test error.', $errors[$id], new FormattableMarkup('Error message found for @id display', [
        '@id' => $id,
      ]));
    }
  }

}

Members