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 function testProperlyDeletingActivityItems()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $count = ZurmoRedBean::getRow('select count(*) count from activity_item');
     $this->assertEquals(0, $count['count']);
     $account = AccountTestHelper::createAccountByNameForOwner('anAccount', Yii::app()->user->userModel);
     $deleted = $account->delete();
     $this->assertTrue($deleted);
     $count = ZurmoRedBean::getRow('select count(*) count from activity_item');
     $this->assertEquals(0, $count['count']);
     $account2 = AccountTestHelper::createAccountByNameForOwner('anAccount2', Yii::app()->user->userModel);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('anOpp', Yii::app()->user->userModel);
     $task = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('aTask', Yii::app()->user->userModel, $account2);
     $task->activityItems->add($opportunity);
     $this->assertTrue($task->save());
     $taskId = $task->id;
     $task->forget();
     RedBeansCache::forgetAll();
     $count = ZurmoRedBean::getRow('select count(*) count from activity_item');
     $this->assertEquals(2, $count['count']);
     $deleted = $account2->delete();
     $this->assertTrue($deleted);
     $account2->forget();
     $count = ZurmoRedBean::getRow('select count(*) count from activity_item');
     $this->assertEquals(1, $count['count']);
     RedBeansCache::forgetAll();
     //Make sure things render ok even with the account deleted.
     $content = ActivitiesUtil::renderSummaryContent(Task::getById($taskId), 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'HomeModule');
 }
