You are here

public function DefaultTableMappingTest::testGetColumnNames in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php \Drupal\Tests\Core\Entity\Sql\DefaultTableMappingTest::testGetColumnNames()

Tests DefaultTableMapping::getColumnNames().

@covers ::__construct @covers ::getColumnNames

File

core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php, line 208

Class

DefaultTableMappingTest
@coversDefaultClass \Drupal\Core\Entity\Sql\DefaultTableMapping @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testGetColumnNames() {
  $definitions['test'] = $this
    ->setUpDefinition('test', []);
  $table_mapping = new TestDefaultTableMapping($this->entityType, $definitions);
  $expected = [];
  $this
    ->assertSame($expected, $table_mapping
    ->getColumnNames('test'));
  $definitions['test'] = $this
    ->setUpDefinition('test', [
    'value',
  ]);
  $table_mapping = new TestDefaultTableMapping($this->entityType, $definitions);
  $expected = [
    'value' => 'test',
  ];
  $this
    ->assertSame($expected, $table_mapping
    ->getColumnNames('test'));
  $definitions['test'] = $this
    ->setUpDefinition('test', [
    'value',
    'format',
  ]);
  $table_mapping = new TestDefaultTableMapping($this->entityType, $definitions);
  $expected = [
    'value' => 'test__value',
    'format' => 'test__format',
  ];
  $this
    ->assertSame($expected, $table_mapping
    ->getColumnNames('test'));
  $definitions['test'] = $this
    ->setUpDefinition('test', [
    'value',
  ]);

  // Set custom storage.
  $definitions['test']
    ->expects($this
    ->any())
    ->method('hasCustomStorage')
    ->wilLReturn(TRUE);
  $table_mapping = new TestDefaultTableMapping($this->entityType, $definitions);

  // Should return empty for column names.
  $this
    ->assertSame([], $table_mapping
    ->getColumnNames('test'));
}