-
-
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.
dev/core#2846 Tests for start/end date form validation
- Loading branch information
1 parent
9594223
commit a726c90
Showing
5 changed files
with
196 additions
and
26 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
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
<?php | ||
|
||
class CRM_Contribute_Form_ContributionPage_SettingsTest extends CiviUnitTestCase { | ||
|
||
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['registration_end_date'] = '00:01'; | ||
$form = new CRM_Contribute_Form_ContributionPage_Settings(); | ||
$validationResult = \CRM_Contribute_Form_ContributionPage_Settings::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_Contribute_Form_ContributionPage_Settings(); | ||
$validationResult = \CRM_Contribute_Form_ContributionPage_Settings::formRule($values, [], $form); | ||
$this->assertArrayHasKey('registration_end_date', $validationResult); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
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,44 @@ | ||
<?php | ||
|
||
class CRM_Event_Form_ManageEvent_EventInfoTest extends CiviUnitTestCase { | ||
|
||
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); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
<?php | ||
|
||
class CRM_Event_Form_ManageEvent_RegistrationTest extends CiviUnitTestCase { | ||
|
||
// @todo More fields are required for formRule to return no errors | ||
private function getCorrectFormFields() { | ||
return [ | ||
'is_online_registration' => 1, | ||
'registration_start_date' => date('Y-m-d'), | ||
'registration_end_date' => date('Y-m-d', time() + 86400), | ||
]; | ||
} | ||
|
||
/** | ||
* 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); | ||
} | ||
|
||
} |
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