public function testSimpleUserImportWhereAllRowsSucceed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $meetings = Meeting::getAll();
     $this->assertEquals(0, count($meetings));
     $import = new Import();
     $serializedData['importRulesType'] = 'Meetings';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.meetings.tests.unit.files'));
     $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeStringColumnMappingData('location'), 'column_2' => ImportMappingUtil::makeDateTimeColumnMappingData('startDateTime'), 'column_3' => ImportMappingUtil::makeDateTimeColumnMappingData('endDateTime'), 'column_4' => ImportMappingUtil::makeDropDownColumnMappingData('category'), 'column_5' => ImportMappingUtil::makeModelDerivedColumnMappingData('AccountDerived'), 'column_6' => ImportMappingUtil::makeModelDerivedColumnMappingData('ContactDerived'), 'column_7' => ImportMappingUtil::makeModelDerivedColumnMappingData('OpportunityDerived'), 'column_8' => ImportMappingUtil::makeTextAreaColumnMappingData('description'));
     $importRules = ImportRulesUtil::makeImportRulesByType('Meetings');
     $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.
     $meetings = Meeting::getAll();
     $this->assertEquals(3, count($meetings));
     $meetings = Meeting::getByName('meeting1');
     $this->assertEquals(1, count($meetings[0]));
     $this->assertEquals(1, count($meetings[0]->activityItems));
     $this->assertEquals('testAccount', $meetings[0]->activityItems[0]->name);
     $this->assertEquals('Account', get_class($meetings[0]->activityItems[0]));
     $this->assertEquals('2011-12-22 05:03', substr($meetings[0]->latestDateTime, 0, -3));
     $meetings = Meeting::getByName('meeting2');
     $this->assertEquals(1, count($meetings[0]));
     $this->assertEquals(1, count($meetings[0]->activityItems));
     $this->assertEquals('testContact', $meetings[0]->activityItems[0]->firstName);
     $this->assertEquals('Contact', get_class($meetings[0]->activityItems[0]));
     $this->assertEquals('2011-12-22 05:03', substr($meetings[0]->latestDateTime, 0, -3));
     $meetings = Meeting::getByName('meeting3');
     $this->assertEquals(1, count($meetings[0]));
     $this->assertEquals(1, count($meetings[0]->activityItems));
     $this->assertEquals('testOpportunity', $meetings[0]->activityItems[0]->name);
     $this->assertEquals('Opportunity', get_class($meetings[0]->activityItems[0]));
     $this->assertEquals('2011-12-22 06:03', substr($meetings[0]->latestDateTime, 0, -3));
     //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));
 }
 public function testSuperUserAllDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
     $superAccountId2 = self::getModelIdByModelNameAndName('Account', 'superAccount2');
     $superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson');
     $superContactId2 = self::getModelIdByModelNameAndName('Contact', 'superContact2 superContact2son');
     $superContactId3 = self::getModelIdByModelNameAndName('Contact', 'superContact3 superContact3son');
     $account = Account::getById($superAccountId);
     $account2 = Account::getById($superAccountId2);
     $contact = Contact::getById($superContactId);
     $contact2 = Contact::getById($superContactId2);
     $contact3 = Contact::getById($superContactId3);
     //confirm no existing activities exist
     $activities = Activity::getAll();
     $this->assertEquals(0, count($activities));
     //Test just going to the create from relation view.
     $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect'));
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/createFromRelation');
     //add related meeting for account using createFromRelation action
     $activityItemPostData = array('Account' => array('id' => $superAccountId));
     $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect'));
     $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Meeting' => array('name' => 'myMeeting', 'startDateTime' => '11/1/2011 7:45 PM')));
     $this->runControllerWithRedirectExceptionAndGetContent('meetings/default/createFromRelation');
     //now test that the new meeting exists, and is related to the account.
     $meetings = Meeting::getAll();
     $this->assertEquals(1, count($meetings));
     $this->assertEquals('myMeeting', $meetings[0]->name);
     $this->assertEquals(1, $meetings[0]->activityItems->count());
     $activityItem1 = $meetings[0]->activityItems->offsetGet(0);
     $this->assertEquals($account, $activityItem1);
     //test viewing the existing meeting in a details view
     $this->setGetArray(array('id' => $meetings[0]->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/details');
     //test editing an existing meeting and saving. Add a second relation, to a contact.
     //First just go to the edit view and confirm it loads ok.
     $this->setGetArray(array('id' => $meetings[0]->id, 'redirectUrl' => 'someRedirect'));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/edit');
     //Save changes via edit action.
     $activityItemPostData = array('Account' => array('id' => $superAccountId), 'Contact' => array('id' => $superContactId));
     $this->setGetArray(array('id' => $meetings[0]->id, 'redirectUrl' => 'someRedirect'));
     $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Meeting' => array('name' => 'myMeetingX')));
     $this->runControllerWithRedirectExceptionAndGetContent('meetings/default/edit');
     //Confirm changes applied correctly.
     $meetings = Meeting::getAll();
     $this->assertEquals(1, count($meetings));
     $this->assertEquals('myMeetingX', $meetings[0]->name);
     $this->assertEquals(2, $meetings[0]->activityItems->count());
     $activityItem1 = $meetings[0]->activityItems->offsetGet(0);
     $activityItem2 = $meetings[0]->activityItems->offsetGet(1);
     $this->assertEquals($account, $activityItem1);
     $this->assertEquals($contact, $activityItem2);
     //Remove contact relation.  Switch account relation to a different account.
     $activityItemPostData = array('Account' => array('id' => $superAccountId2));
     $this->setGetArray(array('id' => $meetings[0]->id));
     $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Meeting' => array('name' => 'myMeetingX')));
     $this->runControllerWithRedirectExceptionAndGetContent('meetings/default/edit');
     //Confirm changes applied correctly.
     $meetings = Meeting::getAll();
     $this->assertEquals(1, count($meetings));
     $this->assertEquals('myMeetingX', $meetings[0]->name);
     $this->assertEquals(1, $meetings[0]->activityItems->count());
     $activityItem1 = $meetings[0]->activityItems->offsetGet(0);
     $this->assertEquals($account2, $activityItem1);
     //test removing a meeting.
     $this->setGetArray(array('id' => $meetings[0]->id));
     $this->resetPostArray();
     $this->runControllerWithRedirectExceptionAndGetContent('meetings/default/delete');
     //Confirm no more meetings exist.
     $meetings = Meeting::getAll();
     $this->assertEquals(0, count($meetings));
     //Test adding a meeting with multiple contacts
     $contactItemPrefix = Meeting::CONTACT_ATTENDEE_PREFIX;
     $meetingAttendeesData = $contactItemPrefix . $superContactId . ',' . $contactItemPrefix . $superContactId2 . ',' . $contactItemPrefix . $superContactId3;
     $activityItemPostData = array('Account' => array('id' => $superAccountId), 'Contact' => array('ids' => $meetingAttendeesData));
     // Not Coding Standard
     $this->setGetArray(array('relationAttributeName' => 'Account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect'));
     $this->setPostArray(array('ActivityItemForm' => $activityItemPostData, 'Meeting' => array('name' => 'myMeeting2', 'startDateTime' => '11/1/2011 7:45 PM')));
     $this->runControllerWithRedirectExceptionAndGetContent('meetings/default/createFromRelation');
     //now test that the new meeting exists, and is related to the account.
     $meetings = Meeting::getAll();
     $this->assertEquals(1, count($meetings));
     $this->assertEquals('myMeeting2', $meetings[0]->name);
     $this->assertEquals(4, $meetings[0]->activityItems->count());
     $activityItem1 = $meetings[0]->activityItems->offsetGet(0);
     $this->assertEquals($account, $activityItem1);
 }
Пример #3
0
 /**
  * @depends testUpdateMeetingFromForm
  */
 public function testDeleteMeeting()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $meetings = Meeting::getAll();
     $this->assertEquals(2, count($meetings));
     $meetings[0]->delete();
     $meetings = Meeting::getAll();
     $this->assertEquals(1, count($meetings));
 }