function EntityDisplayModeBaseUnitTest::testSetTargetType

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\EntityDisplayModeBaseUnitTest::testSetTargetType()
  2. 10 core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\EntityDisplayModeBaseUnitTest::testSetTargetType()
  3. 9 core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\EntityDisplayModeBaseUnitTest::testSetTargetType()
  4. 8.9.x core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\EntityDisplayModeBaseUnitTest::testSetTargetType()

Tests set target type.

File

core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php, line 119

Class

EntityDisplayModeBaseUnitTest
Tests Drupal\Core\Entity\EntityDisplayModeBase.

Namespace

Drupal\Tests\Core\Config\Entity

Code

public function testSetTargetType() : void {
  $mock = new EntityDisplayModeBaseTestableClass([
    'something' => 'nothing',
  ], 'test_type');
  // Some test values.
  $bad_target = 'uninitialized';
  $target = 'test_target_type';
  // Gain access to the protected property.
  $property = new \ReflectionProperty($mock, 'targetEntityType');
  // Set the property to a known state.
  $property->setValue($mock, $bad_target);
  // Set the target type.
  $mock->setTargetType($target);
  // Test the outcome.
  $this->assertNotEquals($bad_target, $property->getValue($mock));
  $this->assertEquals($target, $property->getValue($mock));
}

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