public function testEntity()
 {
     NotificationManager::instance()->addTemplate('newNotification', ['title' => 'New Notification', 'body' => ':from has sent :to a notification about :about']);
     $notify = NotificationManager::instance()->notify(['users' => 1, 'template' => 'newNotification', 'vars' => ['from' => 'Bob', 'to' => 'Leonardo', 'about' => 'Programming Stuff']]);
     $entity = $this->Notifications->get(2);
     $this->assertEquals('newNotification', $entity->template);
     $this->assertEquals('New Notification', $entity->title);
     $this->assertEquals('Bob has sent Leonardo a notification about Programming Stuff', $entity->body);
 }
 public function setUp()
 {
     parent::setUp();
     $this->Manager = NotificationManager::instance();
     $this->Model = TableRegistry::get('Bakkerij/Notifier.Notifications');
     // Setup our component and fake the controller
     $request = new Request();
     $response = new Response();
     $this->controller = $this->getMockBuilder('Cake\\Controller\\Controller')->setConstructorArgs([$request, $response])->setMethods(['redirect'])->getMock();
     $this->controller->loadComponent('Auth');
     $this->controller->Auth->setUser(['id' => 1]);
     $registry = new ComponentRegistry($this->controller);
     $this->Notifier = new NotifierComponent($registry);
 }
示例#3
0
 /**
  * notify
  *
  * Sends notifications to specific users.
  * The first parameter `$data` is an array with multiple options.
  *
  * ### Options
  * - `users` - An array or int with id's of users who will receive a notification.
  * - `roles` - An array or int with id's of roles which all users ill receive a notification.
  * - `template` - The template wich will be used.
  * - `vars` - The variables used in the template.
  *
  * ### Example
  * ```
  *  NotificationManager::instance()->notify([
  *      'users' => 1,
  *      'template' => 'newOrder',
  *      'vars' => [
  *          'receiver' => $receiver->name
  *          'total' => $order->total
  *      ],
  *  ]);
  * ```
  *
  * @param array $data Data with options.
  * @return string
  */
 public function notify($data)
 {
     return NotificationManager::instance()->notify($data);
 }
 public function testInstance()
 {
     $instance = NotificationManager::instance();
     $this->assertInstanceOf('Bakkerij\\Notifier\\Utility\\NotificationManager', $instance);
 }