function ViewExecutableTest::testAddHandlerWithEntityField

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Unit/ViewExecutableTest.php \Drupal\Tests\views\Unit\ViewExecutableTest::testAddHandlerWithEntityField()
  2. 8.9.x core/modules/views/tests/src/Unit/ViewExecutableTest.php \Drupal\Tests\views\Unit\ViewExecutableTest::testAddHandlerWithEntityField()
  3. 10 core/modules/views/tests/src/Unit/ViewExecutableTest.php \Drupal\Tests\views\Unit\ViewExecutableTest::testAddHandlerWithEntityField()

@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 415

Class

ViewExecutableTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21views%21src%21ViewExecutable.php/class/ViewExecutable/11.x" title="Represents a view as a whole." class="local">\Drupal\views\ViewExecutable</a> @group views

Namespace

Drupal\Tests\views\Unit

Code

public function testAddHandlerWithEntityField($option, $handler_type) : void {
    
    /** @var \Drupal\views\ViewExecutable|\PHPUnit\Framework\MockObject\MockObject $view */
    
    /** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit\Framework\MockObject\MockObject $display */
    [
        $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);
    $display->expects($this->atLeastOnce())
        ->method('setOption')
        ->with($option, [
        'test_field' => [
            'id' => 'test_field',
            'table' => 'test_entity',
            'field' => 'test_field',
            'entity_type' => 'test_entity_type',
            'entity_field' => 'test_field',
            'plugin_id' => 'standard',
        ],
    ]);
    $view->addHandler('default', $handler_type, 'test_entity', 'test_field');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.