public function testGetExportValue() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $currencies = Currency::getAll(); $currencyValue = new CurrencyValue(); $currencyValue->value = 100; $currencyValue->currency = $currencies[0]; $this->assertEquals('USD', $currencyValue->currency->code); $data = array(); $model = new ExportTestModelItem(); $model->currencyValue = $currencyValue; $model->lastName = "Smith"; $model->string = "Some Test String"; // We have to save model, to get correct currencyValue id. $this->assertTrue($model->save()); $adapter = new CurrencyValueRedBeanModelAttributeValueToExportValueAdapter($model, 'currencyValue'); $adapter->resolveData($data); $compareData = array($currencyValue->value, $currencyValue->currency->code); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('currencyValue'), $model->getAttributeLabel('currencyValue') . " " . Zurmo::t('ZurmoModule', 'Currency')); $this->assertEquals($compareData, $data); $data = array(); $model = new ExportTestModelItem(); $adapter = new CurrencyValueRedBeanModelAttributeValueToExportValueAdapter($model, 'currencyValue'); $adapter->resolveData($data); $compareData = array('', ''); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('currencyValue'), $model->getAttributeLabel('currencyValue') . " " . Zurmo::t('ZurmoModule', 'Currency')); $this->assertEquals($compareData, $data); }
public function testGetExportValue() { $values = array('Test1', 'Test2', 'Test3', 'Sample', 'Demo'); $customFieldData = CustomFieldData::getByName('ExportTestRadioDropDown'); $customFieldData->serializedData = serialize($values); $saved = $customFieldData->save(); $this->assertTrue($saved); $data = array(); $model = new ExportTestModelItem(); $model->radioDropDown->value = $values[1]; $model->lastName = "Smith"; $model->string = "Some Test String"; // We have to save model, to get correct currencyValue id. $this->assertTrue($model->save()); $adapter = new RadioDropDownRedBeanModelAttributeValueToExportValueAdapter($model, 'radioDropDown'); $adapter->resolveData($data); $compareData = array('Test2'); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('radioDropDown')); $this->assertEquals($compareData, $data); $data = array(); $model = new ExportTestModelItem(); $adapter = new RadioDropDownRedBeanModelAttributeValueToExportValueAdapter($model, 'radioDropDown'); $adapter->resolveData($data); $compareData = array(''); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('radioDropDown')); $this->assertEquals($compareData, $data); }
public function testGetExportValue() { $data = array(); $model = new ExportTestModelItem(); $model->lastName = 'testLastName'; $model->string = 'testString'; $model->primaryAddress->city = 'testCity'; $model->primaryAddress->country = 'testCountry'; $model->primaryAddress->postalCode = 'testPostalCode'; $model->primaryAddress->street1 = 'testStreet1'; $model->primaryAddress->street2 = 'testStreet2'; $model->primaryAddress->state = 'testState'; $this->assertTrue($model->save()); $adapter = new AddressRedBeanModelAttributeValueToExportValueAdapter($model, 'primaryAddress'); $adapter->resolveData($data); $compareData = array('testCity', 'testCountry', 'testPostalCode', 'testStreet1', 'testStreet2', 'testState'); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('primaryAddress') . ' - ' . Zurmo::t('ZurmoModule', 'City'), $model->getAttributeLabel('primaryAddress') . ' - ' . Zurmo::t('ZurmoModule', 'Country'), $model->getAttributeLabel('primaryAddress') . ' - ' . Zurmo::t('ZurmoModule', 'Postal Code'), $model->getAttributeLabel('primaryAddress') . ' - ' . Zurmo::t('ZurmoModule', 'Street 1'), $model->getAttributeLabel('primaryAddress') . ' - ' . Zurmo::t('ZurmoModule', 'Street 2'), $model->getAttributeLabel('primaryAddress') . ' - ' . Zurmo::t('ExportModule', 'State')); $this->assertEquals($compareData, $data); $data = array(); $model = new ExportTestModelItem(); $adapter = new AddressRedBeanModelAttributeValueToExportValueAdapter($model, 'primaryAddress'); $adapter->resolveData($data); $compareData = array(null, null, null, null, null, null); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('primaryAddress') . ' - ' . Zurmo::t('ZurmoModule', 'City'), $model->getAttributeLabel('primaryAddress') . ' - ' . Zurmo::t('ZurmoModule', 'Country'), $model->getAttributeLabel('primaryAddress') . ' - ' . Zurmo::t('ZurmoModule', 'Postal Code'), $model->getAttributeLabel('primaryAddress') . ' - ' . Zurmo::t('ZurmoModule', 'Street 1'), $model->getAttributeLabel('primaryAddress') . ' - ' . Zurmo::t('ZurmoModule', 'Street 2'), $model->getAttributeLabel('primaryAddress') . ' - ' . Zurmo::t('ExportModule', 'State')); $this->assertEquals($compareData, $data); }
public function testGetExportValue() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $data = array(); $model = new ExportTestModelItem(); $model->lastName = "Smith"; $model->string = "Some Test String"; $model->user = $super; $this->assertTrue($model->save()); $adapter = new UserRedBeanModelAttributeValueToExportValueAdapter($model, 'user'); $adapter->resolveData($data); $compareData = array('Clark Kent'); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('user')); $this->assertEquals($compareData, $data); $data = array(); $model = new ExportTestModelItem(); $adapter = new UserRedBeanModelAttributeValueToExportValueAdapter($model, 'user'); $adapter->resolveData($data); $compareData = array(''); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('user')); $this->assertEquals($compareData, $data); }
public function testGetExportValue() { $data = array(); $model = new ExportTestModelItem(); $model->email = '*****@*****.**'; $adapter = new EmailRedBeanModelAttributeValueToExportValueAdapter($model, 'email'); $adapter->resolveData($data); $compareData = array('*****@*****.**'); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('email')); $this->assertEquals($compareData, $data); $data = array(); $model = new ExportTestModelItem(); $adapter = new EmailRedBeanModelAttributeValueToExportValueAdapter($model, 'email'); $adapter->resolveData($data); $compareData = array(''); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('email')); $this->assertEquals($compareData, $data); $model = new ExportTestModelItem(); $model->lastName = 'testLastName'; $model->string = 'testString'; $model->secondaryEmail->emailAddress = '*****@*****.**'; $model->secondaryEmail->isInvalid = false; $model->secondaryEmail->optOut = true; $this->assertTrue($model->save()); $data = array(); $adapter = new EmailAddressInformationRedBeanModelAttributeValueToExportValueAdapter($model, 'secondaryEmail'); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('secondaryEmail') . ' - ' . Zurmo::t('ZurmoModule', 'Email Address'), $model->getAttributeLabel('secondaryEmail') . ' - ' . Zurmo::t('ZurmoModule', 'Is Invalid'), $model->getAttributeLabel('secondaryEmail') . ' - ' . Zurmo::t('ZurmoModule', 'Opt Out')); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveData($data); $compareData = array('*****@*****.**', false, true); $this->assertEquals($compareData, $data); }
public function testGetExportValue() { $tagCloudValues = array('Tag 1', 'Tag 2', 'Tag 3'); $customFieldData = CustomFieldData::getByName('ExportTestTagCloud'); $customFieldData->serializedData = serialize($tagCloudValues); $saved = $customFieldData->save(); $this->assertTrue($saved); $data = array(); $model = new ExportTestModelItem(); $model->lastName = "Smith"; $model->string = "Some Test String"; $customFieldValue = new CustomFieldValue(); $customFieldValue->value = 'Tag 2'; $model->tagCloud->values->add($customFieldValue); $customFieldValue = new CustomFieldValue(); $customFieldValue->value = 'Tag 3'; $model->tagCloud->values->add($customFieldValue); $this->assertTrue($model->save()); $adapter = new TagCloudRedBeanModelAttributeValueToExportValueAdapter($model, 'tagCloud'); $adapter->resolveData($data); $compareData = array('Tag 2,Tag 3'); // Not Coding Standard $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('tagCloud')); $this->assertEquals($compareData, $data); $data = array(); $model = new ExportTestModelItem(); $adapter = new TagCloudRedBeanModelAttributeValueToExportValueAdapter($model, 'tagCloud'); $adapter->resolveData($data); $compareData = array(''); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('tagCloud')); $this->assertEquals($compareData, $data); }
public function testGetExportValue() { $multiSelectValues = array('Multi 1', 'Multi 2', 'Multi 3'); $customFieldData = CustomFieldData::getByName('ExportTestMultiDropDown'); $customFieldData->serializedData = serialize($multiSelectValues); $saved = $customFieldData->save(); $this->assertTrue($saved); $data = array(); $model = new ExportTestModelItem(); $model->lastName = "Smith"; $model->string = "Some Test String"; $customFieldValue = new CustomFieldValue(); $customFieldValue->value = 'Multi 1'; $model->multiDropDown->values->add($customFieldValue); $customFieldValue = new CustomFieldValue(); $customFieldValue->value = 'Multi 3'; $model->multiDropDown->values->add($customFieldValue); $this->assertTrue($model->save()); $adapter = new MultiSelectDropDownRedBeanModelAttributeValueToExportValueAdapter($model, 'multiDropDown'); $adapter->resolveData($data); $compareData = array('Multi 1,Multi 3'); // Not Coding Standard $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('multiDropDown')); $this->assertEquals($compareData, $data); $data = array(); $model = new ExportTestModelItem(); $adapter = new MultiSelectDropDownRedBeanModelAttributeValueToExportValueAdapter($model, 'multiDropDown'); $adapter->resolveData($data); $compareData = array(''); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($model->getAttributeLabel('multiDropDown')); $this->assertEquals($compareData, $data); }
/** * @depends testGetDataWithAllHasOneOrOwnedRelationsSet */ public function testGetDataWithHasOneRelatedModel() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $currencies = Currency::getAll(); $currencyValue = new CurrencyValue(); $currencyValue->value = 100; $currencyValue->currency = $currencies[0]; $this->assertEquals('USD', $currencyValue->currency->code); $testItem2 = new ExportTestModelItem2(); $testItem2->name = 'John'; $this->assertTrue($testItem2->save()); $testItem4 = new ExportTestModelItem4(); $testItem4->name = 'John'; $this->assertTrue($testItem4->save()); //HAS_MANY and MANY_MANY relationships should be ignored. $testItem3_1 = new ExportTestModelItem3(); $testItem3_1->name = 'Kevin'; $this->assertTrue($testItem3_1->save()); $testItem3_2 = new ExportTestModelItem3(); $testItem3_2->name = 'Jim'; $this->assertTrue($testItem3_2->save()); $testItem = new ExportTestModelItem(); $testItem->firstName = 'Bob3'; $testItem->lastName = 'Bob3'; $testItem->boolean = true; $testItem->date = '2002-04-03'; $testItem->dateTime = '2002-04-03 02:00:43'; $testItem->float = 54.22; $testItem->integer = 10; $testItem->phone = '21313213'; $testItem->string = 'aString'; $testItem->textArea = 'Some Text Area'; $testItem->url = 'http://www.asite.com'; $testItem->email = '*****@*****.**'; $testItem->owner = $super; $testItem->currencyValue = $currencyValue; $testItem->hasOne = $testItem2; $testItem->hasMany->add($testItem3_1); $testItem->hasMany->add($testItem3_2); $testItem->hasOneAlso = $testItem4; $createStamp = strtotime(DateTimeUtil::convertTimestampToDbFormatDateTime(time())); $this->assertTrue($testItem->save()); $id = $testItem->id; $testItem->forget(); unset($testItem); $testItem = ExportTestModelItem::getById($id); $adapter = new ModelToExportAdapter($testItem); $data = $adapter->getData(); $headerData = $adapter->getHeaderData(); $compareData = array($id, 'stubDateTime', 'stubDateTime', 'super', 'super', 'super', 'Bob3', 'Bob3', '1', '2002-04-03', '2002-04-03 02:00:43', 54.22, 10, '21313213', 'aString', 'Some Text Area', 'http://www.asite.com', '*****@*****.**', null, 100, 'USD', null, null, null, null, '(None)', '(None)', null, null, null, null, null, null, null, null, null, null, null, null, null); $compareHeaderData = array($testItem->getAttributeLabel('id'), $testItem->getAttributeLabel('createdDateTime'), $testItem->getAttributeLabel('modifiedDateTime'), $testItem->getAttributeLabel('createdByUser'), $testItem->getAttributeLabel('modifiedByUser'), $testItem->getAttributeLabel('owner'), $testItem->getAttributeLabel('firstName'), $testItem->getAttributeLabel('lastName'), $testItem->getAttributeLabel('boolean'), $testItem->getAttributeLabel('date'), $testItem->getAttributeLabel('dateTime'), $testItem->getAttributeLabel('float'), $testItem->getAttributeLabel('integer'), $testItem->getAttributeLabel('phone'), $testItem->getAttributeLabel('string'), $testItem->getAttributeLabel('textArea'), $testItem->getAttributeLabel('url'), $testItem->getAttributeLabel('email'), $testItem->getAttributeLabel('currency'), $testItem->getAttributeLabel('currencyValue'), $testItem->getAttributeLabel('currencyValue') . ' ' . 'Currency', $testItem->getAttributeLabel('dropDown'), $testItem->getAttributeLabel('radioDropDown'), $testItem->getAttributeLabel('multiDropDown'), $testItem->getAttributeLabel('tagCloud'), $testItem->getAttributeLabel('hasOne') . ' - ' . 'Name', $testItem->getAttributeLabel('hasOneAlso') . ' - ' . 'Name', 'Primary Email - Email Address', 'Primary Email - Is Invalid', 'Primary Email - Opt Out', 'Primary Address - City', 'Primary Address - Country', 'Primary Address - Postal Code', 'Primary Address - Street 1', 'Primary Address - Street 2', 'Primary Address - State', 'Secondary Email - Email Address', 'Secondary Email - Is Invalid', 'Secondary Email - Opt Out', $testItem->getAttributeLabel('user')); // Because small delay in IO operation, allow tresholds $createdDateTimeKey = array_search($testItem->getAttributeLabel('createdDateTime'), $headerData); $modifiedDateTimeKey = array_search($testItem->getAttributeLabel('modifiedDateTime'), $headerData); $this->assertEquals($createStamp, strtotime($data[$createdDateTimeKey]), '', 2); $this->assertEquals($createStamp, strtotime($data[$modifiedDateTimeKey]), '', 2); $data[$createdDateTimeKey] = 'stubDateTime'; $data[$modifiedDateTimeKey] = 'stubDateTime'; $this->assertEquals($compareData, $data); $this->assertEquals($compareHeaderData, $headerData); }
protected function isValidCsvConversion($textAreaContent) { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $testItem = new ExportTestModelItem(); $testItem->firstName = 'Bob3'; $testItem->lastName = 'Bob3'; $testItem->boolean = true; $testItem->date = '2002-04-03'; $testItem->dateTime = '2002-04-03 02:00:43'; $testItem->float = 54.22; $testItem->integer = 10; $testItem->phone = '21313213'; $testItem->string = 'aString'; $testItem->textArea = $textAreaContent; $testItem->url = 'http://www.asite.com'; $testItem->email = '*****@*****.**'; $testItem->save(); $id = $testItem->id; $testItem->forget(); unset($testItem); $data = array(); $testItem = ExportTestModelItem::getById($id); $adapter = new ModelToExportAdapter($testItem); $data[] = $adapter->getData(); $headerData = $adapter->getHeaderData(); // Export data to csv, and then revert csv back to array, so we compare data $csvData = ExportItemToCsvFileUtil::export($data, $headerData, 'exports.csv', false); $revertedData = CsvParser::parseFromString($csvData); // We are testing ModelToExportAdapter in details in another test // so in this test we suppose that ModelToExportAdapter::getData // return correct results $adapter = new ModelToExportAdapter($testItem); $compareData = $adapter->getData(); $compareHeaderData = $adapter->getHeaderData(); // Using === here would fail as we are not setting all keys part of getData()'s return array if ($compareData == array_values($revertedData[0]) && $compareHeaderData == array_keys($revertedData[0])) { return true; } return false; }