Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ReportsSuperUserWalkthroughTest.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 
41  {
42  public static function setUpBeforeClass()
43  {
44  parent::setUpBeforeClass();
45  SecurityTestHelper::createSuperAdmin();
46  $super = User::getByUsername('super');
47  Yii::app()->user->userModel = $super;
48 
49  //Setup test data owned by the super user.
50  $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
51  AccountTestHelper::createAccountByNameForOwner('superAccount2', $super);
52  ContactTestHelper::createContactWithAccountByNameForOwner('superContact', $super, $account);
53  }
54 
55  public static function makeRowsAndColumnsReportPostDataForAccounts()
56  {
57  return array(
58  'validationScenario' => 'ValidateForDisplayAttributes',
59  'RowsAndColumnsReportWizardForm' => array(
60  'moduleClassName' => 'AccountsModule',
61  'Filters' => array(
62  '0' => array(
63  'structurePosition' => 1,
64  'attributeIndexOrDerivedType' => 'name',
65  'operator' => 'isNotNull',
66  'value' => '',
67  'availableAtRunTime' => '0')),
68  'filtersStructure' => '1',
69  'displayAttributes' => '',
70  'DisplayAttributes' => array(
71  '0' => array(
72  'attributeIndexOrDerivedType' => 'name',
73  'label' => 'Name')),
74 
75  'name' => 'some rows and columns report for accounts',
76  'description' => 'some rows and columns report description for accounts',
77  'currencyConversionType' => '1',
78  'spotConversionCurrencyCode' => '',
79  'ownerId' => Yii::app()->user->userModel->id,
80  'ownerName' => 'Super User',
81  'explicitReadWriteModelPermissions' => array(
82  'type' => '',
83  'nonEveryoneGroup' => '4')),
84  'FiltersRowCounter' => '1',
85  'DisplayAttributesRowCounter' => '1',
86  'OrderBysRowCounter' => '0',
87  );
88  }
89 
90  public static function makeRowsAndColumnsReportPostData()
91  {
92  return array(
93  'validationScenario' => 'ValidateForDisplayAttributes',
94  'RowsAndColumnsReportWizardForm' => array(
95  'moduleClassName' => 'ReportsTestModule',
96  'Filters' => array(
97  '0' => array(
98  'structurePosition' => 1,
99  'attributeIndexOrDerivedType' => 'string',
100  'operator' => 'isNotNull',
101  'value' => '',
102  'availableAtRunTime' => '0')),
103  'filtersStructure' => '1',
104  'displayAttributes' => '',
105  'DisplayAttributes' => array(
106  '0' => array(
107  'attributeIndexOrDerivedType' => 'string',
108  'label' => 'String')),
109 
110  'name' => 'some rows and columns report',
111  'description' => 'some rows and columns report description',
112  'currencyConversionType' => '1',
113  'spotConversionCurrencyCode' => '',
114  'ownerId' => Yii::app()->user->userModel->id,
115  'ownerName' => 'Super User',
116  'explicitReadWriteModelPermissions' => array(
117  'type' => '',
118  'nonEveryoneGroup' => '4')),
119  'FiltersRowCounter' => '1',
120  'DisplayAttributesRowCounter' => '1',
121  'OrderBysRowCounter' => '0',
122  );
123  }
124 
125  public static function makeSummationReportPostData()
126  {
127  return array(
128  'validationScenario' => 'ValidateForDisplayAttributes',
129  'SummationReportWizardForm' => array(
130  'moduleClassName' => 'ReportsTestModule',
131  'Filters' => array(
132  '0' => array(
133  'structurePosition' => 1,
134  'attributeIndexOrDerivedType' => 'string',
135  'operator' => 'isNotNull',
136  'value' => '',
137  'availableAtRunTime' => '0')),
138  'filtersStructure' => '1',
139  'displayAttributes' => '',
140  'DisplayAttributes' => array(
141  '0' => array(
142  'attributeIndexOrDerivedType' => 'string',
143  'label' => 'Name')),
144 
145  'name' => 'some summation report',
146  'description' => 'some summation report description',
147  'currencyConversionType' => '1',
148  'spotConversionCurrencyCode' => '',
149  'ownerId' => Yii::app()->user->userModel->id,
150  'ownerName' => 'Super User',
151  'explicitReadWriteModelPermissions' => array(
152  'type' => '',
153  'nonEveryoneGroup' => '4')),
154  'FiltersRowCounter' => '1',
155  'DisplayAttributesRowCounter' => '1',
156  'OrderBysRowCounter' => '0',
157  );
158  }
159 
160  public static function getDependentTestModelClassNames()
161  {
162  return array('ReportModelTestItem', 'ReportModelTestItem2');
163  }
164 
165  public function setUp()
166  {
167  parent::setUp();
168  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
169  }
170 
171  public function testSuperUserAllDefaultControllerActions()
172  {
173  $this->runControllerWithNoExceptionsAndGetContent ('reports/default/list');
174  $this->runControllerWithExitExceptionAndGetContent ('reports/default/create');
175  $this->runControllerWithNoExceptionsAndGetContent ('reports/default/selectType');
176  }
177 
182  {
183  $savedReports = SavedReport::getAll();
184  $this->assertEquals(0, count($savedReports));
185  $content = $this->runControllerWithExitExceptionAndGetContent ('reports/default/create');
186  $this->assertContains('Rows and Columns Report', $content);
187  $this->assertContains('Summation Report', $content);
188  $this->assertContains('Matrix Report', $content);
189 
190  $this->setGetArray(array('type' => 'RowsAndColumns'));
191  $this->resetPostArray();
192  $content = $this->runControllerWithNoExceptionsAndGetContent ('reports/default/create');
193  $this->assertContains('Accounts', $content);
194 
195  $this->setGetArray(array('type' => 'RowsAndColumns'));
196  $postData = static::makeRowsAndColumnsReportPostData();
197  $postData['save'] = 'save';
198  $postData['ajax'] = 'edit-form';
199  $this->setPostArray($postData);
200  $content = $this->runControllerWithExitExceptionAndGetContent('reports/default/save');
201  $this->assertEquals('[]', $content);
202  $postData = static::makeRowsAndColumnsReportPostData();
203  $postData['save'] = 'save';
204  $this->setPostArray($postData);
205  $this->runControllerWithExitExceptionAndGetContent('reports/default/save');
206  $savedReports = SavedReport::getAll();
207  $this->assertEquals(1, count($savedReports));
208  $this->setGetArray(array('id' => $savedReports[0]->id));
209  $this->resetPostArray();
210  $this->runControllerWithNoExceptionsAndGetContent('reports/default/details');
211  $this->setGetArray(array('id' => $savedReports[0]->id));
212  $this->resetPostArray();
213  $this->runControllerWithNoExceptionsAndGetContent('reports/default/edit');
214  //Save an existing report
215  $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id));
216  $postData = static::makeRowsAndColumnsReportPostData();
217  $postData['save'] = 'save';
218  $this->setPostArray($postData);
219  $this->runControllerWithExitExceptionAndGetContent('reports/default/save');
220  $this->assertEquals(1, count($savedReports));
221  //Clone existing report
222  $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id, 'isBeingCopied' => '1'));
223  $postData = static::makeRowsAndColumnsReportPostData();
224  $postData['save'] = 'save';
225  $this->setPostArray($postData);
226  $this->runControllerWithExitExceptionAndGetContent('reports/default/save');
227  $savedReports = SavedReport::getAll();
228  $this->assertEquals(2, count($savedReports));
229  }
230 
234  public function testExportAction()
235  {
236  $notificationsBeforeCount = Notification::getCount();
237  $notificationMessagesBeforeCount = NotificationMessage::getCount();
238 
239  $savedReports = SavedReport::getAll();
240  $this->assertEquals(2, count($savedReports));
241  $this->setGetArray(array('id' => $savedReports[0]->id));
242  //Test where there is no data to export
243  $this->runControllerWithRedirectExceptionAndGetContent('reports/default/export');
244  $this->assertContains('There is no data to export.',
245  Yii::app()->user->getFlash('notification'));
246 
247  $reportModelTestItem = new ReportModelTestItem();
248  $reportModelTestItem->string = 'string1';
249  $reportModelTestItem->lastName = 'xLast1';
250  $this->assertTrue($reportModelTestItem->save());
251 
252  $reportModelTestItem = new ReportModelTestItem();
253  $reportModelTestItem->string = 'string2';
254  $reportModelTestItem->lastName = 'xLast2';
255  $this->assertTrue($reportModelTestItem->save());
256 
257  $content = $this->runControllerWithExitExceptionAndGetContent('reports/default/export');
258  $this->assertEquals('Testing download.', $content);
259 
260  ExportModule::$asynchronousThreshold = 1;
261  $this->runControllerWithRedirectExceptionAndGetUrl('reports/default/export');
262 
263  // Start background job
264  $job = new ExportJob();
265  $this->assertTrue($job->run());
266 
267  $exportItems = ExportItem::getAll();
268  $this->assertEquals(1, count($exportItems));
269  $fileModel = $exportItems[0]->exportFileModel;
270  $this->assertEquals(1, $exportItems[0]->isCompleted);
271  $this->assertEquals('csv', $exportItems[0]->exportFileType);
272  $this->assertEquals('reports', $exportItems[0]->exportFileName);
273  $this->assertTrue($fileModel instanceOf ExportFileModel);
274 
275  $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount());
276  $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount());
277  }
278 
283  {
284  $this->setGetArray(array('type' => 'RowsAndColumns', 'treeType' => ComponentForReportForm::TYPE_FILTERS));
285  $postData = static::makeRowsAndColumnsReportPostData();
286  $this->setPostArray($postData);
287  $content = $this->runControllerWithNoExceptionsAndGetContent('reports/default/relationsAndAttributesTree');
288  $this->assertContains('<div class="ReportRelationsAndAttributesTreeView', $content);
289  //With node id
290  $this->setGetArray(array('type' => 'RowsAndColumns', 'treeType' => ComponentForReportForm::TYPE_FILTERS,
291  'nodeId' => 'Filters_hasOne'));
292  $postData = static::makeRowsAndColumnsReportPostData();
293  $this->setPostArray($postData);
294  $content = $this->runControllerWithExitExceptionAndGetContent('reports/default/relationsAndAttributesTree');
295  $this->assertContains('{"id":"Filters_hasOne___createdByUser__User",', $content); // Not Coding Standard
296  }
297 
302  {
303  $this->setGetArray(array('type' => 'RowsAndColumns',
305  'nodeId' => 'Filters_phone',
306  'rowNumber' => 4));
307  $postData = static::makeRowsAndColumnsReportPostData();
308  $this->setPostArray($postData);
309  $content = $this->runControllerWithNoExceptionsAndGetContent('reports/default/addAttributeFromTree');
310  $this->assertContains('<option value="equals">Equals</option>', $content);
311  }
312 
317  {
318  $this->setGetArray(array('type' => 'Summation'));
319  $postData = static::makeSummationReportPostData();
320  $this->setPostArray($postData);
321  $content = $this->runControllerWithNoExceptionsAndGetContent('reports/default/getAvailableSeriesAndRangesForChart');
322  $this->assertContains('{"firstSeriesDataAndLabels":{"":"(None)"},"firstRangeDataAndLabels":', $content); // Not Coding Standard
323  }
324 
329  {
330  $savedReports = SavedReport::getAll();
331  $this->assertEquals(2, count($savedReports));
332  $this->setGetArray(array('id' => $savedReports[0]->id));
333  //validate filters, where it doesn't validate, the value is missing
334  $this->setPostArray(array('RowsAndColumnsReportWizardForm' => array('Filters' => array(
335  array('attributeIndexOrDerivedType' => 'string',
336  'operator' => 'equals'))),
337  'ajax' => 'edit-form'));
338  $this->runControllerWithExitExceptionAndGetContent('reports/default/applyRuntimeFilters');
339  //apply filters
340  $this->setPostArray(array('RowsAndColumnsReportWizardForm' => array('Filters' => array(
341  array('attributeIndexOrDerivedType' => 'string',
342  'operator' => 'equals',
343  'value' => 'text')))));
344  $this->runControllerWithNoExceptionsAndGetContent('reports/default/applyRuntimeFilters', true);
345  //Reset filters
346  $this->setGetArray(array('id' => $savedReports[0]->id));
347  $this->resetPostArray();
348  $this->runControllerWithNoExceptionsAndGetContent('reports/default/resetRuntimeFilters', true);
349  }
350 
354  public function testDrillDownDetails()
355  {
356  $savedReport = SavedReportTestHelper::makeSummationWithDrillDownReport();
357  $this->setGetArray(array('id' => $savedReport->id,
358  'rowId' => 2,
359  'runReport' => true,
360  'groupByRowValueowner__User' => Yii::app()->user->userModel->id));
361  $postData = static::makeSummationReportPostData();
362  $this->setPostArray($postData);
363  $content = $this->runControllerWithNoExceptionsAndGetContent('reports/default/drillDownDetails');
364  $this->assertContains('<th id="report-results-grid-view2_c2">Currency Value</th>', $content);
365  $this->assertContains('No results found', $content);
366 
367  //Check drillDown works with runtime filters
368  $this->setPostArray(array('SummationReportWizardForm' => array('Filters' => array(
369  array('attributeIndexOrDerivedType' => 'string',
370  'operator' => OperatorRules::TYPE_EQUALS,
371  'value' => 'string1')))));
372  $this->runControllerWithNoExceptionsAndGetContent('reports/default/applyRuntimeFilters', true);
373  $content = $this->runControllerWithNoExceptionsAndGetContent('reports/default/drillDownDetails');
374  $this->assertContains('<th id="report-results-grid-view2_c2">Currency Value</th>', $content);
375  $this->assertContains('1 result(s)', $content);
376  }
377 
381  public function testAutoComplete()
382  {
383  $this->setGetArray(array('term' => 'a test',
384  'moduleClassName' => 'ReportsModule',
385  'type' => Report::TYPE_SUMMATION));
386  $content = $this->runControllerWithNoExceptionsAndGetContent('reports/default/autoComplete');
387  $this->assertEquals('[]', $content);
388  }
389 
393  public function testDelete()
394  {
395  $savedReports = SavedReport::getAll();
396  $this->assertEquals(3, count($savedReports));
397  $this->setGetArray(array('id' => $savedReports[0]->id));
398  $this->runControllerWithRedirectExceptionAndGetContent('reports/default/delete');
399  $savedReports = SavedReport::getAll();
400  $this->assertEquals(2, count($savedReports));
401  }
402 
403  public function testCloneSetsRightPermissions()
404  {
405  // create users and groups.
406  $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
407  $everyoneGroup->setRight('ReportsModule', ReportsModule::getAccessRight());
408  $everyoneGroup->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
409  $this->assertTrue($everyoneGroup->save());
410  $everyoneGroup->forgetAll();
411 
412  $jim = UserTestHelper::createBasicUser('jim');
413  $john = UserTestHelper::createBasicUser('john');
414  $johnGroup = new Group();
415  $johnGroup->name = 'John Group';
416  $johnGroup->users->add($john);
417  $this->assertTrue($johnGroup->save());
418  $john->forgetAll();
419  $johnGroup->forgetAll();
420  $john = User::getByUsername('john');
421  $johnGroup = Group::getByName('John Group');
422 
423  $basePostData = static::makeRowsAndColumnsReportPostDataForAccounts();
424  $basePostData['save'] = 'save';
425  $description = StringUtil::generateRandomString(40);
426 
427  // create a report with everyone group permission, ensure everyone can access it.
428  // clone it, ensure everyone group can still access it.
429  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
431  $modelSpecificPostData = array('RowsAndColumnsReportWizardForm' => array(
432  'name' => 'Everyone Report 01',
433  'description' => $description,
434  'ownerId' => $super->id,
435  'ownerName' => strval($super),
436  'explicitReadWriteModelPermissions' => array(
437  'type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP,
438  'nonEveryoneGroup' => null,
439  )
440  ),
441  );
442  $postData = CMap::mergeArray($basePostData, $modelSpecificPostData);
443  $this->setGetArray(array('type' => 'RowsAndColumns'));
444  $this->setPostArray($postData);
445  $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
446  ForgetAllCacheUtil::forgetAllCaches();
447  $savedReports = SavedReport::getAll();
448  $this->assertCount(1, $savedReports);
449  $this->assertEquals(Permission::ALL, $savedReports[0]->getEffectivePermissions($super));
450  $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($everyoneGroup));
451  $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($jim));
452 
453  // ensure jim can access it.
455  $this->resetPostArray();
456  $this->resetGetArray();
457  $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
458  $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
459  $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
460 
461  $this->setGetArray(array('id' => $savedReports[0]->id));
462  $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
463  $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
464  $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
465 
466  // clone the report.
468  $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id, 'isBeingCopied' => '1'));
469  $postData['RowsAndColumnsReportWizardForm']['name'] = 'Cloned ' . $postData['RowsAndColumnsReportWizardForm']['name'];
470  $this->setPostArray($postData);
471  $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
472  ForgetAllCacheUtil::forgetAllCaches();
473  $savedReports = SavedReport::getAll();
474  $this->assertCount(2, $savedReports);
475  $sourcePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[0]);
476  $clonePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[1]);
477  $this->assertEquals($sourcePermissions, $clonePermissions);
478  $this->assertEquals(Permission::ALL, $savedReports[1]->getEffectivePermissions($super));
479  $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($everyoneGroup));
480  $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($jim));
481 
482  // ensure jim can access it.
484  $this->resetPostArray();
485  $this->resetGetArray();
486  $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
487  $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
488  $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
489 
490  $this->setGetArray(array('id' => $savedReports[1]->id));
491  $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
492  $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
493  $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
494 
495  // create a report with specific group permissions, ensure only members of that group can access it.
496  // clone it, ensure only that specific group members can access it.
497  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
499  $modelSpecificPostData = array('RowsAndColumnsReportWizardForm' => array(
500  'name' => 'Group Specific Report 01',
501  'description' => $description,
502  'ownerId' => $super->id,
503  'ownerName' => strval($super),
504  'explicitReadWriteModelPermissions' => array(
505  'type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_NONEVERYONE_GROUP,
506  'nonEveryoneGroup' => $johnGroup->id,
507  )
508  ),
509  );
510 
511  $postData = CMap::mergeArray($basePostData, $modelSpecificPostData);
512  $this->setGetArray(array('type' => 'RowsAndColumns'));
513  $this->setPostArray($postData);
514  $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
515  ForgetAllCacheUtil::forgetAllCaches();
516  $savedReports = SavedReport::getAll();
517  $this->assertCount(1, $savedReports);
518  $this->assertEquals(Permission::ALL, $savedReports[0]->getEffectivePermissions($super));
519  $this->assertEquals(Permission::NONE, $savedReports[0]->getEffectivePermissions($everyoneGroup));
520  $this->assertEquals(Permission::NONE, $savedReports[0]->getEffectivePermissions($jim));
521  $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($johnGroup));
522  $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($john));
523 
524  // ensure john can access it.
526  $this->resetPostArray();
527  $this->resetGetArray();
528  $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
529  $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
530  $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
531  $this->setGetArray(array('id' => $savedReports[0]->id));
532  $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
533  $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
534  $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
535 
536  // ensure jim can not access it.
538  $this->resetGetArray();
539  $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
540  $this->assertNotContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
541  $this->setGetArray(array('id' => $savedReports[0]->id));
542  $this->runControllerWithAccessDeniedSecurityExceptionAndGetContent('/reports/default/details');
543 
544  // clone the report.
546  $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id, 'isBeingCopied' => '1'));
547  $postData['RowsAndColumnsReportWizardForm']['name'] = 'Cloned ' . $postData['RowsAndColumnsReportWizardForm']['name'];
548  $this->setPostArray($postData);
549  $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
550  ForgetAllCacheUtil::forgetAllCaches();
551  $savedReports = SavedReport::getAll();
552  $this->assertCount(2, $savedReports);
553  $sourcePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[0]);
554  $clonePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[1]);
555  $this->assertEquals($sourcePermissions, $clonePermissions);
556  $this->assertEquals(Permission::ALL, $savedReports[1]->getEffectivePermissions($super));
557  $this->assertEquals(Permission::NONE, $savedReports[1]->getEffectivePermissions($everyoneGroup));
558  $this->assertEquals(Permission::NONE, $savedReports[1]->getEffectivePermissions($jim));
559  $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($johnGroup));
560  $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($john));
561 
562  // ensure john can access it.
564  $this->resetPostArray();
565  $this->resetGetArray();
566  $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
567  $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
568  $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
569 
570  $this->setGetArray(array('id' => $savedReports[1]->id));
571  $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
572  $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
573  $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
574 
575  // ensure jim can not access it.
577  $this->resetGetArray();
578  $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
579  $this->assertNotContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
580  $this->setGetArray(array('id' => $savedReports[0]->id));
581  $this->runControllerWithAccessDeniedSecurityExceptionAndGetContent('/reports/default/details');
582  }
583 
584  //todo: test saving a report and changing owner so you don't have permissions anymore. it should do a flashbar and redirect you to the list view.
585  //todo: test details view comes up ok when user cant delete or edit report, make sure options button doesn't blow up since it shouldn't display
586  }
587 ?>
static makeBySecurableItem(SecurableItem $securableItem)
static getByUsername($username)
Definition: User.php:49
runControllerWithRedirectExceptionAndGetContent($route, $compareUrl=null, $compareUrlContains=false)
const TYPE_SUMMATION
Definition: Report.php:57
runControllerWithAccessDeniedSecurityExceptionAndGetContent($route)
Definition: Group.php:37
static getByName($name)
Definition: Group.php:57
static deleteAll()
static getCount(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $where=null, $modelClassName=null, $selectDistinct=false)
logoutCurrentUserLoginNewUserAndGetByUsername($username)
static getAccessRight()
runControllerWithNoExceptionsAndGetContent($route, $empty=false)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static generateRandomString($length=10, $characterSet=null)
Definition: StringUtil.php:156
Generated on Sun Aug 9 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.