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

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

https://bitbucket.org/zurmo/zurmo/
PHP | 780 lines | 684 code | 50 blank | 46 comment | 21 complexity | a278000ce77e21bd6827ec985b92cd75 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-2-Clause
  1. <?php
  2. /*********************************************************************************
  3. * Zurmo is a customer relationship management program developed by
  4. * Zurmo, Inc. Copyright (C) 2015 Zurmo Inc.
  5. *
  6. * Zurmo is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero 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 Affero General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Affero 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 27 North Wacker Drive
  24. * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
  25. *
  26. * The interactive user interfaces in original and modified versions
  27. * of this program must display Appropriate Legal Notices, as required under
  28. * Section 5 of the GNU Affero General Public License version 3.
  29. *
  30. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  31. * these Appropriate Legal Notices must retain the display of the Zurmo
  32. * logo and Zurmo copyright notice. If the display of the logo is not reasonably
  33. * feasible for technical reasons, the Appropriate Legal Notices must display the words
  34. * "Copyright Zurmo Inc. 2015. All rights reserved".
  35. ********************************************************************************/
  36. /**
  37. * Test MatrixReportToExportAdapter
  38. */
  39. class MatrixReportToExportAdapterTest extends ZurmoBaseTest
  40. {
  41. public static function setUpBeforeClass()
  42. {
  43. parent::setUpBeforeClass();
  44. $super = SecurityTestHelper::createSuperAdmin();
  45. }
  46. public static function getDependentTestModelClassNames()
  47. {
  48. return array('ReportModelTestItem', 'ReportModelTestItem7');
  49. }
  50. public function setUp()
  51. {
  52. parent::setUp();
  53. Yii::app()->user->userModel = User::getByUsername('super');
  54. DisplayAttributeForReportForm::resetCount();
  55. }
  56. public function testGetDataWithNoRelationsSet()
  57. {
  58. $values = array(
  59. 'Test1',
  60. 'Test2',
  61. 'Test3',
  62. 'Sample',
  63. 'Demo',
  64. );
  65. $customFieldData = CustomFieldData::getByName('ReportTestDropDown');
  66. $customFieldData->serializedData = serialize($values);
  67. $saved = $customFieldData->save();
  68. $this->assertTrue($saved);
  69. //for fullname attribute (derived attribute)
  70. $reportModelTestItem1 = new ReportModelTestItem();
  71. $reportModelTestItem1->firstName = 'xFirst';
  72. $reportModelTestItem1->lastName = 'xLast';
  73. $reportModelTestItem1->boolean = true;
  74. $reportModelTestItem1->date = '2013-02-12';
  75. $reportModelTestItem1->dateTime = '2013-02-12 10:15:00';
  76. $reportModelTestItem1->float = 10.5;
  77. $reportModelTestItem1->integer = 10;
  78. $reportModelTestItem1->phone = '7842151012';
  79. $reportModelTestItem1->string = 'xString';
  80. $reportModelTestItem1->textArea = 'xtextAreatest';
  81. $reportModelTestItem1->url = 'http://www.test.com';
  82. $reportModelTestItem1->dropDown->value = $values[1];
  83. $currencies = Currency::getAll();
  84. $currencyValue = new CurrencyValue();
  85. $currencyValue->value = 100;
  86. $currencyValue->currency = $currencies[0];
  87. $this->assertEquals('USD', $currencyValue->currency->code);
  88. $reportModelTestItem1->currencyValue = $currencyValue;
  89. $reportModelTestItem1->primaryAddress->street1 = 'someString';
  90. $reportModelTestItem1->primaryEmail->emailAddress = "test@someString.com";
  91. $customFieldValue = new CustomFieldValue();
  92. $customFieldValue->value = 'Multi 1';
  93. $reportModelTestItem1->multiDropDown->values->add($customFieldValue);
  94. $customFieldValue = new CustomFieldValue();
  95. $customFieldValue->value = 'Multi 2';
  96. $reportModelTestItem1->multiDropDown->values->add($customFieldValue);
  97. $customFieldValue = new CustomFieldValue();
  98. $customFieldValue->value = 'Cloud 2';
  99. $reportModelTestItem1->tagCloud->values->add($customFieldValue);
  100. $customFieldValue = new CustomFieldValue();
  101. $customFieldValue->value = 'Cloud 3';
  102. $reportModelTestItem1->tagCloud->values->add($customFieldValue);
  103. $reportModelTestItem1->radioDropDown->value = $values[1];
  104. $reportModelTestItem7 = new ReportModelTestItem7;
  105. $reportModelTestItem7->name = 'someName';
  106. $reportModelTestItem1->likeContactState = $reportModelTestItem7;
  107. $reportModelTestItem1->owner = Yii::app()->user->userModel;
  108. $saved = $reportModelTestItem1->save();
  109. $this->assertTrue($saved);
  110. $reportModelTestItem2 = new ReportModelTestItem();
  111. $reportModelTestItem2->firstName = 'xFirst';
  112. $reportModelTestItem2->lastName = 'xLast';
  113. $reportModelTestItem2->boolean = true;
  114. $reportModelTestItem2->date = '2013-02-14';
  115. $reportModelTestItem2->dateTime = '2013-02-14 23:15:00';
  116. $reportModelTestItem2->float = 200.5;
  117. $reportModelTestItem2->integer = 1010;
  118. $reportModelTestItem2->phone = '7842151012';
  119. $reportModelTestItem2->string = 'xString';
  120. $reportModelTestItem2->textArea = 'xtextAreatest';
  121. $reportModelTestItem2->url = 'http://www.test.com';
  122. $reportModelTestItem2->dropDown->value = $values[1];
  123. $reportModelTestItem2->currencyValue = $currencyValue;
  124. $reportModelTestItem2->primaryAddress->street1 = 'someString';
  125. $reportModelTestItem2->primaryEmail->emailAddress = "test@someString.com";
  126. $reportModelTestItem2->multiDropDown->values->add($customFieldValue);
  127. $reportModelTestItem2->tagCloud->values->add($customFieldValue);
  128. $reportModelTestItem2->radioDropDown->value = $values[1];
  129. $reportModelTestItem2->likeContactState = $reportModelTestItem7;
  130. $reportModelTestItem2->owner = Yii::app()->user->userModel;
  131. $saved = $reportModelTestItem2->save();
  132. $this->assertTrue($saved);
  133. $report = new Report();
  134. $report->setType(Report::TYPE_MATRIX);
  135. $report->setModuleClassName('ReportsTestModule');
  136. $report->setFiltersStructure('');
  137. //for date summation
  138. $displayAttribute1 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  139. Report::TYPE_MATRIX);
  140. $displayAttribute1->attributeIndexOrDerivedType = 'date__Maximum';
  141. $displayAttribute1->label = 'New Label For Date -(Max)';
  142. $this->assertTrue($displayAttribute1->columnAliasName == 'col0');
  143. $report->addDisplayAttribute($displayAttribute1);
  144. $displayAttribute2 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  145. Report::TYPE_MATRIX);
  146. $displayAttribute2->attributeIndexOrDerivedType = 'date__Minimum';
  147. $this->assertTrue($displayAttribute2->columnAliasName == 'col1');
  148. $report->addDisplayAttribute($displayAttribute2);
  149. //for dateTime summation
  150. $displayAttribute3 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  151. Report::TYPE_MATRIX);
  152. $displayAttribute3->attributeIndexOrDerivedType = 'dateTime__Maximum';
  153. $this->assertTrue($displayAttribute3->columnAliasName == 'col2');
  154. $report->addDisplayAttribute($displayAttribute3);
  155. $displayAttribute4 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  156. Report::TYPE_MATRIX);
  157. $displayAttribute4->attributeIndexOrDerivedType = 'dateTime__Minimum';
  158. $this->assertTrue($displayAttribute4->columnAliasName == 'col3');
  159. $report->addDisplayAttribute($displayAttribute4);
  160. //for createdDateTime summation
  161. $displayAttribute5 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  162. Report::TYPE_MATRIX);
  163. $displayAttribute5->attributeIndexOrDerivedType = 'createdDateTime__Maximum';
  164. $this->assertTrue($displayAttribute5->columnAliasName == 'col4');
  165. $report->addDisplayAttribute($displayAttribute5);
  166. $displayAttribute6 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  167. Report::TYPE_MATRIX);
  168. $displayAttribute6->attributeIndexOrDerivedType = 'createdDateTime__Minimum';
  169. $this->assertTrue($displayAttribute6->columnAliasName == 'col5');
  170. $report->addDisplayAttribute($displayAttribute6);
  171. //for modifiedDateTime summation
  172. $displayAttribute7 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  173. Report::TYPE_MATRIX);
  174. $displayAttribute7->attributeIndexOrDerivedType = 'modifiedDateTime__Maximum';
  175. $this->assertTrue($displayAttribute7->columnAliasName == 'col6');
  176. $report->addDisplayAttribute($displayAttribute7);
  177. $displayAttribute8 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  178. Report::TYPE_MATRIX);
  179. $displayAttribute8->attributeIndexOrDerivedType = 'modifiedDateTime__Minimum';
  180. $this->assertTrue($displayAttribute8->columnAliasName == 'col7');
  181. $report->addDisplayAttribute($displayAttribute8);
  182. //for float summation
  183. $displayAttribute9 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  184. Report::TYPE_MATRIX);
  185. $displayAttribute9->attributeIndexOrDerivedType = 'float__Minimum';
  186. $this->assertTrue($displayAttribute9->columnAliasName == 'col8');
  187. $report->addDisplayAttribute($displayAttribute9);
  188. $displayAttribute10 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  189. Report::TYPE_MATRIX);
  190. $displayAttribute10->attributeIndexOrDerivedType = 'float__Maximum';
  191. $this->assertTrue($displayAttribute10->columnAliasName == 'col9');
  192. $report->addDisplayAttribute($displayAttribute10);
  193. $displayAttribute11 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  194. Report::TYPE_MATRIX);
  195. $displayAttribute11->attributeIndexOrDerivedType = 'float__Summation';
  196. $this->assertTrue($displayAttribute11->columnAliasName == 'col10');
  197. $report->addDisplayAttribute($displayAttribute11);
  198. $displayAttribute12 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  199. Report::TYPE_MATRIX);
  200. $displayAttribute12->attributeIndexOrDerivedType = 'float__Average';
  201. $this->assertTrue($displayAttribute12->columnAliasName == 'col11');
  202. $report->addDisplayAttribute($displayAttribute12);
  203. //for integer summation
  204. $displayAttribute13 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  205. Report::TYPE_MATRIX);
  206. $displayAttribute13->attributeIndexOrDerivedType = 'integer__Minimum';
  207. $this->assertTrue($displayAttribute13->columnAliasName == 'col12');
  208. $report->addDisplayAttribute($displayAttribute13);
  209. $displayAttribute14 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  210. Report::TYPE_MATRIX);
  211. $displayAttribute14->attributeIndexOrDerivedType = 'integer__Maximum';
  212. $this->assertTrue($displayAttribute14->columnAliasName == 'col13');
  213. $report->addDisplayAttribute($displayAttribute14);
  214. $displayAttribute15 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  215. Report::TYPE_MATRIX);
  216. $displayAttribute15->attributeIndexOrDerivedType = 'integer__Summation';
  217. $this->assertTrue($displayAttribute15->columnAliasName == 'col14');
  218. $report->addDisplayAttribute($displayAttribute15);
  219. $displayAttribute16 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  220. Report::TYPE_MATRIX);
  221. $displayAttribute16->attributeIndexOrDerivedType = 'integer__Average';
  222. $this->assertTrue($displayAttribute16->columnAliasName == 'col15');
  223. $report->addDisplayAttribute($displayAttribute16);
  224. //for currency summation
  225. $displayAttribute17 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  226. Report::TYPE_MATRIX);
  227. $displayAttribute17->attributeIndexOrDerivedType = 'currencyValue__Minimum';
  228. $this->assertTrue($displayAttribute17->columnAliasName == 'col16');
  229. $report->addDisplayAttribute($displayAttribute17);
  230. $displayAttribute18 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  231. Report::TYPE_MATRIX);
  232. $displayAttribute18->attributeIndexOrDerivedType = 'currencyValue__Maximum';
  233. $this->assertTrue($displayAttribute18->columnAliasName == 'col17');
  234. $report->addDisplayAttribute($displayAttribute18);
  235. $displayAttribute19 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  236. Report::TYPE_MATRIX);
  237. $displayAttribute19->attributeIndexOrDerivedType = 'currencyValue__Summation';
  238. $this->assertTrue($displayAttribute19->columnAliasName == 'col18');
  239. $report->addDisplayAttribute($displayAttribute19);
  240. $displayAttribute20 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  241. Report::TYPE_MATRIX);
  242. $displayAttribute20->attributeIndexOrDerivedType = 'currencyValue__Average';
  243. $this->assertTrue($displayAttribute20->columnAliasName == 'col19');
  244. $report->addDisplayAttribute($displayAttribute20);
  245. $displayAttribute21 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  246. Report::TYPE_MATRIX);
  247. $displayAttribute21->attributeIndexOrDerivedType = 'Count';
  248. $this->assertTrue($displayAttribute21->columnAliasName == 'col20');
  249. $report->addDisplayAttribute($displayAttribute21);
  250. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem',
  251. Report::TYPE_MATRIX);
  252. $groupBy->attributeIndexOrDerivedType = 'firstName';
  253. $report->addGroupBy($groupBy);
  254. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem',
  255. Report::TYPE_MATRIX);
  256. $groupBy->attributeIndexOrDerivedType = 'lastName';
  257. $groupBy->axis = 'y';
  258. $report->addGroupBy($groupBy);
  259. $dataProvider = new MatrixReportDataProvider($report);
  260. $adapter = ReportToExportAdapterFactory::createReportToExportAdapter($report, $dataProvider);
  261. $compareRowData = array(array(null,
  262. 'xFirst',
  263. 'xFirst',
  264. 'xFirst',
  265. 'xFirst',
  266. 'xFirst',
  267. 'xFirst',
  268. 'xFirst',
  269. 'xFirst',
  270. 'xFirst',
  271. 'xFirst',
  272. 'xFirst',
  273. 'xFirst',
  274. 'xFirst',
  275. 'xFirst',
  276. 'xFirst',
  277. 'xFirst',
  278. 'xFirst',
  279. 'xFirst',
  280. 'xFirst',
  281. 'xFirst',
  282. 'xFirst',
  283. 'xFirst',
  284. 'xFirst',
  285. 'xFirst',
  286. 'xFirst',
  287. 'Total',
  288. ),
  289. array('Last Name',
  290. 'New Label For Date -(Max)',
  291. 'Date -(Min)',
  292. 'Date Time -(Max)',
  293. 'Date Time -(Min)',
  294. 'Created Date Time -(Max)',
  295. 'Created Date Time -(Min)',
  296. 'Modified Date Time -(Max)',
  297. 'Modified Date Time -(Min)',
  298. 'Float -(Min)',
  299. 'Float -(Max)',
  300. 'Float -(Sum)',
  301. 'Float -(Avg)',
  302. 'Integer -(Min)',
  303. 'Integer -(Max)',
  304. 'Integer -(Sum)',
  305. 'Integer -(Avg)',
  306. 'Currency Value -(Min)',
  307. 'Currency Value -(Min) Currency',
  308. 'Currency Value -(Max)',
  309. 'Currency Value -(Max) Currency',
  310. 'Currency Value -(Sum)',
  311. 'Currency Value -(Sum) Currency',
  312. 'Currency Value -(Avg)',
  313. 'Currency Value -(Avg) Currency',
  314. 'Count',
  315. 'New Label For Date -(Max)',
  316. 'Date -(Min)',
  317. 'Date Time -(Max)',
  318. 'Date Time -(Min)',
  319. 'Created Date Time -(Max)',
  320. 'Created Date Time -(Min)',
  321. 'Modified Date Time -(Max)',
  322. 'Modified Date Time -(Min)',
  323. 'Float -(Min)',
  324. 'Float -(Max)',
  325. 'Float -(Sum)',
  326. 'Float -(Avg)',
  327. 'Integer -(Min)',
  328. 'Integer -(Max)',
  329. 'Integer -(Sum)',
  330. 'Integer -(Avg)',
  331. 'Currency Value -(Min)',
  332. 'Currency Value -(Max)',
  333. 'Currency Value -(Sum)',
  334. 'Currency Value -(Avg)',
  335. 'Count',
  336. ),
  337. array('xLast',
  338. '2013-02-14',
  339. '2013-02-12',
  340. '2013-02-14 23:15:00',
  341. '2013-02-12 10:15:00',
  342. $reportModelTestItem2->createdDateTime,
  343. $reportModelTestItem1->createdDateTime,
  344. $reportModelTestItem2->modifiedDateTime,
  345. $reportModelTestItem1->modifiedDateTime,
  346. '10.5',
  347. '200.5',
  348. '211',
  349. '105.5',
  350. '10',
  351. '1010',
  352. '1020',
  353. '510.0000',
  354. '100',
  355. 'Mixed Currency',
  356. '100',
  357. 'Mixed Currency',
  358. '200',
  359. 'Mixed Currency',
  360. '100',
  361. 'Mixed Currency',
  362. '2',
  363. '2013-02-14',
  364. '2013-02-12',
  365. '2013-02-14 23:15:00',
  366. '2013-02-12 10:15:00',
  367. $reportModelTestItem2->createdDateTime,
  368. $reportModelTestItem1->createdDateTime,
  369. $reportModelTestItem2->modifiedDateTime,
  370. $reportModelTestItem1->modifiedDateTime,
  371. '10.5',
  372. '200.5',
  373. '211',
  374. '105.5',
  375. '10',
  376. '1010',
  377. '1020',
  378. '510.0000',
  379. '100',
  380. '100',
  381. '200',
  382. '100',
  383. '2'
  384. ),
  385. array('Total',
  386. '2013-02-14',
  387. '2013-02-12',
  388. '2013-02-14 23:15:00',
  389. '2013-02-12 10:15:00',
  390. $reportModelTestItem2->createdDateTime,
  391. $reportModelTestItem1->createdDateTime,
  392. $reportModelTestItem2->modifiedDateTime,
  393. $reportModelTestItem1->modifiedDateTime,
  394. '10.5',
  395. '200.5',
  396. '211',
  397. '105.5',
  398. '10',
  399. '1010',
  400. '1020',
  401. '510.0000',
  402. '100',
  403. null,
  404. '100',
  405. null,
  406. '200',
  407. null,
  408. '100',
  409. null,
  410. '2',
  411. ),
  412. );
  413. $this->assertEmpty($adapter->getHeaderData());
  414. $this->assertEquals($compareRowData, $adapter->getData());
  415. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem',
  416. Report::TYPE_MATRIX);
  417. $groupBy->attributeIndexOrDerivedType = 'boolean';
  418. $report->addGroupBy($groupBy);
  419. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem',
  420. Report::TYPE_MATRIX);
  421. $groupBy->attributeIndexOrDerivedType = 'phone';
  422. $groupBy->axis = 'y';
  423. $report->addGroupBy($groupBy);
  424. $dataProvider = new MatrixReportDataProvider($report);
  425. $adapter = ReportToExportAdapterFactory::createReportToExportAdapter($report, $dataProvider);
  426. $compareRowData = array(array(null,
  427. null,
  428. 'xFirst',
  429. 'xFirst',
  430. 'xFirst',
  431. 'xFirst',
  432. 'xFirst',
  433. 'xFirst',
  434. 'xFirst',
  435. 'xFirst',
  436. 'xFirst',
  437. 'xFirst',
  438. 'xFirst',
  439. 'xFirst',
  440. 'xFirst',
  441. 'xFirst',
  442. 'xFirst',
  443. 'xFirst',
  444. 'xFirst',
  445. 'xFirst',
  446. 'xFirst',
  447. 'xFirst',
  448. 'xFirst',
  449. 'xFirst',
  450. 'xFirst',
  451. 'xFirst',
  452. 'xFirst',
  453. 'Total',
  454. ),
  455. array('',
  456. '',
  457. 'Yes',
  458. 'Yes',
  459. 'Yes',
  460. 'Yes',
  461. 'Yes',
  462. 'Yes',
  463. 'Yes',
  464. 'Yes',
  465. 'Yes',
  466. 'Yes',
  467. 'Yes',
  468. 'Yes',
  469. 'Yes',
  470. 'Yes',
  471. 'Yes',
  472. 'Yes',
  473. 'Yes',
  474. 'Yes',
  475. 'Yes',
  476. 'Yes',
  477. 'Yes',
  478. 'Yes',
  479. 'Yes',
  480. 'Yes',
  481. 'Yes',
  482. 'Total',
  483. ),
  484. array('Last Name',
  485. 'Phone',
  486. 'New Label For Date -(Max)',
  487. 'Date -(Min)',
  488. 'Date Time -(Max)',
  489. 'Date Time -(Min)',
  490. 'Created Date Time -(Max)',
  491. 'Created Date Time -(Min)',
  492. 'Modified Date Time -(Max)',
  493. 'Modified Date Time -(Min)',
  494. 'Float -(Min)',
  495. 'Float -(Max)',
  496. 'Float -(Sum)',
  497. 'Float -(Avg)',
  498. 'Integer -(Min)',
  499. 'Integer -(Max)',
  500. 'Integer -(Sum)',
  501. 'Integer -(Avg)',
  502. 'Currency Value -(Min)',
  503. 'Currency Value -(Min) Currency',
  504. 'Currency Value -(Max)',
  505. 'Currency Value -(Max) Currency',
  506. 'Currency Value -(Sum)',
  507. 'Currency Value -(Sum) Currency',
  508. 'Currency Value -(Avg)',
  509. 'Currency Value -(Avg) Currency',
  510. 'Count',
  511. 'New Label For Date -(Max)',
  512. 'Date -(Min)',
  513. 'Date Time -(Max)',
  514. 'Date Time -(Min)',
  515. 'Created Date Time -(Max)',
  516. 'Created Date Time -(Min)',
  517. 'Modified Date Time -(Max)',
  518. 'Modified Date Time -(Min)',
  519. 'Float -(Min)',
  520. 'Float -(Max)',
  521. 'Float -(Sum)',
  522. 'Float -(Avg)',
  523. 'Integer -(Min)',
  524. 'Integer -(Max)',
  525. 'Integer -(Sum)',
  526. 'Integer -(Avg)',
  527. 'Currency Value -(Min)',
  528. 'Currency Value -(Max)',
  529. 'Currency Value -(Sum)',
  530. 'Currency Value -(Avg)',
  531. 'Count',
  532. ),
  533. array('xLast',
  534. '7842151012',
  535. '2013-02-14',
  536. '2013-02-12',
  537. '2013-02-14 23:15:00',
  538. '2013-02-12 10:15:00',
  539. $reportModelTestItem2->createdDateTime,
  540. $reportModelTestItem1->createdDateTime,
  541. $reportModelTestItem2->modifiedDateTime,
  542. $reportModelTestItem1->modifiedDateTime,
  543. '10.5',
  544. '200.5',
  545. '211',
  546. '105.5',
  547. '10',
  548. '1010',
  549. '1020',
  550. '510.0000',
  551. '100',
  552. 'Mixed Currency',
  553. '100',
  554. 'Mixed Currency',
  555. '200',
  556. 'Mixed Currency',
  557. '100',
  558. 'Mixed Currency',
  559. '2',
  560. '2013-02-14',
  561. '2013-02-12',
  562. '2013-02-14 23:15:00',
  563. '2013-02-12 10:15:00',
  564. $reportModelTestItem2->createdDateTime,
  565. $reportModelTestItem1->createdDateTime,
  566. $reportModelTestItem2->modifiedDateTime,
  567. $reportModelTestItem1->modifiedDateTime,
  568. '10.5',
  569. '200.5',
  570. '211',
  571. '105.5',
  572. '10',
  573. '1010',
  574. '1020',
  575. '510.0000',
  576. '100',
  577. '100',
  578. '200',
  579. '100',
  580. '2'
  581. ),
  582. array('Total',
  583. 'Total',
  584. '2013-02-14',
  585. '2013-02-12',
  586. '2013-02-14 23:15:00',
  587. '2013-02-12 10:15:00',
  588. $reportModelTestItem2->createdDateTime,
  589. $reportModelTestItem1->createdDateTime,
  590. $reportModelTestItem2->modifiedDateTime,
  591. $reportModelTestItem1->modifiedDateTime,
  592. '10.5',
  593. '200.5',
  594. '211',
  595. '105.5',
  596. '10',
  597. '1010',
  598. '1020',
  599. '510.0000',
  600. '100',
  601. null,
  602. '100',
  603. null,
  604. '200',
  605. null,
  606. '100',
  607. null,
  608. '2',
  609. ),
  610. );
  611. $this->assertEmpty($adapter->getHeaderData());
  612. $this->assertEquals($compareRowData, $adapter->getData());
  613. //Test currency type is resolved
  614. $report = new Report();
  615. $report->setType(Report::TYPE_MATRIX);
  616. $report->setModuleClassName('ReportsTestModule');
  617. $report->setFiltersStructure('');
  618. $report->setCurrencyConversionType(Report::CURRENCY_CONVERSION_TYPE_BASE);
  619. $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
  620. Report::TYPE_MATRIX);
  621. $displayAttribute->attributeIndexOrDerivedType = 'currencyValue__Summation';
  622. $report->addDisplayAttribute($displayAttribute);
  623. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem',
  624. Report::TYPE_MATRIX);
  625. $groupBy->attributeIndexOrDerivedType = 'firstName';
  626. $report->addGroupBy($groupBy);
  627. $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem',
  628. Report::TYPE_MATRIX);
  629. $groupBy->attributeIndexOrDerivedType = 'lastName';
  630. $groupBy->axis = 'y';
  631. $report->addGroupBy($groupBy);
  632. $dataProvider = new MatrixReportDataProvider($report);
  633. $adapter = ReportToExportAdapterFactory::createReportToExportAdapter($report, $dataProvider);
  634. $compareRowData = array(
  635. array(
  636. null,
  637. 'xFirst',
  638. 'xFirst',
  639. 'Total',
  640. ),
  641. array(
  642. 'Last Name',
  643. 'Currency Value -(Sum)',
  644. 'Currency Value -(Sum) Currency',
  645. 'Currency Value -(Sum)',
  646. 'Currency Value -(Sum) Currency',
  647. ),
  648. array(
  649. 'xLast',
  650. 200,
  651. 'USD',
  652. 200,
  653. 'USD',
  654. ),
  655. array(
  656. 'Total',
  657. 200,
  658. null,
  659. ),
  660. );
  661. $this->assertEquals($compareRowData, $adapter->getData());
  662. }
  663. public function testGetLeadingHeadersDataFromMatrixReportDataProviderWithALinkableAttribute()
  664. {
  665. $reportModelTestItem2 = new ReportModelTestItem2();
  666. $reportModelTestItem2->name = 'report name';
  667. $reportModelTestItem2->phone = '123456789';
  668. $this->assertTrue($reportModelTestItem2->save());
  669. $reportModelTestItem2 = new ReportModelTestItem2();
  670. $reportModelTestItem2->name = 'report name';
  671. $reportModelTestItem2->phone = '987654321';
  672. $this->assertTrue($reportModelTestItem2->save());
  673. $report = new Report();
  674. $report->setType(Report::TYPE_MATRIX);
  675. $report->setModuleClassName('ReportsTest2Module');
  676. $report->setFiltersStructure('');
  677. $displayAttribute = new DisplayAttributeForReportForm('ReportsTest2Module', 'ReportModelTestItem2',
  678. Report::TYPE_MATRIX);
  679. $displayAttribute->attributeIndexOrDerivedType = 'Count';
  680. $report->addDisplayAttribute($displayAttribute);
  681. $groupBy = new GroupByForReportForm('ReportsTest2Module', 'ReportModelTestItem2',
  682. Report::TYPE_MATRIX);
  683. $groupBy->attributeIndexOrDerivedType = 'phone';
  684. $report->addGroupBy($groupBy);
  685. $groupBy = new GroupByForReportForm('ReportsTest2Module', 'ReportModelTestItem2',
  686. Report::TYPE_MATRIX);
  687. $groupBy->attributeIndexOrDerivedType = 'name';
  688. $groupBy->axis = 'y';
  689. $report->addGroupBy($groupBy);
  690. $dataProvider = new MatrixReportDataProvider($report);
  691. $adapter = ReportToExportAdapterFactory::createReportToExportAdapter($report, $dataProvider);
  692. $compareRowData = array(
  693. array(null, '123456789', '987654321', 'Total'),
  694. array('Name', 'Count', 'Count', 'Count'),
  695. array('report name', 1, 1, 2),
  696. array('Total', 1, 1)
  697. );
  698. $this->assertEmpty($adapter->getHeaderData());
  699. $this->assertEquals($compareRowData, $adapter->getData());
  700. $report = new Report();
  701. $report->setType(Report::TYPE_MATRIX);
  702. $report->setModuleClassName('ReportsTest2Module');
  703. $report->setFiltersStructure('');
  704. $displayAttribute = new DisplayAttributeForReportForm('ReportsTest2Module', 'ReportModelTestItem2',
  705. Report::TYPE_MATRIX);
  706. $displayAttribute->attributeIndexOrDerivedType = 'Count';
  707. $report->addDisplayAttribute($displayAttribute);
  708. $groupBy = new GroupByForReportForm('ReportsTest2Module', 'ReportModelTestItem2',
  709. Report::TYPE_MATRIX);
  710. $groupBy->attributeIndexOrDerivedType = 'name';
  711. $report->addGroupBy($groupBy);
  712. $groupBy = new GroupByForReportForm('ReportsTest2Module', 'ReportModelTestItem2',
  713. Report::TYPE_MATRIX);
  714. $groupBy->attributeIndexOrDerivedType = 'phone';
  715. $groupBy->axis = 'y';
  716. $report->addGroupBy($groupBy);
  717. $dataProvider = new MatrixReportDataProvider($report);
  718. $adapter = ReportToExportAdapterFactory::createReportToExportAdapter($report, $dataProvider);
  719. $compareRowData = array(
  720. array(null, 'report name', 'Total'),
  721. array('Phone', 'Count', 'Count'),
  722. array('123456789', 1, 1),
  723. array('987654321', 1, 1),
  724. array('Total', 2)
  725. );
  726. $this->assertEmpty($adapter->getHeaderData());
  727. $this->assertEquals($compareRowData, $adapter->getData());
  728. }
  729. }
  730. ?>