You are here

protected function AreaDisplayLinkTest::setUp in Drupal 9

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

Parameters

bool $import_test_views: Should the views specified on the test class be imported. If you need to setup some additional stuff, like fields, you need to call false and then call createTestViews for your own.

Overrides ViewsKernelTestBase::setUp

File

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

Class

AreaDisplayLinkTest
Tests the core views_handler_area_display_link handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

protected function setUp($import_test_views = TRUE) : void {
  parent::setUp($import_test_views);
  $this
    ->installConfig([
    'system',
    'filter',
  ]);
  $this
    ->installEntitySchema('user');
  $view = Views::getView('test_view');

  // Add two page displays and a block display.
  $page_1 = $view
    ->newDisplay('page', 'Page 1', 'page_1');
  $page_1
    ->setOption('path', 'page_1');
  $page_2 = $view
    ->newDisplay('page', 'Page 2', 'page_2');
  $page_2
    ->setOption('path', 'page_2');
  $view
    ->newDisplay('block', 'Block 1', 'block_1');

  // Add default filter criteria, sort criteria, pager settings and contextual
  // filters.
  $default = $view->displayHandlers
    ->get('default');
  $default
    ->setOption('filters', [
    'status' => [
      'id' => 'status',
      'table' => 'views_test_data',
      'field' => 'status',
      'relationship' => 'none',
      'operator' => '=',
      'value' => 1,
    ],
  ]);
  $default
    ->setOption('sorts', [
    'name' => [
      'id' => 'name',
      'table' => 'views_test_data',
      'field' => 'name',
      'relationship' => 'none',
      'order' => 'ASC',
    ],
  ]);
  $default
    ->setOption('pager', [
    'type' => 'mini',
    'options' => [
      'items_per_page' => 10,
    ],
  ]);
  $default
    ->setOption('arguments', [
    'uid' => [
      'id' => 'uid',
      'table' => 'views_test_data',
      'field' => 'uid',
      'relationship' => 'none',
    ],
  ]);

  // Add display links to both page displays.
  $display_links = [
    'display_link_1' => [
      'id' => 'display_link_1',
      'table' => 'views',
      'field' => 'display_link',
      'display_id' => 'page_1',
      'label' => 'Page 1',
      'plugin_id' => 'display_link',
    ],
    'display_link_2' => [
      'id' => 'display_link_2',
      'table' => 'views',
      'field' => 'display_link',
      'display_id' => 'page_2',
      'label' => 'Page 2',
      'plugin_id' => 'display_link',
    ],
  ];
  $default
    ->setOption('header', $display_links);
  $view
    ->save();

  // Ensure that the theme system does not log any errors about missing theme
  // hooks when rendering the link.
  $logger = $this
    ->prophesize(LoggerInterface::class);
  $logger
    ->log(RfcLogLevel::WARNING, 'Theme hook %hook not found.', Argument::withEntry('%hook', 'link'))
    ->shouldNotBeCalled();
  $this->container
    ->get('logger.factory')
    ->get('theme')
    ->addLogger($logger
    ->reveal());
}