* Process the form after the input has been submitted and validated.
*
* @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
public function postProcess() {
$formValues = $this->controller->exportValues($this->getName());
CRM_Contact_Form_Task_PDFLetterCommon::createActivities($this, $html_message, $contactIds, CRM_Utils_Array::value('subject', $formValues, ts('Thank you letter')), CRM_Utils_Array::value('campaign_id', $formValues), $contactHtml);
$html = array_diff_key($html, $emailedHtml);
- if (!empty($formValues['is_unit_test'])) {
- return $html;
- }
-
//CRM-19761
if (!empty($html)) {
// Set the filename for the PDF using the Activity Subject, if defined. Remove unwanted characters and limit the length to 200 characters.
'marginBottom' => self::toTwip(CRM_Core_BAO_PdfFormat::getValue('margin_bottom', $format), $metric),
'marginLeft' => self::toTwip(CRM_Core_BAO_PdfFormat::getValue('margin_left', $format), $metric),
];
+ if (CIVICRM_UF === 'UnitTests' && headers_sent()) {
+ // Streaming content will 'die' in unit tests unless ob_start()
+ // has been called.
+ throw new CRM_Core_Exception_PrematureExitException('_html2doc called', [
+ 'html' => $pages,
+ 'fileName' => $fileName,
+ 'pageStyle' => $pageStyle,
+ ]);
+ }
$ext = pathinfo($fileName, PATHINFO_EXTENSION);
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
- * @throws \CiviCRM_API3_Exception
*/
public function tearDown(): void {
CRM_Utils_Token::$_tokens['contribution'] = NULL;
$date = CRM_Utils_Date::getToday();
$displayDate = CRM_Utils_Date::customFormat($date, $format);
- $html = $form->postProcess();
+ try {
+ $form->postProcess();
+ $this->fail('Exception expected');
+ }
+ catch (CRM_Core_Exception_PrematureExitException $e) {
+ $html = $e->errorData['html'];
+ }
$expectedValues = [
'Hello Anthony',
'$ 100.00',
];
foreach ($expectedValues as $val) {
- $this->assertTrue(strpos($html[$contributionId], $val) !== 0);
+ $this->assertNotSame(strpos($html[$contributionId], $val), 0);
}
}
}
$this->_individualId2 = $this->individualCreate();
$htmlMessage = "{aggregate.rendered_token}";
$formValues = [
- 'is_unit_test' => TRUE,
'group_by' => 'contact_id',
'html_message' => $htmlMessage,
'email_options' => 'both',
$form = $this->getFormObject('CRM_Contribute_Form_Task_PDFLetter', $formValues);
$form->setContributionIds($contributionIDs);
- $html = $form->postProcess();
+ try {
+ $form->postProcess();
+ $this->fail('exception expected.');
+ }
+ catch (CRM_Core_Exception_PrematureExitException $e) {
+ $html = $e->errorData['html'];
+ }
$this->assertEquals("<table border='1' cellpadding='2' cellspacing='0' class='table'>
<tbody>
<tr>
/**
* Implements civicrm_tokens().
*/
- public function hook_tokens(&$tokens) {
+ public function hook_tokens(&$tokens): void {
$this->hookTokensCalled++;
$tokens['aggregate'] = ['rendered_token' => 'rendered_token'];
}
* @param array $tokens
* @param null $context
*/
- public function hook_aggregateTokenValues(&$values, $contactIDs, $job = NULL, $tokens = [], $context = NULL) {
+ public function hook_aggregateTokenValues(array &$values, $contactIDs, $job = NULL, $tokens = [], $context = NULL) {
foreach ($contactIDs as $contactID) {
CRM_Core_Smarty::singleton()->assign('messageContactID', $contactID);
$values[$contactID]['aggregate.rendered_token'] = CRM_Core_Smarty::singleton()
*
* @dataProvider isHtmlTokenInTableCellProvider
*/
- public function testIsHtmlTokenInTableCell($token, $entity, $textToSearch, $expected) {
+ public function testIsHtmlTokenInTableCell($token, $entity, $textToSearch, $expected): void {
$this->assertEquals($expected,
CRM_Contribute_Form_Task_PDFLetter::isHtmlTokenInTableCell($token, $entity, $textToSearch)
);
}
/**
+ * @param array $contributionParams
+ *
* @return mixed
- * @throws \CRM_Core_Exception
- * @throws \CiviCRM_API3_Exception
*/
- protected function createContribution($contributionParams = []) {
+ protected function createContribution(array $contributionParams = []) {
$contributionParams = array_merge([
'contact_id' => $this->individualCreate(),
'total_amount' => 100,