All Data Structures Functions Variables Pages
ProjectsNotificationUtilTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
39  protected static $super;
40 
41  protected static $steve;
42 
43  protected static $sally;
44 
45  protected static $katie;
46 
47  public static function setUpBeforeClass()
48  {
49  parent::setUpBeforeClass();
50  Yii::app()->user->userModel = SecurityTestHelper::createSuperAdmin();
51  self::$super = Yii::app()->user->userModel;
52  self::$steve = UserTestHelper::createBasicUserWithEmailAddress('steve');
53  NotificationTestHelper::setNotificationSettingsForUser(self::$steve, 'NewTaskNotificationRules');
54  self::$sally = UserTestHelper::createBasicUserWithEmailAddress('sally');
55  self::$katie = UserTestHelper::createBasicUserWithEmailAddress('katie');
56  }
57 
58  public function setUp()
59  {
60  parent::setUp();
61  Yii::app()->user->userModel = User::getByUsername('super');
64  }
65 
66  public function testNewNotificationWhenNewProjectTaskIsCreated()
67  {
68  $project = new Project();
69  $project->name = 'project-'. __FUNCTION__;
70  $project->owner = self::$steve;
71  $task = new Task();
72  $task->name = 'task-' . __FUNCTION__;
73  $task->owner = self::$sally;
74 
75  $this->assertEquals(0, EmailMessage::getCount());
76  $this->assertEquals(0, Notification::getCount());
77 
79  $project, ProjectAuditEvent::TASK_ADDED, $task, self::$sally);
80 
81  $emailMessages = EmailMessage::getAll();
82  $notifications = Notification::getAll();
83  $this->assertCount(1, $emailMessages);
84  $this->assertCount(1, $notifications);
85  $this->assertEquals('NEW TASK: task-'. __FUNCTION__ . ' for PROJECT: project-' . __FUNCTION__,
86  $emailMessages[0]->subject);
87  $this->assertContains("New task, task-" . __FUNCTION__ . ", was created for project, 'project-" . __FUNCTION__ . "'. Created by sally sallyson",
88  $emailMessages[0]->content->textContent);
89  $this->assertContains("New task, task-" . __FUNCTION__ . ", was created for project, 'project-" . __FUNCTION__ . "'. Created by sally sallyson",
90  $emailMessages[0]->content->htmlContent);
91  $this->assertContains("New task, task-" . __FUNCTION__ . ", was created for project, 'project-" . __FUNCTION__ . "'. Created by sally sallyson",
92  $notifications[0]->notificationMessage->textContent);
93  $this->assertContains("New task, task-" . __FUNCTION__ . ", was created for project, 'project-" . __FUNCTION__ . "'. Created by sally sallyson",
94  $notifications[0]->notificationMessage->htmlContent);
95  }
96 
97  public function testNewNotificationWhenNewProjectIsCreated()
98  {
99  $project = new Project();
100  $project->name = 'project-' . __FUNCTION__;
101  $project->owner = self::$steve;
102 
103  $this->assertEquals(0, EmailMessage::getCount());
104  $this->assertEquals(0, Notification::getCount());
105 
107  $project, ProjectAuditEvent::PROJECT_CREATED);
108 
109  $emailMessages = EmailMessage::getAll();
110  $notifications = Notification::getAll();
111  $this->assertCount(1, $emailMessages);
112  $this->assertCount(1, $notifications);
113  $this->assertEquals('PROJECT: project-'. __FUNCTION__,
114  $emailMessages[0]->subject);
115  $this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now owned by you.",
116  $emailMessages[0]->content->textContent);
117 
118  $this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now owned by you.",
119  $emailMessages[0]->content->htmlContent);
120 
121  $this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now owned by you.",
122  $notifications[0]->notificationMessage->textContent);
123 
124  $this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now owned by you.",
125  $notifications[0]->notificationMessage->htmlContent);
126  }
127 
128  public function testNewNotificationWhenProjectIsArchived()
129  {
130  $project = new Project();
131  $project->name = 'project-' . __FUNCTION__;
132  $project->owner = self::$steve;
133  $project->status = Project::STATUS_ARCHIVED;
134 
135  $this->assertEquals(0, EmailMessage::getCount());
136  $this->assertEquals(0, Notification::getCount());
137 
139  $project, ProjectAuditEvent::PROJECT_ARCHIVED);
140 
141  $emailMessages = EmailMessage::getAll();
142  $notifications = Notification::getAll();
143  $this->assertCount(1, $emailMessages);
144  $this->assertCount(1, $notifications);
145  $this->assertEquals('PROJECT: project-'. __FUNCTION__,
146  $emailMessages[0]->subject);
147  $this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now archived.",
148  $emailMessages[0]->content->textContent);
149 
150  $this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now archived.",
151  $emailMessages[0]->content->htmlContent);
152 
153  $this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now archived.",
154  $notifications[0]->notificationMessage->textContent);
155 
156  $this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now archived.",
157  $notifications[0]->notificationMessage->htmlContent);
158  }
159  }
160 ?>
static getByUsername($username)
Definition: User.php:49
Definition: Task.php:37
static deleteAll()
static getCount(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $where=null, $modelClassName=null, $selectDistinct=false)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static submitProjectNotificationMessage(Project $project, $action, Task $task=null, User $relatedUser=null)
Generated on Fri Jun 5 2020 07:10:34