/** * Used on first load to install ContactState data * and the startingState for the Contacts module. * @return true/false if data was in fact loaded. */ public static function loadStartingData() { if (count(ContactState::GetAll()) != 0) { return false; } $data = array(Zurmo::t('Core', 'New'), Zurmo::t('Core', 'In Progress'), Zurmo::t('ContactsModule', 'Recycled'), Zurmo::t('ContactsModule', 'Dead'), Zurmo::t('ContactsModule', 'Qualified'), Zurmo::t('ZurmoModule', 'Customer')); $order = 0; $startingStateId = null; foreach ($data as $stateName) { $state = new ContactState(); $state->name = $stateName; $state->order = $order; $saved = $state->save(); assert('$saved'); if ($stateName == Zurmo::t('ContactsModule', 'Qualified')) { $startingStateId = $state->id; } $order++; } if ($startingStateId == null) { throw new NotSupportedException(); } $metadata = ContactsModule::getMetadata(); $metadata['global']['startingStateId'] = $startingStateId; ContactsModule::setMetadata($metadata); assert('count(ContactState::GetAll()) == 6'); return true; }
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, ContactState::getCount()); // do a getAll to ensure we create base currency $baseCurrency = Currency::getAll(); $this->assertCount(1, $baseCurrency); $this->assertEquals(1, Currency::getCount()); $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, ContactState::getCount()); $this->assertEquals(1, Currency::getCount()); }
/** * Given a contact state id, attempt to get and return a contact state object. If the id is invalid, then an * InvalidValueToSanitizeException will be thrown. * @param mixed $value * @return sanitized value * @throws InvalidValueToSanitizeException * @throws NotFoundException */ public function sanitizeValue($value) { assert('$this->attributeName == null'); if ($value == null) { return $value; } try { if ((int) $value <= 0) { $states = ContactState::getByName($value); if (count($states) > 1) { throw new InvalidValueToSanitizeException(Zurmo::t('ContactsModule', 'Status specified is not unique and is invalid.')); } elseif (count($states) == 0) { throw new NotFoundException(); } $state = $states[0]; } else { $state = ContactState::getById($value); } $startingState = ContactsUtil::getStartingState(); if (!static::resolvesValidStateByOrder($state->order, $startingState->order)) { throw new InvalidValueToSanitizeException(Zurmo::t('ZurmoModule', 'Status specified is invalid.')); } return $state; } catch (NotFoundException $e) { throw new InvalidValueToSanitizeException(Zurmo::t('ContactsModule', 'Status specified does not exist.')); } }
public function testGetExportValue() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $data = array(); $contactStates = ContactState::getByName('Qualified'); $contact = new Contact(); $contact->owner = $super; $contact->firstName = 'Super'; $contact->lastName = 'Man'; $contact->jobTitle = 'Superhero'; $contact->description = 'Some Description'; $contact->department = 'Red Tape'; $contact->officePhone = '1234567890'; $contact->mobilePhone = '0987654321'; $contact->officeFax = '1222222222'; $contact->state = $contactStates[0]; $this->assertTrue($contact->save()); $adapter = new ContactStateRedBeanModelAttributeValueToExportValueAdapter($contact, 'state'); $adapter->resolveData($data); $compareData = array($contactStates[0]->name); $this->assertEquals($compareData, $data); $data = array(); $adapter->resolveHeaderData($data); $compareData = array($contact->getAttributeLabel('state')); $this->assertEquals($compareData, $data); }
public function testCreateAndGetContactWebFormById() { $allAttributes = ContactWebFormsUtil::getAllAttributes(); $placedAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle'); $contactFormAttributes = ContactWebFormsUtil::getAllPlacedAttributes($allAttributes, $placedAttributes); $attributes = array_keys($contactFormAttributes); $this->assertTrue(ContactsModule::loadStartingData()); $contactStates = ContactState::getByName('New'); $contactWebForm = new ContactWebForm(); $contactWebForm->name = 'Test Form'; $contactWebForm->redirectUrl = 'http://google.com'; $contactWebForm->submitButtonLabel = 'Save'; $contactWebForm->defaultState = $contactStates[0]; $contactWebForm->serializedData = serialize($attributes); $contactWebForm->defaultOwner = Yii::app()->user->userModel; $this->assertTrue($contactWebForm->save()); $id = $contactWebForm->id; unset($contactWebForm); $contactWebForm = ContactWebForm::getById($id); $this->assertEquals('Test Form', $contactWebForm->name); $this->assertEquals('http://google.com', $contactWebForm->redirectUrl); $this->assertEquals('Save', $contactWebForm->submitButtonLabel); $this->assertEquals('New', $contactWebForm->defaultState->name); $this->assertEquals($attributes, unserialize($contactWebForm->serializedData)); }
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(); } }
/** * Utilized to create or update model attribute values after a workflow's triggers are fired as true. * @param WorkflowActionProcessingModelAdapter $adapter * @param string $attribute * @throws NotSupportedException */ public function resolveValueAndSetToModel(WorkflowActionProcessingModelAdapter $adapter, $attribute) { assert('is_string($attribute)'); if ($this->type == WorkflowActionAttributeForm::TYPE_STATIC) { $adapter->getModel()->{$attribute} = ContactState::getById((int) $this->value); //todo: what if it doesn't exist anymore? } else { throw new NotSupportedException(); } }
public function testCreateAndGetContactWebFormEntryById() { $allAttributes = ContactWebFormsUtil::getAllAttributes(); $placedAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle'); $contactFormAttributes = ContactWebFormsUtil::getAllPlacedAttributes($allAttributes, $placedAttributes); $attributes = array_keys($contactFormAttributes); $this->assertTrue(ContactsModule::loadStartingData()); $contactStates = ContactState::getByName('New'); $contactWebForm = new ContactWebForm(); $contactWebForm->name = 'Test Form'; $contactWebForm->redirectUrl = 'http://google.com'; $contactWebForm->submitButtonLabel = 'Save'; $contactWebForm->defaultState = $contactStates[0]; $contactWebForm->defaultOwner = Yii::app()->user->userModel; $contactWebForm->serializedData = serialize($attributes); $contactWebForm->save(); $contact = new Contact(); $contact->owner = $contactWebForm->defaultOwner; $contact->state = $contactWebForm->defaultState; $contact->firstName = 'Super'; $contact->lastName = 'Man'; $contact->jobTitle = 'Superhero'; $contact->companyName = 'Test Inc.'; if ($contact->validate()) { $contactWebFormEntryStatus = ContactWebFormEntry::STATUS_SUCCESS; $contactWebFormEntryMessage = ContactWebFormEntry::STATUS_SUCCESS_MESSAGE; } else { $contactWebFormEntryStatus = ContactWebFormEntry::STATUS_ERROR; $contactWebFormEntryMessage = ContactWebFormEntry::STATUS_ERROR_MESSAGE; } $contact->save(); foreach ($contactFormAttributes as $attributeName => $attributeValue) { $contactFormAttributes[$attributeName] = $contact->{$attributeName}; } $contactFormAttributes['owner'] = $contactWebForm->defaultOwner->id; $contactFormAttributes['state'] = $contactWebForm->defaultState->id; $contactWebFormEntry = new ContactWebFormEntry(); $contactWebFormEntry->serializedData = serialize($contactFormAttributes); $contactWebFormEntry->status = $contactWebFormEntryStatus; $contactWebFormEntry->message = $contactWebFormEntryMessage; $contactWebFormEntry->contactWebForm = $contactWebForm; $contactWebFormEntry->contact = $contact; $this->assertTrue($contactWebFormEntry->save()); $contactWebFormEntryId = $contactWebFormEntry->id; unset($contactWebFormEntry); $contactWebFormEntry = ContactWebFormEntry::getById($contactWebFormEntryId); $this->assertEquals('Test Form', $contactWebFormEntry->contactWebForm->name); $this->assertEquals('Super', $contactWebFormEntry->contact->firstName); $this->assertEquals('Man', $contactWebFormEntry->contact->lastName); $contactFormAttributes = unserialize($contactWebFormEntry->serializedData); $this->assertEquals('Super', $contactFormAttributes['firstName']); $this->assertEquals('Man', $contactFormAttributes['lastName']); $this->assertEquals('Superhero', $contactFormAttributes['jobTitle']); $this->assertEquals('Test Inc.', $contactFormAttributes['companyName']); }
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; }
/** * @depends testGetModelsByFullName */ public function testCasingInsensitivity() { Yii::app()->user->userModel = User::getByUsername('super'); $user = User::getByUsername('billy'); ContactsModule::loadStartingData(); $states = ContactState::GetAll(); $contact = new Contact(); $contact->owner = $user; $contact->title->value = 'Mr.'; $contact->firstName = 'super'; $contact->lastName = 'man'; $contact->state = $states[0]; $this->assertTrue($contact->save()); $id = $contact->id; $this->assertNotEmpty($id); unset($contact); $contacts = ZurmoModelSearch::getModelsByFullName('Contact', 'Super Man'); $this->assertEquals(2, count($contacts)); }
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 static function createContactWebFormByName($name, $owner = null) { if ($owner === null) { $owner = Yii::app()->user->userModel; } $placedAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle'); ContactsModule::loadStartingData(); $contactStates = ContactState::getByName('New'); $contactWebForm = new ContactWebForm(); $contactWebForm->name = $name; $contactWebForm->redirectUrl = 'http://www.zurmo.com/'; $contactWebForm->submitButtonLabel = 'Save'; $contactWebForm->defaultState = $contactStates[0]; $contactWebForm->serializedData = serialize($placedAttributes); $contactWebForm->defaultOwner = $owner; $saved = $contactWebForm->save(); assert('$saved'); return $contactWebForm; }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); $loaded = ContactsModule::loadStartingData(); assert($loaded); // Not Coding Standard $contactStates = ContactState::getByName('New'); self::$newState = $contactStates[0]; $contactStates = ContactState::getByName('In progress'); self::$inProgressState = $contactStates[0]; $contactStates = ContactState::getByName('Recycled'); self::$recycledState = $contactStates[0]; $contactStates = ContactState::getByName('Dead'); self::$deadState = $contactStates[0]; $contactStates = ContactState::getByName('Qualified'); self::$qualifiedState = $contactStates[0]; $contactStates = ContactState::getByName('Customer'); self::$customerState = $contactStates[0]; }
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]); }
/** * Contact state is required. If the value provided is null then the sanitizer will attempt use a default * value if provided. If this is missing then a InvalidValueToSanitizeException will be thrown. * @param mixed $value * @return sanitized value * @throws InvalidValueToSanitizeException */ public function sanitizeValue($value) { assert('$this->attributeName == null'); assert('is_string($value) || $value == null || $value instanceof ContactState'); $modelClassName = $this->modelClassName; $model = new $modelClassName(false); if ($value == null) { if (isset($this->mappingRuleData['defaultStateId']) && $this->mappingRuleData['defaultStateId'] != null) { try { $state = ContactState::getById((int) $this->mappingRuleData['defaultStateId']); } catch (NotFoundException $e) { throw new InvalidValueToSanitizeException(Zurmo::t('ContactsModule', 'The default status specified does not exist.')); } return $state; } else { throw new InvalidValueToSanitizeException(Zurmo::t('ContactsModule', 'The status is required. Neither a value nor a default was specified.')); } } return $value; }
public function testRenderHtmlContentLabelFromContactAndKeyword() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $contact = new Contact(); $contact->firstName = 'johnny'; $contact->lastName = 'five'; $contact->owner = $super; $contact->state = ContactState::getById(5); $contact->primaryEmail = new Email(); $contact->primaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($contact->save()); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $contact2 = new Contact(); $contact2->firstName = 'johnny'; $contact2->lastName = 'six'; $contact2->owner = $super; $contact2->state = ContactState::getById(5); $contact2->primaryEmail = new Email(); $contact2->primaryEmail->emailAddress = '*****@*****.**'; $contact2->secondaryEmail = new Email(); $contact2->secondaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($contact2->save()); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $contact3 = new Contact(); $contact3->firstName = 'johnny'; $contact3->lastName = 'seven'; $contact3->owner = $super; $contact3->state = ContactState::getById(5); $this->assertTrue($contact3->save()); $content = MultipleContactsForMeetingElement::renderHtmlContentLabelFromContactAndKeyword($contact, 'asdad'); $this->assertEquals('johnny five  <b>a@a.com</b>', $content); $content = MultipleContactsForMeetingElement::renderHtmlContentLabelFromContactAndKeyword($contact2, 'b@b'); $this->assertEquals('johnny six  <b>b@b.com</b>', $content); $content = MultipleContactsForMeetingElement::renderHtmlContentLabelFromContactAndKeyword($contact2, 'cc'); $this->assertEquals('johnny six  <b>a@a.com</b>', $content); $content = MultipleContactsForMeetingElement::renderHtmlContentLabelFromContactAndKeyword($contact3, 'cx'); $this->assertEquals('johnny seven', $content); }
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 function testCreateAndGetContactWebFormById() { ContactWebFormTestHelper::deleteAllContactWebForms(); $placedAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle'); $this->assertTrue(ContactsModule::loadStartingData()); $contactStates = ContactState::getByName('New'); $contactWebForm = new ContactWebForm(); $contactWebForm->name = 'Test Form'; $contactWebForm->redirectUrl = 'http://zurmo.com'; $contactWebForm->submitButtonLabel = 'Save'; $contactWebForm->defaultState = $contactStates[0]; $contactWebForm->serializedData = serialize($placedAttributes); $contactWebForm->defaultOwner = Yii::app()->user->userModel; $this->assertTrue($contactWebForm->save()); $id = $contactWebForm->id; unset($contactWebForm); $contactWebForm = ContactWebForm::getById($id); $this->assertEquals('Test Form', $contactWebForm->name); $this->assertEquals('http://zurmo.com', $contactWebForm->redirectUrl); $this->assertEquals('Save', $contactWebForm->submitButtonLabel); $this->assertEquals('New', $contactWebForm->defaultState->name); $this->assertEquals($placedAttributes, unserialize($contactWebForm->serializedData)); $this->assertNull($contactWebForm->defaultPermissionSetting); $this->assertNull($contactWebForm->defaultPermissionGroupSetting); $contactWebForm->name = 'New Test Form'; $contactWebForm->redirectUrl = 'http://zurmo.org'; $contactWebForm->submitButtonLabel = 'Save and Redirect'; $contactWebForm->defaultPermissionSetting = UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_EVERYONE; $this->assertTrue($contactWebForm->save()); $id = $contactWebForm->id; unset($contactWebForm); $contactWebForm = ContactWebForm::getById($id); $this->assertEquals('New Test Form', $contactWebForm->name); $this->assertEquals('http://zurmo.org', $contactWebForm->redirectUrl); $this->assertEquals('Save and Redirect', $contactWebForm->submitButtonLabel); $this->assertEquals($contactWebForm->defaultPermissionSetting, UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_EVERYONE); $this->assertNull($contactWebForm->defaultPermissionGroupSetting); }
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 testAccountAndContactIndustries() { Yii::app()->user->userModel = User::getByUsername('super'); $values = array('Automotive', 'Adult Entertainment', 'Financial Services', 'Mercenaries & Armaments'); $industryFieldData = CustomFieldData::getByName('Industries'); $industryFieldData->defaultValue = $values[0]; $industryFieldData->serializedData = serialize($values); $this->assertTrue($industryFieldData->save()); unset($industryFieldData); $user = UserTestHelper::createBasicUser('Billy'); $account = new Account(); $account->name = 'Consoladores-R-Us'; $account->owner = $user; $data = unserialize($account->industry->data->serializedData); $this->assertEquals('Automotive', $account->industry->value); $account->industry->value = $values[1]; $this->assertTrue($account->save()); unset($account); ContactsModule::loadStartingData(); $states = ContactState::GetAll(); $contact = new Contact(); $contact->firstName = 'John'; $contact->lastName = 'Johnson'; $contact->owner = $user; $contact->state = $states[0]; $values = unserialize($contact->industry->data->serializedData); $this->assertEquals(4, count($values)); $contact->industry->value = $values[3]; $this->assertTrue($contact->save()); unset($contact); $accounts = Account::getByName('Consoladores-R-Us'); $account = $accounts[0]; $this->assertEquals('Adult Entertainment', $account->industry->value); $contacts = Contact::getAll(); $contact = $contacts[0]; $this->assertEquals('Mercenaries & Armaments', $contact->industry->value); }
public static function getSecondModel($user) { $industryValues = AccountListViewMergeTestHelper::getIndustryValues(); $account = new Account(); $account->name = 'New Account'; $account->owner = $user; assert($account->save()); // Not Coding Standard $contactCustomerStates = ContactState::getByName('Customer'); $contact2 = ContactTestHelper::createContactByNameForOwner('shozin', Yii::app()->user->userModel); $contact2->title->value = 'Mrs.'; $contact2->state = $contactCustomerStates[0]; $contact2->jobTitle = 'Myhero'; $contact2->source->value = 'Trade Show'; $contact2->companyName = 'Test Company1'; $contact2->account = $account; $contact2->description = 'Hey Description'; $contact2->industry->value = $industryValues[1]; $contact2->department = 'Black Tape'; $contact2->officePhone = '1234567899'; $contact2->mobilePhone = '0987654123'; $contact2->officeFax = '1222222444'; $contact2->website = 'http://yahoo1.com'; $contact2->primaryEmail->emailAddress = '*****@*****.**'; $contact2->primaryEmail->optOut = 0; $contact2->primaryEmail->isInvalid = 0; $contact2->secondaryEmail->emailAddress = '*****@*****.**'; $contact2->secondaryEmail->optOut = 1; $contact2->secondaryEmail->isInvalid = 1; $contact2->primaryAddress->street1 = '302'; $contact2->primaryAddress->street2 = '9A/1'; $contact2->primaryAddress->city = 'New Delhi'; $contact2->primaryAddress->state = 'New Delhi'; $contact2->primaryAddress->postalCode = '110005'; $contact2->primaryAddress->country = 'India'; $contact2->secondaryAddress->street1 = 'A-8'; $contact2->secondaryAddress->street2 = 'Sector 56'; $contact2->secondaryAddress->city = 'Gurgaon'; $contact2->secondaryAddress->state = 'Haryana'; $contact2->secondaryAddress->postalCode = '5123-4'; $contact2->secondaryAddress->country = 'IndiaTest'; assert($contact2->save()); // Not Coding Standard return $contact2; }
/** * @depends testSuperUserDeleteAction */ public function testSuperUserCreateAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //Confirm the starting states exist $this->assertEquals(6, count(ContactState::GetAll())); $startingState = LeadsUtil::getStartingState(); //Create a new contact. $this->resetGetArray(); $this->setPostArray(array('Contact' => array('firstName' => 'myNewLead', 'lastName' => 'myNewLeadson', 'officePhone' => '456765421', 'state' => array('id' => $startingState->id)))); $this->runControllerWithRedirectExceptionAndGetContent('contacts/default/create'); $leads = Contact::getByName('myNewLead myNewLeadson'); $this->assertEquals(1, count($leads)); $this->assertTrue($leads[0]->id > 0); $this->assertTrue($leads[0]->owner == $super); $this->assertTrue($leads[0]->state == $startingState); $this->assertEquals('456765421', $leads[0]->officePhone); $leads = Contact::getAll(); $this->assertEquals(12, count($leads)); }
/** * @depends testApiServerUrl */ public function testCreateLead() { $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'); $industryValues = array('Automotive', 'Adult Entertainment', 'Financial Services', 'Mercenaries & Armaments'); $industryFieldData = CustomFieldData::getByName('Industries'); $industryFieldData->serializedData = serialize($industryValues); $this->assertTrue($industryFieldData->save()); $sourceValues = array('Word of Mouth', 'Outbound', 'Trade Show'); $sourceFieldData = CustomFieldData::getByName('LeadSources'); $sourceFieldData->serializedData = serialize($sourceValues); $this->assertTrue($sourceFieldData->save()); $titles = array('Mr.', 'Mrs.', 'Ms.', 'Dr.', 'Swami'); $customFieldData = CustomFieldData::getByName('Titles'); $customFieldData->serializedData = serialize($titles); $this->assertTrue($customFieldData->save()); $this->assertEquals(6, count(ContactState::GetAll())); $contactStates = ContactState::GetAll(); $primaryEmail['emailAddress'] = "*****@*****.**"; $primaryEmail['optOut'] = 1; $secondaryEmail['emailAddress'] = "*****@*****.**"; $secondaryEmail['optOut'] = 0; $secondaryEmail['isInvalid'] = 1; $primaryAddress['street1'] = '129 Noodle Boulevard'; $primaryAddress['street2'] = 'Apartment 6000A'; $primaryAddress['city'] = 'Noodleville'; $primaryAddress['postalCode'] = '23453'; $primaryAddress['country'] = 'The Good Old US of A'; $secondaryAddress['street1'] = '25 de Agosto 2543'; $secondaryAddress['street2'] = 'Local 3'; $secondaryAddress['city'] = 'Ciudad de Los Fideos'; $secondaryAddress['postalCode'] = '5123-4'; $secondaryAddress['country'] = 'Latinoland'; $account = new Account(); $account->name = 'Some Account'; $account->owner = $super; $this->assertTrue($account->save()); $data['firstName'] = "Michael"; $data['lastName'] = "Smith"; $data['jobTitle'] = "President"; $data['department'] = "Sales"; $data['officePhone'] = "653-235-7824"; $data['mobilePhone'] = "653-235-7821"; $data['officeFax'] = "653-235-7834"; $data['description'] = "Some desc."; $data['companyName'] = "Michael Co"; $data['website'] = "http://sample.com"; $data['industry']['value'] = $industryValues[2]; $data['source']['value'] = $sourceValues[1]; $data['title']['value'] = $titles[3]; $data['state']['id'] = LeadsUtil::getStartingState()->id; $data['account']['id'] = $account->id; $data['primaryEmail'] = $primaryEmail; $data['secondaryEmail'] = $secondaryEmail; $data['primaryAddress'] = $primaryAddress; $data['secondaryAddress'] = $secondaryAddress; $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/create/', 'POST', $headers, array('data' => $data)); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $data['owner'] = array('id' => $super->id, 'username' => 'super'); $data['createdByUser'] = array('id' => $super->id, 'username' => 'super'); $data['modifiedByUser'] = array('id' => $super->id, 'username' => 'super'); // We need to unset some empty values from response. unset($response['data']['createdDateTime']); unset($response['data']['modifiedDateTime']); unset($response['data']['primaryEmail']['id']); unset($response['data']['primaryEmail']['isInvalid']); unset($response['data']['secondaryEmail']['id']); unset($response['data']['primaryAddress']['id']); unset($response['data']['primaryAddress']['state']); unset($response['data']['primaryAddress']['longitude']); unset($response['data']['primaryAddress']['latitude']); unset($response['data']['primaryAddress']['invalid']); unset($response['data']['secondaryAddress']['id']); unset($response['data']['secondaryAddress']['state']); unset($response['data']['secondaryAddress']['longitude']); unset($response['data']['secondaryAddress']['latitude']); unset($response['data']['secondaryAddress']['invalid']); unset($response['data']['industry']['id']); unset($response['data']['source']['id']); unset($response['data']['title']['id']); unset($response['data']['id']); unset($response['data']['googleWebTrackingId']); ksort($data); ksort($response['data']); $this->assertEquals($data, $response['data']); }
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); }
public function testArePermissionsFlushedOnRemovingParentFromChildRole() { Contact::deleteAll(); try { $role = Role::getByName('Parent'); $role->delete(); } catch (NotFoundException $e) { } try { $user = User::getByUsername('jim'); $user->delete(); } catch (NotFoundException $e) { } try { $user = User::getByUsername('jane'); $user->delete(); } catch (NotFoundException $e) { } // we could have used helpers to do a lot of the following stuff (such as creating users, roles, // etc) but we wanted to mimic user's interaction as closely as possible. Hence using walkthroughs // for everything // create Parent and Child Roles, Create Jim to be member of Child role // create parent role $this->resetGetArray(); $this->setPostArray(array('Role' => array('name' => 'Parent'))); $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/role/create'); $parentRole = Role::getByName('Parent'); $this->assertNotNull($parentRole); $this->assertEquals('Parent', strval($parentRole)); $parentRoleId = $parentRole->id; // create child role $this->resetGetArray(); $this->setPostArray(array('Role' => array('name' => 'Child', 'role' => array('id' => $parentRoleId)))); $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/role/create'); $childRole = Role::getByName('Child'); $this->assertNotNull($childRole); $this->assertEquals('Child', strval($childRole)); $parentRole->forgetAll(); $parentRole = Role::getById($parentRoleId); $childRoleId = $childRole->id; $childRole->forgetAll(); $childRole = Role::getById($childRoleId); $this->assertEquals($childRole->id, $parentRole->roles[0]->id); // create jim's user $this->resetGetArray(); $this->setPostArray(array('UserPasswordForm' => array('firstName' => 'Some', 'lastName' => 'Body', 'username' => 'jim', 'newPassword' => 'myPassword123', 'newPassword_repeat' => 'myPassword123', 'officePhone' => '456765421', 'userStatus' => 'Active', 'role' => array('id' => $childRoleId)))); $this->runControllerWithRedirectExceptionAndGetContent('/users/default/create'); $jim = User::getByUsername('jim'); $this->assertNotNull($jim); $childRole->forgetAll(); $childRole = Role::getById($childRoleId); $this->assertEquals($childRole->id, $jim->role->id); // give jim rights to contact's module $jim->setRight('ContactsModule', ContactsModule::getAccessRight()); $jim->setRight('ContactsModule', ContactsModule::getCreateRight()); $this->assertTrue($jim->save()); $jim->forgetAll(); $jim = User::getByUsername('jim'); // create jane's user $this->resetGetArray(); $this->setPostArray(array('UserPasswordForm' => array('firstName' => 'Some', 'lastName' => 'Body', 'username' => 'jane', 'newPassword' => 'myPassword123', 'newPassword_repeat' => 'myPassword123', 'officePhone' => '456765421', 'userStatus' => 'Active', 'role' => array('id' => $parentRoleId)))); $this->runControllerWithRedirectExceptionAndGetContent('/users/default/create'); $jane = User::getByUsername('jane'); $this->assertNotNull($jane); $parentRole->forgetAll(); $parentRole = Role::getById($parentRoleId); $this->assertEquals($parentRole->id, $jane->role->id); // give jane rights to contact's module, we need to do this because once the link between parent and child // role is broken jane won't be able to access the listview of contacts $jane->setRight('ContactsModule', ContactsModule::getAccessRight()); $this->assertTrue($jane->save()); $jane->forgetAll(); $jane = User::getByUsername('jane'); // create a contact from jim's account // create ContactStates ContactsModule::loadStartingData(); // ensure contact states have been created $this->assertEquals(6, count(ContactState::GetAll())); $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim'); // go ahead and create contact with parent role given readwrite. $startingState = ContactsUtil::getStartingState(); $this->resetGetArray(); $this->setPostArray(array('Contact' => array('firstName' => 'Jim', 'lastName' => 'Doe', 'officePhone' => '456765421', 'state' => array('id' => $startingState->id)))); $url = $this->runControllerWithRedirectExceptionAndGetUrl('/contacts/default/create'); $jimDoeContactId = intval(substr($url, strpos($url, 'id=') + 3)); $jimDoeContact = Contact::getById($jimDoeContactId); $this->assertNotNull($jimDoeContact); $this->resetPostArray(); $this->setGetArray(array('id' => $jimDoeContactId)); $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details'); $this->assertContains('Who can read and write Owner', $content); // create a contact using jane which she would see at all times $this->logoutCurrentUserLoginNewUserAndGetByUsername('jane'); $this->resetGetArray(); $this->setPostArray(array('Contact' => array('firstName' => 'Jane', 'lastName' => 'Doe', 'officePhone' => '456765421', 'state' => array('id' => $startingState->id)))); $url = $this->runControllerWithRedirectExceptionAndGetUrl('/contacts/default/create'); $janeDoeContactId = intval(substr($url, strpos($url, 'id=') + 3)); $janeDoeContact = Contact::getById($jimDoeContactId); $this->assertNotNull($janeDoeContact); $this->resetPostArray(); $this->setGetArray(array('id' => $janeDoeContactId)); $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details'); $this->assertContains('Who can read and write Owner', $content); // ensure jim can see that contact everywhere // jim should have access to see contact on list view $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim'); $this->resetGetArray(); // get the page, ensure the name of contact does show up there. $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default'); $this->assertContains('Jim Doe</a></td><td>', $content); $this->assertNotContains('Jane Doe</a></td><td>', $content); // jim should have access to jimDoeContact's detail view $this->setGetArray(array('id' => $jimDoeContactId)); $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details'); // jim should have access to jimDoeContact's edit view $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit'); // jim should not have access to janeDoeContact's detail view $this->setGetArray(array('id' => $janeDoeContactId)); try { $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details'); $this->fail('Accessing details action should have thrown ExitException'); } catch (ExitException $e) { // just cleanup buffer $this->endAndGetOutputBuffer(); } // jim should have access to janeDoeContact's edit view try { $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit'); $this->fail('Accessing edit action should have thrown ExitException'); } catch (ExitException $e) { // just cleanup buffer $this->endAndGetOutputBuffer(); } // ensure jane can see that contact everywhere // jane should have access to see contact on list view $this->logoutCurrentUserLoginNewUserAndGetByUsername('jane'); $this->resetGetArray(); // get the page, ensure the name of contact does show up there. $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default'); $this->assertContains('Jim Doe</a></td><td>', $content); $this->assertContains('Jane Doe</a></td><td>', $content); // jane should have access to jimDoeContact's detail view $this->setGetArray(array('id' => $jimDoeContactId)); $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details'); // jane should have access to jimDoeContact's edit view $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit'); // jane should have access to janeDoeContact's detail view $this->setGetArray(array('id' => $janeDoeContactId)); $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details'); // jane should have access to janeDoeContact's edit view $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit'); // unlink Parent role from child $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $this->setGetArray(array('id' => $childRoleId)); $this->setPostArray(array('Role' => array('name' => 'Child', 'role' => array('id' => '')))); $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/role/edit'); $childRole = Role::getByName('Child'); $this->assertNotNull($childRole); $this->assertEquals('Child', strval($childRole)); $parentRole->forgetAll(); $parentRole = Role::getById($parentRoleId); $this->assertNotNull($parentRole); $this->assertCount(0, $parentRole->roles); // ensure jim can still see that contact everywhere // jim should have access to see contact on list view $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim'); $this->resetGetArray(); // get the page, ensure the name of contact does show up there. $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default'); $this->assertContains('Jim Doe</a></td><td>', $content); $this->assertNotContains('Jane Doe</a></td><td>', $content); // jim should have access to jimDoeContact's detail view $this->setGetArray(array('id' => $jimDoeContactId)); $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details'); // jim should have access to jimDoeContact's edit view $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit'); // jim should not have access to janeDoeContact's detail view $this->setGetArray(array('id' => $janeDoeContactId)); try { $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details'); $this->fail('Accessing details action should have thrown ExitException'); } catch (ExitException $e) { // just cleanup buffer $this->endAndGetOutputBuffer(); } // jim should have access to janeDoeContact's edit view try { $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit'); $this->fail('Accessing edit action should have thrown ExitException'); } catch (ExitException $e) { // just cleanup buffer $this->endAndGetOutputBuffer(); } // ensure jane can not see that contact anywhere // jane should have access to see contact on list view $this->logoutCurrentUserLoginNewUserAndGetByUsername('jane'); $this->resetGetArray(); // get the page, ensure the name of contact does not show up there. $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default'); $this->assertNotContains('Jim Doe</a></td><td>', $content); $this->assertContains('Jane Doe</a></td><td>', $content); // jane should have access to janeDoeContact's detail view $this->setGetArray(array('id' => $janeDoeContactId)); $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details'); // jane should have access to janeDoeContact's edit view $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit'); // jane should not have access to jimDoeContact's detail view $this->setGetArray(array('id' => $jimDoeContactId)); try { $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details'); $this->fail('Accessing details action should have thrown ExitException'); } catch (ExitException $e) { // just cleanup buffer $this->endAndGetOutputBuffer(); } // jane should not have access to jimDoeContact's edit view try { $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit'); $this->fail('Accessing edit action should have thrown ExitException'); } catch (ExitException $e) { // just cleanup buffer $this->endAndGetOutputBuffer(); } }
/** * @depends testDeleteOfTheContactForTheCustomFieldsPlacedForContactsModule */ public function testWhetherSearchWorksForTheCustomFieldsPlacedForContactsModuleAfterDeletingTheContact() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //Retrieve the super account id and the super user id. $accountId = self::getModelIdByModelNameAndName('Account', 'superAccount'); $superUserId = $super->id; //Retrieve the Contact State (Status) Id based on the name. $contactState = ContactState::getByName('RecycledC'); $contactStateId = $contactState[0]->id; //Search a created contact using the customfields. $this->resetPostArray(); $this->setGetArray(array('ContactsSearchForm' => ContactsDesignerWalkthroughHelperUtil::fetchContactsSearchFormGetData($contactStateId, $superUserId, $accountId), 'ajax' => 'list-view')); $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default'); //Assert that the edit contact does not exits after the search. $this->assertTrue(strpos($content, "No results found.") > 0); $this->assertFalse(strpos($content, "26378 South Arlington Ave") > 0); }
/** * There was a bug with showing address->state on a contact rows and columns report. it was showing the * contact->state instead. this test passes after this bug was fixed */ public function testDisplayingAOwnedModelAttributeThatIsAlsoDefinedAsAnAttributeOnTheOwningModel() { $contactStates = ContactState::getByName('Qualified'); $contact = new Contact(); $contact->owner = Yii::app()->user->userModel; $contact->title->value = 'Mr.'; $contact->firstName = 'Super'; $contact->lastName = 'Man'; $contact->jobTitle = 'Superhero'; $contact->description = 'Some Description'; $contact->department = 'Red Tape'; $contact->officePhone = '1234567890'; $contact->mobilePhone = '0987654321'; $contact->officeFax = '1222222222'; $contact->state = $contactStates[0]; $contact->primaryAddress->state = 'IL'; $this->assertTrue($contact->save()); $displayAttribute = new DisplayAttributeForReportForm('ContactsModule', 'Contact', Report::TYPE_ROWS_AND_COLUMNS); $displayAttribute->setModelAliasUsingTableAliasName('abc'); $displayAttribute->attributeIndexOrDerivedType = 'primaryAddress___state'; $this->assertEquals('col0', $displayAttribute->columnAliasName); $reportResultsRowData = new ReportResultsRowData(array($displayAttribute), 4); $reportResultsRowData->addModelAndAlias($contact, 'abc'); $model = $reportResultsRowData->getModel('attribute0'); $this->assertEquals('IL', $model->primaryAddress->state); $this->assertEquals('IL', $reportResultsRowData->attribute0); }
/** * @depends testDeleteOfTheLeadUserForTheCustomFieldsPlacedForLeadsModule */ public function testWhetherSearchWorksForTheCustomFieldsPlacedForLeadsModuleAfterDeletingTheLead() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //Retrieve the super user id. $superUserId = $super->id; //Retrieve the Lead State (Status) Id based on the name. $leadState = ContactState::getByName('In Progress'); $leadStateId = $leadState[0]->id; //Search a created lead using the customfields. $this->resetPostArray(); $this->setGetArray(array('LeadsSearchForm' => LeadsDesignerWalkthroughHelperUtil::fetchLeadsSearchFormGetData($leadStateId, $superUserId), 'ajax' => 'list-view')); $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default'); //Assert that the edit lead does not exits after the search. $this->assertContains("No results found", $content); $this->assertNotContains("26378 South Arlington Ave", $content); }