From 79259b593a5bf99ec332f67b9ec6be3584908f34 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 11 Jan 2021 15:58:56 +1300 Subject: [PATCH 1/2] FIX Visibility of subsequent form fields and step buttons --- code/Control/UserDefinedFormController.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/code/Control/UserDefinedFormController.php b/code/Control/UserDefinedFormController.php index 6ef9b7d..1e73ad6 100644 --- a/code/Control/UserDefinedFormController.php +++ b/code/Control/UserDefinedFormController.php @@ -548,6 +548,7 @@ JS $operations = implode(" {$conjunction} ", $rule['operations']); $target = $rule['targetFieldID']; $holder = $rule['holder']; + $isFormStep = strpos($target, 'EditableFormStep') !== false; $result .= << Date: Wed, 10 Mar 2021 15:56:24 +1300 Subject: [PATCH 2/2] MNT Behat test for hidden form steps --- .editorconfig | 2 +- .travis.yml | 6 ++ behat.yml | 34 ++++++++ composer.json | 3 +- tests/behat/README.md | 1 + tests/behat/_manifest_exclude | 0 tests/behat/features/next-form-step.feature | 21 +++++ tests/behat/files/testfile.txt | 1 + tests/behat/src/FeatureContext.php | 9 +++ tests/behat/src/FixtureContext.php | 74 ++++++++++++++++++ .../Control/UserDefinedFormAdminTest.php | 0 .../Control/UserDefinedFormControllerTest.php | 0 tests/{ => php}/Control/fixtures/testfile.jpg | Bin .../Extension/UserFormFileExtensionTest.php | 0 tests/{ => php}/Form/UserFormTest.php | 0 .../Form/UserFormsRequiredFieldsTest.php | 0 .../UserFormsCheckboxSetFieldTest.php | 0 .../FormField/UserFormsOptionSetFieldTest.php | 0 .../Model/EditableCustomRuleTest.php | 0 .../Model/EditableCustomRuleTest.yml | 0 .../EditableCheckboxGroupFieldTest.php | 0 .../EditableCheckboxTest.php | 0 .../EditableCountryDropdownFieldTest.php | 0 .../EditableDateFieldTest.php | 0 .../EditableDropdownTest.php | 0 .../EditableEmailFieldTest.php | 0 .../EditableFieldGroupTest.php | 0 .../EditableFileFieldTest.php | 0 .../EditableFormHeadingTest.php | 0 .../EditableFormStepTest.php | 0 .../EditableLiteralFieldTest.php | 0 .../EditableMemberListFieldTest.php | 0 .../EditableMemberListFieldTest.yml | 0 .../EditableNumericFieldTest.php | 0 .../EditableRadioFieldTest.php | 0 .../EditableTextFieldTest.php | 0 .../{ => php}/Model/EditableFormFieldTest.php | 0 .../{ => php}/Model/EditableFormFieldTest.yml | 0 .../Recipient/EmailRecipientConditionTest.php | 0 .../Recipient/EmailRecipientConditionTest.yml | 0 .../Model/Recipient/EmailRecipientTest.php | 0 .../Model/Recipient/EmailRecipientTest.yml | 0 tests/{ => php}/Model/UserDefinedFormTest.php | 0 tests/{ => php}/UserFormsTest.yml | 0 .../Control/UserDefinedFormControllerTest.ss | 0 45 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 behat.yml create mode 100644 tests/behat/README.md create mode 100644 tests/behat/_manifest_exclude create mode 100644 tests/behat/features/next-form-step.feature create mode 100644 tests/behat/files/testfile.txt create mode 100644 tests/behat/src/FeatureContext.php create mode 100644 tests/behat/src/FixtureContext.php rename tests/{ => php}/Control/UserDefinedFormAdminTest.php (100%) rename tests/{ => php}/Control/UserDefinedFormControllerTest.php (100%) rename tests/{ => php}/Control/fixtures/testfile.jpg (100%) rename tests/{ => php}/Extension/UserFormFileExtensionTest.php (100%) rename tests/{ => php}/Form/UserFormTest.php (100%) rename tests/{ => php}/Form/UserFormsRequiredFieldsTest.php (100%) rename tests/{ => php}/FormField/UserFormsCheckboxSetFieldTest.php (100%) rename tests/{ => php}/FormField/UserFormsOptionSetFieldTest.php (100%) rename tests/{ => php}/Model/EditableCustomRuleTest.php (100%) rename tests/{ => php}/Model/EditableCustomRuleTest.yml (100%) rename tests/{ => php}/Model/EditableFormField/EditableCheckboxGroupFieldTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableCheckboxTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableCountryDropdownFieldTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableDateFieldTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableDropdownTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableEmailFieldTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableFieldGroupTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableFileFieldTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableFormHeadingTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableFormStepTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableLiteralFieldTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableMemberListFieldTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableMemberListFieldTest.yml (100%) rename tests/{ => php}/Model/EditableFormField/EditableNumericFieldTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableRadioFieldTest.php (100%) rename tests/{ => php}/Model/EditableFormField/EditableTextFieldTest.php (100%) rename tests/{ => php}/Model/EditableFormFieldTest.php (100%) rename tests/{ => php}/Model/EditableFormFieldTest.yml (100%) rename tests/{ => php}/Model/Recipient/EmailRecipientConditionTest.php (100%) rename tests/{ => php}/Model/Recipient/EmailRecipientConditionTest.yml (100%) rename tests/{ => php}/Model/Recipient/EmailRecipientTest.php (100%) rename tests/{ => php}/Model/Recipient/EmailRecipientTest.yml (100%) rename tests/{ => php}/Model/UserDefinedFormTest.php (100%) rename tests/{ => php}/UserFormsTest.yml (100%) rename tests/{ => php}/templates/SilverStripe/UserForms/Tests/Control/UserDefinedFormControllerTest.ss (100%) diff --git a/.editorconfig b/.editorconfig index 4bbbf9c..a5ea69a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,7 +10,7 @@ indent_style = space insert_final_newline = true trim_trailing_whitespace = true -[{*.yml,package.json,*.js,*.scss}] +[{*.yml,package.json,*.js,*.scss,*.feature}] indent_size = 2 # The indent size used in the package.json file cannot be changed: diff --git a/.travis.yml b/.travis.yml index abbe63d..3558479 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,12 @@ jobs: - REQUIRE_INSTALLER="4.7.x-dev" - PHPUNIT_TEST=1 - PHPCS_TEST=1 + - php: 7.3 + env: + - DB=MYSQL + - REQUIRE_INSTALLER="4.7.x-dev" + - BEHAT_TEST=1 + - BEHAT_SUITE="userforms" - php: 7.4 env: - DB=MYSQL diff --git a/behat.yml b/behat.yml new file mode 100644 index 0000000..d4d0103 --- /dev/null +++ b/behat.yml @@ -0,0 +1,34 @@ +# Run asset-admin behat tests with this command (installed with silverstripe/installer) +# Note that asset-admin behat tests require CMS module +# ========================================================================= # +# vendor/bin/selenium-server-standalone -Dwebdriver.firefox.bin="/Applications/Firefox31.app/Contents/MacOS/firefox-bin" +# vendor/bin/serve --bootstrap-file vendor/silverstripe/cms/tests/behat/serve-bootstrap.php +# vendor/bin/behat @asset-admin +# ========================================================================= # +default: + suites: + userforms: + paths: + - "%paths.modules.userforms%/tests/behat/features" + contexts: + - SilverStripe\UserForms\Tests\Behat\Context\FeatureContext + - SilverStripe\Framework\Tests\Behaviour\CmsFormsContext + - SilverStripe\Framework\Tests\Behaviour\CmsUiContext + - SilverStripe\BehatExtension\Context\BasicContext + - SilverStripe\BehatExtension\Context\EmailContext + - SilverStripe\BehatExtension\Context\LoginContext + - + SilverStripe\UserForms\Tests\Behat\Context\FixtureContext: + - "%paths.modules.userforms%/tests/behat/files/" + extensions: + SilverStripe\BehatExtension\Extension: + bootstrap_file: vendor/silverstripe/cms/tests/behat/serve-bootstrap.php + screenshot_path: "%paths.base%/artifacts/screenshots" + retry_seconds: 4 # default is 2 + 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 diff --git a/composer.json b/composer.json index ba385a3..346e9b2 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,8 @@ "autoload": { "psr-4": { "SilverStripe\\UserForms\\": "code/", - "SilverStripe\\UserForms\\Tests\\": "tests/" + "SilverStripe\\UserForms\\Tests\\": "tests/php/", + "SilverStripe\\UserForms\\Tests\\Behat\\Context\\": "tests/behat/src/" } }, "suggest": { diff --git a/tests/behat/README.md b/tests/behat/README.md new file mode 100644 index 0000000..e072aec --- /dev/null +++ b/tests/behat/README.md @@ -0,0 +1 @@ +See https://github.com/silverstripe-labs/silverstripe-behat-extension \ No newline at end of file diff --git a/tests/behat/_manifest_exclude b/tests/behat/_manifest_exclude new file mode 100644 index 0000000..e69de29 diff --git a/tests/behat/features/next-form-step.feature b/tests/behat/features/next-form-step.feature new file mode 100644 index 0000000..233ba73 --- /dev/null +++ b/tests/behat/features/next-form-step.feature @@ -0,0 +1,21 @@ +@assets @retry +Feature: Next form step for userforms + As a website user + I want to click to the next form step button to see the next form step + + Background: + Given a userform with a hidden form step "My userform" + + Scenario: Next step button does not navigate to hidden form steps + When I go to "/my-userform" + And I wait for 2 seconds + And the ".progress-title" element should contain "EditableFormStep_01" + When I click the ".step-button-next" element + Then the ".progress-title" element should contain "EditableFormStep_03" + When I click the ".step-button-prev" element + And I fill in "abc" for "EditableTextField_01" + And I click the ".step-button-next" element + Then the ".progress-title" element should contain "EditableFormStep_02" + # prevent the 'form has unsaved changes' alrt + When I click the ".step-button-prev" element + And I fill in "" for "EditableTextField_01" diff --git a/tests/behat/files/testfile.txt b/tests/behat/files/testfile.txt new file mode 100644 index 0000000..8baef1b --- /dev/null +++ b/tests/behat/files/testfile.txt @@ -0,0 +1 @@ +abc diff --git a/tests/behat/src/FeatureContext.php b/tests/behat/src/FeatureContext.php new file mode 100644 index 0000000..3d37093 --- /dev/null +++ b/tests/behat/src/FeatureContext.php @@ -0,0 +1,9 @@ +getMainContext()->getSession()->getPage(); + $element = $page->find('css', $selector); + assertNotNull($element, sprintf('Element %s not found', $selector)); + $element->click(); + } + + /** + * Example: Given a userform with a hidden form step "My userform" + * + * @Given /^a userform with a hidden form step "([^"]+)"$/ + * @param string $udfTitle + */ + public function stepCreateUserFormWithHiddenFormStep(string $udfTitle): void + { + /** @var UserDefinedForm|Versioned $udf */ + /** @var EditableTextField $tf01 */ + /** @var EditableFormStep $fs02 */ + $udf = $this->getFixtureFactory()->createObject(UserDefinedForm::class, $udfTitle); + $this->createEditableFormField(EditableFormStep::class, 'EditableFormStep_01', $udf); + $tf01 = $this->createEditableFormField(EditableTextField::class, 'EditableTextField_01', $udf); + $fs02 = $this->createEditableFormField(EditableFormStep::class, 'EditableFormStep_02', $udf); + $this->createEditableFormField(EditableTextField::class, 'EditableTextField_02', $udf); + $fs02->ShowOnLoad = 0; + $fs02->write(); + $this->createCustomRule('cr1', $fs02, $tf01); + $this->createEditableFormField(EditableFormStep::class, 'EditableFormStep_03', $udf); + $this->createEditableFormField(EditableTextField::class, 'EditableTextField_03', $udf); + $udf->publishRecursive(); + } + + private function createEditableFormField(string $class, string $id, UserDefinedForm $udf): DataObject + { + $field = $this->getFixtureFactory()->createObject($class, $id); + $field->Title = $id; + $field->Parent = $udf; + $field->write(); + return $field; + } + + private function createCustomRule(string $id, EditableFormStep $fs, EditableTextField $tf): EditableCustomRule + { + /** @var EditableCustomRule $rule */ + $rule = $this->getFixtureFactory()->createObject(EditableCustomRule::class, $id); + $rule->Parent = $fs; + $rule->ConditionField = $tf; + $rule->Display = 'Show'; + $rule->ConditionOption = 'IsNotBlank'; + $rule->write(); + return $rule; + } +} diff --git a/tests/Control/UserDefinedFormAdminTest.php b/tests/php/Control/UserDefinedFormAdminTest.php similarity index 100% rename from tests/Control/UserDefinedFormAdminTest.php rename to tests/php/Control/UserDefinedFormAdminTest.php diff --git a/tests/Control/UserDefinedFormControllerTest.php b/tests/php/Control/UserDefinedFormControllerTest.php similarity index 100% rename from tests/Control/UserDefinedFormControllerTest.php rename to tests/php/Control/UserDefinedFormControllerTest.php diff --git a/tests/Control/fixtures/testfile.jpg b/tests/php/Control/fixtures/testfile.jpg similarity index 100% rename from tests/Control/fixtures/testfile.jpg rename to tests/php/Control/fixtures/testfile.jpg diff --git a/tests/Extension/UserFormFileExtensionTest.php b/tests/php/Extension/UserFormFileExtensionTest.php similarity index 100% rename from tests/Extension/UserFormFileExtensionTest.php rename to tests/php/Extension/UserFormFileExtensionTest.php diff --git a/tests/Form/UserFormTest.php b/tests/php/Form/UserFormTest.php similarity index 100% rename from tests/Form/UserFormTest.php rename to tests/php/Form/UserFormTest.php diff --git a/tests/Form/UserFormsRequiredFieldsTest.php b/tests/php/Form/UserFormsRequiredFieldsTest.php similarity index 100% rename from tests/Form/UserFormsRequiredFieldsTest.php rename to tests/php/Form/UserFormsRequiredFieldsTest.php diff --git a/tests/FormField/UserFormsCheckboxSetFieldTest.php b/tests/php/FormField/UserFormsCheckboxSetFieldTest.php similarity index 100% rename from tests/FormField/UserFormsCheckboxSetFieldTest.php rename to tests/php/FormField/UserFormsCheckboxSetFieldTest.php diff --git a/tests/FormField/UserFormsOptionSetFieldTest.php b/tests/php/FormField/UserFormsOptionSetFieldTest.php similarity index 100% rename from tests/FormField/UserFormsOptionSetFieldTest.php rename to tests/php/FormField/UserFormsOptionSetFieldTest.php diff --git a/tests/Model/EditableCustomRuleTest.php b/tests/php/Model/EditableCustomRuleTest.php similarity index 100% rename from tests/Model/EditableCustomRuleTest.php rename to tests/php/Model/EditableCustomRuleTest.php diff --git a/tests/Model/EditableCustomRuleTest.yml b/tests/php/Model/EditableCustomRuleTest.yml similarity index 100% rename from tests/Model/EditableCustomRuleTest.yml rename to tests/php/Model/EditableCustomRuleTest.yml diff --git a/tests/Model/EditableFormField/EditableCheckboxGroupFieldTest.php b/tests/php/Model/EditableFormField/EditableCheckboxGroupFieldTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableCheckboxGroupFieldTest.php rename to tests/php/Model/EditableFormField/EditableCheckboxGroupFieldTest.php diff --git a/tests/Model/EditableFormField/EditableCheckboxTest.php b/tests/php/Model/EditableFormField/EditableCheckboxTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableCheckboxTest.php rename to tests/php/Model/EditableFormField/EditableCheckboxTest.php diff --git a/tests/Model/EditableFormField/EditableCountryDropdownFieldTest.php b/tests/php/Model/EditableFormField/EditableCountryDropdownFieldTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableCountryDropdownFieldTest.php rename to tests/php/Model/EditableFormField/EditableCountryDropdownFieldTest.php diff --git a/tests/Model/EditableFormField/EditableDateFieldTest.php b/tests/php/Model/EditableFormField/EditableDateFieldTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableDateFieldTest.php rename to tests/php/Model/EditableFormField/EditableDateFieldTest.php diff --git a/tests/Model/EditableFormField/EditableDropdownTest.php b/tests/php/Model/EditableFormField/EditableDropdownTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableDropdownTest.php rename to tests/php/Model/EditableFormField/EditableDropdownTest.php diff --git a/tests/Model/EditableFormField/EditableEmailFieldTest.php b/tests/php/Model/EditableFormField/EditableEmailFieldTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableEmailFieldTest.php rename to tests/php/Model/EditableFormField/EditableEmailFieldTest.php diff --git a/tests/Model/EditableFormField/EditableFieldGroupTest.php b/tests/php/Model/EditableFormField/EditableFieldGroupTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableFieldGroupTest.php rename to tests/php/Model/EditableFormField/EditableFieldGroupTest.php diff --git a/tests/Model/EditableFormField/EditableFileFieldTest.php b/tests/php/Model/EditableFormField/EditableFileFieldTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableFileFieldTest.php rename to tests/php/Model/EditableFormField/EditableFileFieldTest.php diff --git a/tests/Model/EditableFormField/EditableFormHeadingTest.php b/tests/php/Model/EditableFormField/EditableFormHeadingTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableFormHeadingTest.php rename to tests/php/Model/EditableFormField/EditableFormHeadingTest.php diff --git a/tests/Model/EditableFormField/EditableFormStepTest.php b/tests/php/Model/EditableFormField/EditableFormStepTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableFormStepTest.php rename to tests/php/Model/EditableFormField/EditableFormStepTest.php diff --git a/tests/Model/EditableFormField/EditableLiteralFieldTest.php b/tests/php/Model/EditableFormField/EditableLiteralFieldTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableLiteralFieldTest.php rename to tests/php/Model/EditableFormField/EditableLiteralFieldTest.php diff --git a/tests/Model/EditableFormField/EditableMemberListFieldTest.php b/tests/php/Model/EditableFormField/EditableMemberListFieldTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableMemberListFieldTest.php rename to tests/php/Model/EditableFormField/EditableMemberListFieldTest.php diff --git a/tests/Model/EditableFormField/EditableMemberListFieldTest.yml b/tests/php/Model/EditableFormField/EditableMemberListFieldTest.yml similarity index 100% rename from tests/Model/EditableFormField/EditableMemberListFieldTest.yml rename to tests/php/Model/EditableFormField/EditableMemberListFieldTest.yml diff --git a/tests/Model/EditableFormField/EditableNumericFieldTest.php b/tests/php/Model/EditableFormField/EditableNumericFieldTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableNumericFieldTest.php rename to tests/php/Model/EditableFormField/EditableNumericFieldTest.php diff --git a/tests/Model/EditableFormField/EditableRadioFieldTest.php b/tests/php/Model/EditableFormField/EditableRadioFieldTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableRadioFieldTest.php rename to tests/php/Model/EditableFormField/EditableRadioFieldTest.php diff --git a/tests/Model/EditableFormField/EditableTextFieldTest.php b/tests/php/Model/EditableFormField/EditableTextFieldTest.php similarity index 100% rename from tests/Model/EditableFormField/EditableTextFieldTest.php rename to tests/php/Model/EditableFormField/EditableTextFieldTest.php diff --git a/tests/Model/EditableFormFieldTest.php b/tests/php/Model/EditableFormFieldTest.php similarity index 100% rename from tests/Model/EditableFormFieldTest.php rename to tests/php/Model/EditableFormFieldTest.php diff --git a/tests/Model/EditableFormFieldTest.yml b/tests/php/Model/EditableFormFieldTest.yml similarity index 100% rename from tests/Model/EditableFormFieldTest.yml rename to tests/php/Model/EditableFormFieldTest.yml diff --git a/tests/Model/Recipient/EmailRecipientConditionTest.php b/tests/php/Model/Recipient/EmailRecipientConditionTest.php similarity index 100% rename from tests/Model/Recipient/EmailRecipientConditionTest.php rename to tests/php/Model/Recipient/EmailRecipientConditionTest.php diff --git a/tests/Model/Recipient/EmailRecipientConditionTest.yml b/tests/php/Model/Recipient/EmailRecipientConditionTest.yml similarity index 100% rename from tests/Model/Recipient/EmailRecipientConditionTest.yml rename to tests/php/Model/Recipient/EmailRecipientConditionTest.yml diff --git a/tests/Model/Recipient/EmailRecipientTest.php b/tests/php/Model/Recipient/EmailRecipientTest.php similarity index 100% rename from tests/Model/Recipient/EmailRecipientTest.php rename to tests/php/Model/Recipient/EmailRecipientTest.php diff --git a/tests/Model/Recipient/EmailRecipientTest.yml b/tests/php/Model/Recipient/EmailRecipientTest.yml similarity index 100% rename from tests/Model/Recipient/EmailRecipientTest.yml rename to tests/php/Model/Recipient/EmailRecipientTest.yml diff --git a/tests/Model/UserDefinedFormTest.php b/tests/php/Model/UserDefinedFormTest.php similarity index 100% rename from tests/Model/UserDefinedFormTest.php rename to tests/php/Model/UserDefinedFormTest.php diff --git a/tests/UserFormsTest.yml b/tests/php/UserFormsTest.yml similarity index 100% rename from tests/UserFormsTest.yml rename to tests/php/UserFormsTest.yml diff --git a/tests/templates/SilverStripe/UserForms/Tests/Control/UserDefinedFormControllerTest.ss b/tests/php/templates/SilverStripe/UserForms/Tests/Control/UserDefinedFormControllerTest.ss similarity index 100% rename from tests/templates/SilverStripe/UserForms/Tests/Control/UserDefinedFormControllerTest.ss rename to tests/php/templates/SilverStripe/UserForms/Tests/Control/UserDefinedFormControllerTest.ss