PageRenderTime 46ms CodeModel.GetById 17ms 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

Large files files are truncated, but you can click here to view the full file

  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' => 'Mod…

Large files files are truncated, but you can click here to view the full file