Skip to content

Commit

Permalink
Merge pull request #21715 from totten/master-no-test
Browse files Browse the repository at this point in the history
flexmailer - Update `[CiviMail Draft]` prefix to match BAO behavior
  • Loading branch information
eileenmcnaughton authored Oct 4, 2021
2 parents 165db98 + e2b2d8a commit 558b41a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions ext/flexmailer/src/API/MailingPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,23 @@ public static function preview($apiRequest) {
$contactID = \CRM_Utils_Array::value('contact_id', $params,
\CRM_Core_Session::singleton()->get('userID'));

$job = new \CRM_Mailing_BAO_MailingJob();
$job = new class extends \CRM_Mailing_BAO_MailingJob {

public function insert() {
throw new \RuntimeException('MailingJob is just a preview. It cannot be saved.');
}

public function update($dataObject = FALSE) {
throw new \RuntimeException('MailingJob is just a preview. It cannot be saved.');
}

public function save($hook = TRUE) {
throw new \RuntimeException('MailingJob is just a preview. It cannot be saved.');
}

};
$job->mailing_id = $mailing->id ?: NULL;
$job->is_test = 1;
$job->status = 'Complete';
// $job->save();

$flexMailer = new FlexMailer(array(
'is_preview' => TRUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testMailerPreview(): void {
$this->assertMaxIds($maxIDs);

$previewResult = $result['values'][$result['id']]['api.Mailing.preview'];
$this->assertEquals("[CiviMail Draft] Hello $displayName",
$this->assertEquals("Hello $displayName",
$previewResult['values']['subject']);

$this->assertStringContainsString("This is $displayName", $previewResult['values']['body_text']);
Expand Down Expand Up @@ -112,7 +112,7 @@ public function testMailerPreviewWithoutId(): void {
$previewResult = $this->callAPISuccess('mailing', 'preview', $params);
$this->assertMaxIds($maxIDs);

$this->assertEquals("[CiviMail Draft] Hello $displayName",
$this->assertEquals("Hello $displayName",
$previewResult['values']['subject']);

$this->assertStringContainsString("This is $displayName", $previewResult['values']['body_text']);
Expand Down

0 comments on commit 558b41a

Please sign in to comment.