diff --git a/behat.yml b/behat.yml
new file mode 100644
index 00000000..36cc262a
--- /dev/null
+++ b/behat.yml
@@ -0,0 +1,25 @@
+default:
+ suites:
+ silverstripe-advancedworkflow:
+ paths:
+ - '%paths.modules.silverstripe-advancedworkflow%/tests/behat/features'
+ contexts:
+ - SilverStripe\Framework\Tests\Behaviour\CmsFormsContext
+ - SilverStripe\Framework\Tests\Behaviour\CmsUiContext
+ - SilverStripe\BehatExtension\Context\BasicContext
+ - SilverStripe\BehatExtension\Context\LoginContext
+ - Symbiote\AdvancedWorkflow\Tests\Behat\Context\FeatureContext
+ - Symbiote\AdvancedWorkflow\Tests\Behat\Context\FixtureContext:
+ # Note: double indent for args is intentional
+ - "%paths.modules.silverstripe-advancedworkflow%/tests/behat/features/files/"
+ extensions:
+ SilverStripe\BehatExtension\MinkExtension:
+ default_session: facebook_web_driver
+ javascript_session: facebook_web_driver
+ facebook_web_driver:
+ browser: chrome
+ wd_host: "http://127.0.0.1:9515" #chromedriver port
+ browser_name: chrome
+ SilverStripe\BehatExtension\Extension:
+ bootstrap_file: vendor/silverstripe/cms/tests/behat/serve-bootstrap.php
+ screenshot_path: '%paths.base%/artifacts/screenshots'
diff --git a/composer.json b/composer.json
index 6bf4a9e1..0f35f0fd 100644
--- a/composer.json
+++ b/composer.json
@@ -43,7 +43,8 @@
"autoload": {
"psr-4": {
"Symbiote\\AdvancedWorkflow\\": "src/",
- "Symbiote\\AdvancedWorkflow\\Tests\\": "tests/"
+ "Symbiote\\AdvancedWorkflow\\Tests\\": "tests/php/",
+ "Symbiote\\AdvancedWorkflow\\Tests\\Behat\\": "tests/behat/"
}
},
"replace": {
@@ -51,4 +52,4 @@
},
"minimum-stability": "dev",
"prefer-stable": true
-}
\ No newline at end of file
+}
diff --git a/tests/behat/Context/FeatureContext.php b/tests/behat/Context/FeatureContext.php
new file mode 100644
index 00000000..cf91abcf
--- /dev/null
+++ b/tests/behat/Context/FeatureContext.php
@@ -0,0 +1,53 @@
+Us!Us"
+ *
+ * @Then /^the workflow diff for the "([^"]+)" field should be "(.*)"$/
+ */
+ public function theFieldDiffShouldBe(string $field, string $diff)
+ {
+ $element = $this->assertSession()->elementExists('css', "#workflow-$field");
+ $actualHtml = $element->getHtml();
+
+ $message = sprintf('The diff "%s" for the "%s" field did not match "%s"', $actualHtml, $field, $diff);
+
+ $this->assertElement(
+ (bool) preg_match($this->convertDiffToRegex($diff), $actualHtml),
+ $message,
+ $element
+ );
+ }
+
+ /**
+ * Allow for arbitrary whitespace before/after HTML tags, and before/after the diff as a whole.
+ */
+ private function convertDiffToRegex(string $diff): string
+ {
+ return '/\s*' . str_replace(['\<', '\>'], ['\s*\<', '\>\s*'], preg_quote($diff, '/')) . '\s*/u';
+ }
+
+ /**
+ * @see Behat\Mink\WebAssert::assertElement()
+ */
+ private function assertElement(bool $condition, string $message, Element $element): void
+ {
+ if ($condition) {
+ return;
+ }
+
+ throw new ElementHtmlException($message, $this->getSession()->getDriver(), $element);
+ }
+}
diff --git a/tests/behat/Context/FixtureContext.php b/tests/behat/Context/FixtureContext.php
new file mode 100644
index 00000000..1c49166d
--- /dev/null
+++ b/tests/behat/Context/FixtureContext.php
@@ -0,0 +1,75 @@
+getWorkflowService()->getNamedTemplate($template),
+ "Workflow template named '$template' does not exist."
+ );
+
+ if ($existingDefinition = WorkflowDefinition::get()->find('Title', $title)) {
+ Assert::assertEquals(
+ $template,
+ $existingDefinition->Template,
+ "A workflow named '$title' already exists, but it doesn't use the '$template' template."
+ );
+ // If we haven't thrown an exception here, it means the exact workflow we want already exists
+ return;
+ }
+
+ $definition = WorkflowDefinition::create();
+ $definition->Title = $title;
+ $definition->Template = $template;
+ $definition->write();
+ }
+
+ /**
+ * Apply a workflow to a record.
+ * Example: Given the "page" "About Us" has the "My Workflow" workflow
+ *
+ * @Given /^(?:an|a|the) "([^"]+)" "([^"]+)" has the "([^"]+)" workflow$/
+ */
+ public function stepPageHasWorkflow(string $type, string $pageName, string $workflowName)
+ {
+ $workflow = WorkflowDefinition::get()->find('Title', $workflowName);
+
+ Assert::assertNotNull($workflow, "Workflow named '$workflowName' does not exist.");
+
+ $class = $this->convertTypeToClass($type);
+ $fixture = $this->getFixtureFactory()->get($class, $pageName);
+ if (!$fixture) {
+ $fixture = $this->getFixtureFactory()->createObject($class, $pageName);
+ }
+
+ $fixture->WorkflowDefinitionID = $workflow->ID;
+ $fixture->write();
+ }
+
+ private function getWorkflowService(): WorkflowService
+ {
+ return Injector::inst()->get(WorkflowService::class);
+ }
+}
diff --git a/tests/behat/features/workflow-history.feature b/tests/behat/features/workflow-history.feature
new file mode 100644
index 00000000..ef49bfd4
--- /dev/null
+++ b/tests/behat/features/workflow-history.feature
@@ -0,0 +1,33 @@
+@javascript
+Feature: Workflow Actions history
+ As a cms author
+ I want to see the history of workflow actions on a page
+ So that I can have assurance that correct processes are being followed
+
+ Background:
+ Given a workflow "Two-Step" using the "Review and Approve" template
+ And a "page" "About Us" has the "Content" "
My content
" + And the "page" "About Us" has the "Two-Step" workflow + And the "page" "About Us" is published + And the "group" "AUTHOR" has permissions "Access to 'Pages' section" + And I am logged in as a member of "AUTHOR" group + And I go to "/admin/pages" + Then I should see "About Us" in the tree + + Scenario: I can see page edits as a diff in the Workflow Actions tab + When I click on "About Us" in the tree + Then I should see an edit page form + When I fill in "Title" with "About Us!" + And I fill in the "Content" HTML field with "my new content
" + And I press the "Apply for approval" button + And I wait for 3 seconds + # Form fields should be readonly + Then I should see a "#Form_EditForm_Title.readonly" element + And I should see a "#Form_EditForm_Content.readonly" element + # Save and Apply for approval buttons shouldn't be there anymore + And I should not see "Apply for approval" + And I should not see "Save" + When I click the "Workflow Actions" CMS tab + Then the workflow diff for the "Title" field should be "About Us!my newMy content