From 4491a19592ba7cb887de3752a11cc0003831396e Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 10 Jan 2017 14:07:51 +0000
Subject: [PATCH] Issue #2842063 by Sam152: Fix undefined index when creating a
 new content_moderation workflow type and expand test coverage for
 content_moderation WorkflowType plugin

---
 .../ContentModerationWorkflowTypeTest.php     | 62 +++++++++++++++++++
 .../workflows/src/Plugin/WorkflowTypeBase.php |  8 +++
 .../src/Plugin/WorkflowType/TestType.php      |  9 +++
 3 files changed, 79 insertions(+)
 create mode 100644 core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php

diff --git a/core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php b/core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php
new file mode 100644
index 000000000000..b49439bf6da8
--- /dev/null
+++ b/core/modules/content_moderation/tests/src/Functional/ContentModerationWorkflowTypeTest.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Drupal\Tests\content_moderation\Functional;
+
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Test the workflow type plugin in the content_moderation module.
+ *
+ * @group content_moderation
+ */
+class ContentModerationWorkflowTypeTest extends BrowserTestBase {
+
+  /**
+   * Modules to install.
+   *
+   * @var array
+   */
+  public static $modules = [
+    'content_moderation',
+    'node',
+  ];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+    $admin = $this->drupalCreateUser([
+      'administer workflows',
+    ]);
+    $this->drupalLogin($admin);
+  }
+
+  /**
+   * Test creating a new workflow using the content moderation plugin.
+   */
+  public function testNewWorkflow() {
+    $entity_bundle_info = \Drupal::service('entity_type.bundle.info');
+
+    $this->drupalPostForm('admin/config/workflow/workflows/add', [
+      'label' => 'Test Workflow',
+      'id' => 'test_workflow',
+      'workflow_type' => 'content_moderation',
+    ], 'Save');
+    $this->assertSession()->pageTextContains('Created the Test Workflow Workflow. In order for the workflow to be enabled there needs to be at least one state.');
+
+    // Ensure after a workflow is created, the bundle information can be
+    // refreshed.
+    $entity_bundle_info->clearCachedBundles();
+    $this->assertNotEmpty($entity_bundle_info->getAllBundleInfo());
+
+    $this->submitForm([
+      'label' => 'Test State',
+      'id' => 'test_state',
+      'type_settings[content_moderation][published]' => TRUE,
+      'type_settings[content_moderation][default_revision]' => FALSE,
+    ], 'Save');
+    $this->assertSession()->pageTextContains('Created Test State state.');
+  }
+
+}
diff --git a/core/modules/workflows/src/Plugin/WorkflowTypeBase.php b/core/modules/workflows/src/Plugin/WorkflowTypeBase.php
index 1b910e923b83..1ed9fcaf134a 100644
--- a/core/modules/workflows/src/Plugin/WorkflowTypeBase.php
+++ b/core/modules/workflows/src/Plugin/WorkflowTypeBase.php
@@ -23,6 +23,14 @@
  */
 abstract class WorkflowTypeBase extends PluginBase implements WorkflowTypeInterface {
 
+  /**
+   * {@inheritdoc}
+   */
+  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition);
+    $this->setConfiguration($configuration);
+  }
+
   /**
    * {@inheritdoc}
    */
diff --git a/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/TestType.php b/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/TestType.php
index 78ebe035bcc4..d328d63d9996 100644
--- a/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/TestType.php
+++ b/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/TestType.php
@@ -13,4 +13,13 @@
  * )
  */
 class TestType extends WorkflowTypeBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function defaultConfiguration() {
+    // No configuration is stored for the test type.
+    return [];
+  }
+
 }
-- 
GitLab