PageRenderTime 65ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/ddonthula/zurmofeb
PHP | 1447 lines | 1183 code | 85 blank | 179 comment | 0 complexity | 2d85d74d42dc48e2c7af0c1eeb113751 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 ModelRelationsAndAttributesToReportAdapterTest extends ZurmoBaseTest
  27. {
  28. public static function setUpBeforeClass()
  29. {
  30. parent::setUpBeforeClass();
  31. SecurityTestHelper::createSuperAdmin();
  32. $attributeName = 'calculated';
  33. $attributeForm = new CalculatedNumberAttributeForm();
  34. $attributeForm->attributeName = $attributeName;
  35. $attributeForm->attributeLabels = array('en' => 'Test Calculated');
  36. $attributeForm->formula = 'integer + float';
  37. $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
  38. $adapter = new $modelAttributesAdapterClassName(new ReportModelTestItem());
  39. $adapter->setAttributeMetadataFromForm($attributeForm);
  40. }
  41. public function setup()
  42. {
  43. parent::setUp();
  44. Yii::app()->user->userModel = User::getByUsername('super');
  45. ModelRelationsAndAttributesToSummableReportAdapter::forgetAll();
  46. }
  47. public function testIsDisplayAttributeMadeViaSelect()
  48. {
  49. $model = new ReportModelTestItem();
  50. $rules = new ReportsTestReportRules(); //ReportsTestModule rules
  51. $report = new Report();
  52. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  53. $report->setModuleClassName('ReportsTestModule');
  54. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  55. $this->assertFalse($adapter->isDisplayAttributeMadeViaSelect('something'));
  56. }
  57. public function testGetAllRelations()
  58. {
  59. $model = new ReportModelTestItem();
  60. $rules = new ReportsTestReportRules(); //ReportsTestModule rules
  61. $report = new Report();
  62. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  63. $report->setModuleClassName('ReportsTestModule');
  64. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  65. $relations = $adapter->getAllRelationsData();
  66. $this->assertEquals(20, count($relations));
  67. }
  68. /**
  69. * @depends testGetAllRelations
  70. * Make sure HAS_MANY_BELONGS_TO relations show up
  71. */
  72. public function testGetHasManyBelongsToRelations()
  73. {
  74. $model = new ReportModelTestItem9();
  75. $rules = new ReportsTestReportRules(); //ReportsTestModule rules
  76. $report = new Report();
  77. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  78. $report->setModuleClassName('ReportsTestModule');
  79. $adapter = new ModelRelationsAndAttributesToRowsAndColumnsReportAdapter($model, $rules,
  80. $report->getType());
  81. $relations = $adapter->getSelectableRelationsData();
  82. $this->assertEquals(9, count($relations));
  83. $compareData = array('label' => 'Report Model Test Item 9');
  84. $this->assertEquals($compareData, $relations['reportModelTestItem9']);
  85. $compareData = array('label' => 'Report Model Test Item 9s');
  86. $this->assertEquals($compareData, $relations['reportModelTestItem9s']);
  87. }
  88. /**
  89. * @depends testGetHasManyBelongsToRelations
  90. */
  91. public function testPassingPrecedingRelationThatHasAssumptiveLinkIsProperlyHandled()
  92. {
  93. $model = new ReportModelTestItem3();
  94. $rules = new ReportsTestReportRules();
  95. $report = new Report();
  96. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  97. $report->setModuleClassName('ReportsTestModule');
  98. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  99. $relations = $adapter->getSelectableRelationsData(new ReportModelTestItem(), 'hasMany');
  100. $this->assertFalse(isset($relations['hasMany1']));
  101. }
  102. /**
  103. * @depends testPassingPrecedingRelationThatHasAssumptiveLinkIsProperlyHandled
  104. */
  105. public function testGetAllReportableRelations()
  106. {
  107. //ReportModelTestItem has hasOne, hasMany, and hasOneAlso. In addition it has a
  108. //derivedRelationsViaCastedUpModel to ReportModelTestItem5.
  109. //Excludes any customField relations and relationsReportedOnAsAttributes
  110. //Also excludes any non-reportable relations
  111. //Get relations through adapter and confirm everything matches up as expected
  112. $model = new ReportModelTestItem();
  113. $rules = new ReportsTestReportRules();
  114. $report = new Report();
  115. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  116. $report->setModuleClassName('ReportsTestModule');
  117. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  118. $relations = $adapter->getSelectableRelationsData();
  119. $this->assertEquals(11, count($relations));
  120. $compareData = array('label' => 'Has One');
  121. $this->assertEquals($compareData, $relations['hasOne']);
  122. $compareData = array('label' => 'Has One Again');
  123. $this->assertEquals($compareData, $relations['hasOneAgain']);
  124. $compareData = array('label' => 'Has Many');
  125. $this->assertEquals($compareData, $relations['hasMany']);
  126. $compareData = array('label' => 'Has One Also');
  127. $this->assertEquals($compareData, $relations['hasOneAlso']);
  128. $compareData = array('label' => 'Model 5 Via Item');
  129. $this->assertEquals($compareData, $relations['model5ViaItem']);
  130. $compareData = array('label' => 'Primary Email');
  131. $this->assertEquals($compareData, $relations['primaryEmail']);
  132. $compareData = array('label' => 'Primary Address');
  133. $this->assertEquals($compareData, $relations['primaryAddress']);
  134. $compareData = array('label' => 'Secondary Email');
  135. $this->assertEquals($compareData, $relations['secondaryEmail']);
  136. $compareData = array('label' => 'Owner');
  137. $this->assertEquals($compareData, $relations['owner']);
  138. $compareData = array('label' => 'Created By User');
  139. $this->assertEquals($compareData, $relations['createdByUser']);
  140. $compareData = array('label' => 'Modified By User');
  141. $this->assertEquals($compareData, $relations['modifiedByUser']);
  142. }
  143. /**
  144. * When retrieving available relations, make sure it does not give a relation based on what model it is coming
  145. * from. If you are in a Contact and the parent relation is account, then Contact should not return the account
  146. * as an available relation.
  147. * @depends testGetAllReportableRelations
  148. */
  149. public function testGetAvailableRelationsDoesNotCauseFeedbackLoop()
  150. {
  151. $model = new ReportModelTestItem2();
  152. $rules = new ReportsTestReportRules();
  153. $report = new Report();
  154. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  155. $report->setModuleClassName('ReportsTestModule');
  156. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  157. $relations = $adapter->getSelectableRelationsData();
  158. $this->assertEquals(5, count($relations));
  159. $compareData = array('label' => 'Has Many 2');
  160. $this->assertEquals($compareData, $relations['hasMany2']);
  161. $compareData = array('label' => 'Has Many 3');
  162. $this->assertEquals($compareData, $relations['hasMany3']);
  163. $compareData = array('label' => 'Owner');
  164. $this->assertEquals($compareData, $relations['owner']);
  165. $compareData = array('label' => 'Created By User');
  166. $this->assertEquals($compareData, $relations['createdByUser']);
  167. $compareData = array('label' => 'Modified By User');
  168. $this->assertEquals($compareData, $relations['modifiedByUser']);
  169. $precedingModel = new ReportModelTestItem();
  170. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  171. $relations = $adapter->getSelectableRelationsData($precedingModel, 'hasOne');
  172. $this->assertEquals(4, count($relations));
  173. $compareData = array('label' => 'Has Many 3');
  174. $this->assertEquals($compareData, $relations['hasMany3']);
  175. $compareData = array('label' => 'Owner');
  176. $this->assertEquals($compareData, $relations['owner']);
  177. $compareData = array('label' => 'Created By User');
  178. $this->assertEquals($compareData, $relations['createdByUser']);
  179. $compareData = array('label' => 'Modified By User');
  180. $this->assertEquals($compareData, $relations['modifiedByUser']);
  181. }
  182. /**
  183. * @depends testGetAvailableRelationsDoesNotCauseFeedbackLoop
  184. */
  185. public function testGetReportableAttributes()
  186. {
  187. $model = new ReportModelTestItem();
  188. $rules = new ReportsTestReportRules();
  189. $report = new Report();
  190. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  191. $report->setModuleClassName('ReportsTestModule');
  192. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  193. $attributes = $adapter->getAttributesIncludingDerivedAttributesData();
  194. $this->assertEquals(27, count($attributes));
  195. $compareData = array('label' => 'Id');
  196. $this->assertEquals($compareData, $attributes['id']);
  197. $compareData = array('label' => 'Created Date Time');
  198. $this->assertEquals($compareData, $attributes['createdDateTime']);
  199. $compareData = array('label' => 'Modified Date Time');
  200. $this->assertEquals($compareData, $attributes['modifiedDateTime']);
  201. $compareData = array('label' => 'First Name');
  202. $this->assertEquals($compareData, $attributes['firstName']);
  203. $compareData = array('label' => 'Last Name');
  204. $this->assertEquals($compareData, $attributes['lastName']);
  205. $compareData = array('label' => 'Boolean');
  206. $this->assertEquals($compareData, $attributes['boolean']);
  207. $compareData = array('label' => 'Date');
  208. $this->assertEquals($compareData, $attributes['date']);
  209. $compareData = array('label' => 'Date Time');
  210. $this->assertEquals($compareData, $attributes['dateTime']);
  211. $compareData = array('label' => 'Float');
  212. $this->assertEquals($compareData, $attributes['float']);
  213. $compareData = array('label' => 'Integer');
  214. $this->assertEquals($compareData, $attributes['integer']);
  215. $compareData = array('label' => 'Phone');
  216. $this->assertEquals($compareData, $attributes['phone']);
  217. $compareData = array('label' => 'String');
  218. $this->assertEquals($compareData, $attributes['string']);
  219. $compareData = array('label' => 'Text Area');
  220. $this->assertEquals($compareData, $attributes['textArea']);
  221. $compareData = array('label' => 'Url');
  222. $this->assertEquals($compareData, $attributes['url']);
  223. $compareData = array('label' => 'Drop Down');
  224. $this->assertEquals($compareData, $attributes['dropDown']);
  225. $compareData = array('label' => 'Drop Down 2');
  226. $this->assertEquals($compareData, $attributes['dropDown2']);
  227. $compareData = array('label' => 'Radio Drop Down');
  228. $this->assertEquals($compareData, $attributes['radioDropDown']);
  229. $compareData = array('label' => 'Multi Drop Down');
  230. $this->assertEquals($compareData, $attributes['multiDropDown']);
  231. $compareData = array('label' => 'Tag Cloud');
  232. $this->assertEquals($compareData, $attributes['tagCloud']);
  233. $compareData = array('label' => 'Reported As Attribute');
  234. $this->assertEquals($compareData, $attributes['reportedAsAttribute']);
  235. //Currency is treated as a relation reported as an attribute just like drop downs
  236. $compareData = array('label' => 'Currency Value');
  237. $this->assertEquals($compareData, $attributes['currencyValue']);
  238. //likeContactState is a relation reported as attribute.
  239. //Makes sure the label is using the proper label translation via attributeLabels
  240. $compareData = array('label' => 'A name for a state');
  241. $this->assertEquals($compareData, $attributes['likeContactState']);
  242. //Includes derived attributes as well
  243. $compareData = array('label' => 'Test Calculated', 'derivedAttributeType' => 'CalculatedNumber');
  244. $this->assertEquals($compareData, $attributes['calculated']);
  245. $compareData = array('label' => 'Full Name', 'derivedAttributeType' => 'FullName');
  246. $this->assertEquals($compareData, $attributes['FullName']);
  247. //Add Dynamically Derived Attributes
  248. $compareData = array('label' => 'Owner');
  249. $this->assertEquals($compareData, $attributes['owner__User']);
  250. $compareData = array('label' => 'Created By User');
  251. $this->assertEquals($compareData, $attributes['createdByUser__User']);
  252. $compareData = array('label' => 'Modified By User');
  253. $this->assertEquals($compareData, $attributes['modifiedByUser__User']);
  254. }
  255. /**
  256. * @depends testGetReportableAttributes
  257. * Testing where a model relates to another model via something like Item. An example is notes which connects
  258. * to accounts via activityItems MANY_MANY through Items. On Notes we need to be able to show these relations
  259. * as selectable in reporting.
  260. *
  261. * In this example ReportModelTestItem5 connects to ReportModelTestItem and ReportModelTestItem2
  262. * via MANY_MANY through Item using the reportItems relation
  263. * Known as viaRelations: model5ViaItem on ReportModelItem and model5ViaItem on ReportModelItem2
  264. */
  265. public function testGetInferredRelationsData()
  266. {
  267. $model = new ReportModelTestItem5();
  268. $rules = new ReportsTestReportRules();
  269. $report = new Report();
  270. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  271. $report->setModuleClassName('ReportsTestModule');
  272. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  273. $relations = $adapter->getInferredRelationsData();
  274. $this->assertEquals(2, count($relations));
  275. $compareData = array('label' => 'ReportModelTestItems');
  276. $this->assertEquals($compareData, $relations['ReportModelTestItem__reportItems__Inferred']);
  277. $compareData = array('label' => 'ReportModelTestItem2s');
  278. $this->assertEquals($compareData, $relations['ReportModelTestItem2__reportItems__Inferred']);
  279. //Getting all selectable relations. Should yield all 3 relations
  280. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  281. $relations = $adapter->getSelectableRelationsData();
  282. $this->assertEquals(6, count($relations));
  283. $compareData = array('label' => 'ReportModelTestItems');
  284. $this->assertEquals($compareData, $relations['ReportModelTestItem__reportItems__Inferred']);
  285. $compareData = array('label' => 'ReportModelTestItem2s');
  286. $this->assertEquals($compareData, $relations['ReportModelTestItem2__reportItems__Inferred']);
  287. $compareData = array('label' => 'Report Items');
  288. $this->assertEquals($compareData, $relations['reportItems']);
  289. //Add Dynamically Derived Attributes
  290. $compareData = array('label' => 'Owner');
  291. $this->assertEquals($compareData, $relations['owner']);
  292. $compareData = array('label' => 'Created By User');
  293. $this->assertEquals($compareData, $relations['createdByUser']);
  294. $compareData = array('label' => 'Modified By User');
  295. $this->assertEquals($compareData, $relations['modifiedByUser']);
  296. }
  297. /**
  298. * @depends testGetInferredRelationsData
  299. */
  300. public function testGetInferredRelationsDataWithPrecedingModel()
  301. {
  302. $model = new ReportModelTestItem5();
  303. $rules = new ReportsTestReportRules();
  304. $report = new Report();
  305. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  306. $precedingModel = new ReportModelTestItem7();
  307. $report->setModuleClassName('ReportsTestModule');
  308. //Test calling on model 5 with a preceding model that is NOT part of reportItems
  309. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  310. $relations = $adapter->getSelectableRelationsData($precedingModel, 'model5');
  311. $this->assertEquals(6, count($relations));
  312. $compareData = array('label' => 'ReportModelTestItems');
  313. $this->assertEquals($compareData, $relations['ReportModelTestItem__reportItems__Inferred']);
  314. $compareData = array('label' => 'ReportModelTestItem2s');
  315. $this->assertEquals($compareData, $relations['ReportModelTestItem2__reportItems__Inferred']);
  316. $compareData = array('label' => 'Report Items');
  317. $this->assertEquals($compareData, $relations['reportItems']);
  318. //Add Dynamically Derived Attributes
  319. $compareData = array('label' => 'Owner');
  320. $this->assertEquals($compareData, $relations['owner']);
  321. $compareData = array('label' => 'Created By User');
  322. $this->assertEquals($compareData, $relations['createdByUser']);
  323. $compareData = array('label' => 'Modified By User');
  324. $this->assertEquals($compareData, $relations['modifiedByUser']);
  325. //Test calling on model 5 with a preceding model that is one of the reportItem models
  326. $precedingModel = new ReportModelTestItem();
  327. $relations = $adapter->getSelectableRelationsData($precedingModel, 'model5ViaItem');
  328. $this->assertEquals(5, count($relations));
  329. $compareData = array('label' => 'ReportModelTestItem2s');
  330. $this->assertEquals($compareData, $relations['ReportModelTestItem2__reportItems__Inferred']);
  331. $compareData = array('label' => 'Report Items');
  332. $this->assertEquals($compareData, $relations['reportItems']);
  333. //Add Dynamically Derived Attributes
  334. $compareData = array('label' => 'Owner');
  335. $this->assertEquals($compareData, $relations['owner']);
  336. $compareData = array('label' => 'Created By User');
  337. $this->assertEquals($compareData, $relations['createdByUser']);
  338. $compareData = array('label' => 'Modified By User');
  339. $this->assertEquals($compareData, $relations['modifiedByUser']);
  340. }
  341. /**
  342. * @depends testGetInferredRelationsDataWithPrecedingModel
  343. */
  344. public function testGetDerivedRelationsViaCastedUpModelDataWithPrecedingModel()
  345. {
  346. //test with preceding model that is not the via relation
  347. $model = new ReportModelTestItem();
  348. $precedingModel = new ReportModelTestItem5();
  349. $rules = new ReportsTestReportRules();
  350. $report = new Report();
  351. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  352. $report->setModuleClassName('ReportsTestModule');
  353. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  354. $relations = $adapter->getSelectableRelationsData($precedingModel, 'nonReportable2');
  355. $this->assertEquals(11, count($relations));
  356. $compareData = array('label' => 'Has One');
  357. $this->assertEquals($compareData, $relations['hasOne']);
  358. $compareData = array('label' => 'Has One Again');
  359. $this->assertEquals($compareData, $relations['hasOneAgain']);
  360. $compareData = array('label' => 'Has Many');
  361. $this->assertEquals($compareData, $relations['hasMany']);
  362. $compareData = array('label' => 'Has One Also');
  363. $this->assertEquals($compareData, $relations['hasOneAlso']);
  364. $compareData = array('label' => 'Model 5 Via Item');
  365. $this->assertEquals($compareData, $relations['model5ViaItem']);
  366. $compareData = array('label' => 'Primary Email');
  367. $this->assertEquals($compareData, $relations['primaryEmail']);
  368. $compareData = array('label' => 'Primary Address');
  369. $this->assertEquals($compareData, $relations['primaryAddress']);
  370. $compareData = array('label' => 'Secondary Email');
  371. $this->assertEquals($compareData, $relations['secondaryEmail']);
  372. $compareData = array('label' => 'Owner');
  373. $this->assertEquals($compareData, $relations['owner']);
  374. $compareData = array('label' => 'Created By User');
  375. $this->assertEquals($compareData, $relations['createdByUser']);
  376. $compareData = array('label' => 'Modified By User');
  377. $this->assertEquals($compareData, $relations['modifiedByUser']);
  378. //test with preceding model that is the via relation
  379. $rules = new ReportsTestReportRules();
  380. $report = new Report();
  381. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  382. $report->setModuleClassName('ReportsTestModule');
  383. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
  384. $relations = $adapter->getSelectableRelationsData($precedingModel, 'reportItems');
  385. $this->assertEquals(10, count($relations));
  386. $compareData = array('label' => 'Has One');
  387. $this->assertEquals($compareData, $relations['hasOne']);
  388. $compareData = array('label' => 'Has One Again');
  389. $this->assertEquals($compareData, $relations['hasOneAgain']);
  390. $compareData = array('label' => 'Has Many');
  391. $this->assertEquals($compareData, $relations['hasMany']);
  392. $compareData = array('label' => 'Has One Also');
  393. $this->assertEquals($compareData, $relations['hasOneAlso']);
  394. $compareData = array('label' => 'Primary Email');
  395. $this->assertEquals($compareData, $relations['primaryEmail']);
  396. $compareData = array('label' => 'Primary Address');
  397. $this->assertEquals($compareData, $relations['primaryAddress']);
  398. $compareData = array('label' => 'Secondary Email');
  399. $this->assertEquals($compareData, $relations['secondaryEmail']);
  400. $compareData = array('label' => 'Owner');
  401. $this->assertEquals($compareData, $relations['owner']);
  402. $compareData = array('label' => 'Created By User');
  403. $this->assertEquals($compareData, $relations['createdByUser']);
  404. $compareData = array('label' => 'Modified By User');
  405. $this->assertEquals($compareData, $relations['modifiedByUser']);
  406. }
  407. /**
  408. * @depends testGetDerivedRelationsViaCastedUpModelDataWithPrecedingModel
  409. */
  410. public function testGetAvailableAttributesForRowsAndColumnsFilters()
  411. {
  412. $model = new ReportModelTestItem();
  413. $rules = new ReportsTestReportRules();
  414. $report = new Report();
  415. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  416. $report->setModuleClassName('ReportsTestModule');
  417. $adapter = new ModelRelationsAndAttributesToRowsAndColumnsReportAdapter($model, $rules, $report->getType());
  418. $attributes = $adapter->getAttributesForFilters();
  419. $this->assertEquals(24, count($attributes));
  420. $compareData = array('label' => 'Created Date Time');
  421. $this->assertEquals($compareData, $attributes['createdDateTime']);
  422. $compareData = array('label' => 'Modified Date Time');
  423. $this->assertEquals($compareData, $attributes['modifiedDateTime']);
  424. $compareData = array('label' => 'First Name');
  425. $this->assertEquals($compareData, $attributes['firstName']);
  426. $compareData = array('label' => 'Last Name');
  427. $this->assertEquals($compareData, $attributes['lastName']);
  428. $compareData = array('label' => 'Boolean');
  429. $this->assertEquals($compareData, $attributes['boolean']);
  430. $compareData = array('label' => 'Date');
  431. $this->assertEquals($compareData, $attributes['date']);
  432. $compareData = array('label' => 'Date Time');
  433. $this->assertEquals($compareData, $attributes['dateTime']);
  434. $compareData = array('label' => 'Float');
  435. $this->assertEquals($compareData, $attributes['float']);
  436. $compareData = array('label' => 'Integer');
  437. $this->assertEquals($compareData, $attributes['integer']);
  438. $compareData = array('label' => 'Phone');
  439. $this->assertEquals($compareData, $attributes['phone']);
  440. $compareData = array('label' => 'String');
  441. $this->assertEquals($compareData, $attributes['string']);
  442. $compareData = array('label' => 'Text Area');
  443. $this->assertEquals($compareData, $attributes['textArea']);
  444. $compareData = array('label' => 'Url');
  445. $this->assertEquals($compareData, $attributes['url']);
  446. $compareData = array('label' => 'Drop Down');
  447. $this->assertEquals($compareData, $attributes['dropDown']);
  448. $compareData = array('label' => 'Drop Down 2');
  449. $this->assertEquals($compareData, $attributes['dropDown2']);
  450. $compareData = array('label' => 'Radio Drop Down');
  451. $this->assertEquals($compareData, $attributes['radioDropDown']);
  452. $compareData = array('label' => 'Multi Drop Down');
  453. $this->assertEquals($compareData, $attributes['multiDropDown']);
  454. $compareData = array('label' => 'Tag Cloud');
  455. $this->assertEquals($compareData, $attributes['tagCloud']);
  456. $compareData = array('label' => 'Reported As Attribute');
  457. $this->assertEquals($compareData, $attributes['reportedAsAttribute']);
  458. //Currency is treated as a relation reported as an attribute just like drop downs
  459. $compareData = array('label' => 'Currency Value');
  460. $this->assertEquals($compareData, $attributes['currencyValue']);
  461. //likeContactState is a relation reported as attribute.
  462. //Makes sure the label is using the proper label translation via attributeLabels
  463. $compareData = array('label' => 'A name for a state');
  464. $this->assertEquals($compareData, $attributes['likeContactState']);
  465. //Add Dynamically Derived Attributes
  466. $compareData = array('label' => 'Owner');
  467. $this->assertEquals($compareData, $attributes['owner__User']);
  468. $compareData = array('label' => 'Created By User');
  469. $this->assertEquals($compareData, $attributes['createdByUser__User']);
  470. $compareData = array('label' => 'Modified By User');
  471. $this->assertEquals($compareData, $attributes['modifiedByUser__User']);
  472. }
  473. /**
  474. * @depends testGetAvailableAttributesForRowsAndColumnsFilters
  475. */
  476. public function testGetAvailableAttributesForRowsAndColumnsDisplayColumns()
  477. {
  478. $model = new ReportModelTestItem();
  479. $rules = new ReportsTestReportRules();
  480. $report = new Report();
  481. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  482. $report->setModuleClassName('ReportsTestModule');
  483. $adapter = new ModelRelationsAndAttributesToRowsAndColumnsReportAdapter($model, $rules, $report->getType());
  484. $attributes = $adapter->getAttributesForDisplayAttributes();
  485. $this->assertEquals(26, count($attributes));
  486. //Includes derived attributes as well
  487. $compareData = array('label' => 'Test Calculated', 'derivedAttributeType' => 'CalculatedNumber');
  488. $this->assertEquals($compareData, $attributes['calculated']);
  489. $compareData = array('label' => 'Full Name', 'derivedAttributeType' => 'FullName');
  490. $this->assertEquals($compareData, $attributes['FullName']);
  491. }
  492. /**
  493. * @depends testGetAvailableAttributesForRowsAndColumnsDisplayColumns
  494. */
  495. public function testGetAvailableAttributesForRowsAndColumnsOrderBys()
  496. {
  497. $model = new ReportModelTestItem();
  498. $rules = new ReportsTestReportRules();
  499. $report = new Report();
  500. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  501. $report->setModuleClassName('ReportsTestModule');
  502. $adapter = new ModelRelationsAndAttributesToRowsAndColumnsReportAdapter($model, $rules, $report->getType());
  503. $attributes = $adapter->getAttributesForOrderBys();
  504. $this->assertEquals(21, count($attributes));
  505. $compareData = array('label' => 'Created Date Time');
  506. $this->assertEquals($compareData, $attributes['createdDateTime']);
  507. $compareData = array('label' => 'Modified Date Time');
  508. $this->assertEquals($compareData, $attributes['modifiedDateTime']);
  509. $compareData = array('label' => 'First Name');
  510. $this->assertEquals($compareData, $attributes['firstName']);
  511. $compareData = array('label' => 'Last Name');
  512. $this->assertEquals($compareData, $attributes['lastName']);
  513. $compareData = array('label' => 'Boolean');
  514. $this->assertEquals($compareData, $attributes['boolean']);
  515. $compareData = array('label' => 'Date');
  516. $this->assertEquals($compareData, $attributes['date']);
  517. $compareData = array('label' => 'Date Time');
  518. $this->assertEquals($compareData, $attributes['dateTime']);
  519. $compareData = array('label' => 'Float');
  520. $this->assertEquals($compareData, $attributes['float']);
  521. $compareData = array('label' => 'Integer');
  522. $this->assertEquals($compareData, $attributes['integer']);
  523. $compareData = array('label' => 'Phone');
  524. $this->assertEquals($compareData, $attributes['phone']);
  525. $compareData = array('label' => 'String');
  526. $this->assertEquals($compareData, $attributes['string']);
  527. $compareData = array('label' => 'Url');
  528. $this->assertEquals($compareData, $attributes['url']);
  529. $compareData = array('label' => 'Drop Down');
  530. $this->assertEquals($compareData, $attributes['dropDown']);
  531. $compareData = array('label' => 'Drop Down 2');
  532. $this->assertEquals($compareData, $attributes['dropDown2']);
  533. $compareData = array('label' => 'Radio Drop Down');
  534. $this->assertEquals($compareData, $attributes['radioDropDown']);
  535. $compareData = array('label' => 'Reported As Attribute');
  536. $this->assertEquals($compareData, $attributes['reportedAsAttribute']);
  537. //Currency is treated as a relation reported as an attribute just like drop downs
  538. $compareData = array('label' => 'Currency Value');
  539. $this->assertEquals($compareData, $attributes['currencyValue']);
  540. //likeContactState is a relation reported as attribute.
  541. //Makes sure the label is using the proper label translation via attributeLabels
  542. $compareData = array('label' => 'A name for a state');
  543. $this->assertEquals($compareData, $attributes['likeContactState']);
  544. //Add Dynamically Derived Attributes
  545. $compareData = array('label' => 'Owner');
  546. $this->assertEquals($compareData, $attributes['owner__User']);
  547. $compareData = array('label' => 'Created By User');
  548. $this->assertEquals($compareData, $attributes['createdByUser__User']);
  549. $compareData = array('label' => 'Modified By User');
  550. $this->assertEquals($compareData, $attributes['modifiedByUser__User']);
  551. }
  552. /**
  553. * @depends testGetAvailableAttributesForRowsAndColumnsOrderBys
  554. */
  555. public function testGetAvailableAttributesForSummationFilters()
  556. {
  557. $model = new ReportModelTestItem();
  558. $rules = new ReportsTestReportRules();
  559. $report = new Report();
  560. $report->setType(Report::TYPE_SUMMATION);
  561. $report->setModuleClassName('ReportsTestModule');
  562. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  563. $attributes = $adapter->getAttributesForFilters();
  564. $this->assertEquals(24, count($attributes));
  565. $compareData = array('label' => 'Created Date Time');
  566. $this->assertEquals($compareData, $attributes['createdDateTime']);
  567. $compareData = array('label' => 'Modified Date Time');
  568. $this->assertEquals($compareData, $attributes['modifiedDateTime']);
  569. $compareData = array('label' => 'First Name');
  570. $this->assertEquals($compareData, $attributes['firstName']);
  571. $compareData = array('label' => 'Last Name');
  572. $this->assertEquals($compareData, $attributes['lastName']);
  573. $compareData = array('label' => 'Boolean');
  574. $this->assertEquals($compareData, $attributes['boolean']);
  575. $compareData = array('label' => 'Date');
  576. $this->assertEquals($compareData, $attributes['date']);
  577. $compareData = array('label' => 'Date Time');
  578. $this->assertEquals($compareData, $attributes['dateTime']);
  579. $compareData = array('label' => 'Float');
  580. $this->assertEquals($compareData, $attributes['float']);
  581. $compareData = array('label' => 'Integer');
  582. $this->assertEquals($compareData, $attributes['integer']);
  583. $compareData = array('label' => 'Phone');
  584. $this->assertEquals($compareData, $attributes['phone']);
  585. $compareData = array('label' => 'String');
  586. $this->assertEquals($compareData, $attributes['string']);
  587. $compareData = array('label' => 'Text Area');
  588. $this->assertEquals($compareData, $attributes['textArea']);
  589. $compareData = array('label' => 'Url');
  590. $this->assertEquals($compareData, $attributes['url']);
  591. $compareData = array('label' => 'Drop Down');
  592. $this->assertEquals($compareData, $attributes['dropDown']);
  593. $compareData = array('label' => 'Drop Down 2');
  594. $this->assertEquals($compareData, $attributes['dropDown2']);
  595. $compareData = array('label' => 'Radio Drop Down');
  596. $this->assertEquals($compareData, $attributes['radioDropDown']);
  597. $compareData = array('label' => 'Multi Drop Down');
  598. $this->assertEquals($compareData, $attributes['multiDropDown']);
  599. $compareData = array('label' => 'Tag Cloud');
  600. $this->assertEquals($compareData, $attributes['tagCloud']);
  601. $compareData = array('label' => 'Reported As Attribute');
  602. $this->assertEquals($compareData, $attributes['reportedAsAttribute']);
  603. //Currency is treated as a relation reported as an attribute just like drop downs
  604. $compareData = array('label' => 'Currency Value');
  605. $this->assertEquals($compareData, $attributes['currencyValue']);
  606. //likeContactState is a relation reported as attribute.
  607. //Makes sure the label is using the proper label translation via attributeLabels
  608. $compareData = array('label' => 'A name for a state');
  609. $this->assertEquals($compareData, $attributes['likeContactState']);
  610. //Add Dynamically Derived Attributes
  611. $compareData = array('label' => 'Owner');
  612. $this->assertEquals($compareData, $attributes['owner__User']);
  613. $compareData = array('label' => 'Created By User');
  614. $this->assertEquals($compareData, $attributes['createdByUser__User']);
  615. $compareData = array('label' => 'Modified By User');
  616. $this->assertEquals($compareData, $attributes['modifiedByUser__User']);
  617. }
  618. /**
  619. * @depends testGetAvailableAttributesForSummationFilters
  620. */
  621. public function testGetAvailableAttributesForSummationDisplayAttributes()
  622. {
  623. //Depends on the selected Group By values. This will determine what is available for display
  624. //Without any group by displayed, nothing is available
  625. $model = new ReportModelTestItem();
  626. $rules = new ReportsTestReportRules();
  627. $report = new Report();
  628. $report->setType(Report::TYPE_SUMMATION);
  629. $report->setModuleClassName('ReportsTestModule');
  630. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  631. $attributes = $adapter->getAttributesForDisplayAttributes($report->getGroupBys());
  632. $this->assertEquals(0, count($attributes));
  633. //Select dropDown as the groupBy attribute
  634. $report = new Report();
  635. $report->setType(Report::TYPE_SUMMATION);
  636. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
  637. $groupBy->attributeIndexOrDerivedType = 'dropDown';
  638. $report->setModuleClassName('ReportsTestModule');
  639. $report->addGroupBy($groupBy);
  640. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  641. $attributes = $adapter->getAttributesForDisplayAttributes($report->getGroupBys());
  642. $this->assertEquals(22, count($attributes));
  643. $compareData = array('label' => 'Drop Down');
  644. $this->assertEquals($compareData, $attributes['dropDown']);
  645. $compareData = array('label' => 'Count');
  646. $this->assertEquals($compareData, $attributes['Count']);
  647. $compareData = array('label' => 'Created Date Time -(Min)');
  648. $this->assertEquals($compareData, $attributes['createdDateTime__Minimum']);
  649. $compareData = array('label' => 'Created Date Time -(Max)');
  650. $this->assertEquals($compareData, $attributes['createdDateTime__Maximum']);
  651. $compareData = array('label' => 'Modified Date Time -(Min)');
  652. $this->assertEquals($compareData, $attributes['modifiedDateTime__Minimum']);
  653. $compareData = array('label' => 'Modified Date Time -(Max)');
  654. $this->assertEquals($compareData, $attributes['modifiedDateTime__Maximum']);
  655. $compareData = array('label' => 'Date -(Min)');
  656. $this->assertEquals($compareData, $attributes['date__Minimum']);
  657. $compareData = array('label' => 'Date -(Max)');
  658. $this->assertEquals($compareData, $attributes['date__Maximum']);
  659. $compareData = array('label' => 'Date Time -(Min)');
  660. $this->assertEquals($compareData, $attributes['dateTime__Minimum']);
  661. $compareData = array('label' => 'Date Time -(Max)');
  662. $this->assertEquals($compareData, $attributes['dateTime__Maximum']);
  663. $compareData = array('label' => 'Float -(Min)');
  664. $this->assertEquals($compareData, $attributes['float__Minimum']);
  665. $compareData = array('label' => 'Float -(Max)');
  666. $this->assertEquals($compareData, $attributes['float__Maximum']);
  667. $compareData = array('label' => 'Float -(Sum)');
  668. $this->assertEquals($compareData, $attributes['float__Summation']);
  669. $compareData = array('label' => 'Float -(Avg)');
  670. $this->assertEquals($compareData, $attributes['float__Average']);
  671. $compareData = array('label' => 'Integer -(Min)');
  672. $this->assertEquals($compareData, $attributes['integer__Minimum']);
  673. $compareData = array('label' => 'Integer -(Max)');
  674. $this->assertEquals($compareData, $attributes['integer__Maximum']);
  675. $compareData = array('label' => 'Integer -(Sum)');
  676. $this->assertEquals($compareData, $attributes['integer__Summation']);
  677. $compareData = array('label' => 'Integer -(Avg)');
  678. $this->assertEquals($compareData, $attributes['integer__Average']);
  679. $compareData = array('label' => 'Currency Value -(Min)');
  680. $this->assertEquals($compareData, $attributes['currencyValue__Minimum']);
  681. $compareData = array('label' => 'Currency Value -(Max)');
  682. $this->assertEquals($compareData, $attributes['currencyValue__Maximum']);
  683. $compareData = array('label' => 'Currency Value -(Sum)');
  684. $this->assertEquals($compareData, $attributes['currencyValue__Summation']);
  685. $compareData = array('label' => 'Currency Value -(Avg)');
  686. $this->assertEquals($compareData, $attributes['currencyValue__Average']);
  687. //Add a second groupBy attribute radioDropDown on the same model
  688. $report = new Report();
  689. $report->setType(Report::TYPE_SUMMATION);
  690. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
  691. $groupBy->attributeIndexOrDerivedType = 'dropDown';
  692. $groupBy2 = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
  693. $groupBy2->attributeIndexOrDerivedType = 'radioDropDown';
  694. $report->setModuleClassName('ReportsTestModule');
  695. $report->addGroupBy($groupBy);
  696. $report->addGroupBy($groupBy2);
  697. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  698. $attributes = $adapter->getAttributesForDisplayAttributes($report->getGroupBys());
  699. $this->assertEquals(23, count($attributes));
  700. $compareData = array('label' => 'Drop Down');
  701. $this->assertEquals($compareData, $attributes['dropDown']);
  702. $compareData = array('label' => 'Radio Drop Down');
  703. $this->assertEquals($compareData, $attributes['radioDropDown']);
  704. }
  705. /**
  706. * @depends testGetAvailableAttributesForSummationDisplayAttributes
  707. */
  708. public function testGroupingOnDifferentModelAndMakingSureCorrectDisplayAttributesAreAvailable()
  709. {
  710. //Grouping on ReportModelTestItem, but we are looking at attributes in ReportModelTestItem2
  711. //so the name attribute should not show up as being available.
  712. $report = new Report();
  713. $report->setType(Report::TYPE_SUMMATION);
  714. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
  715. $groupBy->attributeIndexOrDerivedType = 'phone';
  716. $model = new ReportModelTestItem2();
  717. $rules = new ReportsTestReportRules();
  718. $report->addGroupBy($groupBy);
  719. $report->setModuleClassName('ReportsTestModule');
  720. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  721. $attributes = $adapter->getAttributesForDisplayAttributes($report->getGroupBys(), new ReportModelTestItem(), 'hasOne');
  722. $this->assertEquals(5, count($attributes));
  723. $compareData = array('label' => 'Count');
  724. $this->assertEquals($compareData, $attributes['Count']);
  725. $compareData = array('label' => 'Created Date Time -(Min)');
  726. $this->assertEquals($compareData, $attributes['createdDateTime__Minimum']);
  727. $compareData = array('label' => 'Created Date Time -(Max)');
  728. $this->assertEquals($compareData, $attributes['createdDateTime__Maximum']);
  729. $compareData = array('label' => 'Modified Date Time -(Min)');
  730. $this->assertEquals($compareData, $attributes['modifiedDateTime__Minimum']);
  731. $compareData = array('label' => 'Modified Date Time -(Max)');
  732. $this->assertEquals($compareData, $attributes['modifiedDateTime__Maximum']);
  733. //Now test where there is a second group by and it is the name attribute on ReportModelTestItem2
  734. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
  735. $groupBy->attributeIndexOrDerivedType = 'hasOne___name';
  736. $report->addGroupBy($groupBy);
  737. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  738. $attributes = $adapter->getAttributesForDisplayAttributes($report->getGroupBys(), new ReportModelTestItem(), 'hasOne');
  739. $this->assertEquals(6, count($attributes));
  740. $compareData = array('label' => 'Name');
  741. $this->assertEquals($compareData, $attributes['name']);
  742. $compareData = array('label' => 'Count');
  743. $this->assertEquals($compareData, $attributes['Count']);
  744. $compareData = array('label' => 'Created Date Time -(Min)');
  745. $this->assertEquals($compareData, $attributes['createdDateTime__Minimum']);
  746. $compareData = array('label' => 'Created Date Time -(Max)');
  747. $this->assertEquals($compareData, $attributes['createdDateTime__Maximum']);
  748. $compareData = array('label' => 'Modified Date Time -(Min)');
  749. $this->assertEquals($compareData, $attributes['modifiedDateTime__Minimum']);
  750. $compareData = array('label' => 'Modified Date Time -(Max)');
  751. $this->assertEquals($compareData, $attributes['modifiedDateTime__Maximum']);
  752. //Now test where there is a second group by and it is the name attribute on ReportModelTestItem2 but we
  753. //are coming from a different relationship
  754. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  755. $attributes = $adapter->getAttributesForDisplayAttributes($report->getGroupBys(), new ReportModelTestItem(), 'hasOneAgain');
  756. $this->assertEquals(5, count($attributes));
  757. $this->assertFalse(isset($attributes['name']));
  758. //Test where the group by is 2 levels above
  759. $model = new ReportModelTestItem3();
  760. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
  761. $groupBy->attributeIndexOrDerivedType = 'hasOne___hasMany3___somethingOn3';
  762. $report->addGroupBy($groupBy);
  763. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  764. $attributes = $adapter->getAttributesForDisplayAttributes($report->getGroupBys(), new ReportModelTestItem2(), 'hasMany3');
  765. $this->assertEquals(6, count($attributes));
  766. $compareData = array('label' => 'Something On 3');
  767. $this->assertEquals($compareData, $attributes['somethingOn3']);
  768. $compareData = array('label' => 'Count');
  769. $this->assertEquals($compareData, $attributes['Count']);
  770. $compareData = array('label' => 'Created Date Time -(Min)');
  771. $this->assertEquals($compareData, $attributes['createdDateTime__Minimum']);
  772. $compareData = array('label' => 'Created Date Time -(Max)');
  773. $this->assertEquals($compareData, $attributes['createdDateTime__Maximum']);
  774. $compareData = array('label' => 'Modified Date Time -(Min)');
  775. $this->assertEquals($compareData, $attributes['modifiedDateTime__Minimum']);
  776. $compareData = array('label' => 'Modified Date Time -(Max)');
  777. $this->assertEquals($compareData, $attributes['modifiedDateTime__Maximum']);
  778. }
  779. /**
  780. * @depends testGroupingOnDifferentModelAndMakingSureCorrectDisplayAttributesAreAvailable
  781. */
  782. public function testGetAvailableAttributesForSummationOrderBys()
  783. {
  784. //You can only order what is grouped on.
  785. //You can order on nothing because there are no group bys selected
  786. $model = new ReportModelTestItem();
  787. $rules = new ReportsTestReportRules();
  788. $report = new Report();
  789. $report->setType(Report::TYPE_SUMMATION);
  790. $report->setModuleClassName('ReportsTestModule');
  791. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  792. $attributes = $adapter->getAttributesForOrderBys($report->getGroupBys());
  793. $this->assertEquals(0, count($attributes));
  794. //A group by is selected on the base model ReportModelTestItem
  795. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
  796. $groupBy->attributeIndexOrDerivedType = 'dropDown';
  797. $model = new ReportModelTestItem();
  798. $report->addGroupBy($groupBy);
  799. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  800. $attributes = $adapter->getAttributesForOrderBys($report->getGroupBys());
  801. $this->assertEquals(1, count($attributes));
  802. $compareData = array('label' => 'Drop Down');
  803. $this->assertEquals($compareData, $attributes['dropDown']);
  804. //Now test when a group by is also selected on the related ReportModelTestItem2
  805. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
  806. $groupBy->attributeIndexOrDerivedType = 'hasOne___phone';
  807. $model = new ReportModelTestItem2();
  808. $report->addGroupBy($groupBy);
  809. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  810. $attributes = $adapter->getAttributesForOrderBys($report->getGroupBys(), array(), new ReportModelTestItem(), 'hasOne');
  811. $this->assertEquals(1, count($attributes));
  812. $compareData = array('label' => 'Phone');
  813. $this->assertEquals($compareData, $attributes['hasOne___phone']);
  814. //Now test a third group by on the base model ReportModelTestItem
  815. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
  816. $groupBy->attributeIndexOrDerivedType = 'radioDropDown';
  817. $model = new ReportModelTestItem();
  818. $report->addGroupBy($groupBy);
  819. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  820. $attributes = $adapter->getAttributesForOrderBys($report->getGroupBys());
  821. $this->assertEquals(2, count($attributes));
  822. $compareData = array('label' => 'Drop Down');
  823. $this->assertEquals($compareData, $attributes['dropDown']);
  824. $compareData = array('label' => 'Radio Drop Down');
  825. $this->assertEquals($compareData, $attributes['radioDropDown']);
  826. }
  827. /**
  828. * @depends testGetAvailableAttributesForSummationOrderBys
  829. */
  830. public function testGetAvailableAttributesForSummationOrderBysThatAreDisplayCalculations()
  831. {
  832. //You can only order what is grouped on or a display calculation attribute
  833. $model = new ReportModelTestItem();
  834. $rules = new ReportsTestReportRules();
  835. $report = new Report();
  836. $report->setType(Report::TYPE_SUMMATION);
  837. $report->setModuleClassName('ReportsTestModule');
  838. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  839. $attributes = $adapter->getAttributesForOrderBys($report->getGroupBys(), $report->getDisplayAttributes());
  840. $this->assertEquals(0, count($attributes));
  841. $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  842. Report::TYPE_SUMMATION);
  843. $this->assertNull($displayAttribute->label);
  844. $displayAttribute->attributeIndexOrDerivedType = 'createdDateTime__Minimum';
  845. $report->addDisplayAttribute($displayAttribute);
  846. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  847. $attributes = $adapter->getAttributesForOrderBys($report->getGroupBys(), $report->getDisplayAttributes());
  848. $this->assertEquals(1, count($attributes));
  849. $this->assertTrue(isset($attributes['createdDateTime__Minimum']));
  850. $compareData = array('label' => 'Created Date Time -(Min)');
  851. $this->assertEquals($compareData, $attributes['createdDateTime__Minimum']);
  852. $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  853. Report::TYPE_SUMMATION);
  854. $this->assertNull($displayAttribute->label);
  855. $displayAttribute->attributeIndexOrDerivedType = 'integer__Minimum';
  856. $report->addDisplayAttribute($displayAttribute);
  857. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  858. $attributes = $adapter->getAttributesForOrderBys($report->getGroupBys(), $report->getDisplayAttributes());
  859. $this->assertEquals(2, count($attributes));
  860. $this->assertTrue(isset($attributes['integer__Minimum']));
  861. $compareData = array('label' => 'Integer -(Min)');
  862. $this->assertEquals($compareData, $attributes['integer__Minimum']);
  863. //This should not add because we are at the wrong point in the chain
  864. $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  865. Report::TYPE_SUMMATION);
  866. $this->assertNull($displayAttribute->label);
  867. $displayAttribute->attributeIndexOrDerivedType = 'hasOne___createdDateTime__Minimum';
  868. $report->addDisplayAttribute($displayAttribute);
  869. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  870. $attributes = $adapter->getAttributesForOrderBys($report->getGroupBys(), $report->getDisplayAttributes());
  871. $this->assertEquals(2, count($attributes));
  872. $this->assertFalse(isset($attributes['hasOne___createdDateTime__Minimum']));
  873. }
  874. /**
  875. * @depends testGetAvailableAttributesForSummationOrderBysThatAreDisplayCalculations
  876. */
  877. public function testGetAvailableAttributesForSummationGroupBys()
  878. {
  879. $model = new ReportModelTestItem();
  880. $rules = new ReportsTestReportRules();
  881. $report = new Report();
  882. $report->setType(Report::TYPE_SUMMATION);
  883. $report->setModuleClassName('ReportsTestModule');
  884. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  885. $attributes = $adapter->getAttributesForGroupBys();
  886. $this->assertEquals(38, count($attributes));
  887. //Date/DateTime columns first...
  888. $compareData = array('label' => 'Date -(Year)');
  889. $this->assertEquals($compareData, $attributes['date__Year']);
  890. $compareData = array('label' => 'Date -(Quarter)');
  891. $this->assertEquals($compareData, $attributes['date__Quarter']);
  892. $compareData = array('label' => 'Date -(Month)');
  893. $this->assertEquals($compareData, $attributes['date__Month']);
  894. $compareData = array('label' => 'Date -(Week)');
  895. $this->assertEquals($compareData, $attributes['date__Week']);
  896. $compareData = array('label' => 'Date -(Day)');
  897. $this->assertEquals($compareData, $attributes['date__Day']);
  898. $compareData = array('label' => 'Date Time -(Year)');
  899. $this->assertEquals($compareData, $attributes['dateTime__Year']);
  900. $compareData = array('label' => 'Date Time -(Quarter)');
  901. $this->assertEquals($compareData, $attributes['dateTime__Quarter']);
  902. $compareData = array('label' => 'Date Time -(Month)');
  903. $this->assertEquals($compareData, $attributes['dateTime__Month']);
  904. $compareData = array('label' => 'Date Time -(Week)');
  905. $this->assertEquals($compareData, $attributes['dateTime__Week']);
  906. $compareData = array('label' => 'Date Time -(Day)');
  907. $this->assertEquals($compareData, $attributes['dateTime__Day']);
  908. $compareData = array('label' => 'Created Date Time -(Year)');
  909. $this->assertEquals($compareData, $attributes['createdDateTime__Year']);
  910. $compareData = array('label' => 'Created Date Time -(Quarter)');
  911. $this->assertEquals($compareData, $attributes['createdDateTime__Quarter']);
  912. $compareData = array('label' => 'Created Date Time -(Month)');
  913. $this->assertEquals($compareData, $attributes['createdDateTime__Month']);
  914. $compareData = array('label' => 'Created Date Time -(Week)');
  915. $this->assertEquals($compareData, $attributes['createdDateTime__Week']);
  916. $compareData = array('label' => 'Created Date Time -(Day)');
  917. $this->assertEquals($compareData, $attributes['createdDateTime__Day']);
  918. $compareData = array('label' => 'Modified Date Time -(Year)');
  919. $this->assertEquals($compareData, $attributes['modifiedDateTime__Year']);
  920. $compareData = array('label' => 'Modified Date Time -(Quarter)');
  921. $this->assertEquals($compareData, $attributes['modifiedDateTime__Quarter']);
  922. $compareData = array('label' => 'Modified Date Time -(Month)');
  923. $this->assertEquals($compareData, $attributes['modifiedDateTime__Month']);
  924. $compareData = array('label' => 'Modified Date Time -(Week)');
  925. $this->assertEquals($compareData, $attributes['modifiedDateTime__Week']);
  926. $compareData = array('label' => 'Modified Date Time -(Day)');
  927. $this->assertEquals($compareData, $attributes['modifiedDateTime__Day']);
  928. //and then the rest of the attributes... (exclude text area)
  929. $compareData = array('label' => 'First Name');
  930. $this->assertEquals($compareData, $attributes['firstName']);
  931. $compareData = array('label' => 'Last Name');
  932. $this->assertEquals($compareData, $attributes['lastName']);
  933. $compareData = array('label' => 'Boolean');
  934. $this->assertEquals($compareData, $attributes['boolean']);
  935. $compareData = array('label' => 'Float');
  936. $this->assertEquals($compareData, $attributes['float']);
  937. $compareData = array('label' => 'Integer');
  938. $this->assertEquals($compareData, $attributes['integer']);
  939. $compareData = array('label' => 'Phone');
  940. $this->assertEquals($compareData, $attributes['phone']);
  941. $compareData = array('label' => 'String');
  942. $this->assertEquals($compareData, $attributes['string']);
  943. $compareData = array('label' => 'Url');
  944. $this->assertEquals($compareData, $attributes['url']);
  945. $compareData = array('label' => 'Drop Down');
  946. $this->assertEquals($compareData, $attributes['dropDown']);
  947. $compareData = array('label' => 'Drop Down 2');
  948. $this->assertEquals($compareData, $attributes['dropDown2']);
  949. $compareData = array('label' => 'Radio Drop Down');
  950. $this->assertEquals($compareData, $attributes['radioDropDown']);
  951. $compareData = array('label' => 'Reported As Attribute');
  952. $this->assertEquals($compareData, $attributes['reportedAsAttribute']);
  953. $compareData = array('label' => 'Currency Value');
  954. $this->assertEquals($compareData, $attributes['currencyValue']);
  955. $compareData = array('label' => 'A name for a state');
  956. $this->assertEquals($compareData, $attributes['likeContactState']);
  957. //Add Id field
  958. $compareData = array('label' => 'Id');
  959. $this->assertEquals($compareData, $attributes['id']);
  960. //Add Dynamically Derived Attributes
  961. $compareData = array('label' => 'Owner');
  962. $this->assertEquals($compareData, $attributes['owner__User']);
  963. $compareData = array('label' => 'Created By User');
  964. $this->assertEquals($compareData, $attributes['createdByUser__User']);
  965. $compareData = array('label' => 'Modified By User');
  966. $this->assertEquals($compareData, $attributes['modifiedByUser__User']);
  967. }
  968. /**
  969. * @depends testGetAvailableAttributesForSummationGroupBys
  970. */
  971. public function testGetAvailableAttributesForSummationDrillDownDisplayAttributes()
  972. {
  973. //Should be the same as the RowsAndColumns display columns
  974. $model = new ReportModelTestItem();
  975. $rules = new ReportsTestReportRules();
  976. $report = new Report();
  977. $report->setType(Report::TYPE_SUMMATION);
  978. $report->setModuleClassName('ReportsTestModule');
  979. $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
  980. $attributes = $adapter->getForDrillDownAttributes();
  981. $this->assertEquals(26, count($attributes));
  982. //Includes derived attributes as well
  983. $compareData = array('label' => 'Test Calculated', 'derivedAttributeType' => 'CalculatedNumber');
  984. $this->assertEquals($compareData, $attributes['calculated']);
  985. $compareData = array('label' => 'Full Name', 'derivedAttributeType' => 'FullName');
  986. $this->assertEquals($compareData, $attributes['FullName']);
  987. }
  988. /**
  989. * @depends testGetAvailableAttributesForSummationDrillDownDisplayAttributes
  990. */
  991. public function testGetAvailableAttributesForMatrixFilters()
  992. {
  993. $model = new ReportModelTestItem();
  994. $rules = new ReportsTestReportRules();
  995. $report = new Report();
  996. $report->setType(Report::TYPE_MATRIX);
  997. $report->setModuleClassName('ReportsTestModule');
  998. $adapter = new ModelRelationsAndAttributesToMatrixReportAdapter($model, $rules, $report->getType());
  999. $attributes = $adapter->getAttributesForFilters();
  1000. $this->assertEquals(24, count($attributes));
  1001. $compareData = array('label' => 'Created Date Time');
  1002. $this->assertEquals($compareData, $attributes['createdDateTime']);
  1003. $compareData = array('label' => 'Modified Date Time');
  1004. $this->assertEquals($compareData, $attributes['modifiedDateTime']);
  1005. $compareData = array('label' => 'First Name');
  1006. $this->assertEquals($compareData, $attributes['firstName']);
  1007. $compareData = array('label' => 'Last Name');
  1008. $this->assertEquals($compareData, $attributes['lastName']);
  1009. $compareData = array('label' => 'Boolean');
  1010. $this->assertEquals($compareData, $attributes['boolean']);
  1011. $compareData = array('label' => 'Date');
  1012. $this->assertEquals($compareData, $attributes['date']);
  1013. $compareData = array('label' => 'Date Time');
  1014. $this->assertEquals($compareData, $attributes['dateTime']);
  1015. $compareData = array('label' => 'Float');
  1016. $this->assertEquals($compareData, $attributes['float']);
  1017. $compareData = array('label' => 'Integer');
  1018. $this->assertEquals($compareData, $attributes['integer']);
  1019. $compareData = array('label' => 'Phone');
  1020. $this->assertEquals($compareData, $attributes['phone']);
  1021. $compareData = array('label' => 'String');
  1022. $this->assertEquals($compareData, $attributes['string']);
  1023. $compareData = array('label' => 'Text Area');
  1024. $this->assertEquals($compareData, $attributes['textArea']);
  1025. $compareData = array('label' => 'Url');
  1026. $this->assertEquals($compareData, $attributes['url']);
  1027. $compareData = array('label' => 'Drop Down');
  1028. $this->assertEquals($compareData, $attributes['dropDown']);
  1029. $compareData = array('label' => 'Drop Down 2');
  1030. $this->assertEquals($compareData, $attributes['dropDown2']);
  1031. $compareData = array('label' => 'Radio Drop Down');
  1032. $this->assertEquals($compareData, $attributes['radioDropDown']);
  1033. $compareData = array('label' => 'Multi Drop Down');
  1034. $this->assertEquals($compareData, $attributes['multiDropDown']);
  1035. $compareData = array('label' => 'Tag Cloud');
  1036. $this->assertEquals($compareData, $attributes['tagCloud']);
  1037. $compareData = array('label' => 'Reported As Attribute');
  1038. $this->assertEquals($compareData, $attributes['reportedAsAttribute']);
  1039. //Currency is treated as a relation reported as an attribute just like drop downs
  1040. $compareData = array('label' => 'Currency Value');
  1041. $this->assertEquals($compareData, $attributes['currencyValue']);
  1042. //likeContactState is a relation reported as attribute.
  1043. //Makes sure the label is using the proper label translation via attributeLabels
  1044. $compareData = array('label' => 'A name for a state');
  1045. $this->assertEquals($compareData, $attributes['likeContactState']);
  1046. //Add Dynamically Derived Attributes
  1047. $compareData = array('label' => 'Owner');
  1048. $this->assertEquals($compareData, $attributes['owner__User']);
  1049. $compareData = array('label' => 'Created By User');
  1050. $this->assertEquals($compareData, $attributes['createdByUser__User']);
  1051. $compareData = array('label' => 'Modified By User');
  1052. $this->assertEquals($compareData, $attributes['modifiedByUser__User']);
  1053. }
  1054. /**
  1055. * @depends testGetAvailableAttributesForMatrixFilters
  1056. */
  1057. public function testGetAvailableAttributesForMatrixGroupBys()
  1058. {
  1059. $model = new ReportModelTestItem();
  1060. $rules = new ReportsTestReportRules();
  1061. $report = new Report();
  1062. $report->setType(Report::TYPE_MATRIX);
  1063. $report->setModuleClassName('ReportsTestModule');
  1064. $adapter = new ModelRelationsAndAttributesToMatrixReportAdapter($model, $rules, $report->getType());
  1065. $attributes = $adapter->getAttributesForGroupBys();
  1066. $this->assertEquals(29, count($attributes));
  1067. //Date/DateTime columns first...
  1068. $compareData = array('label' => 'Date -(Year)');
  1069. $this->assertEquals($compareData, $attributes['date__Year']);
  1070. $compareData = array('label' => 'Date -(Quarter)');
  1071. $this->assertEquals($compareData, $attributes['date__Quarter']);
  1072. $compareData = array('label' => 'Date -(Month)');
  1073. $this->assertEquals($compareData, $attributes['date__Month']);
  1074. $compareData = array('label' => 'Date -(Week)');
  1075. $this->assertEquals($compareData, $attributes['date__Week']);
  1076. $compareData = array('label' => 'Date -(Day)');
  1077. $this->assertEquals($compareData, $attributes['date__Day']);
  1078. $compareData = array('label' => 'Date Time -(Year)');
  1079. $this->assertEquals($compareData, $attributes['dateTime__Year']);
  1080. $compareData = array('label' => 'Date Time -(Quarter)');
  1081. $this->assertEquals($compareData, $attributes['dateTime__Quarter']);
  1082. $compareData = array('label' => 'Date Time -(Month)');
  1083. $this->assertEquals($compareData, $attributes['dateTime__Month']);
  1084. $compareData = array('label' => 'Date Time -(Week)');
  1085. $this->assertEquals($compareData, $attributes['dateTime__Week']);
  1086. $compareData = array('label' => 'Date Time -(Day)');
  1087. $this->assertEquals($compareData, $attributes['dateTime__Day']);
  1088. $compareData = array('label' => 'Created Date Time -(Year)');
  1089. $this->assertEquals($compareData, $attributes['createdDateTime__Year']);
  1090. $compareData = array('label' => 'Created Date Time -(Quarter)');
  1091. $this->assertEquals($compareData, $attributes['createdDateTime__Quarter']);
  1092. $compareData = array('label' => 'Created Date Time -(Month)');
  1093. $this->assertEquals($compareData, $attributes['createdDateTime__Month']);
  1094. $compareData = array('label' => 'Created Date Time -(Week)');
  1095. $this->assertEquals($compareData, $attributes['createdDateTime__Week']);
  1096. $compareData = array('label' => 'Created Date Time -(Day)');
  1097. $this->assertEquals($compareData, $attributes['createdDateTime__Day']);
  1098. $compareData = array('label' => 'Modified Date Time -(Year)');
  1099. $this->assertEquals($compareData, $attributes['modifiedDateTime__Year']);
  1100. $compareData = array('label' => 'Modified Date Time -(Quarter)');
  1101. $this->assertEquals($compareData, $attributes['modifiedDateTime__Quarter']);
  1102. $compareData = array('label' => 'Modified Date Time -(Month)');
  1103. $this->assertEquals($compareData, $attributes['modifiedDateTime__Month']);
  1104. $compareData = array('label' => 'Modified Date Time -(Week)');
  1105. $this->assertEquals($compareData, $attributes['modifiedDateTime__Week']);
  1106. $compareData = array('label' => 'Modified Date Time -(Day)');
  1107. $this->assertEquals($compareData, $attributes['modifiedDateTime__Day']);
  1108. //and then the rest of the attributes... (exclude text area)
  1109. $compareData = array('label' => 'Boolean');
  1110. $this->assertEquals($compareData, $attributes['boolean']);
  1111. $compareData = array('label' => 'Drop Down');
  1112. $this->assertEquals($compareData, $attributes['dropDown']);
  1113. $compareData = array('label' => 'Drop Down 2');
  1114. $this->assertEquals($compareData, $attributes['dropDown2']);
  1115. $compareData = array('label' => 'Radio Drop Down');
  1116. $this->assertEquals($compareData, $attributes['radioDropDown']);
  1117. $compareData = array('label' => 'Reported As Attribute');
  1118. $this->assertEquals($compareData, $attributes['reportedAsAttribute']);
  1119. $compareData = array('label' => 'A name for a state');
  1120. $this->assertEquals($compareData, $attributes['likeContactState']);
  1121. //Add Dynamically Derived Attributes
  1122. $compareData = array('label' => 'Owner');
  1123. $this->assertEquals($compareData, $attributes['owner__User']);
  1124. $compareData = array('label' => 'Created By User');
  1125. $this->assertEquals($compareData, $attributes['createdByUser__User']);
  1126. $compareData = array('label' => 'Modified By User');
  1127. $this->assertEquals($compareData, $attributes['modifiedByUser__User']);
  1128. }
  1129. /**
  1130. * @depends testGetAvailableAttributesForMatrixGroupBys
  1131. */
  1132. public function testGetAvailableAttributesForMatrixDisplayAttributes()
  1133. {
  1134. //Without any group by displayed, nothing is available
  1135. $model = new ReportModelTestItem();
  1136. $rules = new ReportsTestReportRules();
  1137. $report = new Report();
  1138. $report->setType(Report::TYPE_MATRIX);
  1139. $report->setModuleClassName('ReportsTestModule');
  1140. $adapter = new ModelRelationsAndAttributesToMatrixReportAdapter($model, $rules, $report->getType());
  1141. $attributes = $adapter->getAttributesForDisplayAttributes($report->getGroupBys());
  1142. $this->assertEquals(0, count($attributes));
  1143. //Select dropDown as the groupBy attribute
  1144. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
  1145. $groupBy->attributeIndexOrDerivedType = 'dropDown';
  1146. $report = new Report();
  1147. $report->setType(Report::TYPE_MATRIX);
  1148. $report->setModuleClassName('ReportsTestModule');
  1149. $report->addGroupBy($groupBy);
  1150. $adapter = new ModelRelationsAndAttributesToMatrixReportAdapter($model, $rules, $report->getType());
  1151. $attributes = $adapter->getAttributesForDisplayAttributes($report->getGroupBys());
  1152. $this->assertEquals(21, count($attributes));
  1153. $compareData = array('label' => 'Count');
  1154. $this->assertEquals($compareData, $attributes['Count']);
  1155. $compareData = array('label' => 'Created Date Time -(Min)');
  1156. $this->assertEquals($compareData, $attributes['createdDateTime__Minimum']);
  1157. $compareData = array('label' => 'Created Date Time -(Max)');
  1158. $this->assertEquals($compareData, $attributes['createdDateTime__Maximum']);
  1159. $compareData = array('label' => 'Modified Date Time -(Min)');
  1160. $this->assertEquals($compareData, $attributes['modifiedDateTime__Minimum']);
  1161. $compareData = array('label' => 'Modified Date Time -(Max)');
  1162. $this->assertEquals($compareData, $attributes['modifiedDateTime__Maximum']);
  1163. $compareData = array('label' => 'Date -(Min)');
  1164. $this->assertEquals($compareData, $attributes['date__Minimum']);
  1165. $compareData = array('label' => 'Date -(Max)');
  1166. $this->assertEquals($compareData, $attributes['date__Maximum']);
  1167. $compareData = array('label' => 'Date Time -(Min)');
  1168. $this->assertEquals($compareData, $attributes['dateTime__Minimum']);
  1169. $compareData = array('label' => 'Date Time -(Max)');
  1170. $this->assertEquals($compareData, $attributes['dateTime__Maximum']);
  1171. $compareData = array('label' => 'Float -(Min)');
  1172. $this->assertEquals($compareData, $attributes['float__Minimum']);
  1173. $compareData = array('label' => 'Float -(Max)');
  1174. $this->assertEquals($compareData, $attributes['float__Maximum']);
  1175. $compareData = array('label' => 'Float -(Sum)');
  1176. $this->assertEquals($compareData, $attributes['float__Summation']);
  1177. $compareData = array('label' => 'Float -(Avg)');
  1178. $this->assertEquals($compareData, $attributes['float__Average']);
  1179. $compareData = array('label' => 'Integer -(Min)');
  1180. $this->assertEquals($compareData, $attributes['integer__Minimum']);
  1181. $compareData = array('label' => 'Integer -(Max)');
  1182. $this->assertEquals($compareData, $attributes['integer__Maximum']);
  1183. $compareData = array('label' => 'Integer -(Sum)');
  1184. $this->assertEquals($compareData, $attributes['integer__Summation']);
  1185. $compareData = array('label' => 'Integer -(Avg)');
  1186. $this->assertEquals($compareData, $attributes['integer__Average']);
  1187. $compareData = array('label' => 'Currency Value -(Min)');
  1188. $this->assertEquals($compareData, $attributes['currencyValue__Minimum']);
  1189. $compareData = array('label' => 'Currency Value -(Max)');
  1190. $this->assertEquals($compareData, $attributes['currencyValue__Maximum']);
  1191. $compareData = array('label' => 'Currency Value -(Sum)');
  1192. $this->assertEquals($compareData, $attributes['currencyValue__Summation']);
  1193. $compareData = array('label' => 'Currency Value -(Avg)');
  1194. $this->assertEquals($compareData, $attributes['currencyValue__Average']);
  1195. }
  1196. /**
  1197. * @depends testGetAvailableAttributesForMatrixDisplayAttributes
  1198. */
  1199. public function testIsRelation()
  1200. {
  1201. $model = new ReportModelTestItem();
  1202. $rules = new ReportsTestReportRules();
  1203. $report = new Report();
  1204. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  1205. $report->setModuleClassName('ReportsTestModule');
  1206. $adapter = new ModelRelationsAndAttributesToMatrixReportAdapter($model, $rules, $report->getType());
  1207. $this->assertTrue($adapter->isReportedOnAsARelation('hasOne'));
  1208. $this->assertFalse($adapter->isReportedOnAsARelation('garbage'));
  1209. $this->assertFalse($adapter->isReportedOnAsARelation('float'));
  1210. $this->assertFalse($adapter->isReportedOnAsARelation('firstname'));
  1211. $this->assertFalse($adapter->isReportedOnAsARelation('createdByUser__User'));
  1212. $this->assertTrue($adapter->isReportedOnAsARelation('modifiedByUser'));
  1213. $this->assertTrue($adapter->isReportedOnAsARelation('model5ViaItem'));
  1214. $this->assertTrue($adapter->isReportedOnAsARelation('primaryEmail'));
  1215. $this->assertFalse($adapter->isReportedOnAsARelation('dropDown'));
  1216. $model = new ReportModelTestItem5();
  1217. $rules = new ReportsTestReportRules();
  1218. $report = new Report();
  1219. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  1220. $report->setModuleClassName('ReportsTestModule');
  1221. $adapter = new ModelRelationsAndAttributesToMatrixReportAdapter($model, $rules, $report->getType());
  1222. $this->assertTrue ($adapter->isReportedOnAsARelation('ReportModelTestItem2__reportItems__Inferred'));
  1223. $this->assertTrue ($adapter->isReportedOnAsARelation('ReportModelTestItem__reportItems__Inferred'));
  1224. $this->assertTrue ($adapter->isReportedOnAsARelation('ReportModelTestItem__reportItems__Inferred'));
  1225. }
  1226. /**
  1227. * @depends testIsRelation
  1228. */
  1229. public function testIsRelationASingularRelation()
  1230. {
  1231. $model = new ReportModelTestItem();
  1232. $rules = new ReportsTestReportRules();
  1233. $report = new Report();
  1234. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  1235. $report->setModuleClassName('ReportsTestModule');
  1236. $adapter = new ModelRelationsAndAttributesToRowsAndColumnsReportAdapter($model, $rules, $report->getType());
  1237. $this->assertTrue($adapter->isRelationASingularRelation('hasOne'));
  1238. $this->assertFalse($adapter->isRelationASingularRelation('hasMany'));
  1239. $model = new ReportModelTestItem5();
  1240. $rules = new ReportsTestReportRules();
  1241. $report = new Report();
  1242. $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
  1243. $report->setModuleClassName('ReportsTestModule');
  1244. $adapter = new ModelRelationsAndAttributesToRowsAndColumnsReportAdapter($model, $rules, $report->getType());
  1245. $this->assertFalse($adapter->isRelationASingularRelation('ReportModelTestItem2__reportItems__Inferred'));
  1246. $this->assertFalse($adapter->isRelationASingularRelation('ReportModelTestItem__reportItems__Inferred'));
  1247. }
  1248. /**
  1249. * @depends testIsRelationASingularRelation
  1250. */
  1251. public function testGetFilterValueElementTypeForNonStatefulAttributes()
  1252. {
  1253. $model = new ReportModelTestItem();
  1254. $rules = new ReportsTestReportRules();
  1255. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, Report::TYPE_ROWS_AND_COLUMNS);
  1256. $this->assertEquals('BooleanForWizardStaticDropDown', $adapter->getFilterValueElementType('boolean'));
  1257. $this->assertEquals('MixedCurrencyValueTypes', $adapter->getFilterValueElementType('currencyValue'));
  1258. $this->assertEquals('MixedDateTypesForReport', $adapter->getFilterValueElementType('date'));
  1259. $this->assertEquals('MixedDateTypesForReport', $adapter->getFilterValueElementType('dateTime'));
  1260. $this->assertEquals('StaticDropDownForReport', $adapter->getFilterValueElementType('dropDown'));
  1261. $this->assertEquals('MixedNumberTypes', $adapter->getFilterValueElementType('float'));
  1262. $this->assertEquals('MixedNumberTypes', $adapter->getFilterValueElementType('integer'));
  1263. $this->assertEquals('StaticDropDownForReport', $adapter->getFilterValueElementType('multiDropDown'));
  1264. $this->assertEquals('Text', $adapter->getFilterValueElementType('phone'));
  1265. $this->assertEquals('StaticDropDownForReport', $adapter->getFilterValueElementType('radioDropDown'));
  1266. $this->assertEquals('Text', $adapter->getFilterValueElementType('string'));
  1267. $this->assertEquals('StaticDropDownForReport', $adapter->getFilterValueElementType('tagCloud'));
  1268. $this->assertEquals('Text', $adapter->getFilterValueElementType('textArea'));
  1269. $this->assertEquals('Text', $adapter->getFilterValueElementType('url'));
  1270. }
  1271. /**
  1272. * @depends testGetFilterValueElementTypeForNonStatefulAttributes
  1273. */
  1274. public function testGetFilterValueElementTypeForAStatefulAttribute()
  1275. {
  1276. $model = new ReportModelTestItem();
  1277. $rules = new ReportsTestReportRules();
  1278. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, Report::TYPE_ROWS_AND_COLUMNS);
  1279. $this->assertEquals('AllContactStatesStaticDropDownForWizardModel', $adapter->getFilterValueElementType('likeContactState'));
  1280. $model = new ReportModelTestItem();
  1281. $rules = new ReportsAlternateStateTestReportRules();
  1282. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, Report::TYPE_ROWS_AND_COLUMNS);
  1283. $this->assertEquals('AllContactStatesStaticDropDownForWizardModel', $adapter->getFilterValueElementType('likeContactState'));
  1284. }
  1285. /**
  1286. * @depends testGetFilterValueElementTypeForAStatefulAttribute
  1287. */
  1288. public function testGetFilterValueElementType()
  1289. {
  1290. $model = new ReportModelTestItem();
  1291. $rules = new ReportsTestReportRules();
  1292. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, Report::TYPE_ROWS_AND_COLUMNS);
  1293. $this->assertEquals('BooleanForWizardStaticDropDown', $adapter->getFilterValueElementType('boolean'));
  1294. $this->assertEquals('MixedCurrencyValueTypes', $adapter->getFilterValueElementType('currencyValue'));
  1295. $this->assertEquals('MixedDateTypesForReport', $adapter->getFilterValueElementType('date'));
  1296. $this->assertEquals('MixedDateTypesForReport', $adapter->getFilterValueElementType('dateTime'));
  1297. $this->assertEquals('StaticDropDownForReport', $adapter->getFilterValueElementType('dropDown'));
  1298. $this->assertEquals('MixedNumberTypes', $adapter->getFilterValueElementType('float'));
  1299. $this->assertEquals('MixedNumberTypes', $adapter->getFilterValueElementType('integer'));
  1300. $this->assertEquals('StaticDropDownForReport', $adapter->getFilterValueElementType('multiDropDown'));
  1301. $this->assertEquals('UserNameId', $adapter->getFilterValueElementType('owner__User'));
  1302. $this->assertEquals('Text', $adapter->getFilterValueElementType('phone'));
  1303. $this->assertEquals('StaticDropDownForReport', $adapter->getFilterValueElementType('radioDropDown'));
  1304. $this->assertEquals('Text', $adapter->getFilterValueElementType('string'));
  1305. $this->assertEquals('StaticDropDownForReport', $adapter->getFilterValueElementType('tagCloud'));
  1306. $this->assertEquals('Text', $adapter->getFilterValueElementType('textArea'));
  1307. $this->assertEquals('Text', $adapter->getFilterValueElementType('url'));
  1308. $this->assertEquals('AllContactStatesStaticDropDownForWizardModel', $adapter->getFilterValueElementType('likeContactState'));
  1309. $model = new ReportModelTestItem();
  1310. $rules = new ReportsAlternateStateTestReportRules();
  1311. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, Report::TYPE_ROWS_AND_COLUMNS);
  1312. $this->assertEquals('AllContactStatesStaticDropDownForWizardModel', $adapter->getFilterValueElementType('likeContactState'));
  1313. }
  1314. /**
  1315. * @depends testGetFilterValueElementType
  1316. */
  1317. public function testGetAvailableOperatorsType()
  1318. {
  1319. $model = new ReportModelTestItem();
  1320. $rules = new ReportsTestReportRules();
  1321. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, Report::TYPE_ROWS_AND_COLUMNS);
  1322. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING,
  1323. $adapter->getAvailableOperatorsType('string'));
  1324. $model = new ReportModelTestItem();
  1325. $rules = new ReportsTestReportRules();
  1326. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, Report::TYPE_ROWS_AND_COLUMNS);
  1327. $this->assertNull($adapter->getAvailableOperatorsType('boolean'));
  1328. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER,
  1329. $adapter->getAvailableOperatorsType('currencyValue'));
  1330. $this->assertNull($adapter->getAvailableOperatorsType('date'));
  1331. $this->assertNull($adapter->getAvailableOperatorsType('dateTime'));
  1332. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_DROPDOWN,
  1333. $adapter->getAvailableOperatorsType('dropDown'));
  1334. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER,
  1335. $adapter->getAvailableOperatorsType('float'));
  1336. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER,
  1337. $adapter->getAvailableOperatorsType('integer'));
  1338. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_DROPDOWN,
  1339. $adapter->getAvailableOperatorsType('multiDropDown'));
  1340. $this->assertNull($adapter->getAvailableOperatorsType('owner__User'));
  1341. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING,
  1342. $adapter->getAvailableOperatorsType('phone'));
  1343. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_DROPDOWN,
  1344. $adapter->getAvailableOperatorsType('radioDropDown'));
  1345. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING,
  1346. $adapter->getAvailableOperatorsType('string'));
  1347. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_DROPDOWN,
  1348. $adapter->getAvailableOperatorsType('tagCloud'));
  1349. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING,
  1350. $adapter->getAvailableOperatorsType('textArea'));
  1351. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING,
  1352. $adapter->getAvailableOperatorsType('url'));
  1353. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_DROPDOWN,
  1354. $adapter->getAvailableOperatorsType('likeContactState'));
  1355. $model = new ReportModelTestItem();
  1356. $rules = new ReportsAlternateStateTestReportRules();
  1357. $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, Report::TYPE_ROWS_AND_COLUMNS);
  1358. $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_DROPDOWN,
  1359. $adapter->getAvailableOperatorsType('likeContactState'));
  1360. }
  1361. }
  1362. ?>