public function testLoad() { $customFieldData = CustomFieldData::getByName('Titles'); $this->assertEquals(0, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('AccountTypes'); $this->assertEquals(0, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('LeadSources'); $this->assertEquals(0, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('Industries'); $this->assertEquals(0, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('MeetingCategories'); $this->assertEquals(0, count(unserialize($customFieldData->serializedData))); $this->assertEquals(0, count(ContactState::getAll())); $this->assertEquals(1, count(Currency::getAll())); $messageLogger = new MessageLogger(); DefaultDataUtil::load($messageLogger); $customFieldData = CustomFieldData::getByName('Titles'); $this->assertEquals(4, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('AccountTypes'); $this->assertEquals(3, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('LeadSources'); $this->assertEquals(4, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('Industries'); $this->assertEquals(9, count(unserialize($customFieldData->serializedData))); $customFieldData = CustomFieldData::getByName('MeetingCategories'); $this->assertEquals(2, count(unserialize($customFieldData->serializedData))); $this->assertEquals(6, count(ContactState::getAll())); $this->assertEquals(1, count(Currency::getAll())); }
public function setAttributeMetadataFromForm(AttributeForm $attributeForm) { $modelClassName = get_class($this->model); $attributeName = $attributeForm->attributeName; $attributeLabels = $attributeForm->attributeLabels; $elementType = $attributeForm->getAttributeTypeName(); $isRequired = (bool) $attributeForm->isRequired; $isAudited = (bool) $attributeForm->isAudited; $contactStatesData = $attributeForm->contactStatesData; $contactStatesLabels = $attributeForm->contactStatesLabels; $startingStateOrder = (int) $attributeForm->startingStateOrder; $contactStatesDataExistingValues = $attributeForm->contactStatesDataExistingValues; if ($contactStatesDataExistingValues == null) { $contactStatesDataExistingValues = array(); } if ($attributeForm instanceof ContactStateAttributeForm) { //update order on existing states. //delete removed states $states = ContactState::getAll('order'); $stateNames = array(); foreach ($states as $state) { if (in_array($state->name, $contactStatesDataExistingValues)) { //todo: just don't match up the swap $order = array_search($state->name, $contactStatesDataExistingValues); $state->name = $contactStatesData[$order]; $state->order = $order; $state->serializedLabels = $this->makeSerializedLabelsByLabelsAndOrder($contactStatesLabels, (int) $state->order); $saved = $state->save(); assert('$saved'); $stateNames[] = $state->name; } elseif (in_array($state->name, $contactStatesData)) { $stateNames[] = $state->name; $state->order = array_search($state->name, $contactStatesData); $state->serializedLabels = $this->makeSerializedLabelsByLabelsAndOrder($contactStatesLabels, (int) $state->order); $saved = $state->save(); assert('$saved'); } else { $stateNames[] = $state->name; $state->delete(); } } //add new states with correct order. foreach ($contactStatesData as $order => $name) { if (!in_array($name, $stateNames)) { $state = new ContactState(); $state->name = $name; $state->order = $order; $state->serializedLabels = $this->makeSerializedLabelsByLabelsAndOrder($contactStatesLabels, (int) $order); $saved = $state->save(); assert('$saved'); } } //Set starting state by order. ContactsUtil::setStartingStateByOrder($startingStateOrder); ModelMetadataUtil::addOrUpdateRelation($modelClassName, $attributeName, $attributeLabels, $elementType, $isRequired, $isAudited, 'ContactState'); } else { throw new NotSupportedException(); } }
public function testSanitizeValueBySanitizerTypesForContactStateTypeThatIsRequired() { $contactStates = ContactState::getAll(); $this->assertEquals(6, count($contactStates)); //Test a required contact state with no value or default value. $importSanitizeResultsUtil = new ImportSanitizeResultsUtil(); $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultStateId' => null))); $sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder(); $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, null, 'column_0', $columnMappingData, $importSanitizeResultsUtil); $this->assertNull($sanitizedValue); $this->assertFalse($importSanitizeResultsUtil->shouldSaveModel()); $messages = $importSanitizeResultsUtil->getMessages(); $this->assertEquals(1, count($messages)); $compareMessage = 'Contact - The status is required. Neither a value nor a default was specified.'; $this->assertEquals($compareMessage, $messages[0]); //Test a required contact state with a valid value, and a default value. The valid value should come through. $importSanitizeResultsUtil = new ImportSanitizeResultsUtil(); $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultStateId' => $contactStates[4]->id))); $sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder(); $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, $contactStates[5]->id, 'column_0', $columnMappingData, $importSanitizeResultsUtil); $this->assertEquals($contactStates[5], $sanitizedValue); $this->assertTrue($importSanitizeResultsUtil->shouldSaveModel()); $messages = $importSanitizeResultsUtil->getMessages(); $this->assertEquals(0, count($messages)); //Test a required contact state with no value, and a default value. $importSanitizeResultsUtil = new ImportSanitizeResultsUtil(); $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultStateId' => $contactStates[4]->id))); $sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder(); $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, null, 'column_0', $columnMappingData, $importSanitizeResultsUtil); $this->assertEquals($contactStates[4], $sanitizedValue); $this->assertTrue($importSanitizeResultsUtil->shouldSaveModel()); $messages = $importSanitizeResultsUtil->getMessages(); $this->assertEquals(0, count($messages)); //Test a required contact state with a value that is invalid $importSanitizeResultsUtil = new ImportSanitizeResultsUtil(); $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultValue' => null))); $sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder(); $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, 'somethingnotright', 'column_0', $columnMappingData, $importSanitizeResultsUtil); $this->assertFalse($importSanitizeResultsUtil->shouldSaveModel()); $messages = $importSanitizeResultsUtil->getMessages(); $this->assertEquals(1, count($messages)); $compareMessage = 'Contact - Status specified does not exist.'; $this->assertEquals($compareMessage, $messages[0]); //Test a required contact state with a state that is for leads, not contacts. $importSanitizeResultsUtil = new ImportSanitizeResultsUtil(); $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultValue' => null))); $sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder(); $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, $contactStates[1]->id, 'column_0', $columnMappingData, $importSanitizeResultsUtil); $this->assertFalse($importSanitizeResultsUtil->shouldSaveModel()); $messages = $importSanitizeResultsUtil->getMessages(); $this->assertEquals(1, count($messages)); $compareMessage = 'Contact - Status specified is invalid.'; $this->assertEquals($compareMessage, $messages[0]); }
public function getStateIds() { $states = ContactState::getAll('order'); $startingStateOrder = ContactsUtil::getStartingStateOrder($states); $stateIds = array(); foreach ($states as $state) { if ($this->shouldIncludeState($state->order, $startingStateOrder)) { $stateIds[] = $state->id; } } return $stateIds; }
public function makeAll(&$demoDataHelper) { assert('$demoDataHelper instanceof DemoDataHelper'); assert('$demoDataHelper->isSetRange("User")'); $contactStates = ContactState::getAll(); $statesBeginningWithStartingState = $this->getStatesBeforeOrStartingWithStartingState($contactStates); $contacts = array(); for ($i = 0; $i < $this->resolveQuantityToLoad(); $i++) { $contact = new Contact(); $contact->owner = $demoDataHelper->getRandomByModelName('User'); $contact->state = RandomDataUtil::getRandomValueFromArray($statesBeginningWithStartingState); $this->populateModel($contact); $saved = $contact->save(); assert('$saved'); $contacts[] = $contact->id; } //We can use dummy model name here ContactsThatAreLeads, so we can distinct between contacts are leads $demoDataHelper->setRangeByModelName('ContactsThatAreLeads', $contacts[0], $contacts[count($contacts) - 1]); }
public function makeAll(&$demoDataHelper) { assert('$demoDataHelper instanceof DemoDataHelper'); assert('$demoDataHelper->isSetRange("User")'); assert('$demoDataHelper->isSetRange("Account")'); $contactStates = ContactState::getAll(); $statesBeginningWithStartingState = $this->getStatesBeforeOrStartingWithStartingState($contactStates); $contacts = array(); for ($i = 0; $i < $this->resolveQuantityToLoad(); $i++) { $contact = new Contact(); $contact->account = $demoDataHelper->getRandomByModelName('Account'); $contact->state = RandomDataUtil::getRandomValueFromArray($statesBeginningWithStartingState); $contact->owner = $contact->account->owner; $this->populateModel($contact); $saved = $contact->save(); assert('$saved'); $contacts[] = $contact->id; } $demoDataHelper->setRangeByModelName('Contact', $contacts[0], $contacts[count($contacts) - 1]); }
public function testUsingStateAdapters() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $contactStates = ContactState::getAll(); $this->assertTrue(count($contactStates) > 1); $firstContactState = $contactStates[0]; $lastContactState = $contactStates[count($contactStates) - 1]; $contact = new Contact(); $contact->title->value = 'Mr.'; $contact->firstName = 'Sallyy'; $contact->lastName = 'Sallyyson'; $contact->owner = $super; $contact->state = $firstContactState; $contact->primaryEmail = new Email(); $contact->primaryEmail->emailAddress = '*****@*****.**'; $contact->secondaryEmail = new Email(); $contact->secondaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($contact->save()); $data = ContactSearch::getContactsByPartialFullNameOrAnyEmailAddress('sally', 5); $this->assertEquals(2, count($data)); $data = ContactSearch::getContactsByPartialFullName('sally', 5); $this->assertEquals(2, count($data)); //Use contact state adapter $data = ContactSearch::getContactsByPartialFullNameOrAnyEmailAddress('sally', 5, 'ContactsStateMetadataAdapter'); $this->assertEquals(1, count($data)); $this->assertEquals($lastContactState, $data[0]->state); $data = ContactSearch::getContactsByPartialFullName('sally', 5, 'ContactsStateMetadataAdapter'); $this->assertEquals(1, count($data)); $this->assertEquals($lastContactState, $data[0]->state); //Use lead state adapter $data = ContactSearch::getContactsByPartialFullNameOrAnyEmailAddress('sally', 5, 'LeadsStateMetadataAdapter'); $this->assertEquals(1, count($data)); $this->assertEquals($firstContactState, $data[0]->state); $data = ContactSearch::getContactsByPartialFullName('sally', 5, 'LeadsStateMetadataAdapter'); $this->assertEquals(1, count($data)); $this->assertEquals($firstContactState, $data[0]->state); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); $user = SecurityTestHelper::createSuperAdmin(); Yii::app()->user->userModel = $user; ContactsModule::loadStartingData(); $contactData = array('Sam' => '123-456-789', 'Sally' => '123-456-789', 'Sarah' => '123-456-789', 'Jason' => '123-456-789', 'James' => '123-456-789', 'Roger' => '987-654-321'); $contactStates = ContactState::getAll(); $lastContactState = $contactStates[count($contactStates) - 1]; foreach ($contactData as $firstName => $phone) { $contact = new Contact(); $contact->title->value = 'Mr.'; $contact->firstName = $firstName; $contact->lastName = 'son'; $contact->owner = $user; $contact->state = $lastContactState; $contact->mobilePhone = $phone; $contact->officePhone = $phone . 'X'; $contact->primaryEmail->emailAddress = strtolower($firstName) . '@zurmoland.com'; $contact->secondaryEmail->emailAddress = strtolower($firstName) . '@zurmoworld.com'; $contact->save(); } }
/** * @param DemoDataHelper $demoDataHelper */ public function makeAll(&$demoDataHelper) { assert('$demoDataHelper instanceof DemoDataHelper'); assert('$demoDataHelper->isSetRange("User")'); $contactStates = ContactState::getAll(); $statesBeginningWithStartingState = ContactsDemoDataMaker::getStatesBeforeOrStartingWithStartingState($contactStates); $contactWebForms = array(); for ($this->index = 0; $this->index < 5; $this->index++) { $contactWebForm = new ContactWebForm(); $contactWebForm->owner = $demoDataHelper->getRandomByModelName('User'); $contactWebForm->defaultOwner = $contactWebForm->owner; $contactWebForm->defaultState = RandomDataUtil::getRandomValueFromArray($statesBeginningWithStartingState); $this->populateModel($contactWebForm); $contactWebForm->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER); $saved = $contactWebForm->save(); assert('$saved'); $contactWebForm = ContactWebForm::getById($contactWebForm->id); AllPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($contactWebForm, Group::getByName(Group::EVERYONE_GROUP_NAME)); $contactWebForm->save(); $contactWebForms[] = $contactWebForm->id; } $demoDataHelper->setRangeByModelName('ContactWebForm', $contactWebForms[0], $contactWebForms[count($contactWebForms) - 1]); }
public function testWorkflowDoesLinkRelatedModelWhenPermissionsIsSetToOwner() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $contactStates = ContactState::getAll(); $this->assertEquals(0, Contact::getCount()); //Create workflow $workflow = new Workflow(); $workflow->setDescription('aDescription'); $workflow->setIsActive(true); $workflow->setOrder(5); $workflow->setModuleClassName('AccountsModule'); $workflow->setName('myFirstWorkflow'); $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING); $workflow->setType(Workflow::TYPE_ON_SAVE); $workflow->setTriggersStructure('1'); //Add action $action = new ActionForWorkflowForm('Account', 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); $account = new Account(); $account->name = 'myTestAccount'; $account->owner = $super; $account->save(); RedBeanModel::forgetAll(); $contacts = Contact::getAll(); $this->assertCount(1, $contacts); $this->assertEquals('myTestAccount', $contacts[0]->account->name); $this->assertEquals('john smith', strval($account->contacts[0])); $this->assertTrue($account->contacts[0]->id > 0); }
public function testGetContactsByAnyEmailAddress() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $contactStates = ContactState::getAll(); $this->assertTrue(count($contactStates) > 1); $firstContactState = $contactStates[0]; $contact = new Contact(); $contact->title->value = 'Mr.'; $contact->firstName = 'test'; $contact->lastName = 'contact'; $contact->owner = $super; $contact->state = $firstContactState; $contact->primaryEmail = new Email(); $contact->primaryEmail->emailAddress = '*****@*****.**'; $contact->secondaryEmail = new Email(); $contact->secondaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($contact->save()); $data = ContactSearch::getContactsByAnyEmailAddress('*****@*****.**'); $this->assertEquals(1, count($data)); }
public function testContactsUtilSetStartingStateByOrder() { $startingStateId = ContactsUtil::getStartingStateId(); $startingState = ContactState::getById($startingStateId); $startingState->delete(); $this->assertEquals(6, count(ContactState::GetAll())); ContactsUtil::setStartingStateByOrder(2); $startingStateId = ContactsUtil::getStartingStateId(); $states = ContactState::getAll('order'); $this->assertEquals($states[1]->id, $startingStateId); $startingState = ContactState::getByName('Recycled'); $this->assertEquals(1, count($startingState)); $this->assertEquals($startingState[0]->id, $startingStateId); }
public function testUpdateRelatedCatalogItemOnAProductBySellPriceCriteria() { $super = User::getByUsername('super'); $contactStates = ContactState::getAll(); //Create workflow $workflow = new Workflow(); $workflow->setDescription('aDescription'); $workflow->setIsActive(true); $workflow->setOrder(1); $workflow->setModuleClassName('ProductsModule'); $workflow->setName('myFirstProductWorkflow'); $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING); $workflow->setType(Workflow::TYPE_ON_SAVE); $workflow->setTriggersStructure('1'); //Add Trigger $trigger = new TriggerForWorkflowForm('ProductsModule', 'Product', Workflow::TYPE_ON_SAVE); $trigger->attributeIndexOrDerivedType = 'sellPrice'; $trigger->value = 600; $trigger->operator = 'greaterThanOrEqualTo'; $workflow->addTrigger($trigger); //Add action $currencies = Currency::getAll(); $action = new ActionForWorkflowForm('Product', Workflow::TYPE_ON_SAVE); $action->type = ActionForWorkflowForm::TYPE_UPDATE_RELATED; $action->relation = 'productTemplate'; $attributes = array('description' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'Set Price'), 'priceFrequency' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 2), 'listPrice' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 800, 'currencyId' => $currencies[0]->id), 'cost' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 700, 'currencyId' => $currencies[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); $productTemplate = ProductTemplateTestHelper::createProductTemplateByName('superProductTemplate'); $productTemplates = ProductTemplate::getByName('superProductTemplate'); $product = ProductTestHelper::createProductByNameForOwner('Test Product', $super); $this->assertTrue($product->id > 0); $product->productTemplate = $productTemplates[0]; //Change product sell price $product->sellPrice->value = 650; $this->assertTrue(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $product)); $saved = $product->save(); $this->assertTrue($saved); $productId = $product->id; $product->forget(); $product = Product::getById($productId); $this->assertEquals('Set Price', $product->productTemplate->description); $this->assertEquals(2, $product->productTemplate->priceFrequency); $this->assertEquals(700, $product->productTemplate->cost->value); $this->assertEquals(800, $product->productTemplate->listPrice->value); }
/** * @depends testResolveUpdateActionWithDynamicValues */ public function testResolveUpdateRelatedActionWithStaticValues() { $contactStates = ContactState::getAll(); $this->assertTrue($contactStates[0]->id > 0); $contactState = $contactStates[0]; $currency = Currency::getByCode('USD'); $bobby = User::getByUsername('bobby'); $workflow = new Workflow(); $workflow->setType(Workflow::TYPE_ON_SAVE); $workflow->setModuleClassName('WorkflowsTest2Module'); $data = array(); $data[ComponentForWorkflowForm::TYPE_ACTIONS][0]['type'] = ActionForWorkflowForm::TYPE_UPDATE_RELATED; $data[ComponentForWorkflowForm::TYPE_ACTIONS][0]['relation'] = 'hasMany2'; $data[ComponentForWorkflowForm::TYPE_ACTIONS][0][ActionForWorkflowForm::ACTION_ATTRIBUTES] = array('boolean' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '1'), 'boolean2' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '0'), 'currencyValue' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '362.24', 'currencyId' => $currency->id), 'date' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '2/24/2012'), 'dateTime' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '2/24/2012 03:00 AM'), 'dropDown' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'Value 1'), 'float' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '54.25'), 'integer' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '32'), 'likeContactState' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => $contactState->id), 'multiDropDown' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => array('Multi Value 1', 'Multi Value 2')), 'owner' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => $bobby->id), 'phone' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '8471112222'), 'primaryAddress___street1' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '123 Main Street'), 'primaryEmail___emailAddress' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '*****@*****.**'), 'radioDropDown' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'Radio Value 1'), 'string' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'), 'tagCloud' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => array('Tag Value 1', 'Tag Value 2')), 'textArea' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'some description'), 'url' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'http://www.zurmo.com')); DataToWorkflowUtil::resolveActions($data, $workflow); $actions = $workflow->getActions(); $this->assertCount(1, $actions); $this->assertEquals(ActionForWorkflowForm::TYPE_UPDATE_RELATED, $actions[0]->type); $this->assertEquals('hasMany2', $actions[0]->relation); $this->assertEquals(ActionForWorkflowForm::RELATION_FILTER_ALL, $actions[0]->relationFilter); $this->assertEquals(19, $actions[0]->getActionAttributeFormsCount()); $this->assertTrue($actions[0]->getActionAttributeFormByName('boolean') instanceof CheckBoxWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('boolean')->type); $this->assertEquals('1', $actions[0]->getActionAttributeFormByName('boolean')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('boolean2') instanceof CheckBoxWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('boolean2')->type); $this->assertEquals('0', $actions[0]->getActionAttributeFormByName('boolean2')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('currencyValue') instanceof CurrencyValueWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('currencyValue')->type); $this->assertEquals(362.24, $actions[0]->getActionAttributeFormByName('currencyValue')->value); $this->assertEquals($currency->id, $actions[0]->getActionAttributeFormByName('currencyValue')->currencyId); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('currencyValue')->currencyIdType); $this->assertTrue($actions[0]->getActionAttributeFormByName('date') instanceof DateWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('date')->type); $this->assertEquals('2012-02-24', $actions[0]->getActionAttributeFormByName('date')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('dateTime') instanceof DateTimeWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('dateTime')->type); $compareDateTime = DateTimeUtil::convertDateTimeLocaleFormattedDisplayToDbFormattedDateTimeWithSecondsAsZero('2/24/2012 03:00 AM'); $this->assertEquals($compareDateTime, $actions[0]->getActionAttributeFormByName('dateTime')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('dropDown') instanceof DropDownWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('dropDown')->type); $this->assertEquals('Value 1', $actions[0]->getActionAttributeFormByName('dropDown')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('float') instanceof DecimalWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('float')->type); $this->assertEquals('54.25', $actions[0]->getActionAttributeFormByName('float')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('integer') instanceof IntegerWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('integer')->type); $this->assertEquals('32', $actions[0]->getActionAttributeFormByName('integer')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('likeContactState') instanceof ContactStateWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('likeContactState')->type); $this->assertEquals($contactState->id, $actions[0]->getActionAttributeFormByName('likeContactState')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('multiDropDown') instanceof MultiSelectDropDownWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('multiDropDown')->type); $this->assertEquals(array('Multi Value 1', 'Multi Value 2'), $actions[0]->getActionAttributeFormByName('multiDropDown')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('owner') instanceof UserWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('owner')->type); $this->assertEquals($bobby->id, $actions[0]->getActionAttributeFormByName('owner')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('phone') instanceof PhoneWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('phone')->type); $this->assertEquals('8471112222', $actions[0]->getActionAttributeFormByName('phone')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('primaryAddress___street1') instanceof TextWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('primaryAddress___street1')->type); $this->assertEquals('123 Main Street', $actions[0]->getActionAttributeFormByName('primaryAddress___street1')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('primaryEmail___emailAddress') instanceof EmailWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('primaryEmail___emailAddress')->type); $this->assertEquals('*****@*****.**', $actions[0]->getActionAttributeFormByName('primaryEmail___emailAddress')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('radioDropDown') instanceof RadioDropDownWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('radioDropDown')->type); $this->assertEquals('Radio Value 1', $actions[0]->getActionAttributeFormByName('radioDropDown')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('string') instanceof TextWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('string')->type); $this->assertEquals('jason', $actions[0]->getActionAttributeFormByName('string')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('tagCloud') instanceof TagCloudWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('tagCloud')->type); $this->assertEquals(array('Tag Value 1', 'Tag Value 2'), $actions[0]->getActionAttributeFormByName('tagCloud')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('textArea') instanceof TextAreaWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('textArea')->type); $this->assertEquals('some description', $actions[0]->getActionAttributeFormByName('textArea')->value); $this->assertTrue($actions[0]->getActionAttributeFormByName('url') instanceof UrlWorkflowActionAttributeForm); $this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('url')->type); $this->assertEquals('http://www.zurmo.com', $actions[0]->getActionAttributeFormByName('url')->value); }
/** * @depends testGetContactState */ public function testListAllContactStates() { $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'); $contactStates = ContactState::getAll(); $this->assertEquals(6, count($contactStates)); foreach ($contactStates as $contactState) { $compareData[] = $this->getModelToApiDataUtilData($contactState); } $response = $this->createApiCallWithRelativeUrl('list/', 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(6, count($response['data']['items'])); $this->assertEquals(6, $response['data']['totalCount']); $this->assertEquals(1, $response['data']['currentPage']); $this->assertEquals($compareData, $response['data']['items']); }
public static function setStartingStateByOrder($startingStateOrder) { $states = ContactState::getAll('order'); foreach ($states as $order => $state) { if ($startingStateOrder == $state->order) { self::setStartingStateById($state->id); return; } } throw new NotSupportedException(); }
/** * @depends testGetByPartialName */ public function testGetGlobalSearchResultsByPartialTerm() { //Unfrozen, there are too many attributes that have to be columns in the database at this point, so //now this is just a frozen test. if (RedBeanDatabase::isFrozen()) { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; //Add an account with an email address. $account = new Account(); $account->name = 'The Zoo'; $account->owner = $super; $email = new Email(); $email->optOut = 0; $email->emailAddress = '*****@*****.**'; $account->primaryEmail = $email; $this->assertTrue($account->save()); //Create a contact with a similar e-mail address $contactStates = ContactState::getAll(); $contact = new Contact(); $contact->title->value = 'Mr.'; $contact->firstName = 'Big'; $contact->lastName = 'Elephant'; $contact->owner = $super; $contact->state = $contactStates[count($contactStates) - 1]; $email = new Email(); $email->optOut = 0; $email->emailAddress = '*****@*****.**'; $contact->primaryEmail = $email; $this->assertTrue($contact->save()); //Add an opportunity $currencies = Currency::getAll(); $currencyValue = new CurrencyValue(); $currencyValue->value = 500.54; $currencyValue->currency = $currencies[0]; $opportunity = new Opportunity(); $opportunity->owner = $super; $opportunity->name = 'Animal Crackers'; $opportunity->amount = $currencyValue; $opportunity->closeDate = '2011-01-01'; //eventually fix to make correct format $opportunity->stage->value = 'Negotiating'; $this->assertTrue($opportunity->save()); //Test where no results are expected. $data = ModelAutoCompleteUtil::getGlobalSearchResultsByPartialTerm('weqqw', 5, $super); $this->assertEquals(array(array('href' => '', 'label' => 'No Results Found', 'iconClass' => '')), $data); //Test where one account is expected searching by account name. $data = ModelAutoCompleteUtil::getGlobalSearchResultsByPartialTerm('Rabbit', 5, $super); $this->assertEquals(1, count($data)); $this->assertEquals('Rabbit Systems', $data[0]['label']); //test anyEmail where results are across more than one module. This will also pick up an opportunity that //has the name 'animal' in it. $data = ModelAutoCompleteUtil::getGlobalSearchResultsByPartialTerm('animal', 5, $super); $this->assertEquals(3, count($data)); $this->assertEquals('The Zoo', $data[0]['label']); $this->assertEquals('Big Elephant', $data[1]['label']); $this->assertEquals('Animal Crackers', $data[2]['label']); } }
/** * @depends testCheckBoxWorkflowAttributeFormSetGetAndValidate */ public function testContactStateWorkflowAttributeFormSetGetAndValidate() { $contactStates = ContactState::getAll(); $this->assertTrue($contactStates[0]->id > 0); $contactState = $contactStates[0]; $form = new ContactStateWorkflowActionAttributeForm('WorkflowModelTestItem', 'likeContactState'); $form->type = WorkflowActionAttributeForm::TYPE_STATIC; $form->shouldSetValue = true; $form->value = $contactState->id; $validated = $form->validate(); $this->assertTrue($validated); }
public function testResolveValueAsLabelForHeaderCellForAnAttributeLikeContactState() { $contactStates = ContactState::getAll(); $displayAttribute = new DisplayAttributeForReportForm('ContactsModule', 'Contact', Report::TYPE_SUMMATION); $displayAttribute->attributeIndexOrDerivedType = 'state'; $this->assertEquals('Recycled', $contactStates[2]->name); $this->assertEquals('Recycled', $displayAttribute->resolveValueAsLabelForHeaderCell($contactStates[2]->id)); }
/** * Get an array of states from the starting state onwards, id/translated label pairings of the * existing contact states ordered by order. * @param string $language * @return array */ public static function getLeadStateDataFromStartingStateLabelByLanguage($language) { assert('is_string($language)'); $leadStatesData = array(); $states = ContactState::getAll('order'); $startingState = ContactsUtil::getStartingStateId(); foreach ($states as $state) { if ($startingState == $state->id) { break; } $state->name = ContactsUtil::resolveStateLabelByLanguage($state, $language); $leadStatesData[] = $state; } return $leadStatesData; }
public function testContactStateModelAttributesAdapter() { Yii::app()->user->userModel = User::getByUsername('super'); $this->assertTrue(ContactsModule::loadStartingData()); $this->assertEquals(6, count(ContactState::GetAll())); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state'); $compareData = array(0 => 'New', 1 => 'In Progress', 2 => 'Recycled', 3 => 'Dead', 4 => 'Qualified', 5 => 'Customer'); $this->assertEquals($compareData, $attributeForm->contactStatesData); $this->assertEquals(null, $attributeForm->contactStatesLabels); $this->assertEquals(4, $attributeForm->startingStateOrder); //Now add new values. $attributeForm->contactStatesData = array(0 => 'New', 1 => 'In Progress', 2 => 'Recycled', 3 => 'Dead', 4 => 'Qualified', 5 => 'Customer', 6 => 'AAA', 7 => 'BBB'); $contactStatesLabels = array('fr' => array('New', 'In ProgressFr', 'RecycledFr', 'DeadFr', 'QualifiedFr', 'CustomerFr', 'AAAFr', 'BBBFr')); $attributeForm->contactStatesLabels = $contactStatesLabels; $attributeForm->startingStateOrder = 5; $adapter = new ContactStateModelAttributesAdapter(new Contact()); $adapter->setAttributeMetadataFromForm($attributeForm); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state'); $compareData = array(0 => 'New', 1 => 'In Progress', 2 => 'Recycled', 3 => 'Dead', 4 => 'Qualified', 5 => 'Customer', 6 => 'AAA', 7 => 'BBB'); $this->assertEquals($compareData, $attributeForm->contactStatesData); $this->assertEquals($contactStatesLabels, $attributeForm->contactStatesLabels); $contactState = ContactState::getByName('Customer'); $this->assertEquals(5, $contactState[0]->order); $this->assertEquals(5, $attributeForm->startingStateOrder); //Test removing existing values. $attributeForm->contactStatesData = array(0 => 'New', 1 => 'In Progress', 2 => 'Recycled', 3 => 'Customer', 4 => 'AAA', 5 => 'BBB'); $attributeForm->startingStateOrder = 5; $adapter = new ContactStateModelAttributesAdapter(new Contact()); $adapter->setAttributeMetadataFromForm($attributeForm); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state'); $compareData = array(0 => 'New', 1 => 'In Progress', 2 => 'Recycled', 3 => 'Customer', 4 => 'AAA', 5 => 'BBB'); $this->assertEquals($compareData, $attributeForm->contactStatesData); $this->assertEquals(5, $attributeForm->startingStateOrder); //Test switching order of existing values. $attributeForm->contactStatesData = array(0 => 'New', 3 => 'In Progress', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB'); $attributeForm->startingStateOrder = 2; $adapter = new ContactStateModelAttributesAdapter(new Contact()); $adapter->setAttributeMetadataFromForm($attributeForm); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state'); $compareData = array(0 => 'New', 3 => 'In Progress', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB'); $this->assertEquals($compareData, $attributeForm->contactStatesData); $this->assertEquals(2, $attributeForm->startingStateOrder); //Test switching order of existing values and adding new values mixed in. $attributeForm->contactStatesData = array(3 => 'New', 6 => 'In Progress', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB', 0 => 'CCC'); $attributeForm->startingStateOrder = 2; $adapter = new ContactStateModelAttributesAdapter(new Contact()); $adapter->setAttributeMetadataFromForm($attributeForm); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state'); $compareData = array(3 => 'New', 6 => 'In Progress', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB', 0 => 'CCC'); $this->assertEquals($compareData, $attributeForm->contactStatesData); $this->assertEquals(2, $attributeForm->startingStateOrder); //Switching name of existing state $this->assertEquals(7, count(ContactState::getAll())); $attributeForm->contactStatesDataExistingValues = array(3 => 'New', 6 => 'In Progress', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB', 0 => 'CCC'); $attributeForm->contactStatesData = array(3 => 'New', 6 => 'In Progress Plastic', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB', 0 => 'CCC'); $attributeForm->startingStateOrder = 2; $adapter = new ContactStateModelAttributesAdapter(new Contact()); $adapter->setAttributeMetadataFromForm($attributeForm); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state'); $compareData = array(3 => 'New', 6 => 'In Progress Plastic', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB', 0 => 'CCC'); $this->assertEquals($compareData, $attributeForm->contactStatesData); $this->assertEquals(2, $attributeForm->startingStateOrder); $this->assertEquals(7, count(ContactState::getAll())); }
public function testGetContactsByAnyPhone() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $contactStates = ContactState::getAll(); $this->assertTrue(count($contactStates) > 1); $firstContactState = $contactStates[0]; $contact = new Contact(); $contact->title->value = 'Mr.'; $contact->firstName = 'test contact'; $contact->lastName = 'for search by any phone'; $contact->owner = $super; $contact->state = $firstContactState; $contact->primaryEmail = new Email(); $contact->primaryEmail->emailAddress = '*****@*****.**'; $contact->mobilePhone = '123-456-789'; $contact->officePhone = '987-654-321'; $this->assertTrue($contact->save()); $data = ContactSearch::getContactsByAnyPhone('123-456-789'); $this->assertEquals(1, count($data)); $data = ContactSearch::getContactsByAnyPhone('987-654-321'); $this->assertEquals(1, count($data)); $data = ContactSearch::getContactsByAnyPhone('987-987-987'); $this->assertEquals(0, count($data)); }