* All local rules are added near the element
*
* @param $fields
- * @param $files
- * @param $errors
*
* @return bool|array
- * @see valid_date
*/
- public static function formRule($fields, $files, $errors) {
+ public static function formRule($fields) {
$errors = [];
// Validate start/end date inputs
<?php
-/*
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC. All rights reserved. |
- | |
- | This work is published under the GNU AGPLv3 license with some |
- | permitted exceptions and without any warranty. For full license |
- | and copyright information, see https://civicrm.org/licensing |
- +--------------------------------------------------------------------+
- */
-/**
- * Test APIv3 civicrm_contribute_* functions
- *
- * @package CiviCRM_APIv3
- * @subpackage API_Contribution
- * @group headless
- */
class CRM_Campaign_Form_CampaignTest extends CiviUnitTestCase {
/**
- * Test the submit function on the contribution page.
+ * Set up a correct array of form values.
+ *
+ * @return array
+ */
+ private function getCorrectFormFields($thousandSeparator) {
+ return [
+ 'goal_revenue' => '$10' . $thousandSeparator . '000',
+ 'is_active' => 1,
+ 'title' => 'Test Campaign',
+ 'start_date' => date('Y-m-d'),
+ 'includeGroups' => [],
+ 'custom' => [],
+ 'campaign_type_id' => 1,
+ ];
+ }
+
+ /**
+ * Test the submit function on the campaign page.
*
* @param string $thousandSeparator
*
$this->createLoggedInUser();
$form = new CRM_Campaign_Form_Campaign();
$form->_action = CRM_Core_Action::ADD;
- $result = CRM_Campaign_Form_Campaign::Submit([
- 'goal_revenue' => '$10' . $thousandSeparator . '000',
- 'is_active' => 1,
- 'title' => 'Test Campaign',
- 'start_date' => date('Y-m-d'),
- 'includeGroups' => [],
- 'custom' => [],
- 'campaign_type_id' => 1,
- ], $form);
+ $values = $this->getCorrectFormFields($thousandSeparator);
+ $result = CRM_Campaign_Form_Campaign::Submit($values, $form);
$campaign = $this->callAPISuccess('campaign', 'get', ['id' => $result['id']]);
$this->assertEquals('10000.00', $campaign['values'][$campaign['id']]['goal_revenue']);
}
+ /**
+ * Test end date not allowed with only 'time' part.
+ *
+ * @param string $thousandSeparator
+ *
+ * @dataProvider getThousandSeparators
+ */
+ public function testEndDateWithoutDateNotAllowed($thousandSeparator) {
+ $this->setCurrencySeparators($thousandSeparator);
+ $values = $this->getCorrectFormFields($thousandSeparator);
+ $values['end_date'] = '00:01';
+ $validationResult = \CRM_Campaign_Form_Campaign::formRule($values);
+ $this->assertArrayHasKey('end_date', $validationResult);
+ }
+
+ /**
+ * Test end date must be after start date.
+ *
+ * @param string $thousandSeparator
+ *
+ * @dataProvider getThousandSeparators
+ */
+ public function testEndDateBeforeStartDateNotAllowed($thousandSeparator) {
+ $this->setCurrencySeparators($thousandSeparator);
+ $values = $this->getCorrectFormFields($thousandSeparator);
+ $values['end_date'] = '1900-01-01 00:00';
+ $validationResult = \CRM_Campaign_Form_Campaign::formRule($values);
+ $this->assertArrayHasKey('end_date', $validationResult);
+ }
+
}
--- /dev/null
+<?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);
+ }
+
+}
--- /dev/null
+<?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);
+ }
+
+}
--- /dev/null
+<?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);
+ }
+
+}
'financial_type_id' => $this->getFinancialTypeId('Event Fee'),
'visibility_id' => $this->visibilityOptionsKeys['public'],
'price' => 10,
+ 'active_on' => date('Y-m-d'),
+ 'expire_on' => '',
];
for ($index = 1; $index <= CRM_Price_Form_Field::NUM_OPTION; $index++) {
], $errors);
}
+ /**
+ * Test end date not allowed with only 'time' part.
+ */
+ public function testEndDateWithoutDateNotAllowed() {
+ $form = new CRM_Price_Form_Field();
+ $form->_action = CRM_Core_Action::ADD;
+ $values = $this->initializeFieldParameters([
+ 'expire_on' => '00:01',
+ ]);
+ $validationResult = \CRM_Price_Form_Field::formRule($values, [], $form);
+ $this->assertArrayHasKey('expire_on', $validationResult);
+ }
+
+ /**
+ * Test end date must be after start date.
+ */
+ public function testEndDateBeforeStartDateNotAllowed() {
+ $form = new CRM_Price_Form_Field();
+ $form->_action = CRM_Core_Action::ADD;
+ $values = $this->initializeFieldParameters([
+ 'expire_on' => '1900-01-01 00:00',
+ ]);
+ $validationResult = \CRM_Price_Form_Field::formRule($values, [], $form);
+ $this->assertArrayHasKey('expire_on', $validationResult);
+ }
+
}