PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/ddonthula/zurmofeb
PHP | 194 lines | 159 code | 10 blank | 25 comment | 0 complexity | 8599381e2d136e294b0b1ef0a4b14d61 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 DataToReportUtilTest extends ZurmoBaseTest
  27. {
  28. public static function setUpBeforeClass()
  29. {
  30. parent::setUpBeforeClass();
  31. SecurityTestHelper::createSuperAdmin();
  32. UserTestHelper::createBasicUser('bobby');
  33. }
  34. public function setUp()
  35. {
  36. parent::setUp();
  37. Yii::app()->user->userModel = User::getByUsername('super');
  38. }
  39. public function testRowsAndColumnsResolveReportByWizardPostData()
  40. {
  41. $bobby = User::getByUserName('bobby');
  42. $wizardFormClassName = 'RowsAndColumnsReportWizardForm';
  43. $report = new Report();
  44. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  45. $data = array();
  46. $data['moduleClassName'] = 'ReportsTestModule';
  47. $data['description'] = 'a description';
  48. $data['name'] = 'name';
  49. $data['filtersStructure'] = '1 AND 2';
  50. $data['ownerId'] = $bobby->id;
  51. $data['currencyConversionType'] = Report::CURRENCY_CONVERSION_TYPE_SPOT;
  52. $data['spotConversionCurrencyCode'] = 'EUR';
  53. $data[ComponentForReportForm::TYPE_FILTERS][] = array('attributeIndexOrDerivedType' => 'date',
  54. 'valueType' => 'Between',
  55. 'value' => '2/24/12',
  56. 'secondValue' => '2/28/12');
  57. $data[ComponentForReportForm::TYPE_ORDER_BYS][] = array('attributeIndexOrDerivedType' => 'string',
  58. 'order' => 'desc');
  59. $data[ComponentForReportForm::TYPE_DISPLAY_ATTRIBUTES][] = array('attributeIndexOrDerivedType' => 'phone',
  60. 'label' => 'custom');
  61. DataToReportUtil::resolveReportByWizardPostData($report, array('RowsAndColumnsReportWizardForm' => $data),
  62. $wizardFormClassName);
  63. $this->assertEquals('ReportsTestModule', $report->getModuleClassName());
  64. $this->assertEquals('a description', $report->getDescription());
  65. $this->assertEquals('name', $report->getName());
  66. $this->assertEquals('1 AND 2', $report->getFiltersStructure());
  67. $this->assertEquals($bobby->id, $report->getOwner()->id);
  68. $this->assertEquals(Report::CURRENCY_CONVERSION_TYPE_SPOT, $report->getCurrencyConversionType());
  69. $this->assertEquals('EUR', $report->getSpotConversionCurrencyCode());
  70. $filters = $report->getFilters();
  71. $this->assertCount(1, $filters);
  72. $this->assertEquals('date', $filters[0]->getAttributeIndexOrDerivedType());
  73. $this->assertEquals('Between', $filters[0]->valueType);
  74. $this->assertEquals('2012-02-24', $filters[0]->value);
  75. $this->assertEquals('2012-02-28', $filters[0]->secondValue);
  76. $orderBys = $report->getOrderBys();
  77. $this->assertCount(1, $orderBys);
  78. $this->assertEquals('string', $orderBys[0]->getAttributeIndexOrDerivedType());
  79. $this->assertEquals('desc', $orderBys[0]->order);
  80. $displayAttributes = $report->getDisplayAttributes();
  81. $this->assertCount(1, $orderBys);
  82. $this->assertEquals('phone', $displayAttributes[0]->getAttributeIndexOrDerivedType());
  83. $this->assertEquals('custom', $displayAttributes[0]->label);
  84. }
  85. public function testSummationResolveReportByWizardPostData()
  86. {
  87. $bobby = User::getByUserName('bobby');
  88. $wizardFormClassName = 'SummationReportWizardForm';
  89. $report = new Report();
  90. $report->setType(Report::TYPE_SUMMATION);
  91. $data = array();
  92. $data['moduleClassName'] = 'ReportsTestModule';
  93. $data['description'] = 'a description';
  94. $data['name'] = 'name';
  95. $data['filtersStructure'] = '1 AND 2';
  96. $data['ownerId'] = $bobby->id;
  97. $data['currencyConversionType'] = Report::CURRENCY_CONVERSION_TYPE_SPOT;
  98. $data['spotConversionCurrencyCode'] = 'EUR';
  99. $data[ComponentForReportForm::TYPE_FILTERS][] = array('attributeIndexOrDerivedType' => 'date',
  100. 'valueType' => 'Between',
  101. 'value' => '2/24/12',
  102. 'secondValue' => '2/28/12');
  103. $data[ComponentForReportForm::TYPE_ORDER_BYS][] = array('attributeIndexOrDerivedType' => 'string',
  104. 'order' => 'desc');
  105. $data[ComponentForReportForm::TYPE_DISPLAY_ATTRIBUTES][] = array('attributeIndexOrDerivedType' => 'phone',
  106. 'label' => 'custom');
  107. $data[ComponentForReportForm::TYPE_DRILL_DOWN_DISPLAY_ATTRIBUTES][] =
  108. array('attributeIndexOrDerivedType' => 'string',
  109. 'label' => 'custom string');
  110. $data[ComponentForReportForm::TYPE_GROUP_BYS][] = array('attributeIndexOrDerivedType' => 'string',
  111. 'axis' => 'y');
  112. $data['ChartForReportForm'] = array('type' => ChartRules::TYPE_BAR_2D,
  113. 'firstSeries' => 'string',
  114. 'firstRange' => 'integer__Maximum');
  115. DataToReportUtil::resolveReportByWizardPostData($report, array('SummationReportWizardForm' => $data),
  116. $wizardFormClassName);
  117. $this->assertEquals('ReportsTestModule', $report->getModuleClassName());
  118. $this->assertEquals('a description', $report->getDescription());
  119. $this->assertEquals('name', $report->getName());
  120. $this->assertEquals('1 AND 2', $report->getFiltersStructure());
  121. $this->assertEquals($bobby->id, $report->getOwner()->id);
  122. $this->assertEquals(Report::CURRENCY_CONVERSION_TYPE_SPOT, $report->getCurrencyConversionType());
  123. $this->assertEquals('EUR', $report->getSpotConversionCurrencyCode());
  124. $filters = $report->getFilters();
  125. $this->assertCount(1, $filters);
  126. $this->assertEquals('date', $filters[0]->getAttributeIndexOrDerivedType());
  127. $this->assertEquals('Between', $filters[0]->valueType);
  128. $this->assertEquals('2012-02-24', $filters[0]->value);
  129. $this->assertEquals('2012-02-28', $filters[0]->secondValue);
  130. $orderBys = $report->getOrderBys();
  131. $this->assertCount(1, $orderBys);
  132. $this->assertEquals('string', $orderBys[0]->getAttributeIndexOrDerivedType());
  133. $this->assertEquals('desc', $orderBys[0]->order);
  134. $displayAttributes = $report->getDisplayAttributes();
  135. $this->assertCount(1, $displayAttributes);
  136. $this->assertEquals('phone', $displayAttributes[0]->getAttributeIndexOrDerivedType());
  137. $this->assertEquals('custom', $displayAttributes[0]->label);
  138. $groupBys = $report->getGroupBys();
  139. $this->assertCount(1, $groupBys);
  140. $this->assertEquals('string', $groupBys[0]->getAttributeIndexOrDerivedType());
  141. $this->assertEquals('y', $groupBys[0]->axis);
  142. $drillDownDisplayAttributes = $report->getDrillDownDisplayAttributes();
  143. $this->assertCount(1, $drillDownDisplayAttributes);
  144. $this->assertEquals('string', $drillDownDisplayAttributes[0]->getAttributeIndexOrDerivedType());
  145. $this->assertEquals('custom string', $drillDownDisplayAttributes[0]->label);
  146. $chart = $report->getChart();
  147. $this->assertEquals(ChartRules::TYPE_BAR_2D, $chart->type);
  148. $this->assertEquals('string', $chart->firstSeries);
  149. $this->assertEquals('integer__Maximum', $chart->firstRange);
  150. }
  151. public function testResolveFiltersAndDateConvertsProperlyToDbFormat()
  152. {
  153. $report = new Report();
  154. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  155. $report->setModuleClassName('ReportsTestModule');
  156. $data = array();
  157. $data[ComponentForReportForm::TYPE_FILTERS][] = array('attributeIndexOrDerivedType' => 'date',
  158. 'valueType' => 'Between',
  159. 'value' => '2/24/12',
  160. 'secondValue' => '2/28/12');
  161. DataToReportUtil::resolveFilters($data, $report);
  162. $filters = $report->getFilters();
  163. $this->assertCount(1, $filters);
  164. $this->assertEquals('Between', $filters[0]->valueType);
  165. $this->assertEquals('2012-02-24', $filters[0]->value);
  166. $this->assertEquals('2012-02-28', $filters[0]->secondValue);
  167. }
  168. public function testSanitizeFiltersData()
  169. {
  170. //test specifically for date/dateTime conversion from local to db format.
  171. $filtersData = array();
  172. $filtersData[0] = array('attributeIndexOrDerivedType' => 'date', 'value' => '2/24/12');
  173. $filtersData[1] = array('attributeIndexOrDerivedType' => 'dateTime', 'value' => '2/25/12');
  174. $filtersData[2] = array('attributeIndexOrDerivedType' => 'date', 'value' => '2/24/12',
  175. 'secondValue' => '2/28/12');
  176. $sanitizedFilterData = DataToReportUtil::sanitizeFiltersData('ReportsTestModule',
  177. Report::TYPE_ROWS_AND_COLUMNS, $filtersData);
  178. $this->assertEquals('2012-02-24', $sanitizedFilterData[0]['value']);
  179. $this->assertEquals('2012-02-25', $sanitizedFilterData[1]['value']);
  180. $this->assertEquals('2012-02-24', $sanitizedFilterData[2]['value']);
  181. $this->assertEquals('2012-02-28', $sanitizedFilterData[2]['secondValue']);
  182. }
  183. }
  184. ?>