function BulkFormTest::testViewsForm

Same name in other branches
  1. 11.x 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 \Drupal\views\Plugin\views\field\BulkForm @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.