/** * @depends testSuperUserKanbanBoardListAction */ public function testUpdateAttributeValueAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $this->assertEquals('Negotiating', self::$contract->stage->value); //actionUpdateAttributeValue($id, $attribute, $value) $this->setGetArray(array('id' => self::$contract->id, 'attribute' => 'stage', 'value' => 'Verbal')); $this->runControllerWithNoExceptionsAndGetContent('contracts/default/updateAttributeValue', true); $id = self::$contract->id; self::$contract->forget(); self::$contract = Contract::getById($id); $this->assertEquals('Verbal', self::$contract->stage->value); }
public function actionCopy($id) { $copyToContract = new Contract(); $postVariableName = get_class($copyToContract); if (!isset($_POST[$postVariableName])) { $contract = Contract::getById((int) $id); ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($contract); ZurmoCopyModelUtil::copy($contract, $copyToContract); } $this->processEdit($copyToContract); }
public function testSuperUserAllDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //Test all default controller actions that do not require any POST/GET variables to be passed. //This does not include portlet controller actions. $this->runControllerWithNoExceptionsAndGetContent('contracts/default'); $this->runControllerWithNoExceptionsAndGetContent('contracts/default/index'); $this->runControllerWithNoExceptionsAndGetContent('contracts/default/create'); $content = $this->runControllerWithNoExceptionsAndGetContent('contracts/default/list'); $this->assertContains('anyMixedAttributes', $content); //Test the search or paging of the listview. Yii::app()->clientScript->reset(); //to make sure old js doesn't make it to the UI $this->setGetArray(array('ajax' => 'list-view')); $content = $this->runControllerWithNoExceptionsAndGetContent('contracts/default/list'); $this->assertNotContains('anyMixedAttributes', $content); $this->resetGetArray(); //Default Controller actions requiring some sort of parameter via POST or GET //Load Model Edit Views $contracts = Contract::getAll(); $this->assertEquals(12, count($contracts)); $superContractId = self::getModelIdByModelNameAndName('Contract', 'superOpp'); $superContractId2 = self::getModelIdByModelNameAndName('Contract', 'superOpp2'); $superContractId3 = self::getModelIdByModelNameAndName('Contract', 'superOpp3'); $superContractId4 = self::getModelIdByModelNameAndName('Contract', 'superOpp4'); $superContractId5 = self::getModelIdByModelNameAndName('Contract', 'superOpp5'); $superContractId6 = self::getModelIdByModelNameAndName('Contract', 'superOpp6'); $superContractId7 = self::getModelIdByModelNameAndName('Contract', 'superOpp7'); $superContractId8 = self::getModelIdByModelNameAndName('Contract', 'superOpp8'); $superContractId9 = self::getModelIdByModelNameAndName('Contract', 'superOpp9'); $superContractId10 = self::getModelIdByModelNameAndName('Contract', 'superOpp10'); $superContractId11 = self::getModelIdByModelNameAndName('Contract', 'superOpp11'); $superContractId12 = self::getModelIdByModelNameAndName('Contract', 'superOpp12'); $this->setGetArray(array('id' => $superContractId)); $this->runControllerWithNoExceptionsAndGetContent('contracts/default/edit'); //Save Contract. $superContract = Contract::getById($superContractId); $this->assertEquals(null, $superContract->description); $this->setPostArray(array('Contract' => array('description' => '456765421'))); $this->runControllerWithRedirectExceptionAndGetContent('contracts/default/edit'); $superContract = Contract::getById($superContractId); $this->assertEquals('456765421', $superContract->description); //Test having a failed validation on the Contract during save. $this->setGetArray(array('id' => $superContractId)); $this->setPostArray(array('Contract' => array('name' => ''))); $content = $this->runControllerWithNoExceptionsAndGetContent('contracts/default/edit'); $this->assertContains('Name cannot be blank', $content); //Load Model Detail Views $this->setGetArray(array('id' => $superContractId)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('contracts/default/details'); //Load Model MassEdit Views. //MassEdit view for single selected ids $this->setGetArray(array('selectedIds' => '4,5,6,7,8,9', 'selectAll' => '')); // Not Coding Standard $this->resetPostArray(); $content = $this->runControllerWithNoExceptionsAndGetContent('contracts/default/massEdit'); $this->assertContains('<strong>6</strong> records selected for updating', $content); //MassEdit view for all result selected ids $this->setGetArray(array('selectAll' => '1')); $this->resetPostArray(); $content = $this->runControllerWithNoExceptionsAndGetContent('contracts/default/massEdit'); $this->assertContains('<strong>12</strong> records selected for updating', $content); //save Model MassEdit for selected Ids //Test that the 2 contacts do not have the office phone number we are populating them with. $contract1 = Contract::getById($superContractId); $contract2 = Contract::getById($superContractId2); $contract3 = Contract::getById($superContractId3); $contract4 = Contract::getById($superContractId4); $this->assertNotEquals('7788', $contract1->description); $this->assertNotEquals('7788', $contract2->description); $this->assertNotEquals('7788', $contract3->description); $this->assertNotEquals('7788', $contract4->description); $this->setGetArray(array('selectedIds' => $superContractId . ',' . $superContractId2, 'selectAll' => '', 'Contract_page' => 1)); $this->setPostArray(array('Contract' => array('description' => '7788'), 'MassEdit' => array('description' => 1))); $pageSize = Yii::app()->pagination->getForCurrentUserByType('massEditProgressPageSize'); $this->assertEquals(5, $pageSize); Yii::app()->pagination->setForCurrentUserByType('massEditProgressPageSize', 20); $this->runControllerWithRedirectExceptionAndGetContent('contracts/default/massEdit'); Yii::app()->pagination->setForCurrentUserByType('massEditProgressPageSize', $pageSize); //Test that the 2 contract have the new office phone number and the other contacts do not. $contract1 = Contract::getById($superContractId); $contract2 = Contract::getById($superContractId2); $contract3 = Contract::getById($superContractId3); $contract4 = Contract::getById($superContractId4); $contract5 = Contract::getById($superContractId5); $contract6 = Contract::getById($superContractId6); $contract7 = Contract::getById($superContractId7); $contract8 = Contract::getById($superContractId8); $contract9 = Contract::getById($superContractId9); $contract10 = Contract::getById($superContractId10); $contract11 = Contract::getById($superContractId11); $contract12 = Contract::getById($superContractId12); $this->assertEquals('7788', $contract1->description); $this->assertEquals('7788', $contract2->description); $this->assertNotEquals('7788', $contract3->description); $this->assertNotEquals('7788', $contract4->description); $this->assertNotEquals('7788', $contract5->description); $this->assertNotEquals('7788', $contract6->description); $this->assertNotEquals('7788', $contract7->description); $this->assertNotEquals('7788', $contract8->description); $this->assertNotEquals('7788', $contract9->description); $this->assertNotEquals('7788', $contract10->description); $this->assertNotEquals('7788', $contract11->description); $this->assertNotEquals('7788', $contract12->description); //save Model MassEdit for entire search result $this->setGetArray(array('selectAll' => '1', 'Contract_page' => 1)); $this->setPostArray(array('Contract' => array('description' => '6654'), 'MassEdit' => array('description' => 1))); $pageSize = Yii::app()->pagination->getForCurrentUserByType('massEditProgressPageSize'); $this->assertEquals(5, $pageSize); Yii::app()->pagination->setForCurrentUserByType('massEditProgressPageSize', 20); $this->runControllerWithRedirectExceptionAndGetContent('contracts/default/massEdit'); Yii::app()->pagination->setForCurrentUserByType('massEditProgressPageSize', $pageSize); //Test that all contracts have the new description. $contract1 = Contract::getById($superContractId); $contract2 = Contract::getById($superContractId2); $contract3 = Contract::getById($superContractId3); $contract4 = Contract::getById($superContractId4); $contract5 = Contract::getById($superContractId5); $contract6 = Contract::getById($superContractId6); $contract7 = Contract::getById($superContractId7); $contract8 = Contract::getById($superContractId8); $contract9 = Contract::getById($superContractId9); $contract10 = Contract::getById($superContractId10); $contract11 = Contract::getById($superContractId11); $contract12 = Contract::getById($superContractId12); $this->assertEquals('6654', $contract1->description); $this->assertEquals('6654', $contract2->description); $this->assertEquals('6654', $contract3->description); $this->assertEquals('6654', $contract4->description); $this->assertEquals('6654', $contract5->description); $this->assertEquals('6654', $contract6->description); $this->assertEquals('6654', $contract7->description); $this->assertEquals('6654', $contract8->description); $this->assertEquals('6654', $contract9->description); $this->assertEquals('6654', $contract10->description); $this->assertEquals('6654', $contract11->description); $this->assertEquals('6654', $contract12->description); //Run Mass Update using progress save. $pageSize = Yii::app()->pagination->getForCurrentUserByType('massEditProgressPageSize'); $this->assertEquals(5, $pageSize); Yii::app()->pagination->setForCurrentUserByType('massEditProgressPageSize', 1); //The page size is smaller than the result set, so it should exit. $this->runControllerWithExitExceptionAndGetContent('contracts/default/massEdit'); //save Modal MassEdit using progress load for page 2, 3 and 4. $this->setGetArray(array('selectAll' => '1', 'Contract_page' => 2)); $content = $this->runControllerWithNoExceptionsAndGetContent('contracts/default/massEditProgressSave'); $this->assertContains('"value":16', $content); $this->setGetArray(array('selectAll' => '1', 'Contract_page' => 3)); $content = $this->runControllerWithNoExceptionsAndGetContent('contracts/default/massEditProgressSave'); $this->assertContains('"value":25', $content); $this->setGetArray(array('selectAll' => '1', 'Contract_page' => 4)); $content = $this->runControllerWithNoExceptionsAndGetContent('contracts/default/massEditProgressSave'); $this->assertContains('"value":33', $content); //Set page size back to old value. Yii::app()->pagination->setForCurrentUserByType('massEditProgressPageSize', $pageSize); //save Model MassEdit for selected Ids //Test that the 2 contacts do not have the closed date populating them with. //Test that closed dates are properly updated $contract1 = Contract::getById($superContractId); $contract2 = Contract::getById($superContractId2); $contract3 = Contract::getById($superContractId3); $contract4 = Contract::getById($superContractId4); $this->assertNotEquals('2012-12-05', $contract1->closeDate); $this->assertNotEquals('2012-12-05', $contract2->closeDate); $this->assertNotEquals('2012-12-05', $contract3->closeDate); $this->assertNotEquals('2012-12-05', $contract4->closeDate); $this->setGetArray(array('selectedIds' => $superContractId . ',' . $superContractId2, 'selectAll' => '', 'Contract_page' => 1)); $this->setPostArray(array('Contract' => array('closeDate' => '12/5/2012'), 'MassEdit' => array('closeDate' => 1))); $pageSize = Yii::app()->pagination->getForCurrentUserByType('massEditProgressPageSize'); $this->assertEquals(5, $pageSize); Yii::app()->pagination->setForCurrentUserByType('massEditProgressPageSize', 20); $content = $this->runControllerWithRedirectExceptionAndGetContent('contracts/default/massEdit'); $contract1 = Contract::getById($superContractId); $contract2 = Contract::getById($superContractId2); $contract3 = Contract::getById($superContractId3); $contract4 = Contract::getById($superContractId4); $this->assertEquals('2012-12-05', $contract1->closeDate); $this->assertEquals('2012-12-05', $contract2->closeDate); $this->assertNotEquals('2012-12-05', $contract3->closeDate); $this->assertNotEquals('2012-12-05', $contract4->closeDate); //Autocomplete for Contract $this->setGetArray(array('term' => 'super')); $this->runControllerWithNoExceptionsAndGetContent('contracts/default/autoComplete'); //actionModalList $this->setGetArray(array('modalTransferInformation' => array('sourceIdFieldId' => 'x', 'sourceNameFieldId' => 'y', 'modalId' => 'z'))); $this->runControllerWithNoExceptionsAndGetContent('contracts/default/modalList'); //actionAuditEventsModalList $this->setGetArray(array('id' => $superContractId)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('contracts/default/auditEventsModalList'); //Select a related Contract for this contact. Go to the select screen. $superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson'); $contract1->forget(); $contract = Contract::getById($superContractId); $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('ContractDetailsAndRelationsView', $super->id, array()); $this->assertEquals(2, count($portlets)); $this->assertEquals(3, count($portlets[1])); $contact = Contact::getById($superContactId); $this->assertEquals(0, $contact->contracts->count()); $this->assertEquals(0, $contract->contacts->count()); $this->setGetArray(array('portletId' => $portlets[1][1]->id, 'relationAttributeName' => 'contracts', 'relationModuleId' => 'contracts', 'relationModelId' => $superContractId, 'uniqueLayoutId' => 'ContractDetailsAndRelationsView_' . $portlets[1][1]->id)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('contacts/default/SelectFromRelatedList'); //Now add an Contract to a contact via the select from related list action. $this->setGetArray(array('portletId' => $portlets[1][1]->id, 'modelId' => $superContactId, 'relationAttributeName' => 'contracts', 'relationModuleId' => 'contracts', 'relationModelId' => $superContractId, 'uniqueLayoutId' => 'ContractDetailsAndRelationsView_' . $portlets[1][1]->id)); $this->resetPostArray(); $this->runControllerWithRedirectExceptionAndGetContent('contacts/defaultPortlet/SelectFromRelatedListSave'); //Run forget in order to refresh the contact and Contract showing the new relation $contact->forget(); $contract->forget(); $contact = Contact::getById($superContactId); $contract = Contract::getById($superContractId); $this->assertEquals(1, $contract->contacts->count()); $this->assertEquals($contact, $contract->contacts[0]); $this->assertEquals(1, $contact->contracts->count()); $this->assertEquals($contract->id, $contact->contracts[0]->id); }
/** * @depends testCreateAndGetContractById */ public function testSetStageAndSourceAndRetrieveDisplayName() { Yii::app()->user->userModel = User::getByUsername('super'); $user = User::getByUsername('billy'); $stageValues = array('Prospecting', 'Negotiating', 'Closed Won'); $stageFieldData = CustomFieldData::getByName('SalesStages'); $stageFieldData->serializedData = serialize($stageValues); $this->assertTrue($stageFieldData->save()); $sourceValues = array('Word of Mouth', 'Outbound', 'Trade Show'); $sourceFieldData = CustomFieldData::getByName('LeadSources'); $sourceFieldData->serializedData = serialize($sourceValues); $this->assertTrue($sourceFieldData->save()); $currencies = Currency::getAll(); $currencyValue = new CurrencyValue(); $currencyValue->value = 500.54; $currencyValue->currency = $currencies[0]; $contract = new Contract(); $contract->owner = $user; $contract->name = '1000 Widgets'; $contract->amount = $currencyValue; $contract->closeDate = '2011-01-01'; //eventually fix to make correct format $contract->stage->value = $stageValues[1]; $contract->source->value = $sourceValues[1]; $saved = $contract->save(); $this->assertTrue($saved); $this->assertTrue($contract->id !== null); $id = $contract->id; unset($contract); $contract = Contract::getById($id); $this->assertEquals('Negotiating', $contract->stage->value); $this->assertEquals('Outbound', $contract->source->value); $this->assertEquals(1, $currencies[0]->rateToBase); }
/** * @depends testEditOfTheContractForTheTagCloudFieldAfterRemovingAllTagsPlacedForContractsModule */ public function testEditOfTheContractForTheCustomFieldsPlacedForContractsModule() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //Set the date and datetime variable values here. $date = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateFormatForInput(), time()); $dateAssert = date('Y-m-d'); $datetime = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateTimeFormatForInput(), time()); $datetimeAssert = date('Y-m-d H:i:') . "00"; $baseCurrency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode()); //Retrieve the account id, the super user id and Contract Id. $accountId = self::getModelIdByModelNameAndName('Account', 'superAccount'); $superUserId = $super->id; $explicitReadWriteModelPermission = ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP; $contract = Contract::getByName('myEditContract'); $contractId = $contract[0]->id; //Edit a new contract based on the custom fields. $this->setGetArray(array('id' => $contractId)); $this->setPostArray(array('Contract' => array('name' => 'myEditContract', 'amount' => array('value' => 288000, 'currency' => array('id' => $baseCurrency->id)), 'account' => array('id' => $accountId), 'closeDate' => $date, 'stage' => array('value' => 'Qualification'), 'source' => array('value' => 'Inbound Call'), 'description' => 'This is the Edit Description', 'owner' => array('id' => $superUserId), 'explicitReadWriteModelPermissions' => array('type' => $explicitReadWriteModelPermission), 'checkboxCstm' => '0', 'currencyCstm' => array('value' => 40, 'currency' => array('id' => $baseCurrency->id)), 'decimalCstm' => '12', 'dateCstm' => $date, 'datetimeCstm' => $datetime, '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'))); $this->runControllerWithRedirectExceptionAndGetUrl('contracts/default/edit'); //Check the details if they are saved properly for the custom fields. $contractId = self::getModelIdByModelNameAndName('Contract', 'myEditContract'); $contract = Contract::getById($contractId); //Retrieve the permission of the Contract. $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($contract); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $readOnlyPermitables = $explicitReadWriteModelPermissions->getReadOnlyPermitables(); $this->assertEquals($contract->name, 'myEditContract'); $this->assertEquals($contract->amount->value, '288000'); $this->assertEquals($contract->amount->currency->id, $baseCurrency->id); $this->assertEquals($contract->account->id, $accountId); $this->assertEquals($contract->probability, '25'); $this->assertEquals($contract->stage->value, 'Qualification'); $this->assertEquals($contract->source->value, 'Inbound Call'); $this->assertEquals($contract->description, 'This is the Edit Description'); $this->assertEquals($contract->owner->id, $superUserId); $this->assertEquals(1, count($readWritePermitables)); $this->assertEquals(0, count($readOnlyPermitables)); $this->assertEquals($contract->checkboxCstm, '0'); $this->assertEquals($contract->currencyCstm->value, 40); $this->assertEquals($contract->currencyCstm->currency->id, $baseCurrency->id); $this->assertEquals($contract->dateCstm, $dateAssert); $this->assertEquals($contract->datetimeCstm, $datetimeAssert); $this->assertEquals($contract->decimalCstm, '12'); $this->assertEquals($contract->picklistCstm->value, 'b'); $this->assertEquals($contract->integerCstm, 11); $this->assertEquals($contract->phoneCstm, '259-784-2069'); $this->assertEquals($contract->radioCstm->value, 'e'); $this->assertEquals($contract->textCstm, 'This is a test Edit Text'); $this->assertEquals($contract->textareaCstm, 'This is a test Edit TextArea'); $this->assertEquals($contract->urlCstm, 'http://wwww.abc-edit.com'); $this->assertEquals($contract->dateCstm, $dateAssert); $this->assertEquals($contract->datetimeCstm, $datetimeAssert); $this->assertEquals($contract->countrylistCstm->value, 'aaaa'); $this->assertEquals($contract->statelistCstm->value, 'aaa1'); $this->assertEquals($contract->citylistCstm->value, 'ab1'); $this->assertContains('gg', $contract->multiselectCstm->values); $this->assertContains('hh', $contract->multiselectCstm->values); $this->assertContains('reading', $contract->tagcloudCstm->values); $this->assertContains('surfing', $contract->tagcloudCstm->values); $metadata = CalculatedDerivedAttributeMetadata::getByNameAndModelClassName('calcnumber', 'Contract'); $testCalculatedValue = CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($metadata->getFormula(), $contract); $this->assertEquals(132, $testCalculatedValue); }