Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
EmailMessageMashableActivityRulesTest.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 $emailMessage;
40 
41  public static function setUpBeforeClass()
42  {
43  parent::setUpBeforeClass();
44  $super = SecurityTestHelper::createSuperAdmin();
45  self::$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('a test message', $super);
46  SecurityTestHelper::createUsers();
47  SecurityTestHelper::createGroups();
48  SecurityTestHelper::createRoles();
51  //do the rebuild to ensure the tables get created properly.
53  }
54 
55  public function setUp()
56  {
57  parent::setUp();
58  Yii::app()->user->userModel = User::getByUsername('super');
59  }
60 
61  public function testResolveSearchAttributesDataByRelatedItemId()
62  {
63  //TODO: @sergio: Fix where and sql asserts
65  $rules = new EmailMessageMashableActivityRules();
66  $searchAttributeData = $rules->resolveSearchAttributesDataByRelatedItemId(5);
67  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('EmailMessage');
68  $where = RedBeanModelDataProvider::makeWhere('EmailMessage', $searchAttributeData, $joinTablesAdapter);
69  $compareWhere = "(({$quote}emailmessagesender{$quote}.{$quote}personoraccount_item_id{$quote} = 5) or (1 = ";
70  $compareWhere .= "(select 1 from {$quote}emailmessagerecipient{$quote} emailmessagerecipient where ";
71  $compareWhere .= "{$quote}emailmessagerecipient{$quote}.{$quote}emailmessage_id` = {$quote}emailmessage";
72  $compareWhere .= "{$quote}.id and {$quote}emailmessagerecipient{$quote}.{$quote}personoraccount_item_id` = 5 limit 1)))";
73  //$this->assertEquals($compareWhere, $where);
74 
75  $sql = EmailMessage::makeSubsetOrCountSqlQuery('emailmessage', $joinTablesAdapter, 1, 5, $where, null);
76  $compareSubsetSql = "select {$quote}emailmessage{$quote}.{$quote}id{$quote} id ";
77  $compareSubsetSql .= "from {$quote}emailmessage{$quote} ";
78  $compareSubsetSql .= "left join {$quote}emailmessagesender{$quote} on ";
79  $compareSubsetSql .= "{$quote}emailmessagesender{$quote}.{$quote}id{$quote} = {$quote}emailmessage{$quote}.";
80  $compareSubsetSql .= "{$quote}sender_emailmessagesender_id{$quote} ";
81  $compareSubsetSql .= "where " . $compareWhere . ' ';
82  $compareSubsetSql .= 'limit 5 offset 1';
83  //$this->assertEquals($compareSubsetSql, $sql);
84 
85  //Make sure the sql runs properly.
86  $data = EmailMessage::getSubset($joinTablesAdapter, 0, 5, $where, null);
87  $this->assertEquals(0, count($data));
88  }
89 
90  public function testResolveSearchAttributesDataByRelatedItemIds()
91  {
92  //TODO: @sergio: Fix where and sql asserts
94  $rules = new EmailMessageMashableActivityRules();
95  $searchAttributeData = $rules->resolveSearchAttributesDataByRelatedItemIds(array(4, 5));
96  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('EmailMessage');
97  $where = RedBeanModelDataProvider::makeWhere('EmailMessage', $searchAttributeData, $joinTablesAdapter);
98  $compareWhere = "(({$quote}emailmessagesender{$quote}.{$quote}personoraccount_item_id{$quote} IN(4,5)) or (1 = "; // Not Coding Standard
99  $compareWhere .= "(select 1 from {$quote}emailmessagerecipient{$quote} emailmessagerecipient where ";
100  $compareWhere .= "{$quote}emailmessagerecipient{$quote}.{$quote}emailmessage_id` = {$quote}emailmessage";
101  $compareWhere .= "{$quote}.id and {$quote}emailmessagerecipient{$quote}.{$quote}personoraccount_item_id` IN(4,5) limit 1)))"; // Not Coding Standard
102  //$this->assertEquals($compareWhere, $where);
103 
104  $sql = EmailMessage::makeSubsetOrCountSqlQuery('emailmessage', $joinTablesAdapter, 1, 5, $where, null);
105  $compareSubsetSql = "select {$quote}emailmessage{$quote}.{$quote}id{$quote} id ";
106  $compareSubsetSql .= "from {$quote}emailmessage{$quote} ";
107  $compareSubsetSql .= "left join {$quote}emailmessagesender{$quote} on ";
108  $compareSubsetSql .= "{$quote}emailmessagesender{$quote}.{$quote}id{$quote} = {$quote}emailmessage{$quote}.";
109  $compareSubsetSql .= "{$quote}sender_emailmessagesender_id{$quote} ";
110  $compareSubsetSql .= "where " . $compareWhere . ' ';
111  $compareSubsetSql .= 'limit 5 offset 1';
112  //$this->assertEquals($compareSubsetSql, $sql);
113 
114  //Make sure the sql runs properly.
115  $data = EmailMessage::getSubset($joinTablesAdapter, 0, 5, $where, null);
116  $this->assertEquals(0, count($data));
117  }
118 
119  public function testResolveSearchAttributesDataByRelatedItemIdWithRegularUser()
120  {
121  //TODO: @sergio: Fix where and sql asserts
122  Yii::app()->user->userModel = User::getByUsername('benny');
123  $mungeIds = AllPermissionsOptimizationUtil::getMungeIdsByUser(Yii::app()->user->userModel);
125  $rules = new EmailMessageMashableActivityRules();
126  $searchAttributeData = $rules->resolveSearchAttributesDataByRelatedItemId(5);
127  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('EmailMessage');
128  $where = RedBeanModelDataProvider::makeWhere('EmailMessage', $searchAttributeData, $joinTablesAdapter);
129  $compareWhere = "(({$quote}emailmessagesender{$quote}.{$quote}personoraccount_item_id{$quote} = 5) or (1 = ";
130  $compareWhere .= "(select 1 from {$quote}emailmessagerecipient{$quote} emailmessagerecipient where ";
131  $compareWhere .= "{$quote}emailmessagerecipient{$quote}.{$quote}emailmessage_id` = {$quote}emailmessage";
132  $compareWhere .= "{$quote}.id and {$quote}emailmessagerecipient{$quote}.{$quote}personoraccount_item_id` = 5 limit 1)))";
133  //$this->assertEquals($compareWhere, $where);
134 
135  $sql = EmailMessage::makeSubsetOrCountSqlQuery('emailmessage', $joinTablesAdapter, 1, 5, $where, null);
136  $compareSubsetSql = "select distinct {$quote}emailmessage{$quote}.{$quote}id{$quote} id ";
137  $compareSubsetSql .= "from ({$quote}emailmessage{$quote}, {$quote}ownedsecurableitem{$quote}) ";
138  $compareSubsetSql .= "left join {$quote}emailmessagesender{$quote} on ";
139  $compareSubsetSql .= "{$quote}emailmessagesender{$quote}.{$quote}id{$quote} = {$quote}emailmessage{$quote}.";
140  $compareSubsetSql .= "{$quote}sender_emailmessagesender_id{$quote} ";
141  $compareSubsetSql .= "left join {$quote}emailmessage_read{$quote} on ";
142  $compareSubsetSql .= "{$quote}emailmessage_read{$quote}.{$quote}securableitem_id{$quote} = ";
143  $compareSubsetSql .= "{$quote}ownedsecurableitem{$quote}.{$quote}securableitem_id{$quote} ";
144  $compareSubsetSql .= "and {$quote}munge_id{$quote} in ('" . join("', '", $mungeIds) . "') ";
145  $compareSubsetSql .= "where (" . $compareWhere . ') ';
146  $compareSubsetSql .= "and ({$quote}ownedsecurableitem{$quote}.{$quote}owner__user_id{$quote} = " . Yii::app()->user->userModel->id. " "; // Not Coding Standard
147  $compareSubsetSql .= "OR {$quote}emailmessage_read{$quote}.{$quote}munge_id{$quote} IS NOT NULL) "; // Not Coding Standard
148  $compareSubsetSql .= "and {$quote}ownedsecurableitem{$quote}.{$quote}id{$quote} = ";
149  $compareSubsetSql .= "{$quote}emailmessage{$quote}.{$quote}ownedsecurableitem_id{$quote} ";
150  $compareSubsetSql .= 'limit 5 offset 1';
151  //$this->assertEquals($compareSubsetSql, $sql);
152 
153  //Make sure the sql runs properly.
154  $data = EmailMessage::getSubset($joinTablesAdapter, 0, 5, $where, null);
155  $this->assertEquals(0, count($data));
156  }
157 
158  public function testResolveSearchAttributeDataForAllLatestActivities()
159  {
160  $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
161  $rules = new EmailMessageMashableActivityRules();
162  $searchAttributeData = array();
163  $searchAttributeData['clauses'] = array();
164  $searchAttributeData['structure'] = null;
165  $searchAttributeData = $rules->resolveSearchAttributeDataForAllLatestActivities($searchAttributeData);
166  $compareData = array('clauses' =>
167  array(1 =>
168  array('attributeName' => 'folder',
169  'relatedModelData' => array('attributeName' => 'emailBox',
170  'operatorType' => 'doesNotEqual',
171  'value' => $box->id))),
172  'structure' => '1');
173  $this->assertEquals($compareData, $searchAttributeData);
174  }
175 
176  public function testGetSenderContent()
177  {
178  //Test without personsOrAccounts
179  $emailMessageSender = new EmailMessageSender();
180  $emailMessageSender->fromName = 'test name';
181  $emailMessageSender->fromAddress = 'test@zurmo.com';
182  $expectedContent = 'test@zurmo.com test name';
183  $content = EmailMessageMashableActivityRules::getSenderContent($emailMessageSender);
184  $this->assertEquals($expectedContent, $content);
185 
186  //Test with one personOrAccount
187  $contact = new Contact();
188  $contact->lastName = 'name1';
189  $emailMessageSender->personsOrAccounts->add($contact);
190  $content = EmailMessageMashableActivityRules::getSenderContent($emailMessageSender);
191  $this->assertContains('href=', $content);
192  $this->assertContains('name1', $content);
193 
194  //Test with more than one personsOrAccounts
195  $contact = new Contact();
196  $contact->lastName = 'name2';
197  $emailMessageSender->personsOrAccounts->add($contact);
198  $content = EmailMessageMashableActivityRules::getSenderContent($emailMessageSender);
199  $this->assertContains('test@zurmo.com', $content);
200  $this->assertContains('href=', $content);
201  $this->assertContains('name', $content);
202  $this->assertContains('name2', $content);
203  }
204 
205  public function testGetRecipientsContent()
206  {
207  //Test without personsOrAccounts
208  $emailMessageRecipient1 = new EmailMessageRecipient();
209  $emailMessageRecipient1->type = EmailMessageRecipient::TYPE_TO;
210  $emailMessageRecipient1->toName = 'test name1';
211  $emailMessageRecipient1->toAddress = 'test1@zurmo.com';
212 
213  $emailMessageRecipient2 = new EmailMessageRecipient();
214  $emailMessageRecipient2->type = EmailMessageRecipient::TYPE_TO;
215  $emailMessageRecipient2->toName = 'test name2';
216  $emailMessageRecipient2->toAddress = 'test2@zurmo.com';
217 
218  $emailMessage = new EmailMessage();
219  $emailMessage->recipients->add($emailMessageRecipient1);
220  $emailMessage->recipients->add($emailMessageRecipient2);
221 
222  $content = EmailMessageMashableActivityRules::getRecipientsContent($emailMessage->recipients);
223  $this->assertContains('test1@zurmo.com test name1', $content);
224  $this->assertContains('test2@zurmo.com test name2', $content);
225 
226  //Test with personOrAccount
227  $contact1 = new Contact();
228  $contact2 = new Contact();
229  $contact1->lastName = 'contact1';
230  $contact2->lastName = 'contact2';
231  $emailMessageRecipient1->personsOrAccounts->add($contact1);
232  $emailMessageRecipient2->personsOrAccounts->add($contact1);
233  $emailMessageRecipient2->personsOrAccounts->add($contact2);
234 
235  $content = EmailMessageMashableActivityRules::getRecipientsContent($emailMessage->recipients);
236  $this->assertContains ('href=', $content);
237  $this->assertNotContains('test1@zurmo.com', $content);
238  $this->assertContains ('test2@zurmo.com', $content);
239  $this->assertContains ('contact1', $content);
240  $this->assertContains ('contact2', $content);
241  }
242  }
243 ?>
static rebuild($overwriteExistingTables=true, $forcePhp=false, $messageStreamer=null)
static getByUsername($username)
Definition: User.php:49
static forgetAll()
static makeSubsetOrCountSqlQuery($tableName, RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $offset=null, $count=null, $where=null, $orderBy=null, $selectCount=false, $selectDistinct=false, array $quotedExtraSelectColumnNameAndAliases=array())
static loadStartingData()
static makeWhere($modelClassName, array $metadata, &$joinTablesAdapter)
static getSubset(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $offset=null, $count=null, $where=null, $orderBy=null, $modelClassName=null, $selectDistinct=false)
Generated on Sun Jan 17 2021 07:10:21
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.