/**
  * @depends testMakeStringForMultipleLinks
  */
 public function testMakeStringForLinkOrLinks()
 {
     $accounts = Account::getByName('account1');
     $account1 = $accounts[0];
     $account2 = $accounts[1];
     $displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account', Report::TYPE_ROWS_AND_COLUMNS);
     $displayAttribute->setModelAliasUsingTableAliasName('abc');
     $displayAttribute->attributeIndexOrDerivedType = 'name';
     $reportResultsRowData = new ReportResultsRowData(array($displayAttribute), 4);
     $reportResultsRowData->addModelAndAlias($account2, 'abc');
     $result = ReportResultsGridUtil::makeStringForLinkOrLinks('attribute0', $reportResultsRowData, true, 'account1');
     $this->assertContains('<span class="tooltip">2</span>', $result);
     $result = ReportResultsGridUtil::makeStringForLinkOrLinks('attribute0', $reportResultsRowData, false, 'account1');
     $this->assertContains('a target="new"', $result);
     $this->assertContains('id=' . $account2->id, $result);
     $this->assertNotContains('tooltip', $result);
 }
 /**
  * @param int $offset
  * @param int $limit
  * @return array
  */
 protected function runQueryAndGetResolveResultsData($offset, $limit)
 {
     assert('is_int($offset) || $offset == null');
     assert('is_int($limit) || $limit == null');
     $selectQueryAdapter = $this->makeSelectQueryAdapter();
     $sql = $this->makeSqlQueryForFetchingData($selectQueryAdapter, $offset, $limit);
     $rows = $this->getRowsData($sql);
     $resultsData = array();
     $idByOffset = self::resolveIdByOffset($offset);
     foreach ($rows as $key => $row) {
         $reportResultsRowData = new ReportResultsRowData($this->resolveDisplayAttributes(), $idByOffset);
         foreach ($selectQueryAdapter->getIdTableAliasesAndModelClassNames() as $tableAlias => $modelClassName) {
             $idColumnName = $selectQueryAdapter->getIdColumNameByTableAlias($tableAlias);
             $id = (int) $row[$idColumnName];
             if ($id != null) {
                 $reportResultsRowData->addModelAndAlias($modelClassName::getById($id), $tableAlias);
             }
             unset($row[$idColumnName]);
         }
         foreach ($row as $columnName => $value) {
             $reportResultsRowData->addSelectedColumnNameAndValue($columnName, $value);
         }
         $resultsData[$key] = $reportResultsRowData;
         $idByOffset++;
     }
     return $resultsData;
 }
 /**
  * There was a bug with showing address->state on a contact rows and columns report. it was showing the
  * contact->state instead. this test passes after this bug was fixed
  */
 public function testDisplayingAOwnedModelAttributeThatIsAlsoDefinedAsAnAttributeOnTheOwningModel()
 {
     $contactStates = ContactState::getByName('Qualified');
     $contact = new Contact();
     $contact->owner = Yii::app()->user->userModel;
     $contact->title->value = 'Mr.';
     $contact->firstName = 'Super';
     $contact->lastName = 'Man';
     $contact->jobTitle = 'Superhero';
     $contact->description = 'Some Description';
     $contact->department = 'Red Tape';
     $contact->officePhone = '1234567890';
     $contact->mobilePhone = '0987654321';
     $contact->officeFax = '1222222222';
     $contact->state = $contactStates[0];
     $contact->primaryAddress->state = 'IL';
     $this->assertTrue($contact->save());
     $displayAttribute = new DisplayAttributeForReportForm('ContactsModule', 'Contact', Report::TYPE_ROWS_AND_COLUMNS);
     $displayAttribute->setModelAliasUsingTableAliasName('abc');
     $displayAttribute->attributeIndexOrDerivedType = 'primaryAddress___state';
     $this->assertEquals('col0', $displayAttribute->columnAliasName);
     $reportResultsRowData = new ReportResultsRowData(array($displayAttribute), 4);
     $reportResultsRowData->addModelAndAlias($contact, 'abc');
     $model = $reportResultsRowData->getModel('attribute0');
     $this->assertEquals('IL', $model->primaryAddress->state);
     $this->assertEquals('IL', $reportResultsRowData->attribute0);
 }
 /**
  * Test for viaSelect and viaModel together
  * @depends testExportSummationAttributes
  */
 public function testViaSelectAndViaModelTogether()
 {
     $reportModelTestItem = new ReportModelTestItem();
     $report = new Report();
     //viaSelect attribute
     $displayAttribute1 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute1->attributeIndexOrDerivedType = 'integer__Minimum';
     $displayAttribute1->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute1->columnAliasName == 'col0');
     //viaModel attribute
     $reportModelTestItem->boolean = true;
     $displayAttribute2 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_ROWS_AND_COLUMNS);
     $displayAttribute2->setModelAliasUsingTableAliasName('model1');
     $displayAttribute2->attributeIndexOrDerivedType = 'boolean';
     $reportResultsRowData = new ReportResultsRowData(array($displayAttribute1, $displayAttribute2), 4);
     $reportResultsRowData->addSelectedColumnNameAndValue('col0', 9000);
     $reportResultsRowData->addModelAndAlias($reportModelTestItem, 'model1');
     $adapter = new ReportToExportAdapter($reportResultsRowData, $report);
     $compareHeaderData = array('Integer -(Min)', 'Boolean');
     $compareRowData = array(9000, true);
     $this->assertEquals($compareHeaderData, $adapter->getHeaderData());
     $this->assertEquals($compareRowData, $adapter->getData());
 }
 public function testResolveValueOnBaseModelAndRelatedModel()
 {
     $reportModelTestItem11 = new ReportModelTestItem11();
     $reportModelTestItem11->integer = 5;
     $currencies = Currency::getAll();
     $currencyValue = new CurrencyValue();
     $currencyValue->value = 100;
     $currencyValue->currency = $currencies[0];
     $reportModelTestItem11->amount = $currencyValue;
     $reportModelTestItem11b = new ReportModelTestItem11();
     $reportModelTestItem11b->integer = 7;
     $currencyValue = new CurrencyValue();
     $currencyValue->value = 200;
     $currencyValue->currency = $currencies[0];
     $reportModelTestItem11b->amount = $currencyValue;
     $reportModelTestItem10 = new ReportModelTestItem10();
     $reportModelTestItem10->integer = 12;
     $currencyValue = new CurrencyValue();
     $currencyValue->value = 400;
     $currencyValue->currency = $currencies[0];
     $reportModelTestItem10->currencyValue = $currencyValue;
     $reportModelTestItem10->reportModelTestItem11->add($reportModelTestItem11);
     $reportModelTestItem10->reportModelTestItem11->add($reportModelTestItem11b);
     $saved = $reportModelTestItem10->save();
     $this->assertTrue($saved);
     $displayAttributeX = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem10', Report::TYPE_ROWS_AND_COLUMNS);
     $displayAttributeX->setModelAliasUsingTableAliasName('abc');
     $displayAttributeX->attributeIndexOrDerivedType = 'reportModelTestItem11___calculated2';
     $this->assertEquals('col0', $displayAttributeX->columnAliasName);
     $displayAttributeY = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem10', Report::TYPE_ROWS_AND_COLUMNS);
     $displayAttributeY->setModelAliasUsingTableAliasName('def');
     $displayAttributeY->attributeIndexOrDerivedType = 'calculated';
     $this->assertEquals('col1', $displayAttributeY->columnAliasName);
     $reportResultsRowData = new ReportResultsRowData(array($displayAttributeX, $displayAttributeY), 4);
     $reportResultsRowData->addModelAndAlias($reportModelTestItem11b, 'abc');
     $reportResultsRowData->addModelAndAlias($reportModelTestItem10, 'def');
     //Get value for calculated which is on base model
     $value = CalculatedNumberForReportListViewColumnAdapter::resolveValue('attribute1', $reportResultsRowData);
     $this->assertEquals('$412.00', $value);
     //Get value for calculated2 which is on a relateds model
     $value = CalculatedNumberForReportListViewColumnAdapter::resolveValue('attribute0', $reportResultsRowData);
     $this->assertEquals('$207.00', $value);
 }
 public function testGetAttributeLabel()
 {
     $reportModelTestItemX = new ReportModelTestItem();
     $reportModelTestItemX->string = 'someString';
     $displayAttributeX = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttributeX->setModelAliasUsingTableAliasName('abc');
     $displayAttributeX->attributeIndexOrDerivedType = 'string';
     $displayAttributeY = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttributeY->attributeIndexOrDerivedType = 'integer__Maximum';
     $reportResultsRowData = new ReportResultsRowData(array($displayAttributeX, $displayAttributeY), 4);
     $reportResultsRowData->addModelAndAlias($reportModelTestItemX, 'abc');
     $reportResultsRowData->addSelectedColumnNameAndValue('col1', 55);
     //Test a viaModel attribute
     $this->assertEquals('String', $reportResultsRowData->getAttributeLabel('attribute0'));
     //Test a viaSelect attriubte
     $this->assertEquals('Integer -(Max)', $reportResultsRowData->getAttributeLabel('col1'));
 }