function FieldTest::testClickSortWithBaseField

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

@dataProvider providerSortOrders

@covers ::clickSort

Parameters

string $order: The sort order.

File

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

Class

FieldTest
@coversDefaultClass \Drupal\views\Plugin\views\field\EntityField[[api-linebreak]] @group views

Namespace

Drupal\Tests\views\Unit\Plugin\field

Code

public function testClickSortWithBaseField($order) : void {
  $definition = [
    'entity_type' => 'test_entity',
    'field_name' => 'title',
  ];
  $handler = new EntityField([], 'field', $definition, $this->entityTypeManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer, $this->entityRepository, $this->entityFieldManager, $this->entityTypeBundleInfo);
  $handler->view = $this->executable;
  $field_storage = $this->getBaseFieldStorage();
  $this->entityFieldManager
    ->expects($this->atLeastOnce())
    ->method('getFieldStorageDefinitions')
    ->with('test_entity')
    ->willReturn([
    'title' => $field_storage,
  ]);
  $table_mapping = $this->createMock('Drupal\\Core\\Entity\\Sql\\TableMappingInterface');
  $table_mapping->expects($this->atLeastOnce())
    ->method('getFieldColumnName')
    ->with($field_storage, 'value')
    ->willReturn('title');
  $entity_storage = $this->createMock('Drupal\\Core\\Entity\\Sql\\SqlEntityStorageInterface');
  $entity_storage->expects($this->atLeastOnce())
    ->method('getTableMapping')
    ->willReturn($table_mapping);
  $this->entityTypeManager
    ->expects($this->atLeastOnce())
    ->method('getStorage')
    ->with('test_entity')
    ->willReturn($entity_storage);
  // Setup a click sort configuration.
  $options = [
    'click_sort_column' => 'value',
    'table' => 'test_entity',
  ];
  $handler->init($this->executable, $this->display, $options);
  $handler->query = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\query\\Sql')
    ->disableOriginalConstructor()
    ->getMock();
  $handler->query
    ->expects($this->atLeastOnce())
    ->method('ensureTable')
    ->with('test_entity', NULL)
    ->willReturn('test_entity');
  $handler->query
    ->expects($this->atLeastOnce())
    ->method('addOrderBy')
    ->with(NULL, NULL, $order, 'test_entity.title', []);
  $handler->clickSort($order);
}

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