You are here

public function FieldTest::testQueryWithGroupByForConfigField in Zircon Profile 8

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

@covers ::query

File

core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php, line 498
Contains \Drupal\Tests\views\Unit\Plugin\field\FieldTest.

Class

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

Namespace

Drupal\Tests\views\Unit\Plugin\field

Code

public function testQueryWithGroupByForConfigField() {
  $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;
  $handler->view->field = [
    $handler,
  ];
  $this
    ->setupLanguageRenderer($handler, $definition);
  $field_storage = $this
    ->getConfigFieldStorage();
  $this->entityManager
    ->expects($this
    ->any())
    ->method('getFieldStorageDefinitions')
    ->with('test_entity')
    ->willReturn([
    'body' => $field_storage,
  ]);
  $table_mapping = $this
    ->getMock('Drupal\\Core\\Entity\\Sql\\TableMappingInterface');
  $table_mapping
    ->expects($this
    ->any())
    ->method('getFieldColumnName')
    ->with($field_storage, 'value')
    ->willReturn('body_value');
  $entity_storage = $this
    ->getMock('Drupal\\Core\\Entity\\Sql\\SqlEntityStorageInterface');
  $entity_storage
    ->expects($this
    ->any())
    ->method('getTableMapping')
    ->willReturn($table_mapping);
  $this->entityManager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->with('test_entity')
    ->willReturn($entity_storage);
  $options = [
    'group_column' => 'value',
    'group_columns' => [],
    'table' => 'test_entity__body',
  ];
  $handler
    ->init($this->executable, $this->display, $options);
  $query = $this
    ->getMockBuilder('Drupal\\views\\Plugin\\views\\query\\Sql')
    ->disableOriginalConstructor()
    ->getMock();
  $query
    ->expects($this
    ->once())
    ->method('ensureTable')
    ->with('test_entity__body', NULL)
    ->willReturn('test_entity__body');

  // Ensure that we add the title field to the query, if we group by some
  // other field in the view.
  $query
    ->expects($this
    ->once())
    ->method('addField')
    ->with('test_entity__body', 'body_value');
  $this->executable->query = $query;
  $handler
    ->query(TRUE);
}