-
-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21513 from JKingsnorth/core-2846-1-improve-start-…
…end-date-validation dev/core#2846 Towards validation of start and end dates. Forms.
- Loading branch information
Showing
11 changed files
with
302 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/phpunit/CRM/Contribute/Form/ContributionPage/SettingsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
class CRM_Contribute_Form_ContributionPage_SettingsTest extends CiviUnitTestCase { | ||
|
||
/** | ||
* Set up a correct array of form values. | ||
* | ||
* @return array | ||
*/ | ||
private function getCorrectFormFields() { | ||
return [ | ||
'title' => 'Test contribution page', | ||
'financial_type_id' => 1, | ||
'start_date' => date('Y-m-d'), | ||
'end_date' => date('Y-m-d', time() + 86400), | ||
]; | ||
} | ||
|
||
/** | ||
* Test correct form submission. | ||
*/ | ||
public function testValidFormSubmission() { | ||
$values = $this->getCorrectFormFields(); | ||
$form = new CRM_Contribute_Form_ContributionPage_Settings(); | ||
$validationResult = \CRM_Contribute_Form_ContributionPage_Settings::formRule($values, [], $form); | ||
$this->assertEmpty($validationResult); | ||
} | ||
|
||
/** | ||
* Test end date not allowed with only 'time' part. | ||
*/ | ||
public function testEndDateWithoutDateNotAllowed() { | ||
$values = $this->getCorrectFormFields(); | ||
$values['end_date'] = '00:01'; | ||
$form = new CRM_Contribute_Form_ContributionPage_Settings(); | ||
$validationResult = \CRM_Contribute_Form_ContributionPage_Settings::formRule($values, [], $form); | ||
$this->assertArrayHasKey('end_date', $validationResult); | ||
} | ||
|
||
/** | ||
* Test end date must be after start date. | ||
*/ | ||
public function testEndDateBeforeStartDateNotAllowed() { | ||
$values = $this->getCorrectFormFields(); | ||
$values['end_date'] = '1900-01-01 00:00'; | ||
$form = new CRM_Contribute_Form_ContributionPage_Settings(); | ||
$validationResult = \CRM_Contribute_Form_ContributionPage_Settings::formRule($values, [], $form); | ||
$this->assertArrayHasKey('end_date', $validationResult); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
tests/phpunit/CRM/Event/Form/ManageEvent/EventInfoTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
class CRM_Event_Form_ManageEvent_EventInfoTest extends CiviUnitTestCase { | ||
|
||
/** | ||
* Set up a correct array of form values. | ||
* | ||
* @return array | ||
*/ | ||
private function getCorrectFormFields() { | ||
return [ | ||
'title' => 'A test event', | ||
'event_type_id' => 1, | ||
'default_role_id' => 1, | ||
'start_date' => date('Y-m-d'), | ||
'end_date' => date('Y-m-d', time() + 86400), | ||
]; | ||
} | ||
|
||
/** | ||
* Test correct form submission. | ||
*/ | ||
public function testValidFormSubmission() { | ||
$values = $this->getCorrectFormFields(); | ||
$validationResult = \CRM_Event_Form_ManageEvent_EventInfo::formRule($values); | ||
$this->assertEmpty($validationResult); | ||
} | ||
|
||
/** | ||
* Test end date not allowed with only 'time' part. | ||
*/ | ||
public function testEndDateWithoutDateNotAllowed() { | ||
$values = $this->getCorrectFormFields(); | ||
$values['end_date'] = '00:01'; | ||
$validationResult = \CRM_Event_Form_ManageEvent_EventInfo::formRule($values); | ||
$this->assertArrayHasKey('end_date', $validationResult); | ||
} | ||
|
||
/** | ||
* Test end date must be after start date. | ||
*/ | ||
public function testEndDateBeforeStartDateNotAllowed() { | ||
$values = $this->getCorrectFormFields(); | ||
$values['end_date'] = '1900-01-01 00:00'; | ||
$validationResult = \CRM_Event_Form_ManageEvent_EventInfo::formRule($values); | ||
$this->assertArrayHasKey('end_date', $validationResult); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
tests/phpunit/CRM/Event/Form/ManageEvent/RegistrationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
class CRM_Event_Form_ManageEvent_RegistrationTest extends CiviUnitTestCase { | ||
|
||
/** | ||
* Set up a correct array of form values. | ||
* @todo More fields are required for formRule to return no errors | ||
* | ||
* @return array | ||
*/ | ||
private function getCorrectFormFields() { | ||
return [ | ||
'is_online_registration' => 1, | ||
'registration_start_date' => date('Y-m-d'), | ||
'registration_end_date' => date('Y-m-d', time() + 86400), | ||
'is_email_confirm' => 0, | ||
'confirm_title' => 'Confirm your registration', | ||
'thankyou_title' => 'Thank you for your registration', | ||
]; | ||
} | ||
|
||
/** | ||
* Test end date not allowed with only 'time' part. | ||
*/ | ||
public function testEndDateWithoutDateNotAllowed() { | ||
$values = $this->getCorrectFormFields(); | ||
$values['registration_end_date'] = '00:01'; | ||
$form = new CRM_Event_Form_ManageEvent_Registration(); | ||
$validationResult = \CRM_Event_Form_ManageEvent_Registration::formRule($values, [], $form); | ||
$this->assertArrayHasKey('registration_end_date', $validationResult); | ||
} | ||
|
||
/** | ||
* Test end date must be after start date. | ||
*/ | ||
public function testEndDateBeforeStartDateNotAllowed() { | ||
$values = $this->getCorrectFormFields(); | ||
$values['registration_end_date'] = '1900-01-01 00:00'; | ||
$form = new CRM_Event_Form_ManageEvent_Registration(); | ||
$validationResult = \CRM_Event_Form_ManageEvent_Registration::formRule($values, [], $form); | ||
$this->assertArrayHasKey('registration_end_date', $validationResult); | ||
} | ||
|
||
} |
Oops, something went wrong.