You are here

public function DefaultTableMappingTest::testGetFieldNames 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::testGetFieldNames()

Tests DefaultTableMapping::getFieldNames().

@covers ::getFieldNames @covers ::setFieldNames

File

core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php, line 181
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 testGetFieldNames() {

  // 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
    ->getFieldNames('foo'));
  $return = $table_mapping
    ->setFieldNames('foo', [
    'id',
    'name',
    'type',
  ]);
  $this
    ->assertSame($table_mapping, $return);
  $expected = [
    'id',
    'name',
    'type',
  ];
  $this
    ->assertSame($expected, $table_mapping
    ->getFieldNames('foo'));
  $this
    ->assertSame([], $table_mapping
    ->getFieldNames('bar'));
  $return = $table_mapping
    ->setFieldNames('bar', [
    'description',
    'owner',
  ]);
  $this
    ->assertSame($table_mapping, $return);
  $expected = [
    'description',
    'owner',
  ];
  $this
    ->assertSame($expected, $table_mapping
    ->getFieldNames('bar'));

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