function ConfigActionTest::testPluralizedEntityMethod
Same name in other branches
- 10 core/tests/Drupal/KernelTests/Core/Config/Action/ConfigActionTest.php \Drupal\KernelTests\Core\Config\Action\ConfigActionTest::testPluralizedEntityMethod()
See also
\Drupal\Core\Config\Action\Plugin\ConfigAction\EntityMethod
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Config/ Action/ ConfigActionTest.php, line 147
Class
- ConfigActionTest
- Tests the config action system.
Namespace
Drupal\KernelTests\Core\Config\ActionCode
public function testPluralizedEntityMethod() : void {
$this->installConfig('config_test');
$storage = \Drupal::entityTypeManager()->getStorage('config_test');
/** @var \Drupal\Core\Config\Action\ConfigActionManager $manager */
$manager = $this->container
->get('plugin.manager.config_action');
// Call a pluralized method action.
$manager->applyAction('entity_method:config_test.dynamic:addToArrayMultipleTimes', 'config_test.dynamic.dotted.default', [
'a',
'b',
'c',
'd',
]);
/** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
$config_test_entity = $storage->load('dotted.default');
$this->assertSame([
'a',
'b',
'c',
'd',
], $config_test_entity->getArrayProperty());
$manager->applyAction('entity_method:config_test.dynamic:addToArrayMultipleTimes', 'config_test.dynamic.dotted.default', [
[
'foo',
],
'bar',
]);
/** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
$config_test_entity = $storage->load('dotted.default');
$this->assertSame([
'a',
'b',
'c',
'd',
[
'foo',
],
'bar',
], $config_test_entity->getArrayProperty());
$config_test_entity->setProtectedProperty('')
->save();
$manager->applyAction('entity_method:config_test.dynamic:appends', 'config_test.dynamic.dotted.default', [
'1',
'2',
'3',
]);
/** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
$config_test_entity = $storage->load('dotted.default');
$this->assertSame('123', $config_test_entity->getProtectedProperty());
// Test that the inflector converts to a good plural form.
$config_test_entity->setProtectedProperty('')
->save();
$manager->applyAction('entity_method:config_test.dynamic:concatProtectedProperties', 'config_test.dynamic.dotted.default', [
[
'1',
'2',
],
[
'3',
'4',
],
]);
/** @var \Drupal\config_test\Entity\ConfigTest $config_test_entity */
$config_test_entity = $storage->load('dotted.default');
$this->assertSame('34', $config_test_entity->getProtectedProperty());
$this->assertTrue($manager->hasDefinition('entity_method:config_test.dynamic:setProtectedProperty'), 'The setProtectedProperty action exists');
// cspell:ignore Propertys
$this->assertFalse($manager->hasDefinition('entity_method:config_test.dynamic:setProtectedPropertys'), 'There is no automatically pluralized version of the setProtectedProperty action');
// Admin label for pluralized form.
$this->assertSame('Test configuration append (multiple calls)', (string) $manager->getDefinition('entity_method:config_test.dynamic:appends')['admin_label']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.