Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
NotificationManagerTest.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  */
12 {
13 
14  public $fixtures = array(
15  'users' => 'User'
16  );
17 
18  public function testAddRemoveNotificator()
19  {
20  $notificationManager = new NotificationManager();
21  $notificationManager->init();
22 
23  $notificationManager->addNotificator('mailNotificator', new MailNotificator());
24  $this->assertArrayHasKey('mailNotificator', $notificationManager->getNotificators());
25 
26  $notificationManager->removeNotificator('mailNotificator');
27  $this->assertArrayNotHasKey('mailNotificator', $notificationManager->getNotificators());
28 
29  $notificationManager->addNotificator('mailNotificator', array(
30  'class' => 'MailNotificator'
31  ));
32  $this->assertArrayHasKey('mailNotificator', $notificationManager->getNotificators());
33  }
34 
35  public function testMailNotificator()
36  {
37  $notificationManager = new NotificationManager();
38 
39  $mailNotificator = $this->getMock('MailNotificator', array('notify'));
40  $mailNotificator
41  ->expects($this->once())
42  ->method('notify');
43  $notificationManager->addNotificator('mailNotificator', $mailNotificator);
44 
45  $notificationManager->notifyAbout(new Notification('', ''));
46  }
47 
48  public function testValidateRecipientSuccess()
49  {
50  $notificationManager = new NotificationManager();
51 
52  $mailNotificator = $this->getMock('MailNotificator', array('createMail'));
53  $mailNotificator
54  ->expects($this->once())
55  ->method('createMail')
56  ->will($this->returnValue(new PHPMailer()));
57  $notificationManager->addNotificator('mailNotificator', $mailNotificator);
58 
59  $notificationManager->notifyAbout(new Notification('test', 'test', array(new EmailRecipient('mail@example.com'))));
60 
61  }
62 
63  public function testValidateRecipientFalse()
64  {
65  $notificationManager = new NotificationManager();
66 
67  $mailNotificator = $this->getMock('MailNotificator', array('createMail'));
68  $mailNotificator
69  ->expects($this->never())
70  ->method('createMail')
71  ->will($this->returnValue(new PHPMailer()));
72  $notificationManager->addNotificator('mailNotificator', $mailNotificator);
73 
74  $notificationManager->notifyAbout(new Notification('test', 'test', array(new EmailRecipient($this->users['sample1']['email']))));
75 
76  }
77 }
78 
79