function testSendNotificationsFirstIsFailure()
 {
     $feedback = new MockFeedback($this);
     // First message fail
     $mail1 = new MockMail($this);
     $mail1->setReturnValue('send', false);
     // Second succeed
     $mail2 = new MockMail($this);
     $mail2->setReturnValue('send', true);
     // Raises an error
     $feedback->expectOnce('log', array('warning', '*'));
     $project = new MockProject($this);
     $project->setReturnValue('getPublicName', 'Guinea Pig');
     $itemFty = new MockDocman_ItemFactory($this);
     $notifDao = new MockNotificationsDao($this);
     $nm = new Docman_NotificationsManager_TestVersion($this);
     $nm->setReturnValue('_getDao', $notifDao);
     $nm->setReturnValue('_getItemFactory', $itemFty);
     $nm->setReturnValue('_groupGetObject', $project);
     $nm->setReturnValueAt(0, '_getMail', $mail1);
     $nm->setReturnValueAt(1, '_getMail', $mail2);
     $nm->__construct(101, '/toto', $feedback);
     $user = mock('PFUser');
     $user->setReturnValue('getEmail', '*****@*****.**');
     $nm->_messages[] = array('title' => 'Move 1', 'content' => 'Changed 1', 'to' => array($user));
     $nm->_messages[] = array('title' => 'Move 2', 'content' => 'Changed 2', 'to' => array($user));
     $nm->sendNotifications('', '');
 }
 function testGetMessageForUserParentListened()
 {
     $language = new MockBaseLanguage();
     $language->setReturnValue('getText', 'notif_modified_by', array('plugin_docman', 'notif_modified_by'));
     $language->setReturnValue('getText', 'notif_wiki_new_version', array('plugin_docman', 'notif_wiki_new_version', 'wiki'));
     $language->setReturnValue('getText', 'notif_something_happen', array('plugin_docman', 'notif_something_happen'));
     $language->setReturnValue('getText', 'notif_footer_message', array('plugin_docman', 'notif_footer_message'));
     $language->setReturnValue('getText', 'notif_footer_message_link', array('plugin_docman', 'notif_footer_message_link'));
     $project = aMockProject()->withId(101)->build();
     $feedback = new MockFeedback($this);
     $mail_builder = new MailBuilder(TemplateRendererFactory::build());
     $notificationsManager = new Docman_NotificationsManager_TestVersion();
     $notificationsManager->__construct($project, '/toto', $feedback, $mail_builder);
     $notificationsManager->setReturnValue('_getLanguageForUser', $language);
     $notificationsManager->_url = 'http://www.example.com/plugins/docman/';
     $user = mock('PFUser');
     $user->setReturnValue('getRealName', 'John Doe');
     $user->setReturnValue('getId', 2);
     $params['path'] = new MockDocman_Path();
     $params['path']->setReturnValue('get', 'Folder1/Folder2/File');
     $params['item'] = new MockDocman_Item();
     $params['item']->setReturnValue('getId', 10);
     $parentItem = new MockDocman_Item();
     $parentItem->setReturnValue('getId', 1);
     $notificationsManager->setReturnValue('getListeningUsers', array($user->getId() => $parentItem));
     $params['wiki_page'] = 'wiki';
     $params['url'] = 'http://www.example.com/plugins/docman/';
     $message1 = "Folder1/Folder2/File notif_modified_by John Doe.\nhttp://www.example.com/plugins/docman/&action=details&id=10\n\n\n--------------------------------------------------------------------\nnotif_footer_message\nnotif_footer_message_link\nhttp://www.example.com/plugins/docman/&action=details&section=notifications&id=1";
     $message2 = "Folder1/Folder2/File notif_modified_by John Doe.\nhttp://www.example.com/plugins/docman/&action=details&id=10\n\n\n--------------------------------------------------------------------\nnotif_footer_message\nnotif_footer_message_link\nhttp://www.example.com/plugins/docman/&action=details&section=notifications&id=1";
     $message3 = "notif_wiki_new_version John Doe.\nhttp://www.example.com/plugins/docman/\n\n\n--------------------------------------------------------------------\nnotif_footer_message\nnotif_footer_message_link\nhttp://www.example.com/plugins/docman/&action=details&section=notifications&id=1";
     $message4 = "notif_something_happen\n\n--------------------------------------------------------------------\nnotif_footer_message\nnotif_footer_message_link\nhttp://www.example.com/plugins/docman/&action=details&section=notifications&id=1";
     $this->assertEqual($message1, $notificationsManager->_getMessageForUser($user, 'modified', $params));
     $this->assertEqual($message2, $notificationsManager->_getMessageForUser($user, 'new_version', $params));
     $this->assertEqual($message3, $notificationsManager->_getMessageForUser($user, 'new_wiki_version', $params));
     $this->assertEqual($message4, $notificationsManager->_getMessageForUser($user, 'something happen', $params));
 }