function EntityFieldValueTraitTest::testGetFieldValueWithScalarValues

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityFieldValueTraitTest.php \Drupal\KernelTests\Core\Entity\EntityFieldValueTraitTest::testGetFieldValueWithScalarValues()

Tests getFieldValue() with scalar values.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityFieldValueTraitTest.php, line 140

Class

EntityFieldValueTraitTest
Tests the EntityFieldValueTrait.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testGetFieldValueWithScalarValues() : void {
  $account = User::create([
    'name' => 'user1',
    'status' => 0,
  ]);
  $account->save();
  $account = User::load($account->id());
  assert($account instanceof User);
  // Zero can be stored as '0' or 0 - use loose comparison.
  $this->assertEquals(0, $this->getFieldValue($account, 'status', 'value'));
  $this->assertSame('user1', $this->getFieldValue($account, 'name', 'value'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.