function ConfigActionTest::testShorthandActionIds

Same name in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Config/Action/ConfigActionTest.php \Drupal\KernelTests\Core\Config\Action\ConfigActionTest::testShorthandActionIds()

See also

\Drupal\Core\Config\Action\ConfigActionManager::getShorthandActionIdsForEntityType()

File

core/tests/Drupal/KernelTests/Core/Config/Action/ConfigActionTest.php, line 271

Class

ConfigActionTest
Tests the config action system.

Namespace

Drupal\KernelTests\Core\Config\Action

Code

public function testShorthandActionIds() : void {
    $storage = \Drupal::entityTypeManager()->getStorage('config_test');
    $this->assertCount(0, $storage->loadMultiple(), 'There are no config_test entities');
    
    /** @var \Drupal\Core\Config\Action\ConfigActionManager $manager */
    $manager = $this->container
        ->get('plugin.manager.config_action');
    $manager->applyAction('createIfNotExists', 'config_test.dynamic.action_test', [
        'label' => 'Action test',
        'protected_property' => '',
    ]);
    
    /** @var \Drupal\config_test\Entity\ConfigTest[] $config_test_entities */
    $config_test_entities = $storage->loadMultiple();
    $this->assertCount(1, $config_test_entities, 'There is 1 config_test entity');
    $this->assertSame('Action test', $config_test_entities['action_test']->label());
    $this->assertSame('', $config_test_entities['action_test']->getProtectedProperty());
    
    /** @var \Drupal\Core\Config\Action\ConfigActionManager $manager */
    $manager = $this->container
        ->get('plugin.manager.config_action');
    // Call a method action.
    $manager->applyAction('setProtectedProperty', 'config_test.dynamic.action_test', 'Test value');
    
    /** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
    $config_test_entity = $storage->load('action_test');
    $this->assertSame('Test value', $config_test_entity->getProtectedProperty());
}

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