function EntityMethodConfigActionsTest::testSet

@testWith ["set", {"property_name": "protected_property", "value": "Here be sandworms..."}]
["setMultiple", [{"property_name": "protected_property", "value": "Here be sandworms..."}, {"property_name": "label", "value": "New face"}]]

File

core/tests/Drupal/KernelTests/Core/Recipe/EntityMethodConfigActionsTest.php, line 104

Class

EntityMethodConfigActionsTest
@group Recipe

Namespace

Drupal\KernelTests\Core\Recipe

Code

public function testSet(string $action_name, array $value) : void {
  $storage = $this->container
    ->get(EntityTypeManagerInterface::class)
    ->getStorage('config_test');
  $entity = $storage->create([
    'id' => 'foo',
    'label' => 'Behold!',
    'protected_property' => 'Here be dragons...',
  ]);
  $this->assertSame('Behold!', $entity->get('label'));
  $this->assertSame('Here be dragons...', $entity->get('protected_property'));
  $entity->save();
  $this->configActionManager
    ->applyAction("entity_method:config_test.dynamic:{$action_name}", $entity->getConfigDependencyName(), $value);
  $expected_values = array_is_list($value) ? $value : [
    $value,
  ];
  $entity = $storage->load('foo');
  foreach ($expected_values as [
    'property_name' => $name,
    'value' => $value,
  ]) {
    $this->assertSame($value, $entity->get($name));
  }
}

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