From d3c596a443f498b1dfe67dfc48b0de3947acfdcb Mon Sep 17 00:00:00 2001 From: nathangray Date: Sat, 21 Oct 2017 10:40:43 +0200 Subject: [PATCH] - Add a parameter to pass in the class of the notification to use so we can pass in a test one - Explicitly tell notification what type of message (plain or html) we're giving it --- api/src/Storage/Tracking.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/api/src/Storage/Tracking.php b/api/src/Storage/Tracking.php index 73fe8d4cfd..21d4d1e584 100644 --- a/api/src/Storage/Tracking.php +++ b/api/src/Storage/Tracking.php @@ -129,6 +129,15 @@ abstract class Tracking */ var $notify_current_user = false; + /** + * Class to use for generating the notifications. + * Normally, just the notification class but for testing we pass in a mocked + * class + * + * @var notification_class + */ + protected $notification_class = notifications::class; + /** * Array with error-messages if track($data,$old) returns false * @@ -190,7 +199,7 @@ abstract class Tracking * @param string $cf_app = null if set, custom field names get added to $field2history * @return bo_tracking */ - function __construct($cf_app = null) + function __construct($cf_app = null, $notification_class=false) { if ($cf_app) { @@ -205,6 +214,10 @@ abstract class Tracking } } } + if($notification_class) + { + $this->notification_class = $notification_class; + } } /** @@ -766,10 +779,11 @@ abstract class Tracking { // send via notification_app try { - $notification = new notifications(); + $class = $this->notification_class; + $notification = new $class(); $notification->set_receivers(array($receiver)); - $notification->set_message($body_cache['text']); - $notification->set_message($body_cache['html']); + $notification->set_message($body_cache['text'], 'plain'); + $notification->set_message($body_cache['html'], 'html'); $notification->set_sender($sender); $notification->set_subject($subject); $notification->set_links(array($link));