Commit 6d68ffd4 authored by larowlan's avatar larowlan

Issue #2842193 by Sam152, tstoeckler, scott_euser, hchonov: Exception in...

Issue #2842193 by Sam152, tstoeckler, scott_euser, hchonov: Exception in Workflow::addState when an invalid machine name is given
parent b67adf08
......@@ -82,9 +82,9 @@ protected function copyFormValuesToEntity(EntityInterface $entity, array $form,
/** @var \Drupal\workflows\WorkflowInterface $entity */
$values = $form_state->getValues();
// This is fired twice so we have to check that the entity does not already
// have the state.
if (!$entity->hasState($values['id'])) {
// Replicate the validation that Workflow::addState() does internally as the
// form values have not been validated at this point.
if (!$entity->hasState($values['id']) && !preg_match('/[^a-z0-9_]+/', $values['id'])) {
$entity->addState($values['id'], $values['label']);
if (isset($values['type_settings'])) {
$configuration = $entity->getTypePlugin()->getConfiguration();
......
......@@ -79,6 +79,24 @@ public function testAccess() {
$this->assertSession()->statusCodeEquals(403);
}
/**
* Test the machine name validation of the state add form.
*/
public function testStateMachineNameValidation() {
Workflow::create([
'id' => 'test_workflow',
'type' => 'workflow_type_test',
])->save();
$this->drupalLogin($this->createUser(['administer workflows']));
$this->drupalPostForm('admin/config/workflow/workflows/manage/test_workflow/add_state', [
'label' => 'Test State',
'id' => 'Invalid ID',
], 'Save');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
}
/**
* Tests the creation of a workflow through the UI.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment