PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/ddonthula/zurmofeb
PHP | 110 lines | 79 code | 6 blank | 25 comment | 0 complexity | 0d5177eee4ee62296d2319c728633f64 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 StickyReportUtilTest extends ZurmoBaseTest
  27. {
  28. public static function setUpBeforeClass()
  29. {
  30. parent::setUpBeforeClass();
  31. SecurityTestHelper::createSuperAdmin();
  32. }
  33. public function setUp()
  34. {
  35. parent::setUp();
  36. Yii::app()->user->userModel = User::getByUsername('super');
  37. }
  38. public function testResolveStickyDataToReport()
  39. {
  40. $filter = new FilterForReportForm('ReportsTestModule', 'ReportModelTestItem',
  41. Report::TYPE_ROWS_AND_COLUMNS);
  42. $filter->attributeIndexOrDerivedType = 'string';
  43. $filter->operator = OperatorRules::TYPE_EQUALS;
  44. $filter->value = 'Zurmo';
  45. $report = new Report();
  46. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  47. $report->setModuleClassName('ReportsTestModule');
  48. $report->addFilter($filter);
  49. $stickyData = array();
  50. $stickyData[ComponentForReportForm::TYPE_FILTERS][] = array('value' => 'changedValue');
  51. StickyReportUtil::resolveStickyDataToReport($report, $stickyData);
  52. $filters = $report->getFilters();
  53. $this->assertCount(1, $filters);
  54. $this->assertEquals('changedValue', $filters[0]->value);
  55. //Test where the stickyData is malformed.
  56. $stickyData = array();
  57. $stickyData[] = array('value' => 'changedValue2');
  58. StickyReportUtil::resolveStickyDataToReport($report, $stickyData);
  59. $filters = $report->getFilters();
  60. $this->assertCount(1, $filters);
  61. $this->assertEquals('changedValue', $filters[0]->value);
  62. }
  63. public function testIsNullConvertsEmptyStringToNull()
  64. {
  65. $filter = new FilterForReportForm('ReportsTestModule', 'ReportModelTestItem',
  66. Report::TYPE_ROWS_AND_COLUMNS);
  67. $filter->attributeIndexOrDerivedType = 'string';
  68. $filter->operator = OperatorRules::TYPE_EQUALS;
  69. $filter->value = 'Zurmo';
  70. $report = new Report();
  71. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  72. $report->setModuleClassName('ReportsTestModule');
  73. $report->addFilter($filter);
  74. $stickyData = array();
  75. $stickyData[ComponentForReportForm::TYPE_FILTERS][] = array('operator' => OperatorRules::TYPE_IS_NULL,
  76. 'value' => '');
  77. StickyReportUtil::resolveStickyDataToReport($report, $stickyData);
  78. $filters = $report->getFilters();
  79. $this->assertCount(1, $filters);
  80. $this->assertEquals(OperatorRules::TYPE_IS_NULL, $filters[0]->operator);
  81. $this->assertNull(null, $filters[0]->value);
  82. }
  83. public function testDateTimeConvertsValueTypeToNullWhenNeeded()
  84. {
  85. $filter = new FilterForReportForm('ReportsTestModule', 'ReportModelTestItem',
  86. Report::TYPE_ROWS_AND_COLUMNS);
  87. $filter->attributeIndexOrDerivedType = 'dateTime';
  88. $filter->value = '2011-05-05';
  89. $filter->valueType = MixedDateTypesSearchFormAttributeMappingRules::TYPE_ON;
  90. $report = new Report();
  91. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  92. $report->setModuleClassName('ReportsTestModule');
  93. $report->addFilter($filter);
  94. $stickyData = array();
  95. $stickyData[ComponentForReportForm::TYPE_FILTERS][] =
  96. array('valueType' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY, 'value' => '');
  97. StickyReportUtil::resolveStickyDataToReport($report, $stickyData);
  98. $filters = $report->getFilters();
  99. $this->assertCount(1, $filters);
  100. $this->assertEquals(MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY, $filters[0]->valueType);
  101. $this->assertNull(null, $filters[0]->value);
  102. }
  103. }
  104. ?>