public function testSaveAndRetrievePortlet()
 {
     $user = UserTestHelper::createBasicUser('Billy');
     $contracts = Contract::getByName('superOpp');
     $portlet = new Portlet();
     $portlet->column = 2;
     $portlet->position = 5;
     $portlet->layoutId = 'Test';
     $portlet->collapsed = true;
     $portlet->viewType = 'ContractsForContactRelatedList';
     $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' => $contracts[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('ContractsForContactRelatedList', $portlet->viewType);
     $this->assertEquals($user->id, $portlet->user->id);
     $view = $portlet->getView();
 }
 /**
  * There is a special way you can import rateToBase and currencyCode for an amount attribute.
  * if the column data is formatted like: $54.67__1.2__USD  then it will split the column and properly
  * handle rate and currency code.  Eventually this will be exposed in the user interface
  */
 public function testImportWithRateAndCurrencyCodeSpecified()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $account = AccountTestHelper::createAccountByNameForOwner('Account', Yii::app()->user->userModel);
     $accountId = $account->id;
     $contracts = Contract::getAll();
     $this->assertEquals(0, count($contracts));
     $import = new Import();
     $serializedData['importRulesType'] = 'Contracts';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importTestIncludingRateAndCurrencyCode.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.contracts.tests.unit.files'));
     //update the ids of the account column to match the parent account.
     ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_3 = " . $account->id . " where id != 1 limit 4");
     $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $currency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());
     $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeDateColumnMappingData('closeDate'), 'column_2' => ImportMappingUtil::makeIntegerColumnMappingData('description'), 'column_3' => ImportMappingUtil::makeHasOneColumnMappingData('account'), 'column_4' => ImportMappingUtil::makeDropDownColumnMappingData('stage'), 'column_5' => ImportMappingUtil::makeDropDownColumnMappingData('source'), 'column_6' => ImportMappingUtil::makeCurrencyColumnMappingData('amount', $currency));
     $importRules = ImportRulesUtil::makeImportRulesByType('Contracts');
     $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.
     $contracts = Contract::getAll();
     $this->assertEquals(3, count($contracts));
     $contracts = Contract::getByName('opp1');
     $this->assertEquals(1, count($contracts[0]));
     $this->assertEquals('opp1', $contracts[0]->name);
     $this->assertEquals('1980-06-03', $contracts[0]->closeDate);
     $this->assertEquals(10, $contracts[0]->probability);
     $this->assertEquals('desc1', $contracts[0]->description);
     $this->assertTrue($contracts[0]->account->isSame($account));
     $this->assertEquals('Prospecting', $contracts[0]->stage->value);
     $this->assertEquals('Self-Generated', $contracts[0]->source->value);
     $this->assertEquals(500, $contracts[0]->amount->value);
     $this->assertEquals(1, $contracts[0]->amount->rateToBase);
     $this->assertEquals('USD', $contracts[0]->amount->currency->code);
     $contracts = Contract::getByName('opp2');
     $this->assertEquals(1, count($contracts[0]));
     $this->assertEquals('opp2', $contracts[0]->name);
     $this->assertEquals('1980-06-04', $contracts[0]->closeDate);
     $this->assertEquals(25, $contracts[0]->probability);
     $this->assertEquals('desc2', $contracts[0]->description);
     $this->assertTrue($contracts[0]->account->isSame($account));
     $this->assertEquals('Qualification', $contracts[0]->stage->value);
     $this->assertEquals('Inbound Call', $contracts[0]->source->value);
     $this->assertEquals(501, $contracts[0]->amount->value);
     // $this->assertEquals(2.7,                       $contracts[0]->amount->rateToBase);
     $this->assertEquals('GBP', $contracts[0]->amount->currency->code);
     $contracts = Contract::getByName('opp3');
     $this->assertEquals(1, count($contracts[0]));
     $this->assertEquals('opp3', $contracts[0]->name);
     $this->assertEquals('1980-06-05', $contracts[0]->closeDate);
     $this->assertEquals(50, $contracts[0]->probability);
     $this->assertEquals('desc3', $contracts[0]->description);
     $this->assertTrue($contracts[0]->account->isSame($account));
     $this->assertEquals('Negotiating', $contracts[0]->stage->value);
     $this->assertEquals('Tradeshow', $contracts[0]->source->value);
     $this->assertEquals(502, $contracts[0]->amount->value);
     // $this->assertEquals(3.2,                       $contracts[0]->amount->rateToBase);
     $this->assertEquals('EUR', $contracts[0]->amount->currency->code);
     //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 account has 3 contracts
     $account->forget();
     $account = Account::getById($accountId);
     $this->assertEquals(3, $account->contracts->count());
 }
 public function testKanbanViewForContractDetails()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $contracts = Contract::getByName('superOpp');
     $task = TaskTestHelper::createTaskWithOwnerAndRelatedItem('MyTask', $super, $contracts[0], Task::STATUS_IN_PROGRESS);
     $taskNew = TaskTestHelper::createTaskWithOwnerAndRelatedItem('MyTask New', $super, $contracts[0], Task::STATUS_NEW);
     $this->setGetArray(array('id' => $task->id, 'kanbanBoard' => '1'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('contracts/default/details');
     $matcher = array('tag' => 'h4', 'ancestor' => array('tag' => 'li', 'id' => 'items_' . $task->id, 'tag' => 'ul', 'id' => 'task-sortable-rows-3'), 'content' => 'MyTask');
     $this->assertTag($matcher, $content);
     $matcher = array('tag' => 'h4', 'ancestor' => array('tag' => 'li', 'id' => 'items_' . $taskNew->id, 'tag' => 'ul', 'id' => 'task-sortable-rows-1'), 'content' => 'MyTask New');
     $this->assertTag($matcher, $content);
 }
示例#4
0
 /**
  * @depends testCreateAndGetcontractById
  */
 public function testUpdateContractFromForm()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $user = User::getByUsername('billy');
     $contracts = Contract::getByName('Test contract');
     $contract = $contracts[0];
     $this->assertEquals($contract->name, 'Test Contract');
     $currencies = Currency::getAll();
     $postData = array('owner' => array('id' => $user->id), 'name' => 'New Name', 'amount' => array('value' => '500.54', 'currency' => array('id' => $currencies[0]->id)), 'closeDate' => '2011-01-01', 'stage' => array('value' => 'Negotiating'));
     $contract->setAttributes($postData);
     $this->assertTrue($contract->save());
     $id = $contract->id;
     unset($contract);
     $contract = Contract::getById($id);
     $this->assertEquals('New Name', $contract->name);
     $this->assertEquals(500.54, $contract->amount->value);
     $this->assertEquals(50, $contract->probability);
     $this->assertEquals(1, $currencies[0]->rateToBase);
     //Updating probability mapping should make changes on saving contract
     $metadata = ContractsModule::getMetadata();
     $metadata['global']['stageToProbabilityMapping']['Negotiating'] = 60;
     ContractsModule::setMetadata($metadata);
     $postData = array();
     $contract->setAttributes($postData);
     $this->assertTrue($contract->save());
     unset($contract);
     $contract = Contract::getById($id);
     $this->assertEquals('New Name', $contract->name);
     $this->assertEquals(500.54, $contract->amount->value);
     $this->assertEquals(60, $contract->probability);
     $this->assertEquals(1, $currencies[0]->rateToBase);
 }
 /**
  * @depends testSuperUserCreateFromRelationAction
  */
 public function testSuperUserCopyAction()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $currencies = Currency::getAll();
     $contracts = Contract::getByName('myNewContract');
     $this->assertCount(1, $contracts);
     $postArray = array('Contract' => array('name' => 'myNewContract', 'amount' => array('value' => '1000', 'currency' => array('id' => $currencies[0]->id)), 'account' => array('name' => 'Linked account'), 'closeDate' => '2012-11-01', 'probability' => 50, 'stage' => array('value' => 'Negotiating'), 'description' => 'some description'));
     $this->updateModelValuesFromPostArray($contracts[0], $postArray);
     $this->assertModelHasValuesFromPostArray($contracts[0], $postArray);
     $this->assertTrue($contracts[0]->save());
     unset($postArray['Contract']['closeDate']);
     $this->assertTrue($this->checkCopyActionResponseAttributeValuesFromPostArray($contracts[0], $postArray, 'Contracts'));
     $postArray['Contract']['name'] = 'myNewClonedContract';
     $postArray['Contract']['closeDate'] = '11/1/2012';
     $this->setGetArray(array('id' => $contracts[0]->id));
     $this->setPostArray($postArray);
     $this->runControllerWithRedirectExceptionAndGetUrl('contracts/default/copy');
     $contracts = Contract::getByName('myNewClonedContract');
     $this->assertCount(1, $contracts);
     $this->assertTrue($contracts[0]->owner->isSame($super));
     $postArray['Contract']['closeDate'] = '2012-11-01';
     $this->assertModelHasValuesFromPostArray($contracts[0], $postArray);
     $contracts = Contract::getAll();
     $this->assertCount(15, $contracts);
     $contracts = Contract::getByName('myNewClonedContract');
     $this->assertCount(1, $contracts);
     $this->assertTrue($contracts[0]->delete());
 }
 /**
  * @depends testWhetherSearchWorksForTheCustomFieldsPlacedForContractsModuleAfterEditingTheContract
  */
 public function testDeleteOfTheContractUserForTheCustomFieldsPlacedForContractsModule()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     //Get the Contract id from the recently edited Contract.
     $contractId = self::getModelIdByModelNameAndName('Contract', 'myEditContract');
     //Set the Contract id so as to delete the Contract.
     $this->setGetArray(array('id' => $contractId));
     $this->runControllerWithRedirectExceptionAndGetUrl('contracts/default/delete');
     //Check wether the Contract is deleted.
     $contract = Contract::getByName('myEditContract');
     $this->assertEquals(0, count($contract));
 }