public function testRegularUserAllControllerActionsNoElevation() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $superAccount = AccountTestHelper::createAccountByNameForOwner('accountOwnedBySuper', $super); //Create address array for the account owned by super user. $address = array('street1' => '123 Knob Street', 'street2' => 'Apartment 4b', 'city' => 'Chicago', 'state' => 'Illinois', 'postalCode' => '60606', 'country' => 'USA'); //Assign Address to the user account. AddressGeoCodeTestHelper::updateTestAccountsWithBillingAddress($superAccount->id, $address, $super); //Fetch Latitute and Longitude values for address and save in Address. AddressMappingUtil::updateChangedAddresses(); $accounts = Account::getByName('accountOwnedBySuper'); $this->assertEquals(1, count($accounts)); $this->assertEquals(round('42.11529', 4), round($accounts[0]->billingAddress->latitude, 4)); $this->assertEquals(round('-87.976399', 4), round($accounts[0]->billingAddress->longitude, 4)); $this->assertEquals(0, $accounts[0]->billingAddress->invalid); $addressString = $accounts[0]->billingAddress->makeAddress(); $this->setGetArray(array('addressString' => $addressString, 'latitude' => $accounts[0]->billingAddress->latitude, 'longitude' => $accounts[0]->billingAddress->longitude)); Yii::app()->user->userModel = User::getByUsername('nobody'); //Now test account details portlet controller actions $this->setGetArray(array('id' => $superAccount->id)); $this->resetPostArray(); $this->runControllerShouldResultInAccessFailureAndGetContent('accounts/default/details'); //The map should always be available. Not controlled by rights. $this->setGetArray(array('addressString' => 'anAddress String', 'latitude' => '45.00', 'longitude' => '45.00')); $content = $this->runControllerWithNoExceptionsAndGetContent('maps/default/mapAndPoint'); $this->assertNotContains('Access Failure', $content); }
public function testCreateAndGetMeetingById() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $accounts = Account::getByName('anAccount'); $contact1 = ContactTestHelper::createContactWithAccountByNameForOwner('superContact', $super, $accounts[0]); $contact2 = ContactTestHelper::createContactWithAccountByNameForOwner('superContact2', $super, $accounts[0]); $contact3 = ContactTestHelper::createContactWithAccountByNameForOwner('superContact3', $super, $accounts[0]); $user = UserTestHelper::createBasicUser('Billy'); $startStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 10000); $endStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 11000); $meeting = new Meeting(); $meeting->name = 'MyMeeting'; $meeting->owner = $user; $meeting->location = 'my location'; $meeting->category->value = 'Call'; $meeting->startDateTime = $startStamp; $meeting->endDateTime = $endStamp; $meeting->description = 'my test description'; $meeting->activityItems->add($accounts[0]); $meeting->activityItems->add($contact1); $meeting->activityItems->add($contact2); $meeting->activityItems->add($contact3); $this->assertTrue($meeting->save()); $id = $meeting->id; unset($meeting); $meeting = Meeting::getById($id); $this->assertEquals('MyMeeting', $meeting->name); $this->assertEquals($startStamp, $meeting->startDateTime); $this->assertEquals($endStamp, $meeting->endDateTime); $this->assertEquals('my test description', $meeting->description); $this->assertEquals($user, $meeting->owner); $this->assertEquals(4, $meeting->activityItems->count()); $this->assertEquals($accounts[0], $meeting->activityItems->offsetGet(0)); }
public function testSaveAndRetrievePortlet() { $user = UserTestHelper::createBasicUser('Steven'); $accounts = Account::getByName('superAccount'); $portlet = new Portlet(); $portlet->column = 2; $portlet->position = 5; $portlet->layoutId = 'Test'; $portlet->collapsed = true; $portlet->viewType = 'AccountsForAccountRelatedList'; $portlet->serializedViewData = serialize(array('title' => 'Testing Title')); $portlet->user = $user; $this->assertTrue($portlet->save()); $portlet = Portlet::getById($portlet->id); $params = array('controllerId' => 'test', 'relationModuleId' => 'test', 'relationModel' => $accounts[0], 'redirectUrl' => 'someRedirect'); $portlet->params = $params; $unserializedViewData = unserialize($portlet->serializedViewData); $this->assertEquals(2, $portlet->column); $this->assertEquals(5, $portlet->position); $this->assertEquals('Testing Title', $portlet->getTitle()); $this->assertEquals(false, $portlet->isEditable()); $this->assertEquals('Test', $portlet->layoutId); //$this->assertEquals(true, $portlet->collapsed); //reenable once working $this->assertEquals('AccountsForAccountRelatedList', $portlet->viewType); $this->assertEquals($user->id, $portlet->user->id); $view = $portlet->getView(); }
public function testKanbanItemSave() { $accounts = Account::getByName('anAccount'); $user = UserTestHelper::createBasicUser('Billy'); $task = new Task(); $task->name = 'MyTask'; $task->owner = $user; $task->requestedByUser = $user; $task->description = 'my test description'; $taskCheckListItem = new TaskCheckListItem(); $taskCheckListItem->name = 'Test Check List Item'; $task->checkListItems->add($taskCheckListItem); $task->activityItems->add($accounts[0]); $task->status = Task::STATUS_IN_PROGRESS; $this->assertTrue($task->save()); $this->assertEquals(1, KanbanItem::getCount()); $id = $task->id; unset($task); $task = Task::getById($id); //KanbanItem is created after saving Task $kanbanItems = KanbanItem::getAll(); $this->assertCount(1, $kanbanItems); $kanbanItem = $kanbanItems[0]; $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem->type); }
public function testGetItemIdsByModelAndUser() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $headquarters = Account::getByName('Headquarters'); $headquarters = $headquarters[0]; $division1 = Account::getByName('Division1'); $division1 = $division1[0]; $division2 = Account::getByName('Division2'); $division2 = $division2[0]; $ceo = Contact::getByName('ceo ceoson'); $ceo = $ceo[0]; $div1President = Contact::getByName('div1 President div1 Presidentson'); $div1President = $div1President[0]; $div2President = Contact::getByName('div2 President div2 Presidentson'); $div2President = $div2President[0]; $opportunity = Opportunity::getByName('big opp'); $opportunity = $opportunity[0]; $opportunityDiv1 = Opportunity::getByName('div1 small opp'); $opportunityDiv1 = $opportunityDiv1[0]; $opportunityDiv2 = Opportunity::getByName('div2 small opp'); $opportunityDiv2 = $opportunityDiv2[0]; //Headquarter rollup should include all items created so far. $this->assertEquals(2, $headquarters->accounts->count()); $itemIds = ModelRollUpUtil::getItemIdsByModelAndUser($headquarters, $super); $compareItemIds = array(); $this->assertEquals(9, count($itemIds)); $this->assertTrue(in_array($headquarters->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($division1->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($division2->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($ceo->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($div1President->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($div2President->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($opportunity->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($opportunityDiv1->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($opportunityDiv2->getClassId('Item'), $itemIds)); //Ceo rollup would only include the ceo and his opportunity $itemIds = ModelRollUpUtil::getItemIdsByModelAndUser($ceo, $super); $compareItemIds = array(); $this->assertEquals(2, count($itemIds)); $this->assertTrue(in_array($ceo->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($opportunity->getClassId('Item'), $itemIds)); //Big Opp rollup will only include big opp and ceo $itemIds = ModelRollUpUtil::getItemIdsByModelAndUser($opportunity, $super); $compareItemIds = array(); $this->assertEquals(2, count($itemIds)); $this->assertTrue(in_array($ceo->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($opportunity->getClassId('Item'), $itemIds)); //Division 1 rollup will only include things related to division 1 $itemIds = ModelRollUpUtil::getItemIdsByModelAndUser($division1, $super); $compareItemIds = array(); $this->assertEquals(3, count($itemIds)); $this->assertTrue(in_array($division1->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($div1President->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($opportunityDiv1->getClassId('Item'), $itemIds)); }
/** * @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); }
public function testAddingMapPortletToAccountsDetailView() { //Lougout previous use and log in as super user $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //Retriving the super account id. $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount'); //Create address array for the super account id. $address = array('street1' => '123 Knob Street', 'street2' => 'Apartment 4b', 'city' => 'Chicago', 'state' => 'Illinois', 'postalCode' => '60606', 'country' => 'USA'); //Assign Address to the super user account. AddressGeoCodeTestHelper::updateTestAccountsWithBillingAddress($superAccountId, $address, $super); //Fetch Latitute and Longitude values for address and save in Address. AddressMappingUtil::updateChangedAddresses(); $accounts = Account::getByName('superAccount'); $this->assertEquals(1, count($accounts)); $this->assertEquals(round('41.8817767', 4), round($accounts[0]->billingAddress->latitude, 4)); $this->assertEquals(round('-87.6371461', 4), round($accounts[0]->billingAddress->longitude, 4)); $this->assertEquals(0, $accounts[0]->billingAddress->invalid); $addressString = $accounts[0]->billingAddress->makeAddress(); $this->setGetArray(array('addressString' => $addressString, 'latitude' => $accounts[0]->billingAddress->latitude, 'longitude' => $accounts[0]->billingAddress->longitude)); $content = $this->runControllerWithNoExceptionsAndGetContent('maps/default/mapAndPoint'); $this->assertContains('plotMap', $content); $accounts = Account::getAll(); $this->assertEquals(1, count($accounts)); //Load Model Detail Views $this->setGetArray(array('id' => $superAccountId, 'lockPortlets' => '0')); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details'); $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('AccountDetailsAndRelationsView', $super->id, array()); $this->assertEquals(3, count($portlets[1])); $this->assertFalse(array_key_exists(3, $portlets)); $this->assertEquals(4, count($portlets[2])); foreach ($portlets[2] as $position => $portlet) { $portlet->delete(); } $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('AccountDetailsAndRelationsView', $super->id, array()); $this->assertFalse(array_key_exists(2, $portlets)); $this->setGetArray(array('modelId' => $superAccountId, 'uniqueLayoutId' => 'AccountDetailsAndRelationsView', 'portletType' => 'MapForAccountAddress', 'redirect' => '0')); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/add', true); $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('AccountDetailsAndRelationsView', $super->id, array()); $this->assertEquals(1, count($portlets[2])); //Load Model Detail Views $this->setGetArray(array('id' => $superAccountId, 'lockPortlets' => '0')); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details'); }
public function testCopy() { Yii::app()->user->userModel = User::getByUsername('super'); $accounts = Account::getByName('anAccount'); $task = new Task(); $task->name = 'My Task'; $task->owner = Yii::app()->user->userModel; $task->completedDateTime = '0000-00-00 00:00:00'; $task->activityItems->add($accounts[0]); $saved = $task->save(); $this->assertTrue($saved); $taskId = $task->id; $task->forget(); unset($task); $task = Task::getById($taskId); $copyToTask = new Task(); ActivityCopyModelUtil::copy($task, $copyToTask); $this->assertEquals('My Task', $copyToTask->name); $this->assertEquals(1, $copyToTask->activityItems->count()); }
/** * @depends testCanCurrentUserPerformAction */ public function testResolveLinkToModelForCurrentUser() { Yii::app()->user->userModel = User::getByUsername('super'); $notSavedAccount = new Account(); $link = ActionSecurityUtil::resolveLinkToModelForCurrentUser('bpoboo', $notSavedAccount, 'AccountsModule', 'accounts/default/details'); $this->assertNull($link); $accounts = Account::getByName('Supermart'); $betty = User::getByUsername('betty'); $bettyAccount = AccountTestHelper::createAccountByNameForOwner('bopbeebop', $betty); Yii::app()->user->userModel = $betty; $link = ActionSecurityUtil::resolveLinkToModelForCurrentUser('bpoboo', $bettyAccount, 'AccountsModule', 'accounts/default/details'); $this->assertEquals('bpoboo', $link); $betty->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS, Right::ALLOW); $this->assertTrue($betty->save()); $link = ActionSecurityUtil::resolveLinkToModelForCurrentUser('bpoboo', $bettyAccount, 'AccountsModule', 'accounts/default/details'); $this->assertContains('accounts/default/details', $link); $this->assertEquals(1, count($accounts)); $link = ActionSecurityUtil::resolveLinkToModelForCurrentUser('bpoboo', $accounts[0], 'AccountsModule', 'accounts/default/details'); $this->assertEquals(null, $link); }
public function testSuperUserAllDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //Retriving the super account id. $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount'); //Create address array for the super account id. $address = array('street1' => '123 Knob Street', 'street2' => 'Apartment 4b', 'city' => 'Chicago', 'state' => 'Illinois', 'postalCode' => '60606', 'country' => 'USA'); //Assign Address to the super user account. AddressGeoCodeTestHelper::updateTestAccountsWithBillingAddress($superAccountId, $address, $super); //Fetch Latitute and Longitude values for address and save in Address. AddressMappingUtil::updateChangedAddresses(); $accounts = Account::getByName('superAccount'); $this->assertEquals(1, count($accounts)); $this->assertEquals(round('41.8817767', 4), round($accounts[0]->billingAddress->latitude, 4)); $this->assertEquals(round('-87.6371461', 4), round($accounts[0]->billingAddress->longitude, 4)); $this->assertEquals(0, $accounts[0]->billingAddress->invalid); $addressString = $accounts[0]->billingAddress->makeAddress(); $this->setGetArray(array('addressString' => $addressString, 'latitude' => $accounts[0]->billingAddress->latitude, 'longitude' => $accounts[0]->billingAddress->longitude)); $content = $this->runControllerWithNoExceptionsAndGetContent('maps/default/mapAndPoint'); $this->assertContains('plotMap', $content); }
/** * @see MissingBeanException (Related to why we needed this test in the first place.) Since superAccount * is created before the attributes, was causing a problem where some parts of the relatedModel beans are not * present. Catching the MissingBeanException in the RedBeanModel solved this problem. */ public function testSuperUserSavingAccountCreatedBeforeThreeoRequiredCustomAttributesAreCreated() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //First create an account before you create multiselect and tagcloud attributes $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super); $account->forget(); //Test create field list. $this->resetPostArray(); $this->setGetArray(array('moduleClassName' => 'AccountsModule')); //Create 2 custom attributes that are required. $this->createDropDownCustomFieldByModule('AccountsModule', 'dropdown'); $this->createMultiSelectDropDownCustomFieldByModule('AccountsModule', 'multiselect'); $this->createTagCloudCustomFieldByModule('AccountsModule', 'tagcloud'); //Save the account again. Everything is fine. $account = Account::getByName('superAccount'); $account[0]->save(false); $account[0]->forget(); //Retrieving the account again at this point should retrieve ok. $account = Account::getByName('superAccount'); $account[0]->save(false); $account[0]->forget(); }
public function testAddParicipantAndHaveParticipantRemoveSelf() { return; //Turn on once issue is fixed with SECURITY_OPTIMIZED and this bug. $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $fileModel = ZurmoTestHelper::createFileModel(); $accounts = Account::getByName('anAccount'); $steven = UserTestHelper::createBasicUser('steven'); $conversation = new Conversation(); $conversation->owner = $super; $conversation->subject = 'My test subject'; $conversation->description = 'My test description'; $this->assertTrue($conversation->save()); $sally = UserTestHelper::createBasicUser('sally'); $conversation->addPermissions($sally, Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER); $conversation->save(); //Log in as sally, and remove her permission Yii::app()->user->userModel = $sally; //Breaks because SecurableItem 2 spots using SECURITY_OPTIMIZATION == false, think it is the first spot //todo: fix. $conversation->removePermissions(Yii::app()->user->userModel, Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, Permission::ALLOW); }
public function testAccountAndContactIndustries() { Yii::app()->user->userModel = User::getByUsername('super'); $values = array('Automotive', 'Adult Entertainment', 'Financial Services', 'Mercenaries & Armaments'); $industryFieldData = CustomFieldData::getByName('Industries'); $industryFieldData->defaultValue = $values[0]; $industryFieldData->serializedData = serialize($values); $this->assertTrue($industryFieldData->save()); unset($industryFieldData); $user = UserTestHelper::createBasicUser('Billy'); $account = new Account(); $account->name = 'Consoladores-R-Us'; $account->owner = $user; $data = unserialize($account->industry->data->serializedData); $this->assertEquals('Automotive', $account->industry->value); $account->industry->value = $values[1]; $this->assertTrue($account->save()); unset($account); ContactsModule::loadStartingData(); $states = ContactState::GetAll(); $contact = new Contact(); $contact->firstName = 'John'; $contact->lastName = 'Johnson'; $contact->owner = $user; $contact->state = $states[0]; $values = unserialize($contact->industry->data->serializedData); $this->assertEquals(4, count($values)); $contact->industry->value = $values[3]; $this->assertTrue($contact->save()); unset($contact); $accounts = Account::getByName('Consoladores-R-Us'); $account = $accounts[0]; $this->assertEquals('Adult Entertainment', $account->industry->value); $contacts = Contact::getAll(); $contact = $contacts[0]; $this->assertEquals('Mercenaries & Armaments', $contact->industry->value); }
public function testGetExportValue() { $data = array(); Yii::app()->user->userModel = User::getByUsername('super'); $accounts = Account::getByName('anAccount'); $user = UserTestHelper::createBasicUser('Billy'); $dueStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 10000); $task = new Task(); $task->name = 'MyTask'; $task->owner = $user; $task->requestedByUser = $user; $task->dueDateTime = $dueStamp; $task->status = Task::STATUS_COMPLETED; $task->description = 'my test description'; $this->assertTrue($task->save()); $adapter = new TaskStatusDropDownRedBeanModelAttributeValueToExportValueAdapter($task, 'status'); $adapter->resolveData($data); $compareData = array('Completed'); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($task->getAttributeLabel('status')); $this->assertEquals($compareData, $data); }
/** * @depends testEditOfTheNoteForTheTagCloudFieldAfterRemovingAllTagsPlacedForNotesModule */ public function testEditOfTheNoteForTheCustomFieldsPlacedForNotesModule() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //Set the date and datetime variable values here. $date = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateFormat(), time()); $dateAssert = date('Y-m-d'); $datetime = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateTimeFormat(), time()); $datetimeAssert = date('Y-m-d H:i:') . "00"; //Get the super user, account, opportunity and contact id. $superUserId = $super->id; $superAccount = Account::getByName('superAccount'); $superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact2 superContact2son'); $superOpportunityId = self::getModelIdByModelNameAndName('Opportunity', 'superOpp'); $baseCurrency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode()); $explicitReadWriteModelPermission = ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP; //Retrieve the note Id based on the created note. $note = Note::getByName('Note Edit Description'); //Edit a note based on the custom fields. $this->setGetArray(array('id' => $note[0]->id)); $this->setPostArray(array('Note' => array('occurredOnDateTime' => $datetime, 'description' => 'Note Edit Description', 'explicitReadWriteModelPermissions' => array('type' => $explicitReadWriteModelPermission), 'owner' => array('id' => $superUserId), 'checkboxCstm' => '0', 'currencyCstm' => array('value' => 40, 'currency' => array('id' => $baseCurrency->id)), 'dateCstm' => $date, 'datetimeCstm' => $datetime, 'decimalCstm' => '12', 'picklistCstm' => array('value' => 'b'), 'multiselectCstm' => array('values' => array('gg', 'hh')), 'tagcloudCstm' => array('values' => array('reading', 'surfing')), 'countrylistCstm' => array('value' => 'aaaa'), 'statelistCstm' => array('value' => 'aaa1'), 'citylistCstm' => array('value' => 'ab1'), 'integerCstm' => '11', 'phoneCstm' => '259-784-2069', 'radioCstm' => array('value' => 'e'), 'textCstm' => 'This is a test Edit Text', 'textareaCstm' => 'This is a test Edit TextArea', 'urlCstm' => 'http://wwww.abc-edit.com'), 'ActivityItemForm' => array('Account' => array('id' => $superAccount[0]->id), 'Contact' => array('id' => $superContactId), 'Opportunity' => array('id' => $superOpportunityId)))); $this->runControllerWithRedirectExceptionAndGetUrl('notes/default/edit'); //Check the details if they are saved properly for the custom fields. $note = Note::getByName('Note Edit Description'); //Retrieve the permission of the note. $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem(Note::getById($note[0]->id)); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $readOnlyPermitables = $explicitReadWriteModelPermissions->getReadOnlyPermitables(); $this->assertEquals($note[0]->description, 'Note Edit Description'); $this->assertEquals($note[0]->occurredOnDateTime, $datetimeAssert); $this->assertEquals($note[0]->owner->id, $superUserId); $this->assertEquals($note[0]->activityItems->count(), 3); $this->assertEquals(1, count($readWritePermitables)); $this->assertEquals(0, count($readOnlyPermitables)); $this->assertEquals($note[0]->checkboxCstm, '0'); $this->assertEquals($note[0]->currencyCstm->value, 40); $this->assertEquals($note[0]->currencyCstm->currency->id, $baseCurrency->id); $this->assertEquals($note[0]->dateCstm, $dateAssert); $this->assertEquals($note[0]->datetimeCstm, $datetimeAssert); $this->assertEquals($note[0]->decimalCstm, '12'); $this->assertEquals($note[0]->picklistCstm->value, 'b'); $this->assertEquals($note[0]->integerCstm, 11); $this->assertEquals($note[0]->phoneCstm, '259-784-2069'); $this->assertEquals($note[0]->radioCstm->value, 'e'); $this->assertEquals($note[0]->textCstm, 'This is a test Edit Text'); $this->assertEquals($note[0]->textareaCstm, 'This is a test Edit TextArea'); $this->assertEquals($note[0]->urlCstm, 'http://wwww.abc-edit.com'); $this->assertEquals($note[0]->countrylistCstm->value, 'aaaa'); $this->assertEquals($note[0]->statelistCstm->value, 'aaa1'); $this->assertEquals($note[0]->citylistCstm->value, 'ab1'); $this->assertContains('gg', $note[0]->multiselectCstm->values); $this->assertContains('hh', $note[0]->multiselectCstm->values); $this->assertContains('reading', $note[0]->tagcloudCstm->values); $this->assertContains('surfing', $note[0]->tagcloudCstm->values); $metadata = CalculatedDerivedAttributeMetadata::getByNameAndModelClassName('calcnumber', 'Note'); $testCalculatedValue = CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($metadata->getFormula(), $note[0]); $this->assertEquals(23, $testCalculatedValue); }
/** * @depends testNewlyImportedDataForUpdateEmailDedupe */ public function testImportedDataForNameUpdateDedupe() { $jim = User::getByUsername('jim'); Yii::app()->user->userModel = $jim; //Confirm Jim can can only view ImportModelTestItems he owns. $item = NamedSecurableItem::getByName('ImportModule'); $this->assertEquals(Permission::NONE, $item->getEffectivePermissions($jim)); $testModels = Account::getByName('hello'); $this->assertEquals(1, count($testModels)); $import = new Import(); $serializedData['importRulesType'] = 'Accounts'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('importDedupeNameTest.csv', $import->getTempTableName(), true); $this->assertEquals(2, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $emailMappingData = ImportMappingUtil::makeEmailColumnMappingData('primaryEmail__emailAddress'); $emailMappingData['mappingRulesData']['EmailModelAttributeDedupeMappingRuleForm'] = array('dedupeRule' => ImportDedupeRulesRadioDropDownElement::DO_NOT_DEDUPE); $nameMappingData = ImportMappingUtil::makeEmailColumnMappingData('name'); $nameMappingData['mappingRulesData']['NameModelAttributeDedupeMappingRuleForm'] = array('dedupeRule' => ImportDedupeRulesRadioDropDownElement::UPDATE_ROW_ON_MATCH_FOUND); $mappingData = array('column_0' => $nameMappingData, 'column_1' => $emailMappingData); $importRules = ImportRulesUtil::makeImportRulesByType('Accounts'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $importResultsUtil = new ImportResultsUtil($import); $messageLogger = new ImportMessageLogger(); ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger); $importResultsUtil->processStatusAndMessagesForEachRow(); $testModels = Account::getByName('hello'); $this->assertEquals(1, count($testModels)); $this->assertEquals('*****@*****.**', $testModels[0]->primaryEmail->emailAddress); }
/** * @depends testSimpleUserImportWhereAllRowsSucceed */ public function testSimpleUserImportWithRelationsWhereAllRowsSucceed() { Yii::app()->user->userModel = User::getByUsername('super'); //Create account $sampleAccount = Account::getByName('sampleAccount'); $accountId = $sampleAccount[0]->id; //Create Contact $contact = ContactTestHelper::createContactByNameForOwner("My Contact", Yii::app()->user->userModel); $import = new Import(); $serializedData['importRulesType'] = 'Products'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('productsSampleWithRelations.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.products.tests.unit.files')); //update the ids of the account column to match the parent account. ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_9 = " . $contact->id . " where id != 1 limit 3"); $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $currencies = Currency::getAll(); $ownerColumnMappingData = array('attributeIndexOrDerivedType' => 'owner', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::ZURMO_USERNAME))); $mappingData = array('column_0' => $ownerColumnMappingData, 'column_1' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_2' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_3' => ImportMappingUtil::makeIntegerColumnMappingData('quantity'), 'column_4' => ImportMappingUtil::makeHasOneColumnMappingData('account', RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_NAME), 'column_5' => ImportMappingUtil::makeStringColumnMappingData('stage'), 'column_6' => ImportMappingUtil::makeCurrencyColumnMappingData('sellPrice', $currencies[0]), 'column_7' => ImportMappingUtil::makeIntegerColumnMappingData('priceFrequency'), 'column_8' => ImportMappingUtil::makeIntegerColumnMappingData('type')); $importRules = ImportRulesUtil::makeImportRulesByType('Products'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $importResultsUtil = new ImportResultsUtil($import); $messageLogger = new ImportMessageLogger(); ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger); $importResultsUtil->processStatusAndMessagesForEachRow(); //Confirm that 3 models where created. $products = Product::getAll(); $this->assertEquals(2, count($products)); $products = Product::getByName('A Bend in the River November Issue import'); $this->assertEquals(1, count($products)); $this->assertEquals('super', $products[0]->owner->username); $this->assertEquals('A Bend in the River November Issue import', $products[0]->name); $this->assertEquals(6, $products[0]->quantity); $this->assertEquals('sampleAccount', $products[0]->account->name); $this->assertEquals('Open', $products[0]->stage->value); $this->assertEquals('Test Desc', $products[0]->description); $this->assertEquals(210, $products[0]->sellPrice->value); $this->assertEquals(2, $products[0]->priceFrequency); $this->assertEquals(2, $products[0]->type); //$this->assertEquals('My Contact', $products[0]->contact->firstName); $products = Product::getByName('A Bend in the River November Issue import copy'); $this->assertEquals(1, count($products)); $this->assertEquals('super', $products[0]->owner->username); $this->assertEquals('A Bend in the River November Issue import copy', $products[0]->name); $this->assertEquals(6, $products[0]->quantity); $this->assertEquals('sampleAccount', $products[0]->account->name); $this->assertEquals('Open', $products[0]->stage->value); $this->assertEquals('Test Desc 1', $products[0]->description); $this->assertEquals(210, $products[0]->sellPrice->value); $this->assertEquals(2, $products[0]->priceFrequency); $this->assertEquals(2, $products[0]->type); //$this->assertEquals('My Contact', $products[0]->contact->firstName); //Confirm that 2 rows were processed as 'updated'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED)); //Confirm 2 rows were processed as 'errors'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR)); $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR); $this->assertEquals(0, count($beansWithErrors)); }
public function testImportWithLatestActivityDateTime() { Yii::app()->user->userModel = User::getByUsername('super'); $accounts = Account::deleteAll(); $import = new Import(); $serializedData['importRulesType'] = 'Accounts'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('importWithLatestActivityDateTimeTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.accounts.tests.unit.files')); $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeDateTimeColumnMappingData('latestActivityDateTime')); $importRules = ImportRulesUtil::makeImportRulesByType('Accounts'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $importResultsUtil = new ImportResultsUtil($import); $messageLogger = new ImportMessageLogger(); ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger); $importResultsUtil->processStatusAndMessagesForEachRow(); //Confirm that 2 models where created. $accounts = Account::getAll(); $this->assertCount(2, $accounts); $accounts = Account::getByName('company1'); $this->assertEquals('2011-12-22 05:03', substr($accounts[0]->latestActivityDateTime, 0, -3)); $accounts = Account::getByName('company2'); $this->assertNull($accounts[0]->latestActivityDateTime); //Confirm 2 rows were processed as 'created'. $this->assertEquals(2, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::CREATED)); //Confirm that 0 rows were processed as 'updated'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED)); //Confirm 0 rows were processed as 'errors'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR)); $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR); $this->assertEquals(0, count($beansWithErrors)); }
public function testProductSaveWithPermissions() { Yii::app()->user->userModel = User::getByUsername('super'); $contacts = Contact::getAll(); $accounts = Account::getByName('superAccount'); $opportunities = Opportunity::getByName('superOpportunity'); $productTemplates = ProductTemplate::getByName('superProductTemplate'); $account = $accounts[0]; $user = $account->owner; $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME); $explicitReadWriteModelPermissions = new ExplicitReadWriteModelPermissions(); $currencyHelper = Yii::app()->currencyHelper; $currencyCode = $currencyHelper->getBaseCode(); $currency = Currency::getByCode($currencyCode); $postData = array('productTemplate' => array('id' => $productTemplates[0]->id), 'name' => 'ProductPermissionTest', 'quantity' => 6, 'account' => array('id' => $accounts[0]->id), 'contact' => array('id' => $contacts[0]->id), 'opportunity' => array('id' => ''), 'type' => ProductTemplate::TYPE_PRODUCT, 'priceFrequency' => ProductTemplate::PRICE_FREQUENCY_ONE_TIME, 'sellPrice' => array('currency' => array('id' => $currency->id), 'value' => 210), 'stage' => array('value' => 'Open'), 'owner' => array('id' => $user->id), 'explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP, 'nonEveryoneGroup' => '')); $model = new Product(); $sanitizedPostData = PostUtil::sanitizePostByDesignerTypeForSavingModel($model, $postData); if ($model instanceof SecurableItem) { $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::resolveByPostDataAndModelThenMake($sanitizedPostData, $model); } else { $explicitReadWriteModelPermissions = null; } $readyToUseData = ExplicitReadWriteModelPermissionsUtil::removeIfExistsFromPostData($sanitizedPostData); $sanitizedOwnerData = PostUtil::sanitizePostDataToJustHavingElementForSavingModel($readyToUseData, 'owner'); $sanitizedDataWithoutOwner = PostUtil::removeElementFromPostDataForSavingModel($readyToUseData, 'owner'); $model->setAttributes($sanitizedDataWithoutOwner); if ($model->validate()) { $modelToStringValue = strval($model); if ($sanitizedOwnerData != null) { $model->setAttributes($sanitizedOwnerData); } if ($model instanceof OwnedSecurableItem) { $passedOwnerValidation = $model->validate(array('owner')); } else { $passedOwnerValidation = true; } if ($passedOwnerValidation && $model->save(false)) { if ($explicitReadWriteModelPermissions != null) { $success = ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($model, $explicitReadWriteModelPermissions); //todo: handle if success is false, means adding/removing permissions save failed. } $savedSuccessfully = true; } } else { } $this->assertEquals('ProductPermissionTest', $model->name); }
public function testEditAccountWIthIncorrectDataType() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $authenticationData = $this->login(); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); AccountTestHelper::createAccountByNameTypeAndIndustryForOwner('Newest Account', 'Customer', 'Automotive', $super); // Provide data with wrong type. $data['name'] = "AAA"; $data['employees'] = "SS"; $response = $this->createApiCallWithRelativeUrl('create/', 'POST', $headers, array('data' => $data)); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']); $this->assertEquals(1, count($response['errors'])); $accounts = Account::getByName('Newest Account'); $this->assertEquals(1, count($accounts)); $id = $accounts[0]->id; $data = array(); $data['employees'] = 'DD'; $response = $this->createApiCallWithRelativeUrl('update/' . $id, 'PUT', $headers, array('data' => $data)); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']); $this->assertEquals(1, count($response['errors'])); }
/** * @depends testCreateAndGetAccountById */ public function testUpdateAccountFromForm() { $accounts = Account::getByName('Test Account'); $account = $accounts[0]; $this->assertEquals($account->name, 'Test Account'); $postData = array('name' => 'New Name'); $account->setAttributes($postData); $this->assertTrue($account->save()); $id = $account->id; unset($account); $account = Account::getById($id); $this->assertEquals('New Name', $account->name); }
/** * @depends testGetUnreadConversationCount */ public function testDeleteConversation() { $conversations = Conversation::getAll(); $this->assertEquals(3, count($conversations)); $comments = Comment::getAll(); $this->assertEquals(4, count($comments)); //check count of conversation_items $count = ZurmoRedBean::getRow('select count(*) count from conversation_item'); $this->assertEquals(2, $count['count']); //remove the account, tests tthat ConversationObserver is correctly removing data from conversation_item $accounts = Account::getByName('anAccount2'); $this->assertTrue($accounts[0]->delete()); $count = ZurmoRedBean::getRow('select count(*) count from conversation_item'); $this->assertEquals(1, $count['count']); foreach ($conversations as $conversation) { $conversationId = $conversation->id; $conversation->forget(); $conversation = Conversation::getById($conversationId); $deleted = $conversation->delete(); $this->assertTrue($deleted); } //Count of conversation items should be 0 since the ConversationsObserver should make sure it gets removed correctly. $count = ZurmoRedBean::getRow('select count(*) count from conversation_item'); $this->assertEquals(0, $count['count']); //check that all comments are removed, since they are owned. $comments = Comment::getAll(); $this->assertEquals(0, count($comments)); }
/** * Check if only new messages are pulled from dropdown * Also check case if message will be matched with user/contact/account primary email * * @depends testRunCaseFour */ public function testRunCaseFive() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $user = User::getByUsername('steve'); Yii::app()->imap->connect(); ContactTestHelper::createContactByNameForOwner('contact', $user); $contacts = Contact::getByName('contact contactson'); $contacts[0]->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress']; $this->assertTrue($contacts[0]->save()); AccountTestHelper::createAccountByNameForOwner('account', $user); $accounts = Account::getByName('account'); $accounts[0]->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress']; $this->assertTrue($accounts[0]->save()); $john = User::getByUsername('john'); $john->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress']; $this->assertTrue($john->save()); EmailMessage::deleteAll(); Yii::app()->imap->deleteMessages(true); // Check if there are no emails in dropbox $job = new EmailArchivingJob(); $this->assertTrue($job->run()); $this->assertEquals(0, EmailMessage::getCount()); $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed(); $this->assertEquals(0, $imapStats->Nmsgs); //Now user send email to another user, and to dropbox $pathToFiles = Yii::getPathOfAlias('application.modules.emailMessages.tests.unit.files'); Yii::app()->emailHelper->sendRawEmail("Email from Steve 3", $user->primaryEmail->emailAddress, array(Yii::app()->params['emailTestAccounts']['testEmailAddress']), 'Email from Steve', '<strong>Email</strong> from Steve', null, array(Yii::app()->imap->imapUsername), null, self::$userMailer); sleep(30); $job = new EmailArchivingJob(); $this->assertTrue($job->run()); $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed(); $this->assertEquals(0, $imapStats->Nmsgs); $this->assertEquals(2, EmailMessage::getCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[1]; $this->assertEquals('Email from Steve 3', $emailMessage->subject); $this->assertEquals('Email from Steve', trim($emailMessage->content->textContent)); $this->assertEquals('<!-- zurmo css inline --><strong>Email</strong> from Steve', preg_replace("/\r|\n/", "", $emailMessage->content->htmlContent)); $this->assertEquals($user->primaryEmail->emailAddress, $emailMessage->sender->fromAddress); $this->assertEquals(1, count($emailMessage->recipients)); $recipient = $emailMessage->recipients[0]; $this->assertCount(3, $recipient->personsOrAccounts); $this->assertEquals($recipient->toAddress, Yii::app()->params['emailTestAccounts']['testEmailAddress']); $this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipient->type); $this->assertEquals(EmailFolder::TYPE_ARCHIVED, $emailMessage->folder->type); $job = new EmailArchivingJob(); $this->assertTrue($job->run()); $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed(); $this->assertEquals(0, $imapStats->Nmsgs); $this->assertEquals(2, EmailMessage::getCount()); $this->assertEquals(1, Notification::getCountByTypeAndUser('EmailMessageArchivingEmailAddressNotMatching', $user)); }
/** * @depends testRegularUserEditExistingAccountAndChangeExplicitPermissions */ public function testRegularUserCreateAccountAndChangeExplicitPermissions() { $nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody'); $group1 = Group::getByName('Group1'); $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME); //Create an account for nobody with no explicit permissions. $this->resetGetArray(); $postData = array('type' => null); $this->setPostArray(array('Account' => array('name' => 'myNewAccount', 'officePhone' => '456765421', 'explicitReadWriteModelPermissions' => $postData))); //Make sure the redirect is to the details view and not the list view. $this->runControllerWithRedirectExceptionAndGetContent('accounts/default/create'); // Not Coding Standard //Confirm the permissions are set right based on how the account was saved. $accounts = Account::getByName('myNewAccount'); $this->assertEquals(1, count($accounts)); $accountId = $accounts[0]->id; $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem(Account::getById($accountId)); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $readOnlyPermitables = $explicitReadWriteModelPermissions->getReadOnlyPermitables(); $this->assertEquals(0, count($readWritePermitables)); $this->assertEquals(0, count($readOnlyPermitables)); //Create an account for nobody and add explicit permissions for the everyone group. $this->resetGetArray(); $postData = array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP); $this->setPostArray(array('Account' => array('name' => 'myNewAccount2', 'officePhone' => '456765421', 'explicitReadWriteModelPermissions' => $postData))); //Make sure the redirect is to the details view and not the list view. $this->runControllerWithRedirectExceptionAndGetContent('accounts/default/create'); // Not Coding Standard //Confirm the permissions are set right based on how the account was saved. $accounts = Account::getByName('myNewAccount2'); $this->assertEquals(1, count($accounts)); $accountId = $accounts[0]->id; $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem(Account::getById($accountId)); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $readOnlyPermitables = $explicitReadWriteModelPermissions->getReadOnlyPermitables(); $this->assertEquals(1, count($readWritePermitables)); $this->assertEquals(0, count($readOnlyPermitables)); $this->assertEquals($everyoneGroup, $readWritePermitables[$everyoneGroup->getClassId('Permitable')]); //Create an account for nobody and add explicit permissions for a non-everyone group. $this->resetGetArray(); $postData = array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_NONEVERYONE_GROUP, 'nonEveryoneGroup' => $group1->id); $this->setPostArray(array('Account' => array('name' => 'myNewAccount3', 'officePhone' => '456765421', 'explicitReadWriteModelPermissions' => $postData))); //Make sure the redirect is to the details view and not the list view. $this->runControllerWithRedirectExceptionAndGetContent('accounts/default/create'); // Not Coding Standard //Confirm the permissions are set right based on how the account was saved. $accounts = Account::getByName('myNewAccount3'); $this->assertEquals(1, count($accounts)); $accountId = $accounts[0]->id; $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem(Account::getById($accountId)); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $readOnlyPermitables = $explicitReadWriteModelPermissions->getReadOnlyPermitables(); $this->assertEquals(1, count($readWritePermitables)); $this->assertEquals(0, count($readOnlyPermitables)); $this->assertEquals($group1, $readWritePermitables[$group1->getClassId('Permitable')]); }
/** * @depends testParentAccountHasCorrectAttributeImportType */ public function testSimpleUserImportWhereAllRowsSucceed() { Yii::app()->user->userModel = User::getByUsername('super'); $parentAccount = AccountTestHelper::createAccountByNameForOwner('parentAccount', Yii::app()->user->userModel); $parentAccountId = $parentAccount->id; $accounts = Account::getAll(); $this->assertEquals(1, count($accounts)); $import = new Import(); $serializedData['importRulesType'] = 'Accounts'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('importTest.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.accounts.tests.unit.files')); //update the ids of the account column to match the parent account. R::exec("update " . $import->getTempTableName() . " set column_16 = " . $parentAccount->id . " where id != 1 limit 4"); $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeStringColumnMappingData('officePhone'), 'column_2' => ImportMappingUtil::makeStringColumnMappingData('officeFax'), 'column_3' => ImportMappingUtil::makeIntegerColumnMappingData('employees'), 'column_4' => ImportMappingUtil::makeUrlColumnMappingData('website'), 'column_5' => ImportMappingUtil::makeFloatColumnMappingData('annualRevenue'), 'column_6' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_7' => ImportMappingUtil::makeStringColumnMappingData('billingAddress__city'), 'column_8' => ImportMappingUtil::makeStringColumnMappingData('billingAddress__country'), 'column_9' => ImportMappingUtil::makeStringColumnMappingData('billingAddress__postalCode'), 'column_10' => ImportMappingUtil::makeStringColumnMappingData('billingAddress__state'), 'column_11' => ImportMappingUtil::makeStringColumnMappingData('billingAddress__street1'), 'column_12' => ImportMappingUtil::makeStringColumnMappingData('billingAddress__street2'), 'column_13' => ImportMappingUtil::makeEmailColumnMappingData('primaryEmail__emailAddress'), 'column_14' => ImportMappingUtil::makeBooleanColumnMappingData('primaryEmail__isInvalid'), 'column_15' => ImportMappingUtil::makeBooleanColumnMappingData('primaryEmail__optOut'), 'column_16' => ImportMappingUtil::makeHasOneColumnMappingData('account'), 'column_17' => ImportMappingUtil::makeDropDownColumnMappingData('industry'), 'column_18' => ImportMappingUtil::makeDropDownColumnMappingData('type')); $importRules = ImportRulesUtil::makeImportRulesByType('Accounts'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $importResultsUtil = new ImportResultsUtil($import); $messageLogger = new ImportMessageLogger(); ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger); $importResultsUtil->processStatusAndMessagesForEachRow(); //Confirm that 3 models where created. $accounts = Account::getAll(); $this->assertEquals(4, count($accounts)); $accounts = Account::getByName('account1'); $this->assertEquals(1, count($accounts[0])); $this->assertEquals(123456, $accounts[0]->officePhone); $this->assertEquals(555, $accounts[0]->officeFax); $this->assertEquals(1, $accounts[0]->employees); $this->assertEquals('http://www.account1.com', $accounts[0]->website); $this->assertEquals(100, $accounts[0]->annualRevenue); $this->assertEquals('desc1', $accounts[0]->description); $this->assertEquals('city1', $accounts[0]->billingAddress->city); $this->assertEquals('country1', $accounts[0]->billingAddress->country); $this->assertEquals('postal1', $accounts[0]->billingAddress->postalCode); $this->assertEquals('state1', $accounts[0]->billingAddress->state); $this->assertEquals('street11', $accounts[0]->billingAddress->street1); $this->assertEquals('street21', $accounts[0]->billingAddress->street2); $this->assertEquals('*****@*****.**', $accounts[0]->primaryEmail->emailAddress); $this->assertEquals(null, $accounts[0]->primaryEmail->isInvalid); $this->assertEquals(null, $accounts[0]->primaryEmail->optOut); $this->assertTrue($accounts[0]->account->isSame($parentAccount)); $this->assertEquals('Automotive', $accounts[0]->industry->value); $this->assertEquals('Prospect', $accounts[0]->type->value); $accounts = Account::getByName('account2'); $this->assertEquals(1, count($accounts[0])); $this->assertEquals(223456, $accounts[0]->officePhone); $this->assertEquals(666, $accounts[0]->officeFax); $this->assertEquals(2, $accounts[0]->employees); $this->assertEquals('http://www.account2.com', $accounts[0]->website); $this->assertEquals(200, $accounts[0]->annualRevenue); $this->assertEquals('desc2', $accounts[0]->description); $this->assertEquals('city2', $accounts[0]->billingAddress->city); $this->assertEquals('country2', $accounts[0]->billingAddress->country); $this->assertEquals('postal2', $accounts[0]->billingAddress->postalCode); $this->assertEquals('state2', $accounts[0]->billingAddress->state); $this->assertEquals('street12', $accounts[0]->billingAddress->street1); $this->assertEquals('street22', $accounts[0]->billingAddress->street2); $this->assertEquals('*****@*****.**', $accounts[0]->primaryEmail->emailAddress); $this->assertEquals('1', $accounts[0]->primaryEmail->isInvalid); $this->assertEquals('1', $accounts[0]->primaryEmail->optOut); $this->assertTrue($accounts[0]->account->isSame($parentAccount)); $this->assertEquals('Banking', $accounts[0]->industry->value); $this->assertEquals('Customer', $accounts[0]->type->value); $accounts = Account::getByName('account3'); $this->assertEquals(1, count($accounts[0])); $this->assertEquals(323456, $accounts[0]->officePhone); $this->assertEquals(777, $accounts[0]->officeFax); $this->assertEquals(3, $accounts[0]->employees); $this->assertEquals('http://www.account3.com', $accounts[0]->website); $this->assertEquals(300, $accounts[0]->annualRevenue); $this->assertEquals('desc3', $accounts[0]->description); $this->assertEquals('city3', $accounts[0]->billingAddress->city); $this->assertEquals('country3', $accounts[0]->billingAddress->country); $this->assertEquals('postal3', $accounts[0]->billingAddress->postalCode); $this->assertEquals('state3', $accounts[0]->billingAddress->state); $this->assertEquals('street13', $accounts[0]->billingAddress->street1); $this->assertEquals('street23', $accounts[0]->billingAddress->street2); $this->assertEquals('*****@*****.**', $accounts[0]->primaryEmail->emailAddress); $this->assertEquals(null, $accounts[0]->primaryEmail->isInvalid); $this->assertEquals(null, $accounts[0]->primaryEmail->optOut); $this->assertTrue($accounts[0]->account->isSame($parentAccount)); $this->assertEquals('Energy', $accounts[0]->industry->value); $this->assertEquals('Vendor', $accounts[0]->type->value); //Confirm 10 rows were processed as 'created'. $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::CREATED)); //Confirm that 0 rows were processed as 'updated'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED)); //Confirm 2 rows were processed as 'errors'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR)); $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR); $this->assertEquals(0, count($beansWithErrors)); //test the parent account has 3 children $parentAccount->forget(); $parentAccount = Account::getById($parentAccountId); $this->assertEquals(3, $parentAccount->accounts->count()); }
protected function setSelectedModels() { $accounts = Account::getByName('Test Account1'); $this->selectedModels[] = $accounts[0]; $accounts = Account::getByName('Test Account2'); $this->selectedModels[] = $accounts[0]; }
/** * @depends testResolveExplicitReadWriteModelPermissions */ public function testResolveByPostDataAndModelThenMake() { Yii::app()->user->userModel = User::getByUsername('super'); $accounts = Account::getByName('aTestAccount'); $this->assertEquals(1, count($accounts)); $account = $accounts[0]; $group3 = Group::getByName('Group3'); //Remove group 2 and 4, and add group 3. $postData = array('explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_NONEVERYONE_GROUP, 'nonEveryoneGroup' => $group3->id)); $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::resolveByPostDataAndModelThenMake($postData, $account); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $readOnlyPermitables = $explicitReadWriteModelPermissions->getReadOnlyPermitables(); $this->assertEquals(1, count($readWritePermitables)); $this->assertEquals(0, count($readOnlyPermitables)); $this->assertEquals($group3, $readWritePermitables[$group3->id]); }
/** * @depends testSuperUserCreateAction */ public function testSuperUserCreateFromRelationAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $currencies = Currency::getAll(); $opportunities = Opportunity::getAll(); $this->assertEquals(12, count($opportunities)); $account = Account::getByName('superAccount2'); $contact = Contact::getByName('superContact2 superContact2son'); $this->assertEquals(1, count($contact)); //Create a new contact from a related account. $this->setGetArray(array('relationAttributeName' => 'account', 'relationModelId' => $account[0]->id, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Opportunity' => array('name' => 'myUltraNewOpportunity', 'description' => '456765421', 'closeDate' => '11/1/11', 'amount' => array('value' => '545', 'currency' => array('id' => $currencies[0]->id)), 'stage' => array('value' => 'Negotiating')))); $this->runControllerWithRedirectExceptionAndGetContent('opportunities/default/createFromRelation'); $opportunities = Opportunity::getByName('myUltraNewOpportunity'); $this->assertEquals(1, count($opportunities)); $this->assertTrue($opportunities[0]->id > 0); $this->assertTrue($opportunities[0]->owner == $super); $this->assertTrue($opportunities[0]->account == $account[0]); $this->assertEquals('456765421', $opportunities[0]->description); $this->assertEquals('545', $opportunities[0]->amount->value); $this->assertEquals('2011-11-01', $opportunities[0]->closeDate); $this->assertEquals('Negotiating', $opportunities[0]->stage->value); $opportunities = Opportunity::getAll(); $this->assertEquals(13, count($opportunities)); //Create a new contact from a related opportunity $this->setGetArray(array('relationAttributeName' => 'contacts', 'relationModelId' => $contact[0]->id, 'relationModuleId' => 'contacts', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Opportunity' => array('name' => 'mySuperNewOpportunity', 'description' => '456765421', 'closeDate' => '11/1/11', 'amount' => array('value' => '545', 'currency' => array('id' => $currencies[0]->id)), 'stage' => array('value' => 'Negotiating')))); $this->runControllerWithRedirectExceptionAndGetContent('opportunities/default/createFromRelation'); $opportunities = Opportunity::getByName('mySuperNewOpportunity'); $this->assertEquals(1, count($opportunities)); $this->assertTrue($opportunities[0]->id > 0); $this->assertTrue($opportunities[0]->owner == $super); $this->assertEquals(1, $opportunities[0]->contacts->count()); $this->assertTrue($opportunities[0]->contacts[0] == $contact[0]); $this->assertEquals('456765421', $opportunities[0]->description); $this->assertEquals('545', $opportunities[0]->amount->value); $this->assertEquals('2011-11-01', $opportunities[0]->closeDate); $this->assertEquals('Negotiating', $opportunities[0]->stage->value); $opportunities = Opportunity::getAll(); $this->assertEquals(14, count($opportunities)); //todo: test save with account. }
public function testAddingNoteAndDeletingNoteAndThenTheSocialItemsAreRemoved() { $super = User::getByUsername('super'); $this->assertEquals(0, SocialItem::getCount()); $accounts = Account::getByName('anAccount'); $note = NoteTestHelper::createNoteWithOwnerAndRelatedAccount('aNote', $super, $accounts[0]); $socialItem = new SocialItem(); $socialItem->description = 'My test description'; $socialItem->note = $note; $saved = $socialItem->save(); $this->assertTrue($saved); $socialItemId = $socialItem->id; $noteId = $note->id; $note->forget(); $this->assertEquals(1, SocialItem::getCount()); $note = Note::getById($noteId); $deleted = $note->delete(); $this->assertTrue($deleted); $this->assertEquals(0, SocialItem::getCount()); }
public function testSecurityExceptionThrownDuringExport() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; SecurityTestHelper::createAccounts(); $billy = User::getByUsername('billy'); Yii::app()->user->userModel = $billy; AllPermissionsOptimizationUtil::rebuild(); $numberOfUserNotifications = Notification::getCountByTypeAndUser('ExportProcessCompleted', $billy); $account = new Account(false); $searchForm = new AccountsSearchForm($account); $dataProvider = ExportTestHelper::makeRedBeanDataProvider($searchForm, 'Account', 0, $billy->id); $totalItems = $dataProvider->getTotalItemCount(); $this->assertEquals(3, $totalItems); $exportItem = new ExportItem(); $exportItem->isCompleted = 0; $exportItem->exportFileType = 'csv'; $exportItem->exportFileName = 'test7'; $exportItem->modelClassName = 'Account'; $exportItem->serializedData = serialize($dataProvider); $exportItem->owner = $billy; $this->assertTrue($exportItem->save()); $id = $exportItem->id; $exportItem->forget(); unset($exportItem); //Delete queued jobs from test exportItems created above Yii::app()->jobQueue->deleteAll(); $accounts = Account::getByName('Microsoft'); $account = $accounts[0]; $account->owner = $super; $this->assertTrue($account->save()); $job = new ExportJob(); //ReadPermissionSubscriptionUpdate should get added to jobQueue $this->assertEquals(0, count(Yii::app()->jobQueue->getAll())); $this->assertTrue($job->run()); $this->assertEquals(0, count(Yii::app()->jobQueue->getAll())); $exportItem = ExportItem::getById($id); $fileModel = $exportItem->exportFileModel; $this->assertEquals(1, $exportItem->isCompleted); $this->assertEquals('csv', $exportItem->exportFileType); $this->assertEquals('test7', $exportItem->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $data = array(); $rows = $dataProvider->getData(); $modelToExportAdapter = new ModelToExportAdapter($rows[0]); $headerData = $modelToExportAdapter->getHeaderData(); foreach ($rows as $model) { //billy lost access to Microsoft account if ($model->id != $account->id) { $modelToExportAdapter = new ModelToExportAdapter($model); $data[] = $modelToExportAdapter->getData(); } } $output = ExportItemToCsvFileUtil::export($data, $headerData, 'test7.csv', false); $this->assertEquals($output, $fileModel->fileContent->content); }