Example #4
0
 public function testDownCasts()
 {
     $possibleDerivationPaths = array(array('SecurableItem', 'OwnedSecurableItem', 'Account'), array('SecurableItem', 'OwnedSecurableItem', 'Person', 'Contact'), array('SecurableItem', 'OwnedSecurableItem', 'Opportunity'));
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $account = AccountTestHelper::createAccountByNameForOwner('Waggle', $super);
     $contact = ContactTestHelper::createContactByNameForOwner('Noddy', $super);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('Noddy', $super);
     $accountItem = Item::getById($account->getClassId('Item'));
     $contactItem = Item::getById($contact->getClassId('Item'));
     $opportunityItem = Item::getById($opportunity->getClassId('Item'));
     $this->assertTrue($accountItem->isSame($account));
     $this->assertTrue($contactItem->isSame($contact));
     $this->assertTrue($opportunityItem->isSame($opportunity));
     $this->assertFalse($accountItem instanceof Account);
     $this->assertFalse($contactItem instanceof Contact);
     $this->assertFalse($opportunityItem instanceof Opportunity);
     $account2 = $accountItem->castDown($possibleDerivationPaths);
     $this->assertEquals('Account', get_class($account2));
     //Demonstrate a single array, making sure it casts down properly.
     $accountItem2 = Item::getById($account->getClassId('Item'));
     $account3 = $accountItem2->castDown(array(array('SecurableItem', 'OwnedSecurableItem', 'Account')));
     $this->assertEquals('Account', get_class($account3));
     $contact2 = $contactItem->castDown($possibleDerivationPaths);
     $opportunity2 = $opportunityItem->castDown($possibleDerivationPaths);
     $this->assertTrue($account2->isSame($account));
     $this->assertTrue($contact2->isSame($contact));
     $this->assertTrue($opportunity2->isSame($opportunity));
     $this->assertTrue($account2 instanceof Account);
     $this->assertTrue($contact2 instanceof Contact);
     $this->assertTrue($opportunity2 instanceof Opportunity);
     $account2 = AccountTestHelper::createAccountByNameForOwner('Waggle2', $super);
     //By adding a second contact with a relation to the account2, we can demonstrate a bug with how castDown works.
     //Since contacts can in fact be attached to accounts via account_id, if a contact exists connected to the account
     //we are trying to cast down, then this will cast down even though it shouldn't.
     $contact2 = ContactTestHelper::createContactWithAccountByNameForOwner('MrWaggle2', $super, $account2);
     try {
         $account2CastedDown = $account2->castDown(array(array('SecurableItem', 'OwnedSecurableItem', 'Person', 'Contact')));
         $this->fail();
     } catch (NotFoundException $e) {
         //success
     }
     //Now try to forget the account and retrieve it.
     $account2Id = $account2->id;
     $account2->forget();
     unset($account2);
     $account2 = Account::getById($account2Id);
     try {
         $account2CastedDown = $account2->castDown(array(array('SecurableItem', 'OwnedSecurableItem', 'Person', 'Contact')));
         $this->fail();
     } catch (NotFoundException $e) {
         //success
     }
 }
 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);
 }
 /**
  * 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;
     Currency::makeBaseCurrency();
     //Create a account for testing.
     $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
     //Create a Opportunity for testing.
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp', $super, $account);
 }
Example #8
0
 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);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('superOpportunity', $super);
     $productTemplate = ProductTemplateTestHelper::createProductTemplateByName('superProductTemplate');
     $contactWithNoAccount = ContactTestHelper::createContactByNameForOwner('noAccountContact', $super);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     UserTestHelper::createBasicUser('jim');
     AllPermissionsOptimizationUtil::rebuild();
     OpportunityTestHelper::createOpportunityStagesIfDoesNotExist();
     OpportunityTestHelper::createOpportunitySourcesIfDoesNotExist();
     $currencies = Currency::getAll();
     //Make opportunities for testing chart data.
     $currencyValue = new CurrencyValue();
     $currencyValue->value = 200;
     $currencyValue->currency = $currencies[0];
     $opportunity = new Opportunity();
     $opportunity->owner = $super;
     $opportunity->name = 'abc1';
     $opportunity->amount = $currencyValue;
     $opportunity->closeDate = '2011-01-01';
     $opportunity->stage->value = 'Negotiating';
     $opportunity->source->value = 'Outbound';
     assert($opportunity->save());
     // Not Coding Standard
     $currencyValue = new CurrencyValue();
     $currencyValue->value = 350;
     $currencyValue->currency = $currencies[0];
     $opportunity = new Opportunity();
     $opportunity->owner = $super;
     $opportunity->name = 'abc2';
     $opportunity->amount = $currencyValue;
     $opportunity->closeDate = '2011-01-01';
     $opportunity->stage->value = 'Negotiating';
     $opportunity->source->value = 'Trade Show';
     assert($opportunity->save());
     // Not Coding Standard
     $currencyValue = new CurrencyValue();
     $currencyValue->value = 100;
     $currencyValue->currency = $currencies[0];
     $opportunity = new Opportunity();
     $opportunity->owner = $super;
     $opportunity->name = 'abc2';
     $opportunity->amount = $currencyValue;
     $opportunity->closeDate = '2011-01-01';
     $opportunity->stage->value = 'Verbal';
     $opportunity->source->value = 'Trade Show';
     assert($opportunity->save());
     // Not Coding Standard
 }
 public function testImportDataAnalysisResults()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $import = new Import();
     $serializedData['importRulesType'] = 'Tasks';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $accountTableName = Account::getTableName('Account');
     $contactTableName = Contact::getTableName('Contact');
     $opportunityTableName = Opportunity::getTableName('Opportunity');
     $account1 = AccountTestHelper::createAccountByNameForOwner('account1', $super);
     $account2 = AccountTestHelper::createAccountByNameForOwner('account2', $super);
     $account3 = AccountTestHelper::createAccountByNameForOwner('account3', $super);
     $contact1 = ContactTestHelper::createContactByNameForOwner('contact1', $super);
     $contact2 = ContactTestHelper::createContactByNameForOwner('contact2', $super);
     $contact3 = ContactTestHelper::createContactByNameForOwner('contact3', $super);
     $opportunity1 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity1', $super);
     $opportunity2 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity2', $super);
     $opportunity3 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity3', $super);
     //Make models externally linked for testing.
     ImportTestHelper::updateModelsExternalId($account2, 'ACC');
     ImportTestHelper::updateModelsExternalId($contact2, 'CON');
     ImportTestHelper::updateModelsExternalId($opportunity2, 'OPP');
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.tasks.tests.unit.files'));
     R::exec("update " . $import->getTempTableName() . " set column_0 = " . $account3->id . " where id != 1 limit 3");
     R::exec("update " . $import->getTempTableName() . " set column_2 = " . $contact3->id . " where id != 1 limit 4");
     R::exec("update " . $import->getTempTableName() . " set column_4 = " . $opportunity3->id . " where id != 1 limit 5");
     $mappingData = array('column_0' => ImportMappingUtil::makeModelDerivedColumnMappingData('AccountDerived', IdValueTypeMappingRuleForm::ZURMO_MODEL_ID), 'column_1' => ImportMappingUtil::makeModelDerivedColumnMappingData('AccountDerived'), 'column_2' => ImportMappingUtil::makeModelDerivedColumnMappingData('ContactDerived', IdValueTypeMappingRuleForm::ZURMO_MODEL_ID), 'column_3' => ImportMappingUtil::makeModelDerivedColumnMappingData('ContactDerived'), 'column_4' => ImportMappingUtil::makeModelDerivedColumnMappingData('OpportunityDerived', IdValueTypeMappingRuleForm::ZURMO_MODEL_ID), 'column_5' => ImportMappingUtil::makeModelDerivedColumnMappingData('OpportunityDerived'));
     $serializedData = unserialize($import->serializedData);
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $importRules = ImportRulesUtil::makeImportRulesByType('Tasks');
     $config = array('pagination' => array('pageSize' => 2));
     //This test csv has a header row.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     //Run data analyzer
     $importDataAnalyzer = new ImportDataAnalyzer($importRules, $dataProvider);
     foreach ($mappingData as $columnName => $columnMappingData) {
         $importDataAnalyzer->analyzeByColumnNameAndColumnMappingData($columnName, $columnMappingData);
     }
     $messagesData = $importDataAnalyzer->getMessagesData();
     $compareData = array('column_0' => array(array('message' => '3 record(s) will be updated and 7 record(s) will be skipped during import.', 'sanitizerUtilType' => 'AccountDerivedIdValueType', 'moreAvailable' => false)), 'column_1' => array(array('message' => '3 record(s) will be updated and 7 record(s) will be skipped during import.', 'sanitizerUtilType' => 'AccountDerivedIdValueType', 'moreAvailable' => false)), 'column_2' => array(array('message' => '4 record(s) will be updated and 6 record(s) will be skipped during import.', 'sanitizerUtilType' => 'ContactDerivedIdValueType', 'moreAvailable' => false)), 'column_3' => array(array('message' => '3 record(s) will be updated and 7 record(s) will be skipped during import.', 'sanitizerUtilType' => 'ContactDerivedIdValueType', 'moreAvailable' => false)), 'column_4' => array(array('message' => '5 record(s) will be updated and 5 record(s) will be skipped during import.', 'sanitizerUtilType' => 'OpportunityDerivedIdValueType', 'moreAvailable' => false)), 'column_5' => array(array('message' => '3 record(s) will be updated and 7 record(s) will be skipped during import.', 'sanitizerUtilType' => 'OpportunityDerivedIdValueType', 'moreAvailable' => false)));
     $this->assertEquals($compareData, $messagesData);
     $importInstructionsData = $importDataAnalyzer->getImportInstructionsData();
     $compareInstructionsData = array();
     $this->assertEquals($compareInstructionsData, $importInstructionsData);
 }
 public function testCopy()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $user = Yii::app()->user->userModel;
     $project = new Project();
     $project->name = 'Project 1';
     $project->owner = $user;
     $project->description = 'Description';
     $user = UserTestHelper::createBasicUser('Steven');
     $account = new Account();
     $account->owner = $user;
     $account->name = DataUtil::purifyHtml("Tom & Jerry's Account");
     $this->assertTrue($account->save());
     $id = $account->id;
     unset($account);
     $account = Account::getById($id);
     $this->assertEquals("Tom & Jerry's Account", $account->name);
     $contact = ContactTestHelper::createContactByNameForOwner('Jerry', $user);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('Jerry Opp', $user);
     $this->assertTrue($project->save());
     $this->assertEquals(1, count($project->auditEvents));
     $id = $project->id;
     $project->forget();
     unset($project);
     $project = Project::getById($id);
     ProjectZurmoControllerUtil::resolveProjectManyManyAccountsFromPost($project, array('accountIds' => $account->id));
     ProjectZurmoControllerUtil::resolveProjectManyManyContactsFromPost($project, array('contactIds' => $contact->id));
     ProjectZurmoControllerUtil::resolveProjectManyManyOpportunitiesFromPost($project, array('opportunityIds' => $opportunity->id));
     $this->assertEquals('Project 1', $project->name);
     $this->assertEquals('Description', $project->description);
     $this->assertEquals(1, $project->accounts->count());
     $this->assertEquals(1, $project->contacts->count());
     $this->assertEquals(1, $project->opportunities->count());
     $task = TaskTestHelper::createTaskByNameWithProjectAndStatus('MyFirstKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS);
     $kanbanItem1 = KanbanItem::getByTask($task->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem1->type);
     $this->assertEquals($task->project->id, $kanbanItem1->kanbanRelatedItem->id);
     $copyToProject = new Project();
     ProjectZurmoCopyModelUtil::copy($project, $copyToProject);
     ProjectZurmoCopyModelUtil::processAfterCopy($project, $copyToProject);
     $this->assertTrue($copyToProject->save());
     $this->assertEquals($copyToProject->name, $project->name);
     $this->assertEquals($copyToProject->description, $project->description);
     $this->assertEquals($copyToProject->status, $project->status);
     $project = Project::getByName('Project 1');
     $this->assertEquals(2, count($project));
     $tasks = Task::getAll();
     $this->assertEquals(2, count($tasks));
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $super = SecurityTestHelper::createSuperAdmin();
     Yii::app()->user->userModel = $super;
     ExternalSystemIdUtil::addExternalIdColumnIfMissing(Account::getTableName());
     ExternalSystemIdUtil::addExternalIdColumnIfMissing(Contact::getTableName());
     ExternalSystemIdUtil::addExternalIdColumnIfMissing(Opportunity::getTableName());
     $account = AccountTestHelper::createAccountByNameForOwner('testAccount', $super);
     ImportTestHelper::updateModelsExternalId($account, 'ACC');
     $contact = ContactTestHelper::createContactByNameForOwner('testContact', $super);
     ImportTestHelper::updateModelsExternalId($contact, 'CON');
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('testOpportunity', $super);
     ImportTestHelper::updateModelsExternalId($opportunity, 'OPP');
 }
Example #13
0
 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);
     OpportunityTestHelper::createOpportunityStagesIfDoesNotExist();
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('superOpportunity', $super);
     $productTemplate = ProductTemplateTestHelper::createProductTemplateByName('superProductTemplate');
     $contactWithNoAccount = ContactTestHelper::createContactByNameForOwner('noAccountContact', $super);
     $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $everyoneGroup->save();
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $super = SecurityTestHelper::createSuperAdmin();
     Yii::app()->user->userModel = $super;
     $columnName = ExternalSystemIdUtil::EXTERNAL_SYSTEM_ID_COLUMN_NAME;
     RedBeanColumnTypeOptimizer::externalIdColumn(ImportModelTestItem::getTableName('Account'), $columnName);
     RedBeanColumnTypeOptimizer::externalIdColumn(ImportModelTestItem2::getTableName('Contact'), $columnName);
     RedBeanColumnTypeOptimizer::externalIdColumn(ImportModelTestItem3::getTableName('Opportunity'), $columnName);
     $account = AccountTestHelper::createAccountByNameForOwner('testAccount', $super);
     ImportTestHelper::updateModelsExternalId($account, 'ACC');
     $contact = ContactTestHelper::createContactByNameForOwner('testContact', $super);
     ImportTestHelper::updateModelsExternalId($contact, 'CON');
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('testOpportunity', $super);
     ImportTestHelper::updateModelsExternalId($opportunity, 'OPP');
 }
 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();
     //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 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');
 }
Example #18
0
 public function testCreateAndGetProjectById()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $user = Yii::app()->user->userModel;
     $project = new Project();
     $project->name = 'Project 1';
     $project->owner = $user;
     $project->description = 'Description';
     $user = UserTestHelper::createBasicUser('Steven');
     $account = new Account();
     $account->owner = $user;
     $account->name = DataUtil::purifyHtml("Tom & Jerry's Account");
     $this->assertTrue($account->save());
     $id = $account->id;
     unset($account);
     $account = Account::getById($id);
     $this->assertEquals("Tom & Jerry's Account", $account->name);
     //$project->accounts->add($account);
     $contact = ContactTestHelper::createContactByNameForOwner('Jerry', $user);
     //$project->contacts->add($contact);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('Jerry Opp', $user);
     //$project->opportunities->add($opportunity);
     $this->assertTrue($project->save());
     $this->assertEquals(1, count($project->auditEvents));
     $id = $project->id;
     $project->forget();
     unset($project);
     $project = Project::getById($id);
     ProjectZurmoControllerUtil::resolveProjectManyManyAccountsFromPost($project, array('accountIds' => $account->id));
     ProjectZurmoControllerUtil::resolveProjectManyManyContactsFromPost($project, array('contactIds' => $contact->id));
     ProjectZurmoControllerUtil::resolveProjectManyManyOpportunitiesFromPost($project, array('opportunityIds' => $opportunity->id));
     $this->assertEquals('Project 1', $project->name);
     $this->assertEquals('Description', $project->description);
     $this->assertEquals(1, $project->accounts->count());
     $this->assertEquals(1, $project->contacts->count());
     $this->assertEquals(1, $project->opportunities->count());
     //Try saving a second project
     $project = new Project();
     $project->name = 'Project 2';
     $project->owner = $user;
     $project->description = 'Description';
     $this->assertTrue($project->save());
     $this->assertEquals(1, count($project->auditEvents));
 }
 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]);
 }
 public function testImportDataAnalysisResults()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $import = new Import();
     $serializedData['importRulesType'] = 'Tasks';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $account1 = AccountTestHelper::createAccountByNameForOwner('account1', $super);
     $account2 = AccountTestHelper::createAccountByNameForOwner('account2', $super);
     $account3 = AccountTestHelper::createAccountByNameForOwner('account3', $super);
     $contact1 = ContactTestHelper::createContactByNameForOwner('contact1', $super);
     $contact2 = ContactTestHelper::createContactByNameForOwner('contact2', $super);
     $contact3 = ContactTestHelper::createContactByNameForOwner('contact3', $super);
     $opportunity1 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity1', $super);
     $opportunity2 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity2', $super);
     $opportunity3 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity3', $super);
     //Make models externally linked for testing.
     ImportTestHelper::updateModelsExternalId($account2, 'ACC');
     ImportTestHelper::updateModelsExternalId($contact2, 'CON');
     ImportTestHelper::updateModelsExternalId($opportunity2, 'OPP');
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.tasks.tests.unit.files'));
     ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_0 = " . $account3->id . " where id != 1 limit 3");
     ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_2 = " . $contact3->id . " where id != 1 limit 4");
     ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_4 = " . $opportunity3->id . " where id != 1 limit 5");
     $mappingData = array('column_0' => ImportMappingUtil::makeModelDerivedColumnMappingData('AccountDerived', IdValueTypeMappingRuleForm::ZURMO_MODEL_ID), 'column_1' => ImportMappingUtil::makeModelDerivedColumnMappingData('AccountDerived'), 'column_2' => ImportMappingUtil::makeModelDerivedColumnMappingData('ContactDerived', IdValueTypeMappingRuleForm::ZURMO_MODEL_ID), 'column_3' => ImportMappingUtil::makeModelDerivedColumnMappingData('ContactDerived'), 'column_4' => ImportMappingUtil::makeModelDerivedColumnMappingData('OpportunityDerived', IdValueTypeMappingRuleForm::ZURMO_MODEL_ID), 'column_5' => ImportMappingUtil::makeModelDerivedColumnMappingData('OpportunityDerived'), 'column_6' => ImportMappingUtil::makeIntegerColumnMappingData('status'));
     $serializedData = unserialize($import->serializedData);
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $importRules = ImportRulesUtil::makeImportRulesByType('Tasks');
     $config = array('pagination' => array('pageSize' => 15));
     //This test csv has a header row.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     //Run data analyzer
     $importDataAnalyzer = new ImportDataAnalyzer($importRules, $dataProvider, $mappingData, array('column_0', 'column_1', 'column_2', 'column_3', 'column_4', 'column_5', 'column_6'));
     $importDataAnalyzer->analyzePage();
     $data = $dataProvider->getData();
     $this->assertEquals(10, count($data));
     $compareData = array();
     $compareData['column_0'][] = 'Is an existing record and will be updated.';
     $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_2'][] = 'Is an existing record and will be updated.';
     $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_4'][] = 'Is an existing record and will be updated.';
     $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[0]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[0]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Is an existing record and will be updated.';
     $compareData['column_1'][] = 'Is an existing record and will be updated.';
     $compareData['column_2'][] = 'Is an existing record and will be updated.';
     $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_4'][] = 'Is an existing record and will be updated.';
     $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[1]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[1]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Is an existing record and will be updated.';
     $compareData['column_1'][] = 'Is an existing record and will be updated.';
     $compareData['column_2'][] = 'Is an existing record and will be updated.';
     $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_4'][] = 'Is an existing record and will be updated.';
     $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[2]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[2]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_1'][] = 'Is an existing record and will be updated.';
     $compareData['column_2'][] = 'Is an existing record and will be updated.';
     $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_4'][] = 'Is an existing record and will be updated.';
     $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[3]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[3]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_3'][] = 'Is an existing record and will be updated.';
     $compareData['column_4'][] = 'Is an existing record and will be updated.';
     $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[4]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[4]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_3'][] = 'Is an existing record and will be updated.';
     $compareData['column_4'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[5]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[5]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_3'][] = 'Is an existing record and will be updated.';
     $compareData['column_4'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $compareData['column_5'][] = 'Is an existing record and will be updated.';
     $this->assertEquals($compareData, unserialize($data[6]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[6]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_4'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $compareData['column_5'][] = 'Is an existing record and will be updated.';
     $this->assertEquals($compareData, unserialize($data[7]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[7]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_4'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_5'][] = 'Is an existing record and will be updated.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[8]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[8]->analysisStatus);
     //Will result with no problems since it is all blank.
     $this->assertFalse(unserialize($data[9]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[9]->analysisStatus);
 }
 public function testProcessForActivityItems()
 {
     $account = AccountTestHelper::createAccountByNameForOwner('testAccount', Yii::app()->user->userModel);
     $task = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('testTask', Yii::app()->user->userModel, $account);
     $meeting = MeetingTestHelper::createMeetingWithOwnerAndRelatedAccount('testMeetig', Yii::app()->user->userModel, $account);
     $contact = ContactTestHelper::createContactByNameForOwner('testContact', Yii::app()->user->userModel);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('testOpportunity', Yii::app()->user->userModel);
     $task->activityItems->add($contact);
     $task->activityItems->add($opportunity);
     $meeting->activityItems->add($contact);
     $meeting->activityItems->add($opportunity);
     $this->assertTrue($task->save());
     $this->assertTrue($meeting->save());
     $emailTemplate = new EmailTemplate();
     $emailTemplate->builtType = EmailTemplate::BUILT_TYPE_PASTED_HTML;
     $emailTemplate->modelClassName = 'Task';
     $emailTemplate->type = 1;
     $emailTemplate->name = 'some template';
     $emailTemplate->subject = 'some subject [[NAME]]';
     $emailTemplate->htmlContent = 'Account: [[ACCOUNT__NAME]] Contact: [[CONTACT__FIRST^NAME]] Opportunity: [[OPPORTUNITY__NAME]]';
     $emailTemplate->textContent = 'Account: [[ACCOUNT__NAME]] Contact: [[CONTACT__FIRST^NAME]] Opportunity: [[OPPORTUNITY__NAME]]';
     $this->assertTrue($emailTemplate->save());
     $message = new EmailMessageForWorkflowForm('Task', Workflow::TYPE_ON_SAVE);
     $recipients = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER, 'audienceType' => EmailMessageRecipient::TYPE_TO, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_CREATED_BY_USER));
     $message->emailTemplateId = $emailTemplate->id;
     $message->sendFromType = EmailMessageForWorkflowForm::SEND_FROM_TYPE_CUSTOM;
     $message->sendFromAddress = '*****@*****.**';
     $message->sendFromName = 'Jason';
     $message->setAttributes(array(EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS => $recipients));
     $helper = new WorkflowEmailMessageProcessingHelper($message, $task, Yii::app()->user->userModel);
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $helper->process();
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $emailMessages = EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX);
     $this->assertEquals('some subject testTask', $emailMessages[0]->subject);
     $this->assertEquals('Account: testAccount Contact: testContact Opportunity: testOpportunity', $emailMessages[0]->content->textContent);
     $this->assertEquals('Account: testAccount Contact: testContact Opportunity: testOpportunity', $emailMessages[0]->content->htmlContent);
     $this->assertEquals('Jason', $emailMessages[0]->sender->fromName);
     $this->assertEquals('*****@*****.**', $emailMessages[0]->sender->fromAddress);
     $this->assertEquals(1, $emailMessages[0]->recipients->count());
     $this->assertEquals('*****@*****.**', $emailMessages[0]->recipients[0]->toAddress);
     $taskId = $task->id;
     $task->forgetAll();
     $task = Task::getById($taskId);
     $message = new EmailMessageForWorkflowForm('Task', Workflow::TYPE_ON_SAVE);
     $recipients = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER, 'audienceType' => EmailMessageRecipient::TYPE_TO, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_CREATED_BY_USER));
     $message->emailTemplateId = $emailTemplate->id;
     $message->sendFromType = EmailMessageForWorkflowForm::SEND_FROM_TYPE_CUSTOM;
     $message->sendFromAddress = '*****@*****.**';
     $message->sendFromName = 'Jason';
     $message->setAttributes(array(EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS => $recipients));
     $helper = new WorkflowEmailMessageProcessingHelper($message, $task, Yii::app()->user->userModel);
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $helper->process();
     $this->assertEquals(2, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $emailMessages = EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX);
     $this->assertEquals('some subject testTask', $emailMessages[1]->subject);
     $this->assertEquals('Account: testAccount Contact: testContact Opportunity: testOpportunity', $emailMessages[1]->content->textContent);
     $this->assertEquals('Account: testAccount Contact: testContact Opportunity: testOpportunity', $emailMessages[1]->content->htmlContent);
     $this->assertEquals('Jason', $emailMessages[1]->sender->fromName);
     $this->assertEquals('*****@*****.**', $emailMessages[1]->sender->fromAddress);
     $this->assertEquals(1, $emailMessages[1]->recipients->count());
     $this->assertEquals('*****@*****.**', $emailMessages[1]->recipients[0]->toAddress);
     $emailMessages[0]->delete();
     $emailMessages[1]->delete();
 }
 public function testGetMeetingWithAttendees()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $evelina = UserTestHelper::createBasicUser('Evelina');
     $amelia = UserTestHelper::createBasicUser('Amelia');
     $amelia->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($amelia->save());
     $contact1 = ContactTestHelper::createContactByNameForOwner('TestContact3', $super);
     $contact2 = ContactTestHelper::createContactByNameForOwner('TestContact4', $super);
     $contact2->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($contact2->save());
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $meeting = MeetingTestHelper::createMeetingByNameForOwner('Meeting 2 With User Attendees', $super);
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $meeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertTrue(isset($response['data']['attendees']));
     $this->assertTrue(isset($response['data']['attendees']['Organizer']));
     $this->assertEquals($super->id, $response['data']['attendees']['Organizer']['id']);
     $this->assertEquals($super->firstName, $response['data']['attendees']['Organizer']['firstName']);
     $this->assertEquals($super->lastName, $response['data']['attendees']['Organizer']['lastName']);
     $this->assertEquals($super->username, $response['data']['attendees']['Organizer']['username']);
     $this->assertFalse(isset($response['data']['attendees']['Organizer']['email']));
     $meeting->activityItems->add($contact1);
     $meeting->activityItems->add($contact2);
     $this->assertTrue($meeting->save());
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $meeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(2, count($response['data']['attendees']['Contact']));
     $this->assertEquals($contact1->id, $response['data']['attendees']['Contact'][0]['id']);
     $this->assertEquals($contact1->firstName, $response['data']['attendees']['Contact'][0]['firstName']);
     $this->assertEquals($contact1->lastName, $response['data']['attendees']['Contact'][0]['lastName']);
     $this->assertEquals($contact2->id, $response['data']['attendees']['Contact'][1]['id']);
     $this->assertEquals($contact2->firstName, $response['data']['attendees']['Contact'][1]['firstName']);
     $this->assertEquals($contact2->lastName, $response['data']['attendees']['Contact'][1]['lastName']);
     $this->assertEquals($contact2->primaryEmail->emailAddress, $response['data']['attendees']['Contact'][1]['email']);
     $meeting->userAttendees->add($evelina);
     $meeting->userAttendees->add($amelia);
     $this->assertTrue($meeting->save());
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $meeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(2, count($response['data']['attendees']['Contact']));
     $this->assertEquals($contact1->id, $response['data']['attendees']['Contact'][0]['id']);
     $this->assertEquals($contact1->firstName, $response['data']['attendees']['Contact'][0]['firstName']);
     $this->assertEquals($contact1->lastName, $response['data']['attendees']['Contact'][0]['lastName']);
     $this->assertEquals($contact2->id, $response['data']['attendees']['Contact'][1]['id']);
     $this->assertEquals($contact2->firstName, $response['data']['attendees']['Contact'][1]['firstName']);
     $this->assertEquals($contact2->lastName, $response['data']['attendees']['Contact'][1]['lastName']);
     $this->assertEquals(2, count($response['data']['attendees']['User']));
     $this->assertEquals($evelina->id, $response['data']['attendees']['User'][0]['id']);
     $this->assertEquals($evelina->firstName, $response['data']['attendees']['User'][0]['firstName']);
     $this->assertEquals($evelina->lastName, $response['data']['attendees']['User'][0]['lastName']);
     $this->assertEquals($evelina->username, $response['data']['attendees']['User'][0]['username']);
     $this->assertEquals($amelia->id, $response['data']['attendees']['User'][1]['id']);
     $this->assertEquals($amelia->primaryEmail->emailAddress, $response['data']['attendees']['User'][1]['email']);
     $this->assertEquals($amelia->firstName, $response['data']['attendees']['User'][1]['firstName']);
     $this->assertEquals($amelia->lastName, $response['data']['attendees']['User'][1]['lastName']);
     $this->assertEquals($amelia->username, $response['data']['attendees']['User'][1]['username']);
     $this->assertTrue(isset($response['data']['attendees']['Organizer']));
     $this->assertEquals($super->id, $response['data']['attendees']['Organizer']['id']);
     $this->assertEquals($super->firstName, $response['data']['attendees']['Organizer']['firstName']);
     $this->assertEquals($super->lastName, $response['data']['attendees']['Organizer']['lastName']);
     $this->assertEquals($super->username, $response['data']['attendees']['Organizer']['username']);
     // Test with opportunity and account activity items
     $account = AccountTestHelper::createAccountByNameForOwner('Account 2', $super);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('TestOpportunity 2', $super);
     $meeting2 = MeetingTestHelper::createMeetingByNameForOwner('Meeting 3 With Account and Opportunity', $super);
     $meeting2->activityItems->add($account);
     $meeting2->activityItems->add($opportunity);
     $this->assertTrue($meeting2->save());
     $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('name' => 'Meeting 3 With Account and Opportunity'), 'sort' => 'name');
     $searchParamsQuery = http_build_query($searchParams);
     $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(1, count($response['data']['items']));
     $this->assertEquals($account->id, $response['data']['items'][0]['attendees']['Account'][0]['id']);
     $this->assertEquals($account->name, $response['data']['items'][0]['attendees']['Account'][0]['name']);
     $this->assertEquals($opportunity->id, $response['data']['items'][0]['attendees']['Opportunity'][0]['id']);
     $this->assertEquals($opportunity->name, $response['data']['items'][0]['attendees']['Opportunity'][0]['name']);
     // Test with regular user if he can get user attendees
     $michael = UserTestHelper::createBasicUser('Michael');
     $michael->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($michael->save());
     $michael->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API);
     $michael->setRight('MeetingsModule', MeetingsModule::getAccessRight());
     $michael->setRight('MeetingsModule', MeetingsModule::getCreateRight());
     $saved = $michael->save();
     $this->assertTrue($saved);
     $michaelMeeting = MeetingTestHelper::createMeetingByNameForOwner('Meeting 4 With User', $michael);
     $michaelMeeting->userAttendees->add($evelina);
     $this->assertTrue($michaelMeeting->save());
     $authenticationData = $this->login('michael', 'michael');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $michaelMeeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(1, count($response['data']['attendees']['User']));
     $this->assertEquals($evelina->id, $response['data']['attendees']['User'][0]['id']);
     $this->assertEquals($evelina->firstName, $response['data']['attendees']['User'][0]['firstName']);
     $this->assertEquals($evelina->lastName, $response['data']['attendees']['User'][0]['lastName']);
     $this->assertEquals($evelina->username, $response['data']['attendees']['User'][0]['username']);
     $this->assertTrue(isset($response['data']['attendees']['Organizer']));
     $this->assertEquals($michael->id, $response['data']['attendees']['Organizer']['id']);
     $this->assertEquals($michael->firstName, $response['data']['attendees']['Organizer']['firstName']);
     $this->assertEquals($michael->lastName, $response['data']['attendees']['Organizer']['lastName']);
     $this->assertEquals($michael->username, $response['data']['attendees']['Organizer']['username']);
     $this->assertEquals($michael->primaryEmail->emailAddress, $response['data']['attendees']['Organizer']['email']);
 }
 public function testEditOpportunityWIthIncorrectDataType()
 {
     $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');
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('Newest Opportunity', $super);
     // Provide data with wrong type.
     $data['probability'] = str_repeat('a', 128);
     $response = $this->createApiCallWithRelativeUrl('create/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals(5, count($response['errors']));
     $id = $opportunity->id;
     $data = array();
     $data['name'] = str_repeat('a', 128);
     $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']));
 }
 private function addOpportunity()
 {
     $primaryModel = $this->getPrimaryModel();
     $this->assertEquals(0, count($primaryModel->opportunities));
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('UI Services', Yii::app()->user->userModel);
     $opportunity->account = $this->selectedModels[1];
     $opportunity->save();
 }
 public function testCreateARelatedContactOnAnOpportunityWhenOpportunityBecomesClosedWon()
 {
     $super = User::getByUsername('super');
     $contactStates = ContactState::getAll();
     //Create workflow
     $workflow = new Workflow();
     $workflow->setDescription('aDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(1);
     $workflow->setModuleClassName('OpportunitiesModule');
     $workflow->setName('myFirstWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_ON_SAVE);
     $workflow->setTriggersStructure('1');
     //Add Trigger
     $trigger = new TriggerForWorkflowForm('OpportunitiesModule', 'Opportunity', Workflow::TYPE_ON_SAVE);
     $trigger->attributeIndexOrDerivedType = 'stage';
     $trigger->value = 'Prospecting';
     $trigger->operator = 'equals';
     $workflow->addTrigger($trigger);
     //Add action
     $action = new ActionForWorkflowForm('Opportunity', Workflow::TYPE_ON_SAVE);
     $action->type = ActionForWorkflowForm::TYPE_CREATE;
     $action->relation = 'contacts';
     $attributes = array('lastName' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'smith'), 'firstName' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'john'), 'owner__User' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => Yii::app()->user->userModel->id), 'state' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => $contactStates[0]->id));
     $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
     $workflow->addAction($action);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('some opp', $super);
     $this->assertTrue($opportunity->id > 0);
     $this->assertEquals(0, $opportunity->contacts->count());
     //Change opportunity to  Prospecting
     $opportunity->stage->value = 'Prospecting';
     $this->assertTrue(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $opportunity));
     $saved = $opportunity->save();
     $this->assertTrue($saved);
     $this->assertEquals(1, $opportunity->contacts->count());
     $this->assertEquals('smith', $opportunity->contacts[0]->lastName);
 }
 /**
  * @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 testCreateWithRelations
  */
 public function testUpdateWithRelations()
 {
     $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');
     $contact = ContactTestHelper::createContactByNameForOwner('Simon', $super);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('My Opportunity', $super);
     $compareData = $this->getModelToApiDataUtilData($contact);
     $contact->forget();
     $data['modelRelations'] = array('opportunities' => array(array('action' => 'add', 'modelId' => $opportunity->id, 'modelClassName' => 'Opportunity')));
     $data['firstName'] = 'Fred';
     $response = $this->createApiCallWithRelativeUrl('update/' . $compareData['id'], 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     unset($response['data']['modifiedDateTime']);
     unset($compareData['modifiedDateTime']);
     $compareData['firstName'] = 'Fred';
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals($compareData, $response['data']);
     RedBeanModel::forgetAll();
     $contact = Contact::getById($compareData['id']);
     $this->assertEquals(1, count($contact->opportunities));
     $this->assertEquals($opportunity->id, $contact->opportunities[0]->id);
     $opportunity = Opportunity::getById($opportunity->id);
     $this->assertEquals(1, count($opportunity->contacts));
     $this->assertEquals($contact->id, $opportunity->contacts[0]->id);
     // Now test remove relations
     $data['modelRelations'] = array('opportunities' => array(array('action' => 'remove', 'modelId' => $opportunity->id, 'modelClassName' => 'Opportunity')));
     $response = $this->createApiCallWithRelativeUrl('update/' . $compareData['id'], 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     RedBeanModel::forgetAll();
     $contact = Contact::getById($compareData['id']);
     $this->assertEquals(0, count($contact->opportunities));
     $opportunity = Opportunity::getById($opportunity->id);
     $this->assertEquals(0, count($opportunity->contacts));
 }
 /**
  * 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()));
 }
 /**
  * @deletes selected leads.
  */
 public function testRegularMassDeleteActionsForSelectedIds()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $confused = User::getByUsername('confused');
     $nobody = User::getByUsername('nobody');
     $this->assertEquals(Right::DENY, $confused->getEffectiveRight('ZurmoModule', ZurmoModule::RIGHT_BULK_DELETE));
     $confused->setRight('ZurmoModule', ZurmoModule::RIGHT_BULK_DELETE);
     //Load MassDelete view for the 3 opportunities.
     $opportunities = Opportunity::getAll();
     $this->assertEquals(9, count($opportunities));
     $opportunity1 = OpportunityTestHelper::createOpportunityByNameForOwner('oppotunityDelete1', $confused);
     $opportunity2 = OpportunityTestHelper::createOpportunityByNameForOwner('oppotunityDelete2', $confused);
     $opportunity3 = OpportunityTestHelper::createOpportunityByNameForOwner('oppotunityDelete3', $nobody);
     $opportunity4 = OpportunityTestHelper::createOpportunityByNameForOwner('oppotunityDelete4', $confused);
     $opportunity5 = OpportunityTestHelper::createOpportunityByNameForOwner('oppotunityDelete5', $confused);
     $opportunity6 = OpportunityTestHelper::createOpportunityByNameForOwner('oppotunityDelete6', $nobody);
     $selectedIds = $opportunity1->id . ',' . $opportunity2->id . ',' . $opportunity3->id;
     // Not Coding Standard
     $this->setGetArray(array('selectedIds' => $selectedIds, 'selectAll' => ''));
     // Not Coding Standard
     $this->resetPostArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('opportunities/default/massDelete');
     $this->assertFalse(strpos($content, '<strong>3</strong>&#160;Opportunities selected for removal') === false);
     $pageSize = Yii::app()->pagination->getForCurrentUserByType('massDeleteProgressPageSize');
     $this->assertEquals(5, $pageSize);
     //calculating leads after adding 6 new records
     $opportunities = Opportunity::getAll();
     $this->assertEquals(15, count($opportunities));
     //Deleting 6 opportunities for pagination scenario
     //Run Mass Delete using progress save for page1
     $selectedIds = $opportunity1->id . ',' . $opportunity2->id . ',' . $opportunity3->id . ',' . $opportunity4->id . ',' . $opportunity5->id . ',' . $opportunity6->id;
     // Not Coding Standard
     $this->setGetArray(array('selectedIds' => $selectedIds, 'selectAll' => '', 'Opportunity_page' => 1));
     $this->setPostArray(array('selectedRecordCount' => 6));
     $content = $this->runControllerWithExitExceptionAndGetContent('opportunities/default/massDelete');
     $opportunities = Opportunity::getAll();
     $this->assertEquals(10, count($opportunities));
     //Run Mass Delete using progress save for page2
     $selectedIds = $opportunity1->id . ',' . $opportunity2->id . ',' . $opportunity3->id . ',' . $opportunity4->id . ',' . $opportunity5->id . ',' . $opportunity6->id;
     // Not Coding Standard
     $this->setGetArray(array('selectedIds' => $selectedIds, 'selectAll' => '', 'Opportunity_page' => 2));
     $this->setPostArray(array('selectedRecordCount' => 6));
     $content = $this->runControllerWithNoExceptionsAndGetContent('opportunities/default/massDeleteProgress');
     $opportunities = Opportunity::getAll();
     $this->assertEquals(9, count($opportunities));
 }