From 8093086b2ad4b32840d04455871197927e12585a Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 9 May 2017 21:40:42 +1200 Subject: [PATCH] Towards testing CRM-19876 This is a commit to establish a testing path for the EmailCommon form. Nothing other than the absence of fatals is currently tested --- CRM/Contact/Form/Task/EmailCommon.php | 12 ++++++++++ .../CRM/Contact/Form/Task/EmailCommonTest.php | 24 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/CRM/Contact/Form/Task/EmailCommon.php b/CRM/Contact/Form/Task/EmailCommon.php index b9217068cd..832125b56b 100644 --- a/CRM/Contact/Form/Task/EmailCommon.php +++ b/CRM/Contact/Form/Task/EmailCommon.php @@ -414,6 +414,18 @@ class CRM_Contact_Form_Task_EmailCommon { // check and ensure that $formValues = $form->controller->exportValues($form->getName()); + self::submit($form, $formValues); + } + + /** + * Submit the form values. + * + * This is also accessible for testing. + * + * @param CRM_Core_Form $form + * @param array $formValues + */ + public static function submit(&$form, $formValues) { self::saveMessageTemplate($formValues); $from = CRM_Utils_Array::value($formValues['fromEmailAddress'], $form->_emails); diff --git a/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php b/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php index 10bd5d2ee0..ad5a510d22 100644 --- a/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php +++ b/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php @@ -55,4 +55,28 @@ class CRM_Contact_Form_Task_EmailCommonTest extends CiviUnitTestCase { $this->assertEquals('"Seamus Lee" ', $optionValue['values'][$this->_optionValue['id']]['label']); } + public function testPostProcess() { + $this->createLoggedInUser(); + $form = new CRM_Contact_Form_Task_Email(); + $_SERVER['REQUEST_METHOD'] = 'GET'; + $form->controller = new CRM_Core_Controller(); + + for ($i = 0; $i < 27; $i++) { + $email = 'spy' . $i . '@secretsquirrels.com'; + $contactID = $this->individualCreate(array('email' => $email)); + $form->_contactIds[$contactID] = $contactID; + $form->_toContactEmails[$this->callAPISuccessGetValue('Email', array('return' => 'id', 'email' => $email))] = $email; + } + $form->_allContactIds = $form->_toContactIds = $form->_contactIds; + $form->_emails = array(1 => 'mickey@mouse.com'); + $form->_fromEmails = array(1 => 'mickey@mouse.com'); + + CRM_Contact_Form_Task_EmailCommon::buildQuickForm($form); + + CRM_Contact_Form_Task_EmailCommon::submit($form, array( + 'fromEmailAddress' => 1, + 'subject' => 'Really interesting stuff', + )); + } + } -- 2.25.1