public function testSendEmailNotification()
 {
     $notification = new SystemNotification();
     $notification->Title = "Notify on event";
     $notification->Description = 'Notifies on an event occurring';
     $notification->NotificationText = 'This is a notfication to $Member.Email about $NotifyOnThis.Title';
     $notification->Identifier = 'NOTIFY_ON_EVENT';
     $notification->NotifyOnClass = 'NotifyOnThis';
     $notification->write();
     // okay, add it to our page
     $page = $this->objFromFixture('NotifyOnThis', 'not1');
     $ns = new NotificationService();
     Config::inst()->update('NotificationService', 'use_queues', false);
     Config::inst()->update('EmailNotificationSender', 'send_notifications_from', '*****@*****.**');
     Config::inst()->update('SystemNotification', 'default_template', false);
     $ns->setSenders(array('email' => 'EmailNotificationSender'));
     $ns->setChannels(array('email'));
     $ns->notify('NOTIFY_ON_EVENT', $page);
     // now check that there was an email sent
     $users = $page->getRecipients($notification->Identifier);
     $expectedTo = $users[0]->Email;
     $expectedFrom = '*****@*****.**';
     $expectedSubject = $notification->Title;
     $expectedBody = "This is a notfication to {$expectedTo} about {$page->Title}";
     $expectedBody = $notification->format(nl2br($expectedBody), $page);
     // TODO
     $this->assertEmailSent($expectedTo, $expectedFrom, $expectedSubject);
 }
 /**
  * Creates a new post for the given member
  *
  * @param Member $member
  *			The member creating the post. Will default to the calling member if not specified
  * @param string $content
  *			The content being loaded into the post
  * @param array $properties
  *			Additional properties to be bound into the post. 
  * @param int $parentId
  *			The ID of a micropost that is considered the 'parent' of this post
  * @param mixed $target
  *			The "target" of this post; may be a data object (ie context of the post) or a user/group
  * @param array $to
  *			The people/groups this post is being sent to. This is an array of
  *			- logged_in: boolean (logged in users; uses a system config setting to determine which group represents 'logged in'
  *			- members: an array, or comma separated string, of member IDs
  *			- groups: an array, or comma separated string, of group IDs
  * @return MicroPost 
  */
 public function createPost(DataObject $member, $content, $properties = null, $parentId = 0, $target = null, $to = null)
 {
     // backwards compatible
     if (is_string($properties)) {
         $properties = array('Title' => $properties);
     }
     if (!$member) {
         $member = $this->securityContext->getMember();
     }
     if (!$member->exists() && !$this->allowAnonymousPosts) {
         throw new Exception("Anonymous posting disallowed");
     }
     $post = MicroPost::create();
     $post->Content = $content;
     if ($properties && count($properties)) {
         foreach ($properties as $field => $value) {
             if (isset($this->allowedProperties[$field])) {
                 $post->{$field} = $value;
             }
         }
     }
     $post->OwnerID = $member->ID;
     $post->Target = $target;
     if ($parentId) {
         $parent = MicroPost::get()->restrictedByID($parentId);
         if ($parent) {
             $post->ParentID = $parentId;
             $post->ThreadID = $parent->ThreadID;
             $post->Target = $parent->Target;
         }
     }
     if (isset($to['public'])) {
         $post->PublicAccess = (bool) $to['public'];
     }
     $post->write();
     // if we're a good poster, scan its content, otherwise post process it for spam
     if ($member->Balance >= MicroBlogMember::BALANCE_THRESHOLD) {
         $post->analyseContent();
         $post->write();
     } else {
         $this->queuedJobService->queueJob(new ProcessPostJob($post));
     }
     // set its thread ID
     if (!$post->ParentID) {
         $post->ThreadID = $post->ID;
         $post->write();
     }
     if ($post->ID != $post->ThreadID) {
         $thread = MicroPost::get()->restrictedByID($post->ThreadID);
         if ($thread) {
             $owner = $thread->Owner();
             $this->transactionManager->run(function () use($post, $thread) {
                 $thread->NumReplies += 1;
                 $thread->write();
             }, $owner);
         }
     }
     $this->rewardMember($member, 2);
     if ($to) {
         $post->giveAccessTo($to);
     }
     // we stick this in here so the UI can update...
     $post->RemainingVotes = $member->VotesToGive;
     $post->extend('onCreated', $member, $target);
     if ($this->notificationService) {
         $this->notificationService->notify('MICRO_POST_CREATED', $post);
     }
     return $post;
 }