You are here

public function NodeFieldOverridesTest::testFieldOverrides in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/NodeFieldOverridesTest.php \Drupal\node\Tests\NodeFieldOverridesTest::testFieldOverrides()

Tests that field overrides work as expected.

File

core/modules/node/src/Tests/NodeFieldOverridesTest.php, line 49
Contains \Drupal\node\Tests\NodeFieldOverridesTest.

Class

NodeFieldOverridesTest
Tests node field overrides.

Namespace

Drupal\node\Tests

Code

public function testFieldOverrides() {
  if (!NodeType::load('ponies')) {
    NodeType::create([
      'name' => 'Ponies',
      'type' => 'ponies',
    ])
      ->save();
  }
  $override = BaseFieldOverride::loadByName('node', 'ponies', 'uid');
  if ($override) {
    $override
      ->delete();
  }
  $uid_field = \Drupal::entityManager()
    ->getBaseFieldDefinitions('node')['uid'];
  $config = $uid_field
    ->getConfig('ponies');
  $config
    ->save();
  $this
    ->assertEqual($config
    ->get('default_value_callback'), 'Drupal\\node\\Entity\\Node::getCurrentUserId');

  /** @var \Drupal\node\NodeInterface $node */
  $node = Node::create([
    'type' => 'ponies',
  ]);
  $owner = $node
    ->getOwner();
  $this
    ->assertTrue($owner instanceof \Drupal\user\UserInterface);
  $this
    ->assertEqual($owner
    ->id(), $this->user
    ->id());
}