/** * 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; }
/** * @depends testResolveContactStateAdapterByModulesUserHasAccessTo */ public function testGetContactStateDataFromStartingStateOnAndKeyedById() { $this->assertTrue(ContactsModule::loadStartingData()); $this->assertEquals(6, count(ContactState::GetAll())); $contactStates = ContactsUtil::GetContactStateDataFromStartingStateOnAndKeyedById(); $this->assertEquals(2, count($contactStates)); }
/** * @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 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 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 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']); }
/** * @depends testCreateContact */ public function testCreateContactWithSpecificExplicitPermissions() { $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 with owner only"; $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'] = ContactsUtil::getStartingState()->id; $data['account']['id'] = $account->id; $data['primaryEmail'] = $primaryEmail; $data['secondaryEmail'] = $secondaryEmail; $data['primaryAddress'] = $primaryAddress; $data['secondaryAddress'] = $secondaryAddress; // TODO: @Shoaibi/@Ivica: null does not work, empty works. null doesn't send it. $data['explicitReadWriteModelPermissions'] = array('nonEveryoneGroup' => '', 'type' => ''); $response = $this->createApiCallWithRelativeUrl('create/', 'POST', $headers, array('data' => $data)); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertArrayHasKey('id', $response['data']); $contactId = $response['data']['id']; $this->assertArrayHasKey('owner', $response['data']); $this->assertCount(2, $response['data']['owner']); $this->assertArrayHasKey('id', $response['data']['owner']); $this->assertEquals($super->id, $response['data']['owner']['id']); $this->assertArrayHasKey('explicitReadWriteModelPermissions', $response['data']); $this->assertCount(2, $response['data']['explicitReadWriteModelPermissions']); $this->assertArrayHasKey('type', $response['data']['explicitReadWriteModelPermissions']); $this->assertEquals('', $response['data']['explicitReadWriteModelPermissions']['type']); // following also works. wonder why. //$this->assertTrue(null === $response['data']['explicitReadWriteModelPermissions']['type']); $this->assertArrayHasKey('nonEveryoneGroup', $response['data']['explicitReadWriteModelPermissions']); $this->assertEquals('', $response['data']['explicitReadWriteModelPermissions']['nonEveryoneGroup']); $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']); unset($response['data']['latestActivityDateTime']); ksort($data); ksort($response['data']); $this->assertEquals($data, $response['data']); $response = $this->createApiCallWithRelativeUrl('read/' . $contactId, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertArrayHasKey('data', $response); $this->assertArrayHasKey('owner', $response['data']); $this->assertCount(2, $response['data']['owner']); $this->assertArrayHasKey('id', $response['data']['owner']); $this->assertEquals($super->id, $response['data']['owner']['id']); $this->assertArrayHasKey('explicitReadWriteModelPermissions', $response['data']); $this->assertCount(2, $response['data']['explicitReadWriteModelPermissions']); $this->assertArrayHasKey('type', $response['data']['explicitReadWriteModelPermissions']); $this->assertEquals('', $response['data']['explicitReadWriteModelPermissions']['type']); $this->assertArrayHasKey('nonEveryoneGroup', $response['data']['explicitReadWriteModelPermissions']); $this->assertEquals('', $response['data']['explicitReadWriteModelPermissions']['nonEveryoneGroup']); }
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, ContactState::getCount()); $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, ContactState::getCount()); }
public function testArePermissionsFlushedOnRemovingParentFromChildGroup() { // cleanup Contact::deleteAll(); try { $group = Group::getByName('Child'); $group->delete(); } catch (NotFoundException $e) { } try { $user = User::getByUsername('jim'); $user->delete(); } catch (NotFoundException $e) { } // we could have used helpers to do a lot of the following stuff (such as creating users, groups, // etc) but we wanted to mimic user's interaction as closely as possible. Hence using walkthroughs // for everything // create Parent and Child Groups, Create Jim to be member of Child group // create parent group $this->resetGetArray(); $this->setPostArray(array('Group' => array('name' => 'Parent'))); $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/group/create'); $parentGroup = Group::getByName('Parent'); $this->assertNotNull($parentGroup); $this->assertEquals('Parent', strval($parentGroup)); $parentGroupId = $parentGroup->id; // create child group $this->resetGetArray(); $this->setPostArray(array('Group' => array('name' => 'Child', 'group' => array('id' => $parentGroupId)))); $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/group/create'); $childGroup = Group::getByName('Child'); $this->assertNotNull($childGroup); $this->assertEquals('Child', strval($childGroup)); $parentGroup->forgetAll(); $parentGroup = Group::getById($parentGroupId); // give child rights for contacts module $childGroup->setRight('ContactsModule', ContactsModule::getAccessRight()); $childGroup->setRight('ContactsModule', ContactsModule::getCreateRight()); $this->assertTrue($childGroup->save()); $childGroupId = $childGroup->id; $childGroup->forgetAll(); $childGroup = Group::getById($childGroupId); $this->assertContains($childGroup, $parentGroup->groups); // 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'))); $this->runControllerWithRedirectExceptionAndGetContent('/users/default/create'); $jim = User::getByUsername('jim'); $this->assertNotNull($jim); // set jim's group to child group $this->setGetArray(array('id' => $childGroup->id)); $this->setPostArray(array('GroupUserMembershipForm' => array('userMembershipData' => array($jim->id)))); $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/group/editUserMembership'); $jim->forgetAll(); $jim = User::getByUsername('jim'); $this->assertNotNull($jim); $childGroup->forgetAll(); $childGroup = Group::getById($childGroupId); $this->assertContains($childGroup, $jim->groups); // create a contact with permissions to Parent group // create ContactStates ContactsModule::loadStartingData(); // ensure contact states have been created $this->assertEquals(6, count(ContactState::GetAll())); // go ahead and create contact with parent group given readwrite. $startingState = ContactsUtil::getStartingState(); $this->resetGetArray(); $this->setPostArray(array('Contact' => array('firstName' => 'John', 'lastName' => 'Doe', 'officePhone' => '456765421', 'state' => array('id' => $startingState->id), 'explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_NONEVERYONE_GROUP, 'nonEveryoneGroup' => $parentGroupId)))); $url = $this->runControllerWithRedirectExceptionAndGetUrl('/contacts/default/create'); $johnDoeContactId = intval(substr($url, strpos($url, 'id=') + 3)); $johnDoeContact = Contact::getById($johnDoeContactId); $this->assertNotNull($johnDoeContact); $this->resetPostArray(); $this->setGetArray(array('id' => $johnDoeContactId)); $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details'); $this->assertContains('Who can read and write Parent', $content); // create a contact using jim which he would see at all times $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim'); $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)); $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details'); // ensure jim can see that contact everywhere // jim should have access to see contact on list view $this->resetGetArray(); // get the page, ensure the name of contact does show up there. $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default'); $this->assertContains('John Doe</a></td><td>', $content); $this->assertContains('Jim 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 have access to johnDoeContact's detail view $this->setGetArray(array('id' => $johnDoeContactId)); $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/details'); // jim should have access to johnDoeContact's edit view $this->runControllerWithNoExceptionsAndGetContent('/contacts/default/edit'); // unlink Parent group from child $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $this->setGetArray(array('id' => $childGroupId)); $this->setPostArray(array('Group' => array('name' => 'Child', 'group' => array('id' => '')))); $this->runControllerWithRedirectExceptionAndGetUrl('/zurmo/group/edit'); $childGroup = Group::getByName('Child'); $this->assertNotNull($childGroup); $this->assertEquals('Child', strval($childGroup)); $parentGroup->forgetAll(); $parentGroup = Group::getById($parentGroupId); $this->assertNotContains($childGroup, $parentGroup->groups); // ensure jim can not see that contact anywhere // jim should not have access to see contact on list view $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim'); $this->resetGetArray(); // get the page, ensure the name of contact does not show up there. $content = $this->runControllerWithNoExceptionsAndGetContent('/contacts/default'); $this->assertNotContains('John Doe</a></td><td>', $content); $this->assertContains('Jim 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 johnDoeContact's detail view $this->setGetArray(array('id' => $johnDoeContactId)); 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 not have access to johnDoeContact'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(); } }
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 testUserCannotSeeRelatedModelInformationWithLimitedPermissions() { Yii::app()->user->userModel = User::getByUsername('super'); ContactsModule::loadStartingData(); $user = UserTestHelper::createBasicUser('dtester'); $this->assertTrue($user->id > 0); $user = UserTestHelper::createBasicUser('etester'); $this->assertTrue($user->id > 0); $account = new Account(); $account->name = 'DAccount'; $account->owner = User::getByUsername('dtester'); $saved = $account->save(); assert('$saved'); // Not Coding Standard $states = ContactState::GetAll(); $contact = new Contact(); $contact->owner = User::getByUsername('etester'); $contact->account = $account; $contact->title->value = 'Mr.'; $contact->firstName = 'Super'; $contact->lastName = 'Man'; $contact->state = $states[0]; $this->assertTrue($contact->save()); $id = $contact->id; $this->assertNotEmpty($id); $contact->forget(); Yii::app()->user->userModel = User::getByUsername('etester'); $contact = Contact::getById($id); $this->assertNotEmpty($contact->id); $this->assertEquals(Permission::NONE, $contact->account->getEffectivePermissions(Yii::app()->user->userModel)); }
public function testResolvePersonOrAccountByEmailAddress() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $user = UserTestHelper::createBasicUser('joseph'); $anotherUser = UserTestHelper::createBasicUser('josephine'); $emailAddress = '*****@*****.**'; // There are no users in system with the email. Yii::app()->user->userModel = $user; $personOrAccount = EmailArchivingUtil::resolvePersonOrAccountByEmailAddress($emailAddress, false, false, false); $this->assertNull($personOrAccount); // There is user is system with the email. Yii::app()->user->userModel = $super; $anotherUser->primaryEmail->emailAddress = $emailAddress; $this->assertTrue($anotherUser->save()); $personOrAccount = EmailArchivingUtil::resolvePersonOrAccountByEmailAddress($emailAddress, false, false, false); $this->assertEquals($anotherUser->id, $personOrAccount->id); $this->assertTrue($personOrAccount instanceof User); // Now test email with accounts. // User can access accounts, but there are no accounts in system with the email. $anotherUser->primaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($anotherUser->save()); Yii::app()->user->userModel = $user; $personOrAccount = EmailArchivingUtil::resolvePersonOrAccountByEmailAddress($emailAddress, false, false, true); $this->assertNull($personOrAccount); // User can access accounts, but there are no accounts in system with the email. // But there is user is system with the email Yii::app()->user->userModel = $super; $anotherUser->primaryEmail->emailAddress = $emailAddress; $this->assertTrue($anotherUser->save()); Yii::app()->user->userModel = $user; $personOrAccount = EmailArchivingUtil::resolvePersonOrAccountByEmailAddress($emailAddress, false, false, true); $this->assertEquals($anotherUser->id, $personOrAccount->id); $this->assertTrue($personOrAccount instanceof User); // User can access accounts, and there is account in system with the email. // But owner of email is super users, so it shouldn't return account Yii::app()->user->userModel = $super; $anotherUser->primaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($anotherUser->save()); Yii::app()->user->userModel = $super; $email = new Email(); $email->emailAddress = $emailAddress; $email2 = new Email(); $email2->emailAddress = '*****@*****.**'; $account = new Account(); $account->owner = $super; $account->name = 'Test Account'; $account->primaryEmail = $email; $account->secondaryEmail = $email2; $this->assertTrue($account->save()); Yii::app()->user->userModel = $user; $personOrAccount = EmailArchivingUtil::resolvePersonOrAccountByEmailAddress($emailAddress, false, false, true); $this->assertNull($personOrAccount); Yii::app()->user->userModel = $super; $account->owner = $user; $this->assertTrue($account->save()); Yii::app()->user->userModel = $user; $personOrAccount = EmailArchivingUtil::resolvePersonOrAccountByEmailAddress($emailAddress, false, false, true); $this->assertEquals($account->id, $personOrAccount->id); $this->assertTrue($personOrAccount instanceof Account); // Now test with contacts/leads. Please note that we are not removing email address // from users and accounts, so if contact or lead exist with this email, they should be returned Yii::app()->user->userModel = $user; $personOrAccount = EmailArchivingUtil::resolvePersonOrAccountByEmailAddress($emailAddress, true, true, false); $this->assertNull($personOrAccount); // User can access contacts, but there are no contact in system with the email. // But there is user and account is system with the email Yii::app()->user->userModel = $super; $anotherUser->primaryEmail->emailAddress = $emailAddress; $this->assertTrue($anotherUser->save()); Yii::app()->user->userModel = $user; $personOrAccount = EmailArchivingUtil::resolvePersonOrAccountByEmailAddress($emailAddress, false, false, true); $this->assertEquals($account->id, $personOrAccount->id); $this->assertTrue($personOrAccount instanceof Account); // User can access contacts, and there is contact in system with the email. // But owner of email is super users, so it shouldn't return contact Yii::app()->user->userModel = $super; $this->assertTrue(ContactsModule::loadStartingData()); $this->assertEquals(6, count(ContactState::GetAll())); $contactStates = ContactState::getByName('Qualified'); $email = new Email(); $email->emailAddress = $emailAddress; $email2 = new Email(); $email2->emailAddress = '*****@*****.**'; $contact = new Contact(); $contact->state = $contactStates[0]; $contact->owner = $super; $contact->firstName = 'Super'; $contact->lastName = 'Man'; $contact->primaryEmail = $email; $contact->secondaryEmail = $email; $this->assertTrue($account->save()); $anotherUser->primaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($anotherUser->save()); Yii::app()->user->userModel = $user; $personOrAccount = EmailArchivingUtil::resolvePersonOrAccountByEmailAddress($emailAddress, true, true, false); $this->assertNull($personOrAccount); Yii::app()->user->userModel = $super; $contact->owner = $user; $this->assertTrue($contact->save()); $anotherUser->primaryEmail->emailAddress = $emailAddress; $this->assertTrue($anotherUser->save()); Yii::app()->user->userModel = $user; $personOrAccount = EmailArchivingUtil::resolvePersonOrAccountByEmailAddress($emailAddress, true, true, true); $this->assertEquals($contact->id, $personOrAccount->id); $this->assertTrue($personOrAccount instanceof Contact); }
public function testIsStateALeadByStateName() { $allContactStates = ContactState::GetAll(); $this->assertGreaterThan(1, count($allContactStates)); foreach ($allContactStates as $contactState) { if ($contactState->id < ContactsUtil::getStartingStateId()) { $isStateALeadByStateNameCorrect = true; } else { $isStateALeadByStateNameCorrect = false; } $isStateALead = LeadsUtil::isStateALeadByStateName($contactState->name); $this->assertEquals($isStateALead, $isStateALeadByStateNameCorrect); } }