From 79b1823101228580f6711e6a6d0cfeaf0f35775c Mon Sep 17 00:00:00 2001 From: JoshuaLicense Date: Tue, 9 Jan 2024 12:22:05 +0000 Subject: [PATCH] fix: remove form unit tests --- .../Form/BusRegApplicationsFilterFormTest.php | 32 - ...sRegApplicationsOperatorFilterFormTest.php | 32 - .../Form/Model/Form/BusRegBrowseFormTest.php | 54 - .../BusRegRegistrationsFilterFormTest.php | 48 - .../Form/Model/Form/EbsrPackUploadTest.php | 58 - .../src/Form/Model/Form/FeePaymentTest.php | 44 - .../Model/Form/Lva/AddGoodsVehicleTest.php | 64 - .../Form/Lva/ApplicationUndertakingsTest.php | 141 -- .../Model/Form/Lva/EditGoodsVehicleTest.php | 58 - .../src/Form/Model/Form/Lva/NewTmUserTest.php | 140 -- .../Form/Lva/VariationUndertakingsTest.php | 123 -- .../src/Form/Model/Form/MyDetailsTest.php | 98 -- .../src/Form/Model/Form/SearchFilterTest.php | 50 - .../Form/Model/Form/SearchOperatorTest.php | 49 - .../src/Form/Model/Form/SimpleSearchTest.php | 38 - .../Model/Form/Surrender/CurrentDiscsTest.php | 421 ------ .../Form/Surrender/OperatorLicenceTest.php | 167 --- .../TransportManagerApplicationResendTest.php | 24 - .../Model/Form/UserForgotUsernameTest.php | 40 - .../Form/UserRegistrationAddressTest.php | 90 -- .../Form/Model/Form/UserRegistrationTest.php | 142 -- test/Olcs/src/Form/Model/Form/UserTest.php | 128 -- .../Form/Model/Form/Vehicle/OCRSOptInTest.php | 146 -- .../AbstractFormValidationTestCase.php | 1307 ----------------- .../Model/Form/DeclineApplicationFormTest.php | 40 - .../Model/Form/LicenceSelectionFormTest.php | 34 - 26 files changed, 3568 deletions(-) delete mode 100644 test/Olcs/src/Form/Model/Form/BusRegApplicationsFilterFormTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/BusRegApplicationsOperatorFilterFormTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/BusRegBrowseFormTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/BusRegRegistrationsFilterFormTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/EbsrPackUploadTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/FeePaymentTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/Lva/AddGoodsVehicleTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/Lva/ApplicationUndertakingsTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/Lva/EditGoodsVehicleTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/Lva/NewTmUserTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/Lva/VariationUndertakingsTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/MyDetailsTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/SearchFilterTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/SearchOperatorTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/SimpleSearchTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/Surrender/CurrentDiscsTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/Surrender/OperatorLicenceTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/TransportManagerApplicationResendTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/UserForgotUsernameTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/UserRegistrationAddressTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/UserRegistrationTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/UserTest.php delete mode 100644 test/Olcs/src/Form/Model/Form/Vehicle/OCRSOptInTest.php delete mode 100644 test/Olcs/src/TestHelpers/AbstractFormValidationTestCase.php delete mode 100644 test/Permits/src/Form/Model/Form/DeclineApplicationFormTest.php delete mode 100644 test/Permits/src/Form/Model/Form/LicenceSelectionFormTest.php diff --git a/test/Olcs/src/Form/Model/Form/BusRegApplicationsFilterFormTest.php b/test/Olcs/src/Form/Model/Form/BusRegApplicationsFilterFormTest.php deleted file mode 100644 index 39e26d5b0..000000000 --- a/test/Olcs/src/Form/Model/Form/BusRegApplicationsFilterFormTest.php +++ /dev/null @@ -1,32 +0,0 @@ -assertFormElementIsRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementDynamicSelect($element); - } - - public function testUpdateResults() - { - $element = ['form-actions', 'updateResults']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/BusRegApplicationsOperatorFilterFormTest.php b/test/Olcs/src/Form/Model/Form/BusRegApplicationsOperatorFilterFormTest.php deleted file mode 100644 index ec833ed87..000000000 --- a/test/Olcs/src/Form/Model/Form/BusRegApplicationsOperatorFilterFormTest.php +++ /dev/null @@ -1,32 +0,0 @@ -assertFormElementIsRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementDynamicSelect($element); - } - - public function testUpdateResults() - { - $element = ['form-actions', 'updateResults']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/BusRegBrowseFormTest.php b/test/Olcs/src/Form/Model/Form/BusRegBrowseFormTest.php deleted file mode 100644 index e04dd6b69..000000000 --- a/test/Olcs/src/Form/Model/Form/BusRegBrowseFormTest.php +++ /dev/null @@ -1,54 +0,0 @@ -assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementDynamicMultiCheckbox($element); - } - - public function testStatus() - { - $element = ['fields', 'status']; - $this->assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementDynamicSelect($element, false); - } - - public function testAcceptedDate() - { - $element = ['fields', 'acceptedDate']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementDate($element); - } - - public function testSubmit() - { - $element = ['form-actions', 'submit']; - $this->assertFormElementActionButton($element); - } - - public function testExport() - { - $element = ['form-actions', 'export']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/BusRegRegistrationsFilterFormTest.php b/test/Olcs/src/Form/Model/Form/BusRegRegistrationsFilterFormTest.php deleted file mode 100644 index 1ab0b62c3..000000000 --- a/test/Olcs/src/Form/Model/Form/BusRegRegistrationsFilterFormTest.php +++ /dev/null @@ -1,48 +0,0 @@ -assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementDynamicSelect($element, false); - } - - public function testBusRegStatus() - { - $element = ['fields', 'busRegStatus']; - $this->assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementDynamicSelect($element, false); - } - - public function testLicId() - { - $element = ['fields', 'licId']; - $this->assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementDynamicSelect($element, false); - } - - public function testUpdateResults() - { - $element = ['form-actions', 'updateResults']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/EbsrPackUploadTest.php b/test/Olcs/src/Form/Model/Form/EbsrPackUploadTest.php deleted file mode 100644 index 4ed83f3ff..000000000 --- a/test/Olcs/src/Form/Model/Form/EbsrPackUploadTest.php +++ /dev/null @@ -1,58 +0,0 @@ -assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementValid($element, 'ebsrt_new'); - $this->assertFormElementValid($element, 'ebsrt_refresh'); - } - - public function testFilesFile() - { - $element = ['fields', 'files', 'file']; - $this->assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - } - - public function testFilesMessages() - { - $element = ['fields', 'files', '__messages__']; - $this->assertFormElementHidden($element); - } - - public function testFilesUpload() - { - $element = ['fields', 'files', 'upload']; - $this->assertFormElementActionButton($element); - } - - public function testUploadedFileCount() - { - $element = ['fields', 'uploadedFileCount']; - $this->assertFormElementHidden($element); - } - - public function testSubmit() - { - $element = ['form-actions', 'submit']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/FeePaymentTest.php b/test/Olcs/src/Form/Model/Form/FeePaymentTest.php deleted file mode 100644 index dd62ed076..000000000 --- a/test/Olcs/src/Form/Model/Form/FeePaymentTest.php +++ /dev/null @@ -1,44 +0,0 @@ -assertFormElementHtml($element); - } - - public function testCard() - { - $element = ['storedCards', 'card']; - $this->assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementText($element); - } - - public function testPay() - { - $element = ['form-actions', 'pay']; - $this->assertFormElementActionButton($element); - } - - public function testCustomCancel() - { - $element = ['form-actions', 'customCancel']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/Lva/AddGoodsVehicleTest.php b/test/Olcs/src/Form/Model/Form/Lva/AddGoodsVehicleTest.php deleted file mode 100644 index b4ba624ad..000000000 --- a/test/Olcs/src/Form/Model/Form/Lva/AddGoodsVehicleTest.php +++ /dev/null @@ -1,64 +0,0 @@ -assertFormElementHidden($element); - } - - public function testVersion() - { - $element = ['data', 'version']; - $this->assertFormElementHidden($element); - } - - public function testVrm() - { - $element = ['data', 'vrm']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementVrm($element); - } - - public function testPlatedWeight() - { - $element = ['data', 'platedWeight']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementVehiclePlatedWeight($element); - } - - public function testSubmit() - { - $element = ['form-actions', 'submit']; - $this->assertFormElementActionButton($element); - } - - public function testCancel() - { - $element = ['form-actions', 'cancel']; - $this->assertFormElementActionButton($element); - } - - public function testAddAnother() - { - $element = ['form-actions', 'addAnother']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/Lva/ApplicationUndertakingsTest.php b/test/Olcs/src/Form/Model/Form/Lva/ApplicationUndertakingsTest.php deleted file mode 100644 index 539879f4e..000000000 --- a/test/Olcs/src/Form/Model/Form/Lva/ApplicationUndertakingsTest.php +++ /dev/null @@ -1,141 +0,0 @@ -assertFormElementHtml($element); - } - - public function testDeclaration() - { - $element = ['declarationsAndUndertakings', 'declaration']; - $this->assertFormElementHtml($element); - } - - public function testSignatureOptions() - { - $element = ['declarationsAndUndertakings', 'signatureOptions']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementValid($element, 'Y'); - $this->assertFormElementValid($element, 'N'); - } - - public function testDisabledReview() - { - $element = ['declarationsAndUndertakings', 'disabledReview']; - $this->assertFormElementHtml($element); - } - - public function testDeclarationDownload() - { - $element = ['declarationsAndUndertakings', 'declarationDownload']; - $this->assertFormElementHtml($element); - } - - public function testDeclarationForVerify() - { - $element = ['declarationsAndUndertakings', 'declarationForVerify']; - $this->assertFormElementHtml($element); - } - - public function testVersion() - { - $element = ['declarationsAndUndertakings', 'version']; - $this->assertFormElementHidden($element); - } - - public function testId() - { - $element = ['declarationsAndUndertakings', 'id']; - $this->assertFormElementHidden($element); - } - - public function testGoodsApplicationInterim() - { - $element = ['interim', 'goodsApplicationInterim']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementValid($element, 'Y'); - $this->assertFormElementValid($element, 'N'); - } - - public function testGoodsApplicationInterimReason() - { - $element = ['interim','YContent','goodsApplicationInterimReason']; - $this->assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementText($element); - $this->assertFormElementAllowEmpty(['interim','YContent','goodsApplicationInterimReason'], true); - } - - public function testDeclarationsAndUndertakingsInterimInterimGuidanceText() - { - $this->assertFormElementHtml(['interim', 'YContent', 'interimGuidanceText']); - } - - public function testSign() - { - $element = ['form-actions', 'sign']; - $this->assertFormElementActionButton($element); - } - - public function testSubmitAndPay() - { - $element = ['form-actions', 'submitAndPay']; - $this->assertFormElementActionButton($element); - } - - public function testSubmit() - { - $element = ['form-actions', 'submit']; - $this->assertFormElementActionButton($element); - } - - public function testChange() - { - $element = ['form-actions', 'change']; - $this->assertFormElementActionButton($element); - } - - public function testSaveAndContinue() - { - $element = ['form-actions', 'saveAndContinue']; - $this->assertFormElementActionButton($element); - } - - public function testSave() - { - $element = ['form-actions', 'save']; - $this->assertFormElementActionButton($element); - } - - public function testCancel() - { - $element = ['form-actions', 'cancel']; - $this->assertFormElementActionButton($element); - } - - public function testInterimFee() - { - $element = ['interim', 'YContent', 'interimFee']; - $this->assertFormElementIsRequired($element, false); - $this->assertFormElementHtml($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/Lva/EditGoodsVehicleTest.php b/test/Olcs/src/Form/Model/Form/Lva/EditGoodsVehicleTest.php deleted file mode 100644 index 2cdf5f0dd..000000000 --- a/test/Olcs/src/Form/Model/Form/Lva/EditGoodsVehicleTest.php +++ /dev/null @@ -1,58 +0,0 @@ -assertFormElementHidden($element); - } - - public function testVersion() - { - $element = ['data', 'version']; - $this->assertFormElementHidden($element); - } - - public function testVrm() - { - $element = ['data', 'vrm']; - $this->assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementText($element); - } - - public function testPlatedWeight() - { - $element = ['data', 'platedWeight']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementVehiclePlatedWeight($element); - } - - public function testSubmit() - { - $element = ['form-actions', 'submit']; - $this->assertFormElementActionButton($element); - } - - public function testCancel() - { - $element = ['form-actions', 'cancel']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/Lva/NewTmUserTest.php b/test/Olcs/src/Form/Model/Form/Lva/NewTmUserTest.php deleted file mode 100644 index a51d4adc7..000000000 --- a/test/Olcs/src/Form/Model/Form/Lva/NewTmUserTest.php +++ /dev/null @@ -1,140 +0,0 @@ -assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementText($element, 0, 35); - } - - public function testFamilyName() - { - $element = ['data', 'familyName']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementText($element, 0, 35); - } - - public function testBirthDate() - { - $element = ['data', 'birthDate']; - - $this->assertFormElementNotValid( - $element, - [ - 'day' => '15', - 'month' => '06', - 'year' => '2060', - ], - [ \Common\Form\Elements\Validators\DateNotInFuture::IN_FUTURE ] - ); - - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementDate($element); - } - - public function testHasEmail() - { - $element = ['data', 'hasEmail']; - $this->assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementValid($element, 'N'); - $this->assertFormElementValid($element, 'Y'); - } - - public function testUsername() - { - $element = ['data', 'username']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementUsernameCreate($element); - } - - public function testEmailAddress() - { - $element = ['data', 'emailAddress']; - $this->assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - - $this->assertFormElementValid( - $element, - 'valid@email.com', - ['data' => ['emailConfirm' => 'valid@email.com']] - ); - - $this->assertFormElementNotValid( - $element, - 'valid@email.com', - \Common\Form\Elements\Validators\EmailConfirm::NOT_SAME, - ['data' => ['emailConfirm' => 'other@email.com']] - ); - - $this->assertFormElementNotValid( - $element, - 'invalid', - [ - \Dvsa\Olcs\Transfer\Validators\EmailAddress::INVALID_FORMAT, - \Common\Form\Elements\Validators\EmailConfirm::NOT_SAME, - ], - ['data' => ['emailConfirm' => 'other@email.com']] - ); - } - - public function testEmailConfirm() - { - $element = ['data', 'emailConfirm']; - $this->assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementText($element); - } - - public function testTranslateToWelsh() - { - $element = ['data', 'translateToWelsh']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementCheckbox($element); - } - - public function testEmailGuidance() - { - $element = ['data', 'emailGuidance']; - $this->assertFormElementHtml($element); - } - - public function testNoEmailGuidance() - { - $element = ['data', 'noEmailGuidance']; - $this->assertFormElementHtml($element); - } - - public function testContinue() - { - $element = ['form-actions', 'continue']; - $this->assertFormElementActionButton($element); - } - - public function testCancel() - { - $element = ['form-actions', 'cancel']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/Lva/VariationUndertakingsTest.php b/test/Olcs/src/Form/Model/Form/Lva/VariationUndertakingsTest.php deleted file mode 100644 index 26c8af5bb..000000000 --- a/test/Olcs/src/Form/Model/Form/Lva/VariationUndertakingsTest.php +++ /dev/null @@ -1,123 +0,0 @@ -assertFormElementHtml($element); - } - - public function testSummaryDownload() - { - $element = ['declarationsAndUndertakings', 'summaryDownload']; - $this->assertFormElementHtml($element); - } - - public function testDeclarationConfirmation() - { - $element = ['declarationsAndUndertakings', 'declarationConfirmation']; - $this->assertFormElementIsRequired($element); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementValid($element, 'Y'); - $this->assertFormElementNotValid($element, 'N', \Laminas\Validator\Identical::NOT_SAME); - } - - public function testVersion() - { - $element = ['declarationsAndUndertakings', 'version']; - $this->assertFormElementHidden($element); - } - - public function testId() - { - $element = ['declarationsAndUndertakings', 'id']; - $this->assertFormElementHidden($element); - } - - public function testGoodsApplicationInterim() - { - $element = ['interim', 'goodsApplicationInterim']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementValid($element, 'Y'); - $this->assertFormElementValid($element, 'N'); - } - - public function testGoodsApplicationInterimReason() - { - $element = ['interim','YContent','goodsApplicationInterimReason']; - $this->assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementText($element); - $this->assertFormElementAllowEmpty(['interim','YContent','goodsApplicationInterimReason'], true); - } - - public function testDeclarationsAndUndertakingsInterimInterimGuidanceText() - { - $this->assertFormElementHtml(['interim', 'YContent', 'interimGuidanceText']); - } - - public function testSign() - { - $element = ['form-actions', 'sign']; - $this->assertFormElementActionButton($element); - } - - public function testSubmitAndPay() - { - $element = ['form-actions', 'submitAndPay']; - $this->assertFormElementActionButton($element); - } - - public function testSubmit() - { - $element = ['form-actions', 'submit']; - $this->assertFormElementActionButton($element); - } - - public function testChange() - { - $element = ['form-actions', 'change']; - $this->assertFormElementActionButton($element); - } - - public function testSaveAndContinue() - { - $element = ['form-actions', 'saveAndContinue']; - $this->assertFormElementActionButton($element); - } - - public function testSave() - { - $element = ['form-actions', 'save']; - $this->assertFormElementActionButton($element); - } - - public function testCancel() - { - $element = ['form-actions', 'cancel']; - $this->assertFormElementActionButton($element); - } - - public function testInterimFee() - { - $element = ['interim', 'YContent', 'interimFee']; - $this->assertFormElementIsRequired($element, false); - $this->assertFormElementHtml($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/MyDetailsTest.php b/test/Olcs/src/Form/Model/Form/MyDetailsTest.php deleted file mode 100644 index b5c8b515e..000000000 --- a/test/Olcs/src/Form/Model/Form/MyDetailsTest.php +++ /dev/null @@ -1,98 +0,0 @@ -assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementText($element, 0, 35); - } - - public function testFamilyName() - { - $element = ['main', 'familyName']; - $this->assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementText($element, 0, 35); - } - - public function testEmailAddress() - { - $element = ['main', 'emailAddress']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - - $this->assertFormElementValid( - $element, - 'valid@email.com', - ['main' => ['emailConfirm' => 'valid@email.com']] - ); - - $this->assertFormElementNotValid( - $element, - 'valid@email.com', - \Common\Form\Elements\Validators\EmailConfirm::NOT_SAME, - ['main' => ['emailConfirm' => 'other@email.com']] - ); - - $this->assertFormElementNotValid( - $element, - 'invalid', - [ - \Dvsa\Olcs\Transfer\Validators\EmailAddress::INVALID_FORMAT, - \Common\Form\Elements\Validators\EmailConfirm::NOT_SAME, - ], - ['main' => ['emailConfirm' => 'other@email.com']] - ); - } - - public function testEmailConfirm() - { - $element = ['main', 'emailConfirm']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementText($element); - } - - public function testTranslateToWelsh() - { - $element = ['main', 'translateToWelsh']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementCheckbox($element); - } - - public function testId() - { - $element = ['main', 'id']; - $this->assertFormElementHidden($element); - } - - public function testVersion() - { - $element = ['main', 'version']; - $this->assertFormElementHidden($element); - } - - public function testSubmit() - { - $element = ['form-actions', 'submit']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/SearchFilterTest.php b/test/Olcs/src/Form/Model/Form/SearchFilterTest.php deleted file mode 100644 index 3229cd726..000000000 --- a/test/Olcs/src/Form/Model/Form/SearchFilterTest.php +++ /dev/null @@ -1,50 +0,0 @@ -assertFormElementHidden($element); - } - - public function testText() - { - $element = ['text', 'search']; - $this->assertFormElementRequired($element, false); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementText($element); - } - - public function testSearch() - { - $element = ['search']; - $this->assertFormElementHidden($element); - } - - public function testSearchBy() - { - $element = ['searchBy']; - $this->assertFormElementHidden($element); - } - - public function testSubmit() - { - $element = ['submit']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/SearchOperatorTest.php b/test/Olcs/src/Form/Model/Form/SearchOperatorTest.php deleted file mode 100644 index e768f5e07..000000000 --- a/test/Olcs/src/Form/Model/Form/SearchOperatorTest.php +++ /dev/null @@ -1,49 +0,0 @@ -assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementValid($element, 'address'); - $this->assertFormElementValid($element, 'business'); - $this->assertFormElementValid($element, 'licence'); - $this->assertFormElementValid($element, 'person'); - } - - public function testSearch() - { - $element = ['search']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementText($element); - } - - public function testSubmit() - { - $element = ['submit']; - $this->assertFormElementActionButton($element); - } - - public function testIndex() - { - $element = ['index']; - $this->assertFormElementHidden($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/SimpleSearchTest.php b/test/Olcs/src/Form/Model/Form/SimpleSearchTest.php deleted file mode 100644 index 561b9109f..000000000 --- a/test/Olcs/src/Form/Model/Form/SimpleSearchTest.php +++ /dev/null @@ -1,38 +0,0 @@ -assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementText($element); - } - - public function testSubmit() - { - $element = ['submit']; - $this->assertFormElementActionButton($element); - } - - public function testIndex() - { - $element = ['index']; - $this->assertFormElementHidden($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/Surrender/CurrentDiscsTest.php b/test/Olcs/src/Form/Model/Form/Surrender/CurrentDiscsTest.php deleted file mode 100644 index 4c8fc79f0..000000000 --- a/test/Olcs/src/Form/Model/Form/Surrender/CurrentDiscsTest.php +++ /dev/null @@ -1,421 +0,0 @@ -assertFormElementType($headerSection, HtmlTranslated::class); - $this->assertFormElementHtml($headerSection); - } - - public function testPossessionInfoNumber() - { - $element = ['possessionSection', 'info', 'number']; - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementType($element, Number::class); - } - - public function testLost() - { - $element = ['lostSection', 'lost']; - $this->assertFormElementType($element, Checkbox::class); - } - - public function testLostInfoNumber() - { - $element = ['lostSection', 'info', 'number']; - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementType($element, Number::class); - } - - public function testLostInfoDetails() - { - $element = ['lostSection', 'info', 'details']; - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementType($element, Textarea::class); - } - - public function testStolen() - { - $element = ['stolenSection', 'stolen']; - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementType($element, OlcsCheckbox::class); - } - - public function testStolenInfoDetails() - { - $element = ['stolenSection', 'info', 'details']; - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementType($element, Textarea::class); - } - - public function testStolenInfoNumber() - { - $element = ['stolenSection', 'info', 'number']; - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementType($element, Number::class); - } - - /** - * @dataProvider dpInfoNumber - */ - public function testInfoNumberValidation($section, $formData, $expected) - { - $form = $this->getForm(); - - $this->setPost($formData); - $form->setData($formData); - $form->setValidationGroup([$section]); - - $valid = $form->isValid(); - $this->assertEquals($expected, $valid); - - $this->clearPost(); - } - - /** - * @dataProvider dpInfoDetails - */ - public function testInfoDetailsValidation($section, $formData, $expected) - { - $form = $this->getForm(); - - $this->setPost($formData); - $form->setData($formData); - $form->setValidationGroup([$section]); - - $valid = $form->isValid(); - $this->assertEquals($expected, $valid); - - $this->clearPost(); - } - - - public function testSubmit() - { - $element = ['submit']; - $this->assertFormElementActionButton($element); - $this->assertFormElementType($element, Button::class); - } - - public function testLostSectionLost() - { - $element = ['lostSection', 'lost']; - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementType($element, OlcsCheckbox::class); - } - - public function testPosessionSectionInPosession() - { - $element = ['possessionSection', 'inPossession']; - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementType($element, OlcsCheckbox::class); - } - - public function dpInfoNumber() - { - return [ - 'case_not_in_possession' => [ - 'section' => 'possessionSection', - 'formData' => [ - 'possessionSection' => [ - 'inPossession' => 'N', - 'info' => [ - 'number' => '' - ] - ] - ], - 'expected' => true - ], - 'case_in_possession_number_valid' => [ - 'section' => 'possessionSection', - 'formData' => [ - 'possessionSection' => [ - 'inPossession' => 'Y', - 'info' => [ - 'number' => 4 - ] - ] - ], - 'expected' => true - ], - 'case_in_possession_number_below_min' => [ - 'section' => 'possessionSection', - 'formData' => [ - 'possessionSection' => [ - 'inPossession' => 'Y', - 'info' => [ - 'number' => 0 - ] - ] - ], - 'expected' => false - ], - 'case_in_possession_number_empty' => [ - 'section' => 'possessionSection', - 'formData' => [ - 'possessionSection' => [ - 'inPossession' => 'Y', - 'info' => [ - 'number' => '' - ] - ] - ], - 'expected' => false - ], - 'case_in_possession_number_string' => [ - 'section' => 'possessionSection', - 'formData' => [ - 'possessionSection' => [ - 'inPossession' => 'Y', - 'info' => [ - 'number' => 'aa' - ] - ] - ], - 'expected' => false - ], - 'case_not_lost' => [ - 'section' => 'lostSection', - 'formData' => [ - 'lostSection' => [ - 'lost' => 'N', - 'info' => [ - 'number' => '', - 'details' => '' - ] - ] - ], - 'expected' => true - ], - 'case_lost_number_valid' => [ - 'section' => 'lostSection', - 'formData' => [ - 'lostSection' => [ - 'lost' => 'Y', - 'info' => [ - 'number' => 4, - 'details' => str_repeat('abcd ', 100) - ] - ] - ], - 'expected' => true - ], - 'case_lost_number_below_min' => [ - 'section' => 'lostSection', - 'formData' => [ - 'lostSection' => [ - 'lost' => 'Y', - 'info' => [ - 'number' => 0, - 'details' => str_repeat('abcd ', 100) - ] - ] - ], - 'expected' => false - ], - 'case_lost_number_empty' => [ - 'section' => 'lostSection', - 'formData' => [ - 'lostSection' => [ - 'lost' => 'Y', - 'info' => [ - 'number' => '', - 'details' => str_repeat('abcd ', 100) - ] - ] - ], - 'expected' => false - ], - 'case_lost_number_string' => [ - 'section' => 'lostSection', - 'formData' => [ - 'lostSection' => [ - 'lost' => 'Y', - 'info' => [ - 'number' => 'aa', - 'details' => str_repeat('abcd ', 100) - ] - ] - ], - 'expected' => false - ], - 'case_not_stolen' => [ - 'section' => 'stolenSection', - 'formData' => [ - 'stolenSection' => [ - 'stolen' => 'N', - 'info' => [ - 'number' => '', - 'details' => '' - ] - ] - ], - 'expected' => true - ], - 'case_stolen_number_valid' => [ - 'section' => 'stolenSection', - 'formData' => [ - 'stolenSection' => [ - 'stolen' => 'Y', - 'info' => [ - 'number' => 4, - 'details' => str_repeat('abcd ', 100) - ] - ] - ], - 'expected' => true - ], - 'case_stolen_number_below_min' => [ - 'section' => 'stolenSection', - 'formData' => [ - 'stolenSection' => [ - 'stolen' => 'Y', - 'info' => [ - 'number' => 0, - 'details' => str_repeat('abcd ', 100) - ] - ] - ], - 'expected' => false - ], - 'case_stolen_number_empty' => [ - 'section' => 'stolenSection', - 'formData' => [ - 'stolenSection' => [ - 'stolen' => 'Y', - 'info' => [ - 'number' => '', - 'details' => str_repeat('abcd ', 100) - ] - ] - ], - 'expected' => false - ], - 'case_stolen_number_string' => [ - 'section' => 'stolenSection', - 'formData' => [ - 'stolenSection' => [ - 'stolen' => 'Y', - 'info' => [ - 'number' => 'aa', - 'details' => str_repeat('abcd ', 100) - ] - ] - ], - 'expected' => false - ], - ]; - } - - public function dpInfoDetails() - { - return [ - 'case_lost_lost_valid' => [ - 'section' => 'lostSection', - 'formData' => [ - 'lostSection' => [ - 'lost' => 'Y', - 'info' => [ - 'number' => 4, - 'details' => str_repeat('abcd ', 100) - ] - ] - ], - 'expected' => true - ], - 'case_lost_lost_below_min' => [ - 'section' => 'lostSection', - 'formData' => [ - 'lostSection' => [ - 'lost' => 'Y', - 'info' => [ - 'number' => 4, - 'details' => str_repeat('abcd ', 101) - ] - ] - ], - 'expected' => false - ], - 'case_lost_lost_over_max' => [ - 'section' => 'lostSection', - 'formData' => [ - 'lostSection' => [ - 'lost' => 'Y', - 'info' => [ - 'number' => 4, - 'details' => '' - ] - ] - ], - 'expected' => false - ], - 'case_stolen_lost_valid' => [ - 'section' => 'stolenSection', - 'formData' => [ - 'stolenSection' => [ - 'stolen' => 'Y', - 'info' => [ - 'number' => 4, - 'details' => str_repeat('abcd ', 100) - ] - ] - ], - 'expected' => true - ], - 'case_stolen_lost_below_min' => [ - 'section' => 'stolenSection', - 'formData' => [ - 'stolenSection' => [ - 'stolen' => 'Y', - 'info' => [ - 'number' => 4, - 'details' => str_repeat('abcd ', 101) - ] - ] - ], - 'expected' => false - ], - 'case_stolen_lost_over_max' => [ - 'section' => 'stolenSection', - 'formData' => [ - 'stolenSection' => [ - 'stolen' => 'Y', - 'info' => [ - 'number' => 4, - 'details' => '' - ] - ] - ], - 'expected' => false - ] - ]; - } - - protected function setPost(array $data) - { - $_POST = $data; - } - - protected function clearPost() - { - $_POST = []; - } -} diff --git a/test/Olcs/src/Form/Model/Form/Surrender/OperatorLicenceTest.php b/test/Olcs/src/Form/Model/Form/Surrender/OperatorLicenceTest.php deleted file mode 100644 index 665fa72f9..000000000 --- a/test/Olcs/src/Form/Model/Form/Surrender/OperatorLicenceTest.php +++ /dev/null @@ -1,167 +0,0 @@ -assertFormElementAllowEmpty($element, false); - $this->assertFormElementType($element, Radio::class); - $validValues = ['possession', 'lost', 'stolen']; - foreach ($validValues as $validValue) { - $this->assertFormElementValid($element, $validValue); - } - $invalidValues = ['one', 'two', 'three']; - foreach ($invalidValues as $invalidValue) { - $this->assertFormElementNotValid($element, $invalidValue, ['notInArray']); - } - } - - public function testPossessionContent() - { - $notice = ['operatorLicenceDocument', 'possessionContent', 'notice']; - $this->assertFormElementAllowEmpty($notice, true); - $this->assertFormElementType($notice, HtmlTranslated::class); - } - - public function testLostContent() - { - $notice = ['operatorLicenceDocument', 'lostContent', 'notice']; - $this->assertFormElementAllowEmpty($notice, true); - $this->assertFormElementType($notice, HtmlTranslated::class); - - $details = ['operatorLicenceDocument', 'lostContent', 'details']; - $this->assertFormElementAllowEmpty($details, true); - $this->assertFormElementType($details, Textarea::class); - } - - public function testLostContentValidLenght() - { - $form = $this->getForm(); - - $data = [ - 'operatorLicenceDocument' => [ - 'operatorLicenceDocument' => 'lost', - 'lostContent' => ['details' => str_repeat('acbd ', 100)] - ] - ]; - $this->setPost($data); - $form->setData($data); - $valid = $form->isValid(); - - $this->assertTrue($valid); - - $this->clearPost(); - } - - /** - * @dataProvider dpTestLostContentNotValidLength - */ - public function testLostContentNotValidLength($string) - { - $form = $this->getForm(); - - $data = [ - 'operatorLicenceDocument' => [ - 'operatorLicenceDocument' => 'lost', - 'lostContent' => ['details' => $string] - ] - ]; - $this->setPost($data); - $form->setData($data); - $valid = $form->isValid(); - - $this->assertFalse($valid); - - $this->clearPost(); - } - - public function dpTestLostContentNotValidLength() - { - return [ - [ - 'more_than_500' => str_repeat('acbd ', 101), - - ], - [ - 'empty_string' => '' - ] - ]; - } - - public function testStolenContent() - { - $notice = ['operatorLicenceDocument', 'stolenContent', 'notice']; - $this->assertFormElementAllowEmpty($notice, true); - $this->assertFormElementType($notice, HtmlTranslated::class); - - $details = ['operatorLicenceDocument', 'stolenContent', 'details']; - $this->assertFormElementAllowEmpty($details, true); - $this->assertFormElementType($details, Textarea::class); - } - - public function testStolenContentValidLength() - { - $form = $this->getForm(); - - $data = [ - 'operatorLicenceDocument' => [ - 'operatorLicenceDocument' => 'stolen', - 'stolenContent' => ['details' => str_repeat('acbd ', 100)] - ] - ]; - $this->setPost($data); - $form->setData($data); - $valid = $form->isValid(); - - $this->assertTrue($valid); - - $this->clearPost(); - } - - public function testStolenContentNotValidLength() - { - $form = $this->getForm(); - - $data = [ - 'operatorLicenceDocument' => [ - 'operatorLicenceDocument' => 'stolen', - 'stolenContent' => ['details' => str_repeat('acbd ', 101)] - ] - ]; - $this->setPost($data); - $form->setData($data); - $valid = $form->isValid(); - - $this->assertFalse($valid); - - $this->clearPost(); - } - - public function testFormActions() - { - $notice = ['form-actions', 'submit']; - $this->assertFormElementType($notice, ActionButton::class); - } - - private function setPost(array $data) - { - $_POST = $data; - } - - private function clearPost() - { - $_POST = []; - } -} diff --git a/test/Olcs/src/Form/Model/Form/TransportManagerApplicationResendTest.php b/test/Olcs/src/Form/Model/Form/TransportManagerApplicationResendTest.php deleted file mode 100644 index e31ff1fe8..000000000 --- a/test/Olcs/src/Form/Model/Form/TransportManagerApplicationResendTest.php +++ /dev/null @@ -1,24 +0,0 @@ -assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/UserForgotUsernameTest.php b/test/Olcs/src/Form/Model/Form/UserForgotUsernameTest.php deleted file mode 100644 index 662de75cf..000000000 --- a/test/Olcs/src/Form/Model/Form/UserForgotUsernameTest.php +++ /dev/null @@ -1,40 +0,0 @@ -assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementText($element, 2, 18); - } - - public function testEmailAddress() - { - $element = ['fields', 'emailAddress']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementEmailAddress($element); - } - - public function testSubmit() - { - $element = ['form-actions', 'submit']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/UserRegistrationAddressTest.php b/test/Olcs/src/Form/Model/Form/UserRegistrationAddressTest.php deleted file mode 100644 index 187ba165c..000000000 --- a/test/Olcs/src/Form/Model/Form/UserRegistrationAddressTest.php +++ /dev/null @@ -1,90 +0,0 @@ -assertFormElementHidden($element); - } - - public function testForename() - { - $element = ['fields', 'forename']; - $this->assertFormElementHidden($element); - } - - public function testFamilyName() - { - $element = ['fields', 'familyName']; - $this->assertFormElementHidden($element); - } - - public function testEmailAddress() - { - $element = ['fields', 'emailAddress']; - $this->assertFormElementHidden($element); - } - - public function testEmailConfirm() - { - $element = ['fields', 'emailConfirm']; - $this->assertFormElementHidden($element); - } - - public function testIsLicenceHolder() - { - $element = ['fields', 'isLicenceHolder']; - $this->assertFormElementHidden($element); - } - - public function testLicenceNumber() - { - $element = ['fields', 'licenceNumber']; - $this->assertFormElementHidden($element); - } - - public function testOrganisationName() - { - $element = ['fields', 'organisationName']; - $this->assertFormElementHidden($element); - } - - public function testBusinessType() - { - $element = ['fields', 'businessType']; - $this->assertFormElementHidden($element); - } - - public function testTranslateToWelsh() - { - $element = ['fields', 'translateToWelsh']; - $this->assertFormElementHidden($element); - } - - public function testTermsAgreed() - { - $element = ['fields', 'termsAgreed']; - $this->assertFormElementHidden($element); - } - - public function testPostAccount() - { - $element = ['form-actions', 'postAccount']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/UserRegistrationTest.php b/test/Olcs/src/Form/Model/Form/UserRegistrationTest.php deleted file mode 100644 index e49b2cd62..000000000 --- a/test/Olcs/src/Form/Model/Form/UserRegistrationTest.php +++ /dev/null @@ -1,142 +0,0 @@ -assertFormElementIsRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementUsernameCreate($element); - } - - public function testForename() - { - $element = ['fields', 'forename']; - $this->assertFormElementIsRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementText($element, 0, 35); - } - - public function testFamilyName() - { - $element = ['fields', 'familyName']; - $this->assertFormElementIsRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementText($element, 0, 35); - } - - public function testEmailAddress() - { - $element = ['fields', 'emailAddress']; - $this->assertFormElementIsRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - - $this->assertFormElementValid( - $element, - 'valid@email.com', - ['fields' => ['emailConfirm' => 'valid@email.com']] - ); - - $this->assertFormElementNotValid( - $element, - 'valid@email.com', - \Common\Form\Elements\Validators\EmailConfirm::NOT_SAME, - ['fields' => ['emailConfirm' => 'other@email.com']] - ); - - $this->assertFormElementNotValid( - $element, - 'invalid', - [ - \Dvsa\Olcs\Transfer\Validators\EmailAddress::INVALID_FORMAT, - \Common\Form\Elements\Validators\EmailConfirm::NOT_SAME, - ], - ['fields' => ['emailConfirm' => 'other@email.com']] - ); - } - - public function testEmailConfirm() - { - $element = ['fields', 'emailConfirm']; - $this->assertFormElementIsRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementText($element); - } - - public function testIsLicenceHolder() - { - $element = ['fields', 'isLicenceHolder']; - $this->assertFormElementIsRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementValid($element, 'N'); - $this->assertFormElementValid($element, 'Y'); - } - - public function testLicenceNumber() - { - $element = ['fields', 'licenceNumber']; - $this->assertFormElementIsRequired($element, true); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementText($element); - - $this->assertFormElementText($element, 2, 35, ['fields' => ['isLicenceHolder' => 'Y']]); - } - - public function testOrganisationName() - { - $element = ['fields', 'organisationName']; - $this->assertFormElementIsRequired($element, true); - $this->assertFormElementAllowEmpty($element, true); - $this->assertFormElementText($element); - - $this->assertFormElementAllowEmpty($element, false, ['fields' => ['isLicenceHolder' => 'N']]); - } - - public function testBusinessType() - { - $element = ['fields', 'businessType']; - $this->assertFormElementIsRequired($element, false); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementDynamicRadio($element, false); - - $this->assertFormElementAllowEmpty($element, false, ['fields' => ['isLicenceHolder' => 'N']]); - } - - public function testTranslateToWelsh() - { - $element = ['fields', 'translateToWelsh']; - $this->assertFormElementIsRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementCheckbox($element); - } - - public function testTermsAgreed() - { - $element = ['fields', 'termsAgreed']; - $this->assertFormElementIsRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementValid($element, 'Y'); - $this->assertFormElementNotValid($element, 'N', \Laminas\Validator\Identical::NOT_SAME); - } - - public function testSubmit() - { - $element = ['form-actions', 'submit']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/UserTest.php b/test/Olcs/src/Form/Model/Form/UserTest.php deleted file mode 100644 index 1539ec3ae..000000000 --- a/test/Olcs/src/Form/Model/Form/UserTest.php +++ /dev/null @@ -1,128 +0,0 @@ -assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementUsernameCreate($element); - } - - public function testForename() - { - $element = ['main', 'forename']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementText($element, 0, 35); - } - - public function testFamilyName() - { - $element = ['main', 'familyName']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementText($element, 0, 35); - } - - public function testEmailAddress() - { - $element = ['main', 'emailAddress']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - - $this->assertFormElementValid( - $element, - 'valid@email.com', - ['main' => ['emailConfirm' => 'valid@email.com']] - ); - - $this->assertFormElementNotValid( - $element, - 'valid@email.com', - \Common\Form\Elements\Validators\EmailConfirm::NOT_SAME, - ['main' => ['emailConfirm' => 'other@email.com']] - ); - - $this->assertFormElementNotValid( - $element, - 'invalid', - [ - \Dvsa\Olcs\Transfer\Validators\EmailAddress::INVALID_FORMAT, - \Common\Form\Elements\Validators\EmailConfirm::NOT_SAME, - ], - ['main' => ['emailConfirm' => 'other@email.com']] - ); - } - - public function testEmailConfirm() - { - $element = ['main', 'emailConfirm']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementText($element); - } - - public function testPermission() - { - $element = ['main', 'permission']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementValid($element, 'user'); - $this->assertFormElementValid($element, 'admin'); - $this->assertFormElementValid($element, 'tm'); - } - - public function testTranslateToWelsh() - { - $element = ['main', 'translateToWelsh']; - $this->assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementCheckbox($element); - } - - public function testCurrentPermission() - { - $element = ['main', 'currentPermission']; - $this->assertFormElementHidden($element); - } - - public function testId() - { - $element = ['main', 'id']; - $this->assertFormElementHidden($element); - } - - public function testVersion() - { - $element = ['main', 'version']; - $this->assertFormElementHidden($element); - } - - public function testSubmit() - { - $element = ['form-actions', 'submit']; - $this->assertFormElementActionButton($element); - } - - public function testCancel() - { - $element = ['form-actions', 'cancel']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/Form/Model/Form/Vehicle/OCRSOptInTest.php b/test/Olcs/src/Form/Model/Form/Vehicle/OCRSOptInTest.php deleted file mode 100644 index 50ee77258..000000000 --- a/test/Olcs/src/Form/Model/Form/Vehicle/OCRSOptInTest.php +++ /dev/null @@ -1,146 +0,0 @@ -assertFormElementValid( - $element, - $value - ); - } - - /** - * @test - * @dataProvider checkboxValueNotValid_DataProvider - * @param $value - * @param array $expectedValidationErrors - */ - public function checkboxValueNotValid($value, array $expectedValidationErrors) - { - $element = ['ocrsCheckbox']; - - $this->assertFormElementNotValid( - $element, - $value, - $expectedValidationErrors - ); - } - - /** - * @dataProvider - */ - public function checkboxValueValid_DataProvider(): array - { - return [ - 'Uppercase Y' => ['Y'], - 'Uppercase N' => ['N'], - ]; - } - - /** - * @dataProvider - */ - public function checkboxValueNotValid_DataProvider(): array - { - return [ - 'Lowercase y' => [ - 'y', - [ - \Laminas\Validator\InArray::NOT_IN_ARRAY - ], - ], - 'Startswith capital Y' => [ - 'YES', - [ - \Laminas\Validator\InArray::NOT_IN_ARRAY - ], - ], - 'Lowercase n' => [ - 'n', - [ - \Laminas\Validator\InArray::NOT_IN_ARRAY - ], - ], - 'Startswith capital N' => [ - 'NO', - [ - \Laminas\Validator\InArray::NOT_IN_ARRAY - ], - ], - 'Number 1' => [ - '1', - [ - \Laminas\Validator\InArray::NOT_IN_ARRAY - ], - ], - 'Number 0' => [ - '0', - [ - \Laminas\Validator\InArray::NOT_IN_ARRAY - ], - ], - 'False' => [ - false, - [ - \Laminas\Validator\NotEmpty::IS_EMPTY - ], - ], - 'True' => [ - true, - [ - \Laminas\Validator\InArray::NOT_IN_ARRAY - ], - ], - 'Whitespace' => [ - ' ', - [ - \Laminas\Validator\NotEmpty::IS_EMPTY - ], - ], - 'Empty string' => [ - '', - [ - \Laminas\Validator\NotEmpty::IS_EMPTY - ], - ], - 'Null' => [ - null, - [ - \Laminas\Validator\NotEmpty::IS_EMPTY - ], - ], - ]; - } - - /** - * @test - */ - public function submitIsActionButton() - { - $element = ['submit']; - $this->assertFormElementActionButton($element); - } -} diff --git a/test/Olcs/src/TestHelpers/AbstractFormValidationTestCase.php b/test/Olcs/src/TestHelpers/AbstractFormValidationTestCase.php deleted file mode 100644 index 3fa964725..000000000 --- a/test/Olcs/src/TestHelpers/AbstractFormValidationTestCase.php +++ /dev/null @@ -1,1307 +0,0 @@ -getName(), 'testMissingTest') === false) { - $this->sut = $this->getForm(); - } - } - - /** - * We can access service manager if we need to add a mock for certain applications - * - * @return \Laminas\ServiceManager\ServiceLocatorInterface - */ - protected function getServiceManager() - { - if ($this->serviceManager === null) { - - $this->serviceManager = self::getRealServiceManager(); - - // inject a real string helper - - $this->serviceManager->setAllowOverride(true); - - $this->serviceManager->get('FormElementManager')->setFactory( - 'DynamicSelect', - function ($serviceLocator, $name, $requestedName) { - $element = new DynamicSelect(); - $element->setValueOptions( - [ - '1' => 'one', - '2' => 'two', - '3' => 'three' - ] - ); - return $element; - } - ); - - $this->serviceManager->get('FormElementManager')->setFactory( - 'DynamicRadio', - function ($serviceLocator, $name, $requestedName) { - $element = new DynamicRadio(); - $element->setValueOptions( - [ - '1' => 'one', - '2' => 'two', - '3' => 'three' - ] - ); - return $element; - } - ); - - $this->serviceManager->get('FormElementManager')->setFactory( - 'Common\Form\Element\DynamicMultiCheckbox', - function ($serviceLocator, $name, $requestedName) { - $element = new DynamicMultiCheckbox(); - $element->setValueOptions( - [ - '1' => 'one', - '2' => 'two', - '3' => 'three' - ] - ); - return $element; - } - ); - } - - return $this->serviceManager; - } - - public static function getRealServiceManager() - { - $serviceManager = new ServiceManager(new ServiceManagerConfig()); - $serviceManager->setService('ApplicationConfig', include __DIR__. '/../../../../config/application.config.php'); - $serviceManager->get('ModuleManager')->loadModules(); - $serviceManager->setAllowOverride(true); - - $mockTranslationLoader = m::mock(TranslationLoader::class); - $mockTranslationLoader->shouldReceive('load')->andReturn(['default' => ['en_GB' => []]]); - $mockTranslationLoader->shouldReceive('loadReplacements')->andReturn([]); - $serviceManager->setService(TranslationLoader::class, $mockTranslationLoader); - - $pluginManager = new LoaderPluginManager($serviceManager); - $pluginManager->setService(TranslationLoader::class, $mockTranslationLoader); - $serviceManager->setService('TranslatorPluginManager', $pluginManager); - - // Mess up the backend, so any real rest calls will fail - $config = $serviceManager->get('Config'); - $config['service_api_mapping']['endpoints']['backend'] = 'http://some-fake-backend/'; - $serviceManager->setService('Config', $config); - - return $serviceManager; - } - - /** - * Get the form object - * - * @return \Common\Form\Form - */ - protected function getForm() - { - if ($this->formName == null) { - throw new \Exception('formName property is not defined'); - } - - if (!isset(self::$forms[$this->formName])) { - /** @var \Common\Form\Annotation\CustomAnnotationBuilder $c */ - $frmAnnotBuilder = $this->getServiceManager()->get('FormAnnotationBuilder'); - - self::$forms[$this->formName] = $frmAnnotBuilder->createForm($this->formName); - } - - return clone self::$forms[$this->formName]; - } - - /** - * Assert that a form element with a value is valid - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param mixed $value The value to be tested in the form element - * @param array $context Form data context required to test the validation - * - * @return void - */ - protected function assertFormElementValid(array $elementHierarchy, $value, array $context = []) - { - self::$testedElements[implode('.', $elementHierarchy)] = true; - - $this->assertElementExists($elementHierarchy); - $this->setData($elementHierarchy, $value, $context); - $this->setValidationGroup($elementHierarchy); - - $valid = $this->sut->isValid(); - $message = sprintf( - '"%s" form element with value "%s" should be valid : %s', - implode('.', $elementHierarchy), - print_r($value, true), - implode(', ', array_keys($this->getFormMessages($elementHierarchy))) - ); - - $this->assertTrue($valid, $message); - } - - /** - * Get the form validation messages for an element - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return array - */ - protected function getFormMessages(array $elementHierarchy) - { - $messages = $this->sut->getMessages(); - foreach ($elementHierarchy as $name) { - if (isset($messages[$name])) { - $messages = $messages[$name]; - } - } - return $messages; - } - - /** - * Set the validation group so that ony the form element is validated - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function setValidationGroup(array $elementHierarchy) - { - $array = null; - foreach (array_reverse($elementHierarchy) as $name) { - if ($array == null) { - $array = [$name]; - } else { - $array = [$name => $array]; - } - } - - $this->sut->setValidationGroup($array); - } - - /** - * Set the form data - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param mixed $value Form element (being tested) value - * @param array $context Form data context required to test the validation - * - * @return void - */ - protected function setData(array $elementHierarchy, $value, $context = []) - { - $element = $this->getElementByHierarchy($elementHierarchy); - if (empty($value) && $element instanceof MonthSelect) { - $value = [ - 'month' => null, - 'year' => null, - ]; - if($element instanceof DateSelect) { - $value['day'] = null; - } - if($element instanceof DateTimeSelect) { - $value['hour'] = null; - $value['minute'] = null; - $value['second'] = null; - } - } - - $array = $value; - foreach (array_reverse($elementHierarchy) as $name) { - $array = [$name => $array]; - } - $this->sut->setData(array_merge_recursive($context, $array)); - } - - /** - * Assert that the form element exists in the form - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertElementExists(array $elementHierarchy) - { - try { - $this->getFormElement($elementHierarchy); - } catch (\Exception $e) { - $this->fail($e->getMessage()); - } - } - - /** - * Get the form element - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return \Laminas\Form\Element - */ - protected function getFormElement(array $elementHierarchy) - { - $element = $this->sut; - foreach ($elementHierarchy as $name) { - if (!$element->has($name)) { - throw new \Exception( - sprintf('Cannot find element by name "%s" in "%s"', $name, implode('.', $elementHierarchy)) - ); - } - $element = $element->get($name); - } - return $element; - } - - /** - * Assert the type of a form element - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param string $type Class name of the type - * - * @return void - */ - protected function assertFormElementType(array $elementHierarchy, $type) - { - $this->assertInstanceOf($type, $this->getFormElement($elementHierarchy)); - } - - /** - * Assert that a form element with a value is NOT valid - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param mixed $value The value to be tested in the form element - * @param string|array $validationMessages A single or an array of expected validation messages keys - * @param array $context Form data context required to test the validation - * - * @return void - */ - protected function assertFormElementNotValid( - array $elementHierarchy, - $value, - $validationMessages, - array $context = [] - ) { - self::$testedElements[implode('.', $elementHierarchy)] = true; - - if (!is_array($validationMessages)) { - $validationMessages = [$validationMessages]; - } - - $this->assertElementExists($elementHierarchy); - $this->setData($elementHierarchy, $value, $context); - $this->setValidationGroup($elementHierarchy); - - $valid = $this->sut->isValid(); - - $this->assertFalse( - $valid, - sprintf( - '"%s" form element with value "%s" should *not* be valid', - implode('.', $elementHierarchy), - print_r($value, true) - ) - ); - - $errorMessages = array_keys($this->getFormMessages($elementHierarchy)); - // If error messages has no keys, it is probably because the top level ErrorMessage has been used - // therefore check the contents of the error, rather than the key - if (array_keys($this->getFormMessages($elementHierarchy)) === [0 => 0]) { - $errorMessages = $this->getFormMessages($elementHierarchy); - } - - $this->assertSame( - $validationMessages, - $errorMessages, - sprintf( - '"%s" form element with value "%s" error messages not as expected', - implode('.', $elementHierarchy), - print_r($value, true) - ) - ); - } - - /** - * Assert than a form element is a text input - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param int $min Minimum allowed string length - * @param int $max Maximum allowed string length - * @param array $context Any form context required for this validation - * - * @return void - */ - protected function assertFormElementText( - $elementHierarchy, - $min = 0, - $max = null, - array $context = [] - ) { - if ($min > 0) { - $this->assertFormElementValid($elementHierarchy, str_pad('', $min, 'x'), $context); - } - if ($min > 1) { - $this->assertFormElementNotValid( - $elementHierarchy, - str_pad('', $min - 1, 'x'), - Validator\StringLength::TOO_SHORT, - $context - ); - } else { - $this->assertFormElementValid($elementHierarchy, 'x', $context); - } - - if ($max !== null) { - $this->assertFormElementValid($elementHierarchy, str_pad('', $max, 'x'), $context); - $this->assertFormElementNotValid( - $elementHierarchy, - str_pad('', $max + 1, 'x'), - Validator\StringLength::TOO_LONG, - $context - ); - } - } - - /** - * Assert than a form element is a number input - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param int $min Minimum allowed value - * @param int $max Maximum allowed value - * @param string|array $validationMessages A single or an array of expected validation messages keys - * - * @return void - */ - protected function assertFormElementNumber($elementHierarchy, $min = 0, $max = null, $validationMessages = null) - { - $this->assertFormElementValid($elementHierarchy, $min); - $this->assertFormElementValid($elementHierarchy, $min + 1); - - if ($min > 0) { - $this->assertFormElementNotValid( - $elementHierarchy, - $min - 1, - $validationMessages ? : Validator\Between::NOT_BETWEEN - ); - } - - if ($max !== null) { - $this->assertFormElementValid($elementHierarchy, $max); - $this->assertFormElementNotValid( - $elementHierarchy, - $max + 1, - $validationMessages ? : Validator\Between::NOT_BETWEEN - ); - } - - if ($validationMessages === null) { - $validationMessages = [Validator\Digits::NOT_DIGITS]; - - if ($min > 0 || $max !== null) { - $validationMessages[] = Validator\Between::VALUE_NOT_NUMERIC; - } - - $this->assertFormElementNotValid($elementHierarchy, 'X', $validationMessages); - } - } - - /** - * Assert than a form element is a float input - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param int $min Minimum allowed value - * @param int $max Maximum allowed value - * - * @return void - */ - protected function assertFormElementFloat($elementHierarchy, $min = 0, $max = null) - { - $this->assertFormElementValid($elementHierarchy, $min); - $this->assertFormElementValid($elementHierarchy, $min + 0.1); - - if ($min > 0) { - $this->assertFormElementNotValid($elementHierarchy, $min - 0.1, Validator\Between::NOT_BETWEEN); - } - - if ($max !== null) { - $this->assertFormElementValid($elementHierarchy, $max); - $this->assertFormElementNotValid($elementHierarchy, $max + 0.1, Validator\LessThan::NOT_LESS_INCLUSIVE); - } - - $this->assertFormElementNotValid($elementHierarchy, 'X', [\Laminas\I18n\Validator\IsFloat::NOT_FLOAT]); - } - - /** - * Assert than a form element is a checkbox input - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementCheckbox($elementHierarchy, $uncheckedValue = 'N', $checkedValue = 'Y') - { - $this->assertFormElementValid($elementHierarchy, $checkedValue); - $this->assertFormElementValid($elementHierarchy, $uncheckedValue); - $this->assertFormElementNotValid($elementHierarchy, 'X', [Validator\InArray::NOT_IN_ARRAY]); - } - - /** - * Assert than a form element is a hidden input - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementHidden($elementHierarchy) - { - $this->assertFormElementRequired($elementHierarchy, false); - $this->assertFormElementAllowEmpty($elementHierarchy, true); - $this->assertFormElementValid($elementHierarchy, 'X'); - } - - /** - * Assert than a form element is a html input - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementHtml($elementHierarchy) - { - $this->assertFormElementRequired($elementHierarchy, false); - $this->assertFormElementAllowEmpty($elementHierarchy, true); - $this->assertFormElementValid($elementHierarchy, 'X'); - } - - /** - * Assert than a form element is a action button input - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementActionButton($elementHierarchy) - { - $this->assertFormElementRequired($elementHierarchy, false); - $this->assertFormElementAllowEmpty($elementHierarchy, true); - $this->assertFormElementValid($elementHierarchy, 'X'); - } - - /** - * Assert than a form element is a usernameCreate input - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementUsernameCreate($elementHierarchy) - { - $this->assertFormElementText($elementHierarchy, 4, 40); - - $this->assertFormElementValid($elementHierarchy, 'usr0001'); - $this->assertFormElementValid($elementHierarchy, 'USR0001'); // Should be transformed to lowercase - $this->assertFormElementValid($elementHierarchy, 'abcdefghijklmnoprstuvwxyz'); - $this->assertFormElementValid($elementHierarchy, 'ABCDEFGHIJKLMNOPRSTUVWXYZ'); // Should be transformed to lowercase - - $this->assertFormElementNotValid($elementHierarchy, '0usr0001', TransferValidator\UsernameCreate::USERNAME_INVALID); - - $this->assertFormElementNotValid($elementHierarchy, 'a¬bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a!bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a£bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a&bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a*bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a(bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a)bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a+bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a_bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a.bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a\bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a/bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a=bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a@bs', TransferValidator\UsernameCreate::USERNAME_INVALID); - } - - /** - * Assert than a form element is a username legacy input (supporting legacy usernames) - * - * @deprecated - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementUsername($elementHierarchy) - { - $this->assertFormElementText($elementHierarchy, 2, 40); - - $this->assertFormElementValid($elementHierarchy, '0123456789'); - $this->assertFormElementValid($elementHierarchy, 'abcdefghijklmnoprstuvwxyz'); - $this->assertFormElementValid($elementHierarchy, 'ABCDEFGHIJKLMNOPRSTUVWXYZ'); - $this->assertFormElementValid($elementHierarchy, '#$%\'+-/=?^_.@`|~",:;<>'); - - $this->assertFormElementNotValid($elementHierarchy, 'a¬b', TransferValidator\Username::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a!b', TransferValidator\Username::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a£b', TransferValidator\Username::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a&b', TransferValidator\Username::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a*b', TransferValidator\Username::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a(b', TransferValidator\Username::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a)b', TransferValidator\Username::USERNAME_INVALID); - $this->assertFormElementNotValid($elementHierarchy, 'a b', TransferValidator\Username::USERNAME_INVALID); - } - - /** - * Assert than a form element is an email address - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementEmailAddress($elementHierarchy) - { - $this->assertFormElementValid($elementHierarchy, 'valid@email.com'); - $this->assertFormElementValid( - $elementHierarchy, - '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890@'. - '123456789012345678901234567890123456789012345678901234567890.com' - ); - // total length greater than 254 - $this->assertFormElementNotValid( - $elementHierarchy, - '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890@'. - '123456789012345678901234567890123456789012345678901234567890.'. - '123456789012345678901234567890123456789012345678901234567890.'. - '123456789012345678901234567890123456789012345678901234567890.com', - TransferValidator\EmailAddress::ERROR_INVALID - ); - // domain parts max greate than 63 chars - $this->assertFormElementNotValid( - $elementHierarchy, - '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'. - '@1234567890123456789012345678901234567890123456789012345678901234.com', - TransferValidator\EmailAddress::INVALID_FORMAT - ); - $this->assertFormElementNotValid( - $elementHierarchy, - '1234567890123456789012345678901234567890123456789012345678901', - TransferValidator\EmailAddress::INVALID_FORMAT - ); - } - - /** - * Assert than a form element is a postcode - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementPostcode($elementHierarchy) - { - $this->assertFormElementValid($elementHierarchy, 'LS9 6NF'); - $this->assertFormElementValid($elementHierarchy, 'ls9 6nf'); - $this->assertFormElementValid($elementHierarchy, 'ls96NF'); - $this->assertFormElementNotValid($elementHierarchy, 'not a postcode', Validator\StringLength::TOO_LONG); - } - - /** - * Assert than a form element is a phone - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementPhone($elementHierarchy) - { - $this->assertFormElementType($elementHierarchy, \Common\Form\Elements\InputFilters\Phone::class); - $this->assertFormElementValid($elementHierarchy, '0123456789'); - $this->assertFormElementValid($elementHierarchy, '+44123456789'); - $this->assertFormElementValid($elementHierarchy, '(0044)1234567889'); - $this->assertFormElementValid($elementHierarchy, '0123-456789'); - $this->assertFormElementNotValid($elementHierarchy, 'not a phone number', Validator\Regex::NOT_MATCH); - } - - /** - * Note for developers - * We are not really testing here. There is a custom validation on the - * frontend (mainly AJAX functionality). For this purpose there is no real - * use testing case. So we skip these searchPostcode elements. - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementPostcodeSearch($elementHierarchy) - { - $searchPostcodeElements = [ - 'postcode', - 'search', - 'addresses', - 'select', - 'manual-link', - ]; - - foreach ($searchPostcodeElements as $element) { - $elementToSkip = array_merge( - $elementHierarchy, - [ - $element, - ] - ); - - self::$testedElements[implode('.', $elementToSkip)] = true; - } - } - - /** - * Assert than a form element is a company number - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementCompanyNumber($elementHierarchy) - { - $this->assertFormElementText($elementHierarchy, 1, 8); - $this->assertFormElementNotValid($elementHierarchy, '#', \Laminas\I18n\Validator\Alnum::NOT_ALNUM); - } - - /** - * Assert than a form element is a company number type - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementCompanyNumberType($elementHierarchy) - { - $this->assertFormElementHtml(array_merge($elementHierarchy, ['description'])); - $this->assertFormElementCompanyNumber(array_merge($elementHierarchy, ['company_number'])); - $this->assertFormElementActionButton(array_merge($elementHierarchy, ['submit_lookup_company'])); - } - - /** - * Assert than a form element is a table - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementTable($elementHierarchy) - { - $this->assertFormElementType($elementHierarchy, \Common\Form\Elements\Types\Table::class); - } - - /** - * Assert than a form element is a NoRender - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementNoRender($elementHierarchy) - { - $this->assertFormElementRequired($elementHierarchy, false); - $this->assertFormElementAllowEmpty($elementHierarchy, true); - $this->assertFormElementType($elementHierarchy, \Common\Form\Elements\InputFilters\NoRender::class); - } - - /** - * Assert than a form element is an ActionLink - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementActionLink($elementHierarchy) - { - $this->assertFormElementRequired($elementHierarchy, false); - $this->assertFormElementAllowEmpty($elementHierarchy, true); - $this->assertFormElementType($elementHierarchy, \Common\Form\Elements\InputFilters\ActionLink::class); - } - - /** - * Assert than a form element is a MultipleFileUpload - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementMultipleFileUpload($elementHierarchy) - { - $fileCountElement = $fileElement = $messagesElement = $uploadElement = $elementHierarchy; - - $fileCountElement[] = 'fileCount'; - $this->assertFormElementRequired($fileCountElement, false); - $this->assertFormElementAllowEmpty($fileCountElement, true); - - $fileElement[] = 'file'; - $this->assertFormElementRequired($fileElement, false); - $this->assertFormElementAllowEmpty($fileElement, true); - $this->assertFormElementType($fileElement, \Common\Form\Elements\Types\AttachFilesButton::class); - - $messagesElement[] = '__messages__'; - $this->assertFormElementHidden($messagesElement); - - $uploadElement[] = 'upload'; - $this->assertFormElementType($uploadElement, \Common\Form\Elements\InputFilters\ActionButton::class); - $this->assertFormElementRequired($uploadElement, false); - - // FileUploadCountV2 validator - $this->assertFormElementValid($elementHierarchy, []); - $this->assertFormElementValid($elementHierarchy, ['fileCount' => 1, 'list' => [1]]); - $this->assertFormElementValid($elementHierarchy, ['fileCount' => 4, 'list' => [1, 2, 3, 4]]); - $this->assertFormElementNotValid( - $elementHierarchy, - ['fileCount' => 0], - 'fileCount' - ); - $this->assertFormElementNotValid( - $elementHierarchy, - ['fileCount' => 0, 'list' => []], - 'fileCount' - ); - $this->assertSame( - [ - 'fileCount' => [ - CommonValidator\FileUploadCountV2::TOO_FEW => 'Too few files uploaded', - ] - ], - $this->getFormMessages($elementHierarchy), - sprintf( - '"%s" form element with value "%s" error messages not as expected', - implode('.', $elementHierarchy), - print_r(['fileCount' => 0, 'list' => []], true) - ) - ); - } - - /** - * Assert than a form element is a VRM - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementVrm($elementHierarchy) - { - $this->assertFormElementValid($elementHierarchy, 'XX59 GTB'); - $this->assertFormElementValid($elementHierarchy, 'FOO1'); - $this->assertFormElementNotValid($elementHierarchy, 'FOO', 'invalid'); - $this->assertFormElementType($elementHierarchy, \Common\Form\Elements\Custom\VehicleVrm::class); - } - - /** - * Assert than a form element is a vehicle plated weight - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementVehiclePlatedWeight($elementHierarchy) - { - $this->assertFormElementNumber($elementHierarchy, 0, 999999); - $this->assertFormElementType($elementHierarchy, \Common\Form\Elements\Custom\VehiclePlatedWeight::class); - } - - /** - * Assert that a form element is a dynamic multi checkbox - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param bool $required Is the form element required - * - * @return void - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - protected function assertFormElementDynamicMultiCheckbox($elementHierarchy, $required = true) - { - $this->assertFormElementValid($elementHierarchy, 1); - $this->assertFormElementValid($elementHierarchy, '1'); - } - - /** - * Assert that a form element is a dynamic radio - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param bool $required Is the form element required - * - * @return void - */ - protected function assertFormElementDynamicRadio($elementHierarchy, $required = true) - { - $this->assertFormElementValid($elementHierarchy, 1); - $this->assertFormElementValid($elementHierarchy, '1'); - if ($required) { - $this->assertFormElementNotValid($elementHierarchy, 'X', Validator\InArray::NOT_IN_ARRAY); - } - } - - /** - * Assert that a form element is a dynamic select - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param bool $required Is the form element required - * - * @return void - */ - protected function assertFormElementDynamicSelect( - $elementHierarchy, - $required = true - ) { - $this->assertFormElementValid($elementHierarchy, 1); - $this->assertFormElementValid($elementHierarchy, '1'); - if ($required) { - //uncomment the following line once "prefer_form_input_filter": true has been removed from the forms - //$this->assertFormElementNotValid($elementHierarchy, 'X', Validator\InArray::NOT_IN_ARRAY); - } - } - - /** - * Assert that a form element is a month select input - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementMonthSelect($elementHierarchy) - { - $this->assertFormElementValid($elementHierarchy, ['month' => '2', 'year' => '1999']); - $this->assertFormElementNotValid( - $elementHierarchy, - ['month' => 'X', 'year' => '1999'], - [ - \Laminas\Validator\Regex::NOT_MATCH - ] - ); - $this->assertFormElementNotValid( - $elementHierarchy, - ['month' => '3', 'year' => 'XXXX'], - [ - \Laminas\Validator\Regex::NOT_MATCH - ] - ); - } - - /** - * Assert that a form element is a date input - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * - * @return void - */ - protected function assertFormElementDate($elementHierarchy, array $context = []) - { - $errorMessages = [ - \Common\Validator\Date::DATE_ERR_CONTAINS_STRING, - \Laminas\Validator\Date::INVALID_DATE - ]; - - $this->assertFormElementValid($elementHierarchy, ['day' => 1, 'month' => '2', 'year' => 1999], $context); - - $this->assertFormElementNotValid( - $elementHierarchy, - ['day' => 'X', 'month' => '2', 'year' => 1999], - $errorMessages, - $context - ); - - $this->assertFormElementNotValid( - $elementHierarchy, - ['day' => '1', 'month' => 'X', 'year' => 1999], - $errorMessages, - $context - ); - - $this->assertFormElementNotValid( - $elementHierarchy, - ['day' => 1, 'month' => 3, 'year' => 'XXXX'], - [ - \Common\Validator\Date::DATE_ERR_CONTAINS_STRING, - \Common\Validator\Date::DATE_ERR_YEAR_LENGTH, - Validator\Date::INVALID_DATE - ], - $context - ); - } - - /** - * Assert that a form element is a date time input. For any complex - * logic such as; `endDate` with contexts - use the individual methods. - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param bool|true $required Is this input required? Default is 'true' - * @param null $value Currently the default will be tomorrow's date - * - * @return void - */ - protected function assertFormElementDateTime(array $elementHierarchy, $required = true, $value = null) - { - if ($value === null) { - $currentDate = new \DateTimeImmutable('tomorrow'); - - // Date inputted will be exact time tomorrow. - $value = [ - 'year' => $currentDate->format('Y'), - 'month' => $currentDate->format('m'), - 'day' => $currentDate->format('j'), - 'hour' => $currentDate->format('h'), - 'minute' => $currentDate->format('i'), - 'second' => $currentDate->format('s'), - ]; - } - - $this->assertFormElementRequired($elementHierarchy, $required); - $this->assertFormElementDateTimeNotValidCheck($elementHierarchy); - $this->assertFormElementDateTimeValidCheck($elementHierarchy, $value); - } - - /** - * To avoid duplication, you can call this method separately and - * pass custom validation messages - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param array $validationMessages Specify if validation messages are expected to be different - * - * @return void - */ - protected function assertFormElementDateTimeNotValidCheck(array $elementHierarchy, $validationMessages = []) - { - if (empty($validationMessages)) { - $validationMessages = [ - \Common\Validator\Date::DATE_ERR_CONTAINS_STRING, - \Common\Validator\Date::DATE_ERR_YEAR_LENGTH, - Validator\Date::INVALID_DATE, - ]; - } - - // String in values - $this->assertFormElementNotValid( - $elementHierarchy, - [ - 'year' => 'XXXX', - 'month' => 'XX', - 'day' => 'XX', - 'hour' => 'XX', - 'minute' => 'XX', - 'second' => 'XX', - ], - $validationMessages - ); - - $validationMessages = [ - Validator\Date::INVALID_DATE - ]; - - // Invalid date - $this->assertFormElementNotValid( - $elementHierarchy, - [ - 'year' => 2000, - 'month' => 15, - 'day' => 35, - 'hour' => 27, - 'minute' => 100, - 'second' => 5000, - ], - $validationMessages - ); - } - - /** - * Developer note; - * Value is expected to be an array with 'year', 'month', 'day', 'hour', 'minute', 'second' - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param null|mixed $value Default date is tomorrows date. Can be changed if future not allowed - * @param array $context Context is normally used for startDate/endDates - * - * @return void - */ - protected function assertFormElementDateTimeValidCheck(array $elementHierarchy, $value = null, array $context = []) - { - if ($value === null) { - $currentDate = new \DateTimeImmutable('tomorrow'); - - // Date inputted will be exact time tomorrow. - $value = [ - 'year' => $currentDate->format('Y'), - 'month' => $currentDate->format('m'), - 'day' => $currentDate->format('j'), - 'hour' => $currentDate->format('h'), - 'minute' => $currentDate->format('i'), - 'second' => $currentDate->format('s'), - ]; - } - - // Valid scenario - $this->assertFormElementValid($elementHierarchy, $value, $context); - } - - /** - * Assert whether a form element allows empty - * - * @param array $elementHierarchy Form element name eg ['fields','numOfCows'] - * @param bool $allowEmpty if true, form element allows empty - * @param array $context Context - * @param string|array $validationMessages A single or an array of expected validation messages keys - * - * @return void - */ - protected function assertFormElementAllowEmpty( - $elementHierarchy, - $allowEmpty, - $context = [], - $validationMessages = null - ) { - if ($allowEmpty === true) { - $this->assertFormElementValid($elementHierarchy, '', $context); - } else { - $this->assertFormElementNotValid( - $elementHierarchy, - '', - $validationMessages ? : Validator\NotEmpty::IS_EMPTY, - $context - ); - } - } - - /** - * Assert whether a form element is required - * - * This method checks the value, but 'required' is about checking for the key. - * New method is: assertFormElementIsRequired. You will notice some of the field validations - * will fail after using the new method. In this scenario, check the requirement of the field - * and check for any clashes. AllowEmpty(true) and Required(true) fields make no sense. - * Resource: http://stackoverflow.com/questions/7242703/zend-framework-how-to-allow-empty-field-for-form-element - * - * @param string $elementHierarchy Form element name - * @param bool $required true, form element is required - * @param string|array $validationMessages A single or an array of expected validation messages keys - * - * @return void - * @deprecated - */ - protected function assertFormElementRequired($elementHierarchy, $required, $validationMessages = null) - { - if ($required === true) { - $this->assertFormElementNotValid( - $elementHierarchy, - null, - $validationMessages ? : Validator\NotEmpty::IS_EMPTY - ); - } else { - $this->assertFormElementValid($elementHierarchy, null); - } - } - - /** - * New method used apart from assertFormElementRequired() - * Avoid using assertFormElementRequired() - * - * @param array $elementHierarchy Element hierarchy as array (including fieldsets) - * @param bool|true $required true, form element is required - * @param array $expectedValidationMessages A single or an array of expected validation messages keys - * - * @return void - */ - protected function assertFormElementIsRequired( - $elementHierarchy, - $required = true, - $expectedValidationMessages = [Validator\NotEmpty::IS_EMPTY] - ) { - self::$testedElements[implode('.', $elementHierarchy)] = true; - - // set no data to get the response from the Validation Groups - $this->setData($elementHierarchy, null); - $this->setValidationGroup($elementHierarchy); - - $this->sut->isValid(); - - $formErrorMessages = $this->sut->getMessages(); - $elementErrorMessages = $this->getElementMessages( - $elementHierarchy, - $formErrorMessages - ); - - if ($required === true) { - $this->assertTrue((!empty($elementErrorMessages))); - $this->assertEquals( - array_keys($elementErrorMessages), - $expectedValidationMessages - ); - } else { - $this->assertFalse($elementErrorMessages); - } - } - - /** - * Test if service name as expected - * - * @param $elementHierarchy - * @param $serviceName - * - * @throws \Exception - */ - public function assertServiceEquals($elementHierarchy, $serviceName) - { - - $element = $this->getFormElement($elementHierarchy); - $this->assertContains('service_name', array_keys($element->getOptions()), "service name option not set"); - $this->assertEquals($element->getOption('service_name'), $serviceName, "service_name option does not match class name provided"); - } - - /** - * Get messages for specified element - * - * @param array $elementHierarchy Element and/or Fieldset hierarchy - * @param array $formErrorMessages Error messages from Form service - * - * @return array|false - */ - private function getElementMessages($elementHierarchy, $formErrorMessages) - { - $elementOrFieldsetName = (is_array($elementHierarchy))? - current($elementHierarchy) : next($elementHierarchy); - - if (isset($formErrorMessages[$elementOrFieldsetName]) && - is_array($formErrorMessages[$elementOrFieldsetName]) - ) { - // are we at the end? - if (next($elementHierarchy) === false) { - return $formErrorMessages[$elementOrFieldsetName]; - } - - return $this->getElementMessages( - $elementHierarchy, - $formErrorMessages[$elementOrFieldsetName] - ); - } - - return false; - } - - /** - * Check that tests exists for all form elements - * This needs to be the last test that runs - * - * @param string $elementName Element name to test - * - * @dataProvider dataProviderAllElementNames - * @doesNotPerformAssertions - * - * @return void - */ - public function testMissingTest($elementName) - { - if (!array_key_exists($elementName, self::$testedElements)) { - $this->markTestIncomplete(sprintf('"%s" form element not tested', $elementName)); - } - } - - /** - * Data provider, a full list of element names on this form - * - * @return array - */ - public function dataProviderAllElementNames() - { - $elementList = $this->getElementList($this->getForm()); - foreach ($elementList as &$elementName) { - $elementName = [$elementName]; - } - return $elementList; - } - - /** - * Get a list of all form elements - * - * @param \Laminas\Form\Fieldset $fieldsset Fieldset - * @param string $prefix Prefix - * - * @return array eg ['fields.numOfCows', 'fields.numOfDogs'] - */ - private function getElementList(\Laminas\Form\Fieldset $fieldsset, $prefix = '') - { - $elementList = []; - /** @var \Laminas\Form\Element $element */ - foreach ($fieldsset->getFieldsets() as $childFieldSet) { - $elementList = array_merge( - $elementList, - $this->getElementList( - $childFieldSet, - $prefix . $childFieldSet->getName() .'.' - ) - ); - } - foreach ($fieldsset->getElements() as $element) { - $elementList[] = $prefix . $element->getName(); - } - return $elementList; - } - - protected function getElementByHierarchy($elementHierarchy): ElementInterface - { - $elementOrFieldSet = $this->sut; - foreach($elementHierarchy as $name) { - $elementOrFieldSet = $elementOrFieldSet->get($name); - } - return $elementOrFieldSet; - } -} diff --git a/test/Permits/src/Form/Model/Form/DeclineApplicationFormTest.php b/test/Permits/src/Form/Model/Form/DeclineApplicationFormTest.php deleted file mode 100644 index 7a0dbe44d..000000000 --- a/test/Permits/src/Form/Model/Form/DeclineApplicationFormTest.php +++ /dev/null @@ -1,40 +0,0 @@ -assertFormElementRequired($element, true); - $this->assertFormElementAllowEmpty($element, false); - $this->assertFormElementType($element, "\Common\Form\Elements\InputFilters\SingleCheckbox"); - - $this->assertFormElementValid($element, '1'); - $this->assertFormElementNotValid($element, 'No', [Validator\Identical::NOT_SAME]); - $this->assertFormElementNotValid($element, 'X', [Validator\Identical::NOT_SAME]); - } - - public function testSubmitDecline() - { - $element = ['Submit', 'SubmitButton']; - $this->assertFormElementActionButton($element); - $this->assertFormElementType($element, ActionButton::class); - } -} diff --git a/test/Permits/src/Form/Model/Form/LicenceSelectionFormTest.php b/test/Permits/src/Form/Model/Form/LicenceSelectionFormTest.php deleted file mode 100644 index 55eb5a4cd..000000000 --- a/test/Permits/src/Form/Model/Form/LicenceSelectionFormTest.php +++ /dev/null @@ -1,34 +0,0 @@ -assertFormElementAllowEmpty($element, false); - $this->assertFormElementType($element, Radio::class); - } - - public function testSubmit() - { - $element = ['Submit', 'SubmitButton']; - $this->assertFormElementActionButton($element); - $this->assertFormElementType($element, ActionButton::class); - } -}