public static function setUpBeforeClass() { parent::setUpBeforeClass(); ZurmoDatabaseCompatibilityUtil::dropStoredFunctionsAndProcedures(); $super = SecurityTestHelper::createSuperAdmin(); Yii::app()->user->userModel = User::getByUsername('super'); $headquarters = AccountTestHelper::createAccountByNameForOwner('Headquarters', $super); $division1 = AccountTestHelper::createAccountByNameForOwner('Division1', $super); $division2 = AccountTestHelper::createAccountByNameForOwner('Division2', $super); $ceo = ContactTestHelper::createContactWithAccountByNameForOwner('ceo', $super, $headquarters); $div1President = ContactTestHelper::createContactWithAccountByNameForOwner('div1 President', $super, $division1); $div2President = ContactTestHelper::createContactWithAccountByNameForOwner('div2 President', $super, $division2); $opportunity = OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('big opp', $super, $headquarters); $opportunityDiv1 = OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('div1 small opp', $super, $division1); $opportunityDiv2 = OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('div2 small opp', $super, $division2); //attach divisions to headquarters $headquarters->accounts->add($division1); $headquarters->accounts->add($division2); assert($headquarters->save()); // Not Coding Standard //attach opportunities to contacts $opportunity->contacts->add($ceo); assert($opportunity->save()); // Not Coding Standard //Forget models to ensure relations are known on the next retrieval $headquarters->forget(); $division1->forget(); $division2->forget(); $ceo->forget(); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; //Setup test data owned by the super user. $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super); AccountTestHelper::createAccountByNameForOwner('superAccount2', $super); ContactTestHelper::createContactWithAccountByNameForOwner('superContact', $super, $account); ContactTestHelper::createContactWithAccountByNameForOwner('superContact2', $super, $account); OpportunityTestHelper::createOpportunityStagesIfDoesNotExist(); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp', $super, $account); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp2', $super, $account); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp3', $super, $account); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp4', $super, $account); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp5', $super, $account); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp6', $super, $account); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp7', $super, $account); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp8', $super, $account); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp9', $super, $account); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp10', $super, $account); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp11', $super, $account); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp12', $super, $account); //Setup default dashboard. Dashboard::getByLayoutIdAndUser(Dashboard::DEFAULT_USER_LAYOUT_ID, $super); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; Currency::makeBaseCurrency(); //Create a account for testing. $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super); //Create a Opportunity for testing. OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp', $super, $account); }
/** * Walkthrough test for synchronous download */ public function testDownloadDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super); $opportunities = array(); for ($i = 0; $i < 2; $i++) { $opportunities[] = OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp' . $i, $super, $account); } // Check if access is denied if user doesn't have access privileges at all to export actions Yii::app()->user->userModel = User::getByUsername('nobody'); $nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody'); $this->runControllerShouldResultInAccessFailureAndGetContent('opportunities/default/list'); // Check if user have access to module action, but not to export action // Now test peon with elevated rights to accounts $nobody->setRight('OpportunitiesModule', OpportunitiesModule::RIGHT_ACCESS_OPPORTUNITIES); $nobody->setRight('OpportunitiesModule', OpportunitiesModule::RIGHT_CREATE_OPPORTUNITIES); $nobody->setRight('OpportunitiesModule', OpportunitiesModule::RIGHT_DELETE_OPPORTUNITIES); $nobody->setRight('ExportModule', ExportModule::RIGHT_ACCESS_EXPORT); $this->assertTrue($nobody->save()); // Check if access is denied if user doesn't have access privileges at all to export actions $nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody'); Yii::app()->user->userModel = User::getByUsername('nobody'); $this->runControllerWithNoExceptionsAndGetContent('opportunities/default/list'); $this->setGetArray(array('Opportunity_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => '')); $response = $this->runControllerWithRedirectExceptionAndGetUrl('opportunities/default/export'); $this->assertTrue(strstr($response, 'opportunities/default/index') !== false); $this->setGetArray(array('OpportunitiesSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'name' => 'superOpp', 'officePhone' => ''), 'Opportunity_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => '')); $response = $this->runControllerWithRedirectExceptionAndGetUrl('opportunities/default/export'); $this->assertTrue(strstr($response, 'opportunities/default/index') !== false); $this->setGetArray(array('OpportunitiesSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'name' => 'superOpp', 'officePhone' => ''), 'Opportunity_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$opportunities[0]->id}, {$opportunities[1]->id}")); $response = $this->runControllerWithRedirectExceptionAndGetUrl('opportunities/default/export'); $this->assertTrue(strstr($response, 'opportunities/default/index') !== false); $this->assertContains('There is no data to export.', Yii::app()->user->getFlash('notification')); //give nobody access to read and write Yii::app()->user->userModel = $super; foreach ($opportunities as $opportunity) { $opportunity->addPermissions($nobody, Permission::READ_WRITE_CHANGE_PERMISSIONS); ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($opportunity, $nobody); $this->assertTrue($opportunity->save()); } //Now the nobody user should be able to access the edit view and still the details view. Yii::app()->user->userModel = $nobody; $this->setGetArray(array('OpportunitiesSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'name' => 'superOpp', 'officePhone' => ''), 'Opportunity_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => '')); $response = $this->runControllerWithExitExceptionAndGetContent('opportunities/default/export'); $this->assertEquals('Testing download.', $response); $this->setGetArray(array('OpportunitiesSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'name' => 'superOpp', 'officePhone' => ''), 'Opportunity_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$opportunities[0]->id}, {$opportunities[1]->id}")); $response = $this->runControllerWithExitExceptionAndGetContent('opportunities/default/export'); $this->assertEquals('Testing download.', $response); // No mathces $this->setGetArray(array('OpportunitiesSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'name' => 'missingName', 'officePhone' => ''), 'Opportunity_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => '')); $response = $this->runControllerWithRedirectExceptionAndGetUrl('opportunities/default/export'); $this->assertTrue(strstr($response, 'opportunities/default/index') !== false); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; //Setup test data owned by the super user. $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super); AccountTestHelper::createAccountByNameForOwner('superAccount2', $super); OpportunityTestHelper::createOpportunityStagesIfDoesNotExist(); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp', $super, $account); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; Currency::makeBaseCurrency(); //Create a account for testing. $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super); //Create a opportunity for testing. OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp', $super, $account); //Create a two contacts for testing. ContactTestHelper::createContactWithAccountByNameForOwner('superContact1', $super, $account); ContactTestHelper::createContactWithAccountByNameForOwner('superContact2', $super, $account); //Create a note for testing. NoteTestHelper::createNoteWithOwnerAndRelatedAccount('superNote', $super, $account); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; //Make sure everyone group is created $group = Group::getByName(Group::EVERYONE_GROUP_NAME); $group->save(); //Setup test data owned by the super user. $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super); ContactTestHelper::createContactWithAccountByNameForOwner('superContact', $super, $account); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpportunity', $super, $account); ProductTestHelper::createProductStagesIfDoesNotExist(); ProductTestHelper::createProductByNameForOwner("My Product 1", $super); //Setup test data owned by the super user. ProductTemplateTestHelper::createProductTemplateByName('My Product Template'); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); //Setup test data owned by the super user. $super = Yii::app()->user->userModel; $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super); AccountTestHelper::createAccountByNameForOwner('superAccount2', $super); ContactTestHelper::createContactWithAccountByNameForOwner('superContact', $super, $account); ContactTestHelper::createContactWithAccountByNameForOwner('superContact2', $super, $account); ContactTestHelper::createContactWithAccountByNameForOwner('superContact3', $super, $account); ContactTestHelper::createContactWithAccountByNameForOwner('superContact4', $super, $account); OpportunityTestHelper::createOpportunityStagesIfDoesNotExist(); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp', $super, $account); //Setup default dashboard. Dashboard::getByLayoutIdAndUser(Dashboard::DEFAULT_USER_LAYOUT_ID, $super); //Make contact DetailsAndRelations portlets AllPermissionsOptimizationUtil::rebuild(); }
public function testForgettingAModelWithAddingAManyToManyRelation() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; //Setup test data owned by the super user. $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super); $contact = ContactTestHelper::createContactWithAccountByNameForOwner('superContact', $super, $account); $contactId = $contact->id; OpportunityTestHelper::createOpportunityStagesIfDoesNotExist(); $opportunity = OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp', $super, $account); $opportunityId = $opportunity->id; //Model forgets ok. $contact->forget(); $contact = Contact::getById($contactId); $opportunity->contacts->add($contact); $opportunity->save(); //Still forgets ok, because we are forgetting both opportunity and contact. If we forget just contact, //it would break later when you try to look at $contact->oppportunities or $opportunity->contacts $contact->forget(); $opportunity->forget(); $contact = Contact::getById($contactId); $opportunity = Opportunity::getById($opportunityId); //Finds many-to-many relationships ok on both sides $this->assertEquals(1, $opportunity->contacts->count()); $this->assertEquals(1, $contact->opportunities->count()); $this->assertEquals($opportunity, $contact->opportunities[0]); $this->assertEquals($contact, $opportunity->contacts[0]); }
/** * @depends testListOpportunities */ public function testBasicSearchOpportunities() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; Opportunity::deleteAll(); $anotherUser = User::getByUsername('steven'); $authenticationData = $this->login(); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); $firstAccount = AccountTestHelper::createAccountByNameTypeAndIndustryForOwner('First Account', 'Customer', 'Automotive', $super); $secondAccount = AccountTestHelper::createAccountByNameTypeAndIndustryForOwner('Second Account', 'Customer', 'Automotive', $super); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('First Opportunity', $super, $firstAccount); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('Second Opportunity', $super, $firstAccount); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('Third Opportunity', $super, $firstAccount); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('Forth Opportunity', $anotherUser, $firstAccount); OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('Fifth Opportunity', $super, $secondAccount); $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('name' => ''), 'sort' => 'name'); $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(3, count($response['data']['items'])); $this->assertEquals(5, $response['data']['totalCount']); $this->assertEquals(1, $response['data']['currentPage']); $this->assertEquals('Fifth Opportunity', $response['data']['items'][0]['name']); $this->assertEquals('First Opportunity', $response['data']['items'][1]['name']); $this->assertEquals('Forth Opportunity', $response['data']['items'][2]['name']); // Second page $searchParams['pagination']['page'] = 2; $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(2, count($response['data']['items'])); $this->assertEquals(5, $response['data']['totalCount']); $this->assertEquals(2, $response['data']['currentPage']); $this->assertEquals('Second Opportunity', $response['data']['items'][0]['name']); $this->assertEquals('Third Opportunity', $response['data']['items'][1]['name']); // Search by name $searchParams['pagination']['page'] = 1; $searchParams['search']['name'] = 'First Opportunity'; $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(1, count($response['data']['items'])); $this->assertEquals(1, $response['data']['totalCount']); $this->assertEquals(1, $response['data']['currentPage']); $this->assertEquals('First Opportunity', $response['data']['items'][0]['name']); // No results $searchParams['pagination']['page'] = 1; $searchParams['search']['name'] = 'First Opportunity 2'; $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(0, $response['data']['totalCount']); $this->assertFalse(isset($response['data']['items'])); // Search by name desc. $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('name' => ''), 'sort' => 'name.desc'); $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(3, count($response['data']['items'])); $this->assertEquals(5, $response['data']['totalCount']); $this->assertEquals(1, $response['data']['currentPage']); $this->assertEquals('Third Opportunity', $response['data']['items'][0]['name']); $this->assertEquals('Second Opportunity', $response['data']['items'][1]['name']); $this->assertEquals('Forth Opportunity', $response['data']['items'][2]['name']); // Second page $searchParams['pagination']['page'] = 2; $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(2, count($response['data']['items'])); $this->assertEquals(5, $response['data']['totalCount']); $this->assertEquals(2, $response['data']['currentPage']); $this->assertEquals('First Opportunity', $response['data']['items'][0]['name']); $this->assertEquals('Fifth Opportunity', $response['data']['items'][1]['name']); // Search by custom fields, order by name desc $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('owner' => array('id' => $anotherUser->id)), 'sort' => 'name.desc'); $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(1, count($response['data']['items'])); $this->assertEquals(1, $response['data']['totalCount']); $this->assertEquals(1, $response['data']['currentPage']); $this->assertEquals('Forth Opportunity', $response['data']['items'][0]['name']); }
/** * Walkthrough test for synchronous download */ public function testAsynchronousDownloadDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $account = AccountTestHelper::createAccountByNameForOwner('superAccount2', $super); $notificationsBeforeCount = count(Notification::getAll()); $notificationMessagesBeforeCount = count(NotificationMessage::getAll()); $opportunities = Opportunity::getAll(); if (count($opportunities)) { foreach ($opportunities as $opportunity) { $opportunity->delete(); } } $opportunities = array(); for ($i = 0; $i <= ExportModule::$asynchronousThreshold + 1; $i++) { $opportunities[] = OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('opportunity' . $i, $super, $account); } $this->setGetArray(array('Opportunity_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => '')); $this->runControllerWithRedirectExceptionAndGetUrl('opportunities/default/export'); // Start background job $job = new ExportJob(); $this->assertTrue($job->run()); $exportItems = ExportItem::getAll(); $this->assertEquals(1, count($exportItems)); $fileModel = $exportItems[0]->exportFileModel; $this->assertEquals(1, $exportItems[0]->isCompleted); $this->assertEquals('csv', $exportItems[0]->exportFileType); $this->assertEquals('opportunities', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll())); $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll())); // Check export job, when many ids are selected. // This will probably never happen, but we need test for this case too. $notificationsBeforeCount = count(Notification::getAll()); $notificationMessagesBeforeCount = count(NotificationMessage::getAll()); // Now test case when multiple ids are selected $exportItems = ExportItem::getAll(); if (count($exportItems)) { foreach ($exportItems as $exportItem) { $exportItem->delete(); } } $selectedIds = ""; foreach ($opportunities as $opportunity) { $selectedIds .= $opportunity->id . ","; // Not Coding Standard } $this->setGetArray(array('OpportunitiesSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'name' => '', 'officePhone' => ''), 'Opportunity_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$selectedIds}")); $this->runControllerWithRedirectExceptionAndGetUrl('opportunities/default/export'); // Start background job $job = new ExportJob(); $this->assertTrue($job->run()); $exportItems = ExportItem::getAll(); $this->assertEquals(1, count($exportItems)); $fileModel = $exportItems[0]->exportFileModel; $this->assertEquals(1, $exportItems[0]->isCompleted); $this->assertEquals('csv', $exportItems[0]->exportFileType); $this->assertEquals('opportunities', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll())); $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll())); }
/** * @depends testSuperUserCreateAction */ public function testSuperUserCreateFromRelationAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $startingState = ContactsUtil::getStartingState(); $contacts = Contact::getAll(); $this->assertEquals(12, count($contacts)); $account = Account::getByName('superAccount2'); $account[0]->billingAddress->street1 = 'some street'; $account[0]->shippingAddress->street1 = 'some street 2'; $saved = $account[0]->save(); $this->assertTrue($saved); $opportunity = OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp', $super, $account[0]); //Create a new contact from a related account. $this->setGetArray(array('relationAttributeName' => 'account', 'relationModelId' => $account[0]->id, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Contact' => array('firstName' => 'another', 'lastName' => 'anotherson', 'officePhone' => '456765421', 'state' => array('id' => $startingState->id)))); $this->runControllerWithRedirectExceptionAndGetContent('contacts/default/createFromRelation'); $contacts = Contact::getByName('another anotherson'); $this->assertEquals(1, count($contacts)); $this->assertTrue($contacts[0]->id > 0); $this->assertTrue($contacts[0]->owner == $super); $this->assertTrue($contacts[0]->account == $account[0]); $this->assertTrue($contacts[0]->state == $startingState); $this->assertEquals('some street', $contacts[0]->primaryAddress->street1); $this->assertEquals('some street 2', $contacts[0]->secondaryAddress->street1); $this->assertEquals('some street', $contacts[0]->account->billingAddress->street1); $this->assertEquals('some street 2', $contacts[0]->account->shippingAddress->street1); $this->assertEquals('456765421', $contacts[0]->officePhone); $contacts = Contact::getAll(); $this->assertEquals(13, count($contacts)); //Create a new contact from a related opportunity $this->setGetArray(array('relationAttributeName' => 'opportunities', 'relationModelId' => $opportunity->id, 'relationModuleId' => 'opportunities', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Contact' => array('firstName' => 'bnother', 'lastName' => 'bnotherson', 'officePhone' => '456765421', 'state' => array('id' => $startingState->id)))); $this->runControllerWithRedirectExceptionAndGetContent('contacts/default/createFromRelation'); $contacts = Contact::getByName('bnother bnotherson'); $this->assertEquals(1, count($contacts)); $this->assertTrue($contacts[0]->id > 0); $this->assertTrue($contacts[0]->owner == $super); $this->assertEquals(1, $contacts[0]->opportunities->count()); $this->assertTrue($contacts[0]->opportunities[0] == $opportunity); $this->assertTrue($contacts[0]->state == $startingState); $this->assertEquals('456765421', $contacts[0]->officePhone); $contacts = Contact::getAll(); $this->assertEquals(14, count($contacts)); //todo: test save with account. }
/** * @depends testRegularUserControllerActionsWithElevationToModels */ public function testRegularUserViewingOpportunityWithoutAccessToAccount() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $aUser = UserTestHelper::createBasicUser('aUser'); $aUser->setRight('OpportunitiesModule', OpportunitiesModule::RIGHT_ACCESS_OPPORTUNITIES); $aUser->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS); $this->assertTrue($aUser->save()); $aUser = User::getByUsername('aUser'); $account = AccountTestHelper::createAccountByNameForOwner('superTestAccount', $super); $opportunity = OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('opportunityOwnedByaUser', $aUser, $account); $account->forget(); $id = $opportunity->id; $opportunity->forget(); unset($opportunity); $this->logoutCurrentUserLoginNewUserAndGetByUsername('aUser'); $content = $this->runControllerWithNoExceptionsAndGetContent('opportunities/default'); $this->assertFalse(strpos($content, 'Fatal error: Method Account::__toString() must not throw an exception') > 0); }