All Data Structures Functions Variables Pages
CampaignItemSummaryListViewColumnAdapterTest.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  ********************************************************************************/
37  {
38  private $campaignItem;
39  private $contact;
40 
41  public static function setUpBeforeClass()
42  {
43  parent::setUpBeforeClass();
44  SecurityTestHelper::createSuperAdmin();
45  SecurityTestHelper::createUsers();
46  $super = User::getByUsername('super');
47  $super->primaryEmail->emailAddress = 'super@zurmo.org';
48  $saved = $super->save();
49  if (!$saved)
50  {
51  throw new FailedToSaveModelException();
52  }
53  MarketingListTestHelper::createMarketingListByName('testMarketingList');
54  $campaign = CampaignTestHelper::createCampaign('testCampaign',
55  'testSubject',
56  'testContent',
57  'testHtmlContent');
58  $contact = ContactTestHelper::createContactByNameForOwner('test', $super);
59  $emailMessage = EmailMessageTestHelper::createArchivedUnmatchedSentMessage($super);
60  $campaignItem = new CampaignItem();
61  $campaignItem->contact = $contact;
62  $campaignItem->processed = true;
63  $campaignItem->campaign = $campaign;
64  $campaignItem->emailMessage = $emailMessage;
65  $campaignItem->unrestrictedSave();
66  if (!$saved)
67  {
68  throw new FailedToSaveModelException();
69  }
71  }
72 
73  public function setUp()
74  {
75  parent::setUp();
76  $super = User::getByUsername('super');
77  Yii::app()->user->userModel = $super;
78  $campaigns = Campaign::getAll();
79  $contacts = Contact::getByName('test testson');
80  $this->contact = $contacts[0];
81  $this->campaignItem = $campaigns[0]->campaignItems[0];
82  }
83 
84  public function testResolveContactAndMetricsSummary()
85  {
86  //Test with super
88  resolveContactAndMetricsSummary($this->campaignItem);
89  $this->assertContains('test testson', $content);
90 
91  //Betty dont have access to contact
92  $betty = User::getByUsername('betty');
93  Yii::app()->user->userModel = $betty;
95  resolveContactAndMetricsSummary($this->campaignItem);
96  $this->assertContains('You cannot see this contact due to limited access', $content);
97 
98  //Giving betty access to contact
99  Yii::app()->user->userModel = User::getByUsername('super');
100  $this->contact->addPermissions($betty, Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
101  $this->assertTrue($this->contact->save());
103 
104  //Forgetting campaignItem is needed because of commit - aeedffa06467
105  //Not entirely sure why this is the case though. It only affects tests when securityOptimization is false
106  $this->campaignItem->forgetAll();
107  $campaigns = Campaign::getAll();
108  $this->campaignItem = $campaigns[0]->campaignItems[0];
109 
110  //Betty has now access to contact but not the emailMessage
111  Yii::app()->user->userModel = $betty;
113  resolveContactAndMetricsSummary($this->campaignItem);
114 
115  $this->assertContains('You cannot see the performance metrics due to limited access', $content);
116 
117  //Giving betty access to emailMessage
118  Yii::app()->user->userModel = User::getByUsername('super');
119  $emailMessage = $this->campaignItem->emailMessage;
120  $emailMessage->addPermissions($betty, Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
121  $this->assertTrue($emailMessage->save());
123 
124  //Betty has now access to contact and emailMessage
125  Yii::app()->user->userModel = $betty;
127  resolveContactAndMetricsSummary($this->campaignItem);
128  $this->assertContains('test testson', $content);
129  }
130 
131  public function testResolveContactWithLink()
132  {
133  $contacts = Contact::getByName('test testson');
135  resolveContactWithLink($contacts[0]);
136  $this->assertContains('test testson', $content);
137 
138  //Benny dont have access to contact
139  Yii::app()->user->userModel = User::getByUsername('benny');
141  resolveContactWithLink($contacts[0]);
142  $this->assertContains('You cannot see this contact due to limited access', $content);
143  }
144  }
145 ?>
static securableItemGivenPermissionsForUser(SecurableItem $securableItem, User $user)
static rebuild($overwriteExistingTables=true, $forcePhp=false, $messageStreamer=null)
static getByUsername($username)
Definition: User.php:49
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Sun May 24 2020 07:10:30