function BulkFormTest::testViewsForm

Same name and namespace in other branches
  1. 10 core/modules/views/tests/src/Unit/Plugin/views/field/BulkFormTest.php \Drupal\Tests\views\Unit\Plugin\views\field\BulkFormTest::testViewsForm()

@covers ::viewsForm

File

core/modules/views/tests/src/Unit/Plugin/views/field/BulkFormTest.php, line 34

Class

BulkFormTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21field%21BulkForm.php/class/BulkForm/11.x" title="Defines an actions-based bulk operation form element." class="local">\Drupal\views\Plugin\views\field\BulkForm</a> @group Views

Namespace

Drupal\Tests\views\Unit\Plugin\views\field

Code

public function testViewsForm() : void {
    $row = new ResultRow();
    $container = new ContainerBuilder();
    $container->set('string_translation', $this->createMock(TranslationInterface::class));
    \Drupal::setContainer($container);
    $field = $this->getMockBuilder(BulkForm::class)
        ->onlyMethods([
        'getEntityType',
        'getEntity',
    ])
        ->disableOriginalConstructor()
        ->getMock();
    $field->expects($this->any())
        ->method('getEntityType')
        ->willReturn('foo');
    $field->expects($this->any())
        ->method('getEntity')
        ->willReturn(NULL);
    $query = $this->getMockBuilder(QueryPluginBase::class)
        ->onlyMethods([
        'getEntityTableInfo',
    ])
        ->disableOriginalConstructor()
        ->getMock();
    $query->expects($this->any())
        ->method('getEntityTableInfo')
        ->willReturn([]);
    $view = $this->getMockBuilder(ViewExecutable::class)
        ->onlyMethods([
        'getQuery',
    ])
        ->disableOriginalConstructor()
        ->getMock();
    $view->expects($this->any())
        ->method('getQuery')
        ->willReturn($query);
    $view->result = [
        $row,
    ];
    $view->query = $query;
    $field->view = $view;
    $field->options = [
        'id' => 'bar',
        'action_title' => 'zee',
    ];
    $form_state = $this->createMock(FormStateInterface::class);
    $form = [];
    $field->viewsForm($form, $form_state);
    $this->assertNotEmpty($form);
    $this->assertIsArray($form[$field->options['id']][0]);
    $this->assertEmpty($form[$field->options['id']][0]);
}

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