You are here

public function ViewExecutableTest::testAddHandler in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Unit/ViewExecutableTest.php \Drupal\Tests\views\Unit\ViewExecutableTest::testAddHandler()

@covers ::addHandler

@dataProvider addHandlerProvider

Parameters

string $option: The option to set on the View.

$handler_type: The handler type to set.

File

core/modules/views/tests/src/Unit/ViewExecutableTest.php, line 351

Class

ViewExecutableTest
@coversDefaultClass \Drupal\views\ViewExecutable @group views

Namespace

Drupal\Tests\views\Unit

Code

public function testAddHandler($option, $handler_type) {

  /** @var \Drupal\views\ViewExecutable|\PHPUnit\Framework\MockObject\MockObject $view */

  /** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit\Framework\MockObject\MockObject $display */
  list($view, $display) = $this
    ->setupBaseViewAndDisplay();
  $views_data = [];
  $views_data['test_field'] = [
    'field' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'standard',
    ],
    'argument' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],
  ];
  $this->viewsData
    ->expects($this
    ->atLeastOnce())
    ->method('get')
    ->with('test_entity')
    ->willReturn($views_data);
  $display
    ->expects($this
    ->atLeastOnce())
    ->method('setOption')
    ->with($option, [
    'test_field' => [
      'id' => 'test_field',
      'table' => 'test_entity',
      'field' => 'test_field',
      'plugin_id' => 'standard',
    ],
  ]);
  $view
    ->addHandler('default', $handler_type, 'test_entity', 'test_field');
}