You are here

public function ViewExecutableTest::testAddHandlerWithEntityField in Zircon Profile 8

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

@covers ::addHandler

File

core/modules/views/tests/src/Unit/ViewExecutableTest.php, line 343
Contains \Drupal\Tests\views\Unit\ViewExecutableTest.

Class

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

Namespace

Drupal\Tests\views\Unit

Code

public function testAddHandlerWithEntityField() {

  /** @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['table']['entity type'] = 'test_entity_type';
  $views_data['test_field'] = [
    'entity field' => '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);
  foreach ([
    'field',
    'filter',
    'argument',
    'sort',
  ] as $handler_type) {
    $display
      ->expects($this
      ->atLeastOnce())
      ->method('setOption')
      ->with($this
      ->callback(function ($argument) {
      return $argument;
    }), [
      'test_field' => [
        'id' => 'test_field',
        'table' => 'test_entity',
        'field' => 'test_field',
        'entity_type' => 'test_entity_type',
        'entity_field' => 'test_field',
        'plugin_id' => 'standard',
      ],
    ]);
  }
  foreach ([
    'field',
    'filter',
    'argument',
    'sort',
  ] as $handler_type) {
    $view
      ->addHandler('default', $handler_type, 'test_entity', 'test_field');
  }
}