You are here

public function DefaultTableMappingTest::testGetExtraColumns in Zircon Profile 8.0

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

Tests DefaultTableMapping::getExtraColumns().

@covers ::getExtraColumns @covers ::setExtraColumns

File

core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php, line 234
Contains \Drupal\Tests\Core\Entity\Sql\DefaultTableMappingTest.

Class

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

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testGetExtraColumns() {

  // The storage definitions are only used in getColumnNames() so we do not
  // need to provide any here.
  $table_mapping = new DefaultTableMapping($this->entityType, []);

  // Test that requesting the list of field names for a table for which no
  // fields have been added does not fail.
  $this
    ->assertSame([], $table_mapping
    ->getExtraColumns('foo'));
  $return = $table_mapping
    ->setExtraColumns('foo', [
    'id',
    'name',
    'type',
  ]);
  $this
    ->assertSame($table_mapping, $return);
  $expected = [
    'id',
    'name',
    'type',
  ];
  $this
    ->assertSame($expected, $table_mapping
    ->getExtraColumns('foo'));
  $this
    ->assertSame([], $table_mapping
    ->getExtraColumns('bar'));
  $return = $table_mapping
    ->setExtraColumns('bar', [
    'description',
    'owner',
  ]);
  $this
    ->assertSame($table_mapping, $return);
  $expected = [
    'description',
    'owner',
  ];
  $this
    ->assertSame($expected, $table_mapping
    ->getExtraColumns('bar'));

  // Test that the previously added field names are unaffected.
  $expected = [
    'id',
    'name',
    'type',
  ];
  $this
    ->assertSame($expected, $table_mapping
    ->getExtraColumns('foo'));
}