function FieldTest::testPrepareItemsByDelta

Same name in other branches
  1. 9 core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php \Drupal\Tests\views\Unit\Plugin\field\FieldTest::testPrepareItemsByDelta()
  2. 10 core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php \Drupal\Tests\views\Unit\Plugin\field\FieldTest::testPrepareItemsByDelta()
  3. 11.x core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php \Drupal\Tests\views\Unit\Plugin\field\FieldTest::testPrepareItemsByDelta()

@covers ::prepareItemsByDelta

@dataProvider providerTestPrepareItemsByDelta

File

core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php, line 581

Class

FieldTest
@coversDefaultClass \Drupal\views\Plugin\views\field\EntityField @group views

Namespace

Drupal\Tests\views\Unit\Plugin\field

Code

public function testPrepareItemsByDelta(array $options, array $expected_values) {
    $definition = [
        'entity_type' => 'test_entity',
        'field_name' => 'integer',
    ];
    $handler = new FieldTestEntityField([], 'field', $definition, $this->entityTypeManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer, $this->entityRepository, $this->entityFieldManager);
    $handler->view = $this->executable;
    $handler->view->field = [
        $handler,
    ];
    $this->setupLanguageRenderer($handler, $definition);
    $field_storage = $this->getConfigFieldStorage();
    $field_storage->expects($this->any())
        ->method('getCardinality')
        ->willReturn(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    $this->entityFieldManager
        ->expects($this->any())
        ->method('getFieldStorageDefinitions')
        ->with('test_entity')
        ->willReturn([
        'integer' => $field_storage,
    ]);
    $table_mapping = $this->createMock('Drupal\\Core\\Entity\\Sql\\TableMappingInterface');
    $table_mapping->expects($this->any())
        ->method('getFieldColumnName')
        ->with($field_storage, 'value')
        ->willReturn('integer_value');
    $entity_storage = $this->createMock('Drupal\\Core\\Entity\\Sql\\SqlEntityStorageInterface');
    $entity_storage->expects($this->any())
        ->method('getTableMapping')
        ->willReturn($table_mapping);
    $this->entityTypeManager
        ->expects($this->any())
        ->method('getStorage')
        ->with('test_entity')
        ->willReturn($entity_storage);
    $options = [
        'group_column' => 'value',
        'group_columns' => [],
        'table' => 'test_entity__integer',
    ] + $options;
    $handler->init($this->executable, $this->display, $options);
    $this->executable->row_index = 0;
    $this->executable->result = [
        0 => new ResultRow([]),
    ];
    $items = [
        3,
        1,
        4,
        1,
        5,
        9,
    ];
    $this->assertEquals($expected_values, $handler->executePrepareItemsByDelta($items));
}

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