// one being generated so we generate one first.
$originalRequest = $_REQUEST;
$qfKey = $_REQUEST['qfKey'] ?? NULL;
+ $_REQUEST['id'] = $params['id'];
+ $requestMethod = $_SERVER['REQUEST_METHOD'] ?? NULL;
+ // This is set to POST in a test - (probably cos we didn't have full form
+ // testing when it was written). It needs to be get for long enough to
+ // get past the constructor.
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+ $form = new CRM_Contribute_Form_Contribution_Main();
+ $form->controller = new CRM_Contribute_Controller_Contribution();
+ if ($requestMethod) {
+ $_SERVER['REQUEST_METHOD'] = $requestMethod;
+ }
+ $form->controller->setStateMachine(new CRM_Contribute_StateMachine_Contribution($form->controller));
+ // The submitted values are on the Main form.
+ $_SESSION['_' . $form->controller->_name . '_container']['values']['Main'] = $params;
if (!$qfKey) {
- $_REQUEST['qfKey'] = CRM_Core_Key::get('CRM_Core_Controller', TRUE);
+ $_REQUEST['qfKey'] = CRM_Core_Key::get('CRM_Contribute_Controller_Contribution', TRUE);
}
- $form = new CRM_Contribute_Form_Contribution_Main();
- $form->controller = new CRM_Core_Controller();
- $form->set('id', $params['id']);
$form->preProcess();
$errors = CRM_Contribute_Form_Contribution_Main::formRule($params, [], $form);
if ($errors === TRUE) {
+--------------------------------------------------------------------+
*/
+use Civi\Test\ContributionPageTestTrait;
+
/**
* Test CRM_Contribute_Form_Contribution_ThankYou
*
*/
class CRM_Contribute_Form_Contribution_ThankYouTest extends CiviUnitTestCase {
+ use ContributionPageTestTrait;
+
/**
* Clean up DB.
*/
/**
* Get CRM_Contribute_Form_Contribution_ThankYou form with attached contribution.
*
- * @param $paymentProcessorID
+ * @param int $paymentProcessorID
* @param bool $withPendingContribution
* @param bool $isTestContribution
* @return CRM_Contribute_Form_Contribution_ThankYou
*/
- private function getThankYouFormWithContribution($paymentProcessorID, $withPendingContribution = FALSE, $isTestContribution = FALSE) {
+ private function getThankYouFormWithContribution(int $paymentProcessorID, $withPendingContribution = FALSE, $isTestContribution = FALSE) {
$pageContribution = $this->getPageContribution((($withPendingContribution) ? 2 : 1), $isTestContribution);
+ if (!isset($this->ids['ContributionPage'])) {
+ $this->contributionPageCreatePaid(['payment_processor' => $paymentProcessorID])['id'];
+ }
$form = $this->getThankYouForm();
$form->_lineItem = [];
$form->_bltID = 5;
$form->_params['email-5'] = 'demo@example.com';
$form->_params['payment_processor_id'] = $paymentProcessorID;
if ($isTestContribution) {
- $form->_mode = 'test';
+ $_REQUEST['action'] = 1024;
}
+
$form->_values = [
'custom_pre_id' => NULL,
'custom_post_id' => NULL,
* @return CRM_Contribute_Form_Contribution_ThankYou
*/
private function getThankYouForm() {
- $form = new CRM_Contribute_Form_Contribution_ThankYou();
- $_SERVER['REQUEST_METHOD'] = 'GET';
- $form->controller = new CRM_Contribute_Controller_Contribution();
+ $form = $this->getFormObject('CRM_Contribute_Form_Contribution_ThankYou', [], ['id' => $this->getContributionPageID()]);
+ $form->preProcess();
return $form;
}