PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/app/protected/modules/reports/tests/unit/ModelRelationsAndAttributesToReportAdapterSecurityTest.php

https://bitbucket.org/ddonthula/zurmofeb
PHP | 116 lines | 86 code | 3 blank | 27 comment | 1 complexity | 35d21c49f4e6a6e240a914d71336225a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-2-Clause, GPL-3.0, BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /*********************************************************************************
  3. * Zurmo is a customer relationship management program developed by
  4. * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
  5. *
  6. * Zurmo is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU 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 General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU 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 113 McHenry Road Suite 207,
  24. * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
  25. ********************************************************************************/
  26. class ModelRelationsAndAttributesToReportAdapterSecurityTest extends ZurmoBaseTest
  27. {
  28. public static function setUpBeforeClass()
  29. {
  30. parent::setUpBeforeClass();
  31. SecurityTestHelper::createSuperAdmin();
  32. $sally = UserTestHelper::createBasicUser('sally');
  33. $sally->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
  34. $sally->setRight('OpportunitiesModule', OpportunitiesModule::RIGHT_ACCESS_OPPORTUNITIES);
  35. $sally->setRight('MeetingsModule', MeetingsModule::RIGHT_ACCESS_MEETINGS);
  36. if(!$sally->save())
  37. {
  38. throw new FailedToSaveModelException();
  39. }
  40. }
  41. public function testGetAllReportableRelationsAsASuperUser()
  42. {
  43. Yii::app()->user->userModel = User::getByUsername('super');
  44. $model = new Account();
  45. $rules = new AccountsReportRules();
  46. $report = new Report();
  47. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  48. $report->setModuleClassName('AccountsModule');
  49. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  50. $relations = $adapter->getSelectableRelationsData();
  51. $relations = $adapter->getSelectableRelationsDataResolvedForUserAccess(Yii::app()->user->userModel, $relations);
  52. $this->assertEquals(12, count($relations));
  53. $compareData = array('label' => 'Billing Address');
  54. $this->assertEquals($compareData, $relations['billingAddress']);
  55. $compareData = array('label' => 'Contacts');
  56. $this->assertEquals($compareData, $relations['contacts']);
  57. $compareData = array('label' => 'Created By User');
  58. $this->assertEquals($compareData, $relations['createdByUser']);
  59. $compareData = array('label' => 'Meetings');
  60. $this->assertEquals($compareData, $relations['meetings']);
  61. $compareData = array('label' => 'Modified By User');
  62. $this->assertEquals($compareData, $relations['modifiedByUser']);
  63. $compareData = array('label' => 'Notes');
  64. $this->assertEquals($compareData, $relations['notes']);
  65. $compareData = array('label' => 'Opportunities');
  66. $this->assertEquals($compareData, $relations['opportunities']);
  67. $compareData = array('label' => 'Owner');
  68. $this->assertEquals($compareData, $relations['owner']);
  69. $compareData = array('label' => 'Primary Email');
  70. $this->assertEquals($compareData, $relations['primaryEmail']);
  71. $compareData = array('label' => 'Shipping Address');
  72. $this->assertEquals($compareData, $relations['shippingAddress']);
  73. $compareData = array('label' => 'Secondary Email');
  74. $this->assertEquals($compareData, $relations['secondaryEmail']);
  75. $compareData = array('label' => 'Tasks');
  76. $this->assertEquals($compareData, $relations['tasks']);
  77. }
  78. /**
  79. * Sally cannot access notes, tasks, or contacts. User is always accessible regardless of right to access
  80. */
  81. public function testGetAllReportableRelationsAsANonElevatedUser()
  82. {
  83. Yii::app()->user->userModel = User::getByUsername('sally');
  84. $model = new Account();
  85. $rules = new AccountsReportRules();
  86. $report = new Report();
  87. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  88. $report->setModuleClassName('AccountsModule');
  89. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  90. $relations = $adapter->getSelectableRelationsData();
  91. $relations = $adapter->getSelectableRelationsDataResolvedForUserAccess(Yii::app()->user->userModel, $relations);
  92. $this->assertEquals(9, count($relations));
  93. $compareData = array('label' => 'Billing Address');
  94. $this->assertEquals($compareData, $relations['billingAddress']);
  95. $compareData = array('label' => 'Created By User');
  96. $this->assertEquals($compareData, $relations['createdByUser']);
  97. $compareData = array('label' => 'Meetings');
  98. $this->assertEquals($compareData, $relations['meetings']);
  99. $compareData = array('label' => 'Modified By User');
  100. $this->assertEquals($compareData, $relations['modifiedByUser']);
  101. $compareData = array('label' => 'Opportunities');
  102. $this->assertEquals($compareData, $relations['opportunities']);
  103. $compareData = array('label' => 'Owner');
  104. $this->assertEquals($compareData, $relations['owner']);
  105. $compareData = array('label' => 'Primary Email');
  106. $this->assertEquals($compareData, $relations['primaryEmail']);
  107. $compareData = array('label' => 'Shipping Address');
  108. $this->assertEquals($compareData, $relations['shippingAddress']);
  109. $compareData = array('label' => 'Secondary Email');
  110. $this->assertEquals($compareData, $relations['secondaryEmail']);
  111. }
  112. }
  113. ?>