/** * @dataProvider providerSortOrders * * @param string $order * The sort order. * * @covers ::clickSort */ public function testClickSortWithConfiguredField($order) { $definition = ['entity_type' => 'test_entity', 'field_name' => 'body']; $handler = new Field([], 'field', $definition, $this->entityManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer); $handler->view = $this->executable; $field_storage = $this->getConfigFieldStorage(); $this->entityManager->expects($this->atLeastOnce())->method('getFieldStorageDefinitions')->with('test_entity')->willReturn(['body' => $field_storage]); $table_mapping = $this->getMock('Drupal\\Core\\Entity\\Sql\\TableMappingInterface'); $table_mapping->expects($this->atLeastOnce())->method('getFieldColumnName')->with($field_storage, 'value')->willReturn('body_value'); $entity_storage = $this->getMock('Drupal\\Core\\Entity\\Sql\\SqlEntityStorageInterface'); $entity_storage->expects($this->atLeastOnce())->method('getTableMapping')->willReturn($table_mapping); $this->entityManager->expects($this->atLeastOnce())->method('getStorage')->with('test_entity')->willReturn($entity_storage); // Setup a click sort configuration. $options = ['click_sort_column' => 'value', 'table' => 'test_entity__body']; $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__body', NULL)->willReturn('test_entity__body_alias'); $handler->query->expects($this->atLeastOnce())->method('addOrderBy')->with(NULL, NULL, $order, 'test_entity__body_alias.body_value', []); $handler->clickSort($order); }