All Data Structures Functions Variables Pages
ModelRelationsAndAttributesToReportAdapterSecurityTest.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  public static function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
42  SecurityTestHelper::createSuperAdmin();
43  $sally = UserTestHelper::createBasicUser('sally');
44  $sally->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
45  $sally->setRight('OpportunitiesModule', OpportunitiesModule::RIGHT_ACCESS_OPPORTUNITIES);
46  $sally->setRight('MeetingsModule', MeetingsModule::RIGHT_ACCESS_MEETINGS);
47  if (!$sally->save())
48  {
49  throw new FailedToSaveModelException();
50  }
51  }
52 
53  public function testGetAllReportableRelationsAsASuperUser()
54  {
55  Yii::app()->user->userModel = User::getByUsername('super');
56  $model = new Account();
57  $rules = new AccountsReportRules();
58  $report = new Report();
59  $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
60  $report->setModuleClassName('AccountsModule');
61  $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
62  $relations = $adapter->getSelectableRelationsData();
63  $relations = $adapter->getSelectableRelationsDataResolvedForUserAccess(Yii::app()->user->userModel, $relations);
64  $this->assertEquals(17, count($relations));
65  $compareData = array('label' => 'Billing Address');
66  $this->assertEquals($compareData, $relations['billingAddress']);
67  $compareData = array('label' => 'Contact Affiliations');
68  $this->assertEquals($compareData, $relations['contactAffiliations']);
69  $compareData = array('label' => 'Contacts');
70  $this->assertEquals($compareData, $relations['contacts']);
71  $compareData = array('label' => 'Created By User');
72  $this->assertEquals($compareData, $relations['createdByUser']);
73  $compareData = array('label' => 'Customer Affiliations');
74  $this->assertEquals($compareData, $relations['secondaryAccountAffiliations']);
75  $compareData = array('label' => 'Meetings');
76  $this->assertEquals($compareData, $relations['meetings']);
77  $compareData = array('label' => 'Modified By User');
78  $this->assertEquals($compareData, $relations['modifiedByUser']);
79  $compareData = array('label' => 'Notes');
80  $this->assertEquals($compareData, $relations['notes']);
81  $compareData = array('label' => 'Opportunities');
82  $this->assertEquals($compareData, $relations['opportunities']);
83  $compareData = array('label' => 'Products');
84  $this->assertEquals($compareData, $relations['products']);
85  $compareData = array('label' => 'Projects');
86  $this->assertEquals($compareData, $relations['projects']);
87  $compareData = array('label' => 'Owner');
88  $this->assertEquals($compareData, $relations['owner']);
89  $compareData = array('label' => 'Partner Affiliations');
90  $this->assertEquals($compareData, $relations['primaryAccountAffiliations']);
91  $compareData = array('label' => 'Primary Email');
92  $this->assertEquals($compareData, $relations['primaryEmail']);
93  $compareData = array('label' => 'Shipping Address');
94  $this->assertEquals($compareData, $relations['shippingAddress']);
95  $compareData = array('label' => 'Secondary Email');
96  $this->assertEquals($compareData, $relations['secondaryEmail']);
97  $compareData = array('label' => 'Tasks');
98  $this->assertEquals($compareData, $relations['tasks']);
99  }
100 
105  {
106  Yii::app()->user->userModel = User::getByUsername('sally');
107  $model = new Account();
108  $rules = new AccountsReportRules();
109  $report = new Report();
110  $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
111  $report->setModuleClassName('AccountsModule');
112  $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
113  $relations = $adapter->getSelectableRelationsData();
114  $relations = $adapter->getSelectableRelationsDataResolvedForUserAccess(Yii::app()->user->userModel, $relations);
115  $this->assertEquals(9, count($relations));
116  $compareData = array('label' => 'Billing Address');
117  $this->assertEquals($compareData, $relations['billingAddress']);
118  $compareData = array('label' => 'Created By User');
119  $this->assertEquals($compareData, $relations['createdByUser']);
120  $compareData = array('label' => 'Meetings');
121  $this->assertEquals($compareData, $relations['meetings']);
122  $compareData = array('label' => 'Modified By User');
123  $this->assertEquals($compareData, $relations['modifiedByUser']);
124  $compareData = array('label' => 'Opportunities');
125  $this->assertEquals($compareData, $relations['opportunities']);
126  $compareData = array('label' => 'Owner');
127  $this->assertEquals($compareData, $relations['owner']);
128  $compareData = array('label' => 'Primary Email');
129  $this->assertEquals($compareData, $relations['primaryEmail']);
130  $compareData = array('label' => 'Shipping Address');
131  $this->assertEquals($compareData, $relations['shippingAddress']);
132  $compareData = array('label' => 'Secondary Email');
133  $this->assertEquals($compareData, $relations['secondaryEmail']);
134  }
135  }
136 ?>
static getByUsername($username)
Definition: User.php:49
getSelectableRelationsData(RedBeanModel $precedingModel=null, $precedingRelation=null)
const TYPE_ROWS_AND_COLUMNS
Definition: Report.php:51
Generated on Sun May 31 2020 07:10:34