PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/ddonthula/zurmofeb
PHP | 189 lines | 155 code | 10 blank | 24 comment | 2 complexity | 0be206985fe9f747c3cc750fdc33d42e 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 MatrixReportDataProviderTest extends ZurmoBaseTest
  27. {
  28. public $freeze = false;
  29. public static function setUpBeforeClass()
  30. {
  31. parent::setUpBeforeClass();
  32. SecurityTestHelper::createSuperAdmin();
  33. }
  34. public function setUp()
  35. {
  36. parent::setUp();
  37. Yii::app()->user->userModel = User::getByUsername('super');
  38. $freeze = false;
  39. if (RedBeanDatabase::isFrozen())
  40. {
  41. RedBeanDatabase::unfreeze();
  42. $freeze = true;
  43. }
  44. $this->freeze = $freeze;
  45. }
  46. public function teardown()
  47. {
  48. if ($this->freeze)
  49. {
  50. RedBeanDatabase::freeze();
  51. }
  52. parent::teardown();
  53. }
  54. public function testResolveDisplayAttributes()
  55. {
  56. Yii::app()->user->userModel = User::getByUsername('super');
  57. $report = new Report();
  58. $report->setType(Report::TYPE_MATRIX);
  59. $report->setModuleClassName('ReportsTestModule');
  60. $report->setFiltersStructure('');
  61. $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  62. Report::TYPE_MATRIX);
  63. $displayAttribute->attributeIndexOrDerivedType = 'integer__Maximum';
  64. $report->addDisplayAttribute($displayAttribute);
  65. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem',
  66. Report::TYPE_MATRIX);
  67. $groupBy->attributeIndexOrDerivedType = 'float';
  68. $groupBy->axis = 'y';
  69. $report->addGroupBy($groupBy);
  70. $reportDataProvider = new MatrixReportDataProvider($report);
  71. $displayAttributes = $reportDataProvider->resolveDisplayAttributes();
  72. $this->assertCount(2, $displayAttributes);
  73. }
  74. public function testResolveGroupBys()
  75. {
  76. Yii::app()->user->userModel = User::getByUsername('super');
  77. $report = new Report();
  78. $report->setType(Report::TYPE_MATRIX);
  79. $report->setModuleClassName('ReportsTestModule');
  80. $report->setFiltersStructure('');
  81. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem',
  82. Report::TYPE_MATRIX);
  83. $groupBy->attributeIndexOrDerivedType = 'integer';
  84. $groupBy->axis = 'x';
  85. $groupBy2 = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem',
  86. Report::TYPE_MATRIX);
  87. $groupBy2->attributeIndexOrDerivedType = 'float';
  88. $groupBy2->axis = 'y';
  89. $report->addGroupBy($groupBy);
  90. $report->addGroupBy($groupBy2);
  91. $reportDataProvider = new MatrixReportDataProvider($report);
  92. $groupBys = $reportDataProvider->resolveGroupBys();
  93. $this->assertCount(2, $groupBys);
  94. $this->assertEquals('float', $groupBys[0]->getAttributeIndexOrDerivedType());
  95. $this->assertEquals('integer', $groupBys[1]->getAttributeIndexOrDerivedType());
  96. }
  97. public function testGetXAxisGroupByDataValuesCount()
  98. {
  99. Yii::app()->user->userModel = User::getByUsername('super');
  100. $report = new Report();
  101. $report->setType(Report::TYPE_MATRIX);
  102. $report->setModuleClassName('ReportsTestModule');
  103. $report->setFiltersStructure('');
  104. $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  105. Report::TYPE_MATRIX);
  106. $displayAttribute->attributeIndexOrDerivedType = 'integer__Maximum';
  107. $report->addDisplayAttribute($displayAttribute);
  108. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem',
  109. Report::TYPE_MATRIX);
  110. $groupBy->attributeIndexOrDerivedType = 'float';
  111. $groupBy->axis = 'x';
  112. $report->addGroupBy($groupBy);
  113. $reportDataProvider = new MatrixReportDataProvider($report);
  114. $count = $reportDataProvider->getXAxisGroupByDataValuesCount();
  115. $this->assertEquals(1, $count);
  116. }
  117. public function testGetYAxisGroupByDataValuesCount()
  118. {
  119. Yii::app()->user->userModel = User::getByUsername('super');
  120. $report = new Report();
  121. $report->setType(Report::TYPE_MATRIX);
  122. $report->setModuleClassName('ReportsTestModule');
  123. $report->setFiltersStructure('');
  124. $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  125. Report::TYPE_MATRIX);
  126. $displayAttribute->attributeIndexOrDerivedType = 'integer__Maximum';
  127. $report->addDisplayAttribute($displayAttribute);
  128. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem',
  129. Report::TYPE_MATRIX);
  130. $groupBy->attributeIndexOrDerivedType = 'float';
  131. $groupBy->axis = 'y';
  132. $report->addGroupBy($groupBy);
  133. $reportDataProvider = new MatrixReportDataProvider($report);
  134. $count = $reportDataProvider->getYAxisGroupByDataValuesCount();
  135. $this->assertEquals(0, $count);
  136. }
  137. public function testMakeXAxisGroupingsForColumnNamesData()
  138. {
  139. Yii::app()->user->userModel = User::getByUsername('super');
  140. $report = new Report();
  141. $report->setType(Report::TYPE_MATRIX);
  142. $report->setModuleClassName('ReportsTestModule');
  143. $report->setFiltersStructure('');
  144. $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  145. Report::TYPE_MATRIX);
  146. $displayAttribute->attributeIndexOrDerivedType = 'integer__Maximum';
  147. $report->addDisplayAttribute($displayAttribute);
  148. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem',
  149. Report::TYPE_MATRIX);
  150. $groupBy->attributeIndexOrDerivedType = 'float';
  151. $groupBy->axis = 'x';
  152. $report->addGroupBy($groupBy);
  153. $reportDataProvider = new MatrixReportDataProvider($report);
  154. $data = $reportDataProvider->makeXAxisGroupingsForColumnNamesData();
  155. $this->assertEquals(array(), $data);
  156. }
  157. public function testMakeAxisCrossingColumnCountAndLeadingHeaderRowsData()
  158. {
  159. Yii::app()->user->userModel = User::getByUsername('super');
  160. $report = new Report();
  161. $report->setType(Report::TYPE_MATRIX);
  162. $report->setModuleClassName('ReportsTestModule');
  163. $report->setFiltersStructure('');
  164. $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  165. Report::TYPE_MATRIX);
  166. $displayAttribute->attributeIndexOrDerivedType = 'integer__Maximum';
  167. $report->addDisplayAttribute($displayAttribute);
  168. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem',
  169. Report::TYPE_MATRIX);
  170. $groupBy->attributeIndexOrDerivedType = 'float';
  171. $groupBy->axis = 'x';
  172. $report->addGroupBy($groupBy);
  173. $reportDataProvider = new MatrixReportDataProvider($report);
  174. $data = $reportDataProvider->makeAxisCrossingColumnCountAndLeadingHeaderRowsData();
  175. $compareData = array('rows' => array(), 'axisCrossingColumnCount' => 0);
  176. $this->assertEquals($compareData, $data);
  177. }
  178. }
  179. ?>