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 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 static function deleteAllContactWebForms() { $contactWebForms = ContactWebForm::getAll(); foreach ($contactWebForms as $webForm) { $webForm->delete(); } }
public static function createContactWebFormByName($name, $owner = null) { if ($owner === null) { $owner = Yii::app()->user->userModel; } $allAttributes = ContactWebFormsUtil::getAllAttributes(); $placedAttributes = array('firstName', 'lastName', 'companyName', 'jobTitle'); $contactFormAttributes = ContactWebFormsUtil::getAllPlacedAttributes($allAttributes, $placedAttributes); $attributes = array_keys($contactFormAttributes); 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($attributes); $contactWebForm->defaultOwner = $owner; $saved = $contactWebForm->save(); assert('$saved'); return $contactWebForm; }
/** * @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 actionDelete($id) { $contactWebForm = ContactWebForm::getById(intval($id)); ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($contactWebForm); $contactWebForm->delete(); $this->redirect(array($this->getId() . '/index')); }
/** * @depends testRegularUserControllerActionsWithElevationToAccessAndCreate */ public function testRegularUserControllerActionsWithElevationToModels() { //Create contact web form owned by user super. $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $contactWebForm = ContactWebFormTestHelper::createContactWebFormByName('contactWebFormForElevationToModelTest', $super); //Test nobody, access to edit and details should fail. $nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody'); $this->setGetArray(array('id' => $contactWebForm->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/edit'); $this->setGetArray(array('id' => $contactWebForm->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/details'); //give nobody access to read Yii::app()->user->userModel = $super; $contactWebForm->addPermissions($nobody, Permission::READ); $this->assertTrue($contactWebForm->save()); AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForUser($contactWebForm, $nobody); //Now the nobody user can access the details view. Yii::app()->user->userModel = $nobody; $this->setGetArray(array('id' => $contactWebForm->id)); $this->runControllerWithNoExceptionsAndGetContent('contactWebForms/default/details'); //Test nobody, access to edit should fail. $this->setGetArray(array('id' => $contactWebForm->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/edit'); $contactWebFormId = $contactWebForm->id; $contactWebForm->forget(); $contactWebForm = ContactWebForm::getById($contactWebFormId); //give nobody access to read and write Yii::app()->user->userModel = $super; $contactWebForm->addPermissions($nobody, Permission::READ_WRITE_CHANGE_PERMISSIONS); $this->assertTrue($contactWebForm->save()); AllPermissionsOptimizationUtil::securableItemLostReadPermissionsForUser($contactWebForm, $nobody); AllPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($contactWebForm, $nobody); //Now the nobody user should be able to access the edit view and still the details view. Yii::app()->user->userModel = $nobody; $this->setGetArray(array('id' => $contactWebForm->id)); $this->runControllerWithNoExceptionsAndGetContent('contactWebForms/default/details'); $this->setGetArray(array('id' => $contactWebForm->id)); $this->runControllerWithNoExceptionsAndGetContent('contactWebForms/default/edit'); $contactWebFormId = $contactWebForm->id; $contactWebForm->forget(); $contactWebForm = ContactWebForm::getById($contactWebFormId); //revoke nobody access to read Yii::app()->user->userModel = $super; $contactWebForm->removePermissions($nobody, Permission::READ_WRITE_CHANGE_PERMISSIONS); $this->assertTrue($contactWebForm->save()); AllPermissionsOptimizationUtil::securableItemLostReadPermissionsForUser($contactWebForm, $nobody); //Test nobody, access to detail should fail. Yii::app()->user->userModel = $nobody; $this->setGetArray(array('id' => $contactWebForm->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/details'); $this->setGetArray(array('id' => $contactWebForm->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/edit'); //create some roles Yii::app()->user->userModel = $super; $parentRole = new Role(); $parentRole->name = 'AAA'; $this->assertTrue($parentRole->save()); $childRole = new Role(); $childRole->name = 'BBB'; $this->assertTrue($childRole->save()); $userInParentRole = User::getByUsername('confused'); $userInChildRole = User::getByUsername('nobody'); $childRole->users->add($userInChildRole); $this->assertTrue($childRole->save()); $parentRole->users->add($userInParentRole); $parentRole->roles->add($childRole); $this->assertTrue($parentRole->save()); $userInChildRole->forget(); $userInChildRole = User::getByUsername('nobody'); $userInParentRole->forget(); $userInParentRole = User::getByUsername('confused'); $parentRoleId = $parentRole->id; $parentRole->forget(); $parentRole = Role::getById($parentRoleId); $childRoleId = $childRole->id; $childRole->forget(); $childRole = Role::getById($childRoleId); //create web form owned by super $contactWebForm2 = ContactWebFormTestHelper::createContactWebFormByName('testingParentRolePermission', $super); //Test userInParentRole, access to details and edit should fail. Yii::app()->user->userModel = $userInParentRole; $this->setGetArray(array('id' => $contactWebForm2->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/details'); $this->setGetArray(array('id' => $contactWebForm2->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/edit'); //give userInChildRole access to READ Yii::app()->user->userModel = $super; $contactWebForm2->addPermissions($userInChildRole, Permission::READ); $this->assertTrue($contactWebForm2->save()); AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForUser($contactWebForm2, $userInChildRole); //Test userInChildRole, access to details should not fail. Yii::app()->user->userModel = $userInChildRole; $this->setGetArray(array('id' => $contactWebForm2->id)); $this->runControllerWithNoExceptionsAndGetContent('contactWebForms/default/details'); //Test userInParentRole, access to details should not fail. Yii::app()->user->userModel = $userInParentRole; $this->setGetArray(array('id' => $contactWebForm2->id)); $this->runControllerWithNoExceptionsAndGetContent('contactWebForms/default/details'); $contactWebFormId = $contactWebForm2->id; $contactWebForm2->forget(); $contactWebForm2 = ContactWebForm::getById($contactWebFormId); //give userInChildRole access to read and write Yii::app()->user->userModel = $super; $contactWebForm2->addPermissions($userInChildRole, Permission::READ_WRITE_CHANGE_PERMISSIONS); $this->assertTrue($contactWebForm2->save()); AllPermissionsOptimizationUtil::securableItemLostReadPermissionsForUser($contactWebForm2, $userInChildRole); AllPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($contactWebForm2, $userInChildRole); //Test userInChildRole, access to edit should not fail. Yii::app()->user->userModel = $userInChildRole; $this->setGetArray(array('id' => $contactWebForm2->id)); $this->runControllerWithNoExceptionsAndGetContent('contactWebForms/default/edit'); //Test userInParentRole, access to edit should not fail. $this->logoutCurrentUserLoginNewUserAndGetByUsername($userInParentRole->username); $this->setGetArray(array('id' => $contactWebForm2->id)); $this->runControllerWithNoExceptionsAndGetContent('contactWebForms/default/edit'); $contactWebFormId = $contactWebForm2->id; $contactWebForm2->forget(); $contactWebForm2 = ContactWebForm::getById($contactWebFormId); //revoke userInChildRole access to read and write Yii::app()->user->userModel = $super; $contactWebForm2->removePermissions($userInChildRole, Permission::READ_WRITE_CHANGE_PERMISSIONS); $this->assertTrue($contactWebForm2->save()); AllPermissionsOptimizationUtil::securableItemLostPermissionsForUser($contactWebForm2, $userInChildRole); //Test userInChildRole, access to detail should fail. Yii::app()->user->userModel = $userInChildRole; $this->setGetArray(array('id' => $contactWebForm2->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/details'); $this->setGetArray(array('id' => $contactWebForm2->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/edit'); //Test userInParentRole, access to detail should fail. Yii::app()->user->userModel = $userInParentRole; $this->setGetArray(array('id' => $contactWebForm2->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/details'); $this->setGetArray(array('id' => $contactWebForm2->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/edit'); //clear up the role relationships between users so not to effect next assertions $parentRole->users->remove($userInParentRole); $parentRole->roles->remove($childRole); $this->assertTrue($parentRole->save()); $childRole->users->remove($userInChildRole); $this->assertTrue($childRole->save()); //create some groups and assign users to groups Yii::app()->user->userModel = $super; $parentGroup = new Group(); $parentGroup->name = 'AAA'; $this->assertTrue($parentGroup->save()); $childGroup = new Group(); $childGroup->name = 'BBB'; $this->assertTrue($childGroup->save()); $userInChildGroup = User::getByUsername('confused'); $userInParentGroup = User::getByUsername('nobody'); $childGroup->users->add($userInChildGroup); $this->assertTrue($childGroup->save()); $parentGroup->users->add($userInParentGroup); $parentGroup->groups->add($childGroup); $this->assertTrue($parentGroup->save()); $parentGroup->forget(); $childGroup->forget(); $parentGroup = Group::getByName('AAA'); $childGroup = Group::getByName('BBB'); //Add access for the confused user to ContactWebForms and creation of ContactWebForms. $userInChildGroup->setRight('ContactWebFormsModule', ContactWebFormsModule::RIGHT_ACCESS_CONTACT_WEB_FORMS); $userInChildGroup->setRight('ContactWebFormsModule', ContactWebFormsModule::RIGHT_CREATE_CONTACT_WEB_FORMS); $this->assertTrue($userInChildGroup->save()); //create web form owned by super $contactWebForm3 = ContactWebFormTestHelper::createContactWebFormByName('testingParentGroupPermission', $super); //Test userInParentGroup, access to details and edit should fail. Yii::app()->user->userModel = $userInParentGroup; $this->setGetArray(array('id' => $contactWebForm3->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/details'); $this->setGetArray(array('id' => $contactWebForm3->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/edit'); //Test userInChildGroup, access to details and edit should fail. Yii::app()->user->userModel = $userInChildGroup; $this->setGetArray(array('id' => $contactWebForm3->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/details'); $this->setGetArray(array('id' => $contactWebForm3->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/edit'); //give parentGroup access to READ Yii::app()->user->userModel = $super; $contactWebForm3->addPermissions($parentGroup, Permission::READ); $this->assertTrue($contactWebForm3->save()); AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForGroup($contactWebForm3, $parentGroup); //Test userInParentGroup, access to details should not fail. Yii::app()->user->userModel = $userInParentGroup; $this->setGetArray(array('id' => $contactWebForm3->id)); $this->runControllerWithNoExceptionsAndGetContent('contactWebForms/default/details'); //Test userInChildGroup, access to details should not fail. Yii::app()->user->userModel = $userInChildGroup; $this->setGetArray(array('id' => $contactWebForm3->id)); $this->runControllerWithNoExceptionsAndGetContent('contactWebForms/default/details'); $contactWebFormId = $contactWebForm3->id; $contactWebForm3->forget(); $contactWebForm3 = ContactWebForm::getById($contactWebFormId); //give parentGroup access to read and write Yii::app()->user->userModel = $super; $contactWebForm3->addPermissions($parentGroup, Permission::READ_WRITE_CHANGE_PERMISSIONS); $this->assertTrue($contactWebForm3->save()); AllPermissionsOptimizationUtil::securableItemLostReadPermissionsForGroup($contactWebForm3, $parentGroup); AllPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($contactWebForm3, $parentGroup); //Test userInParentGroup, access to edit should not fail. Yii::app()->user->userModel = $userInParentGroup; $this->setGetArray(array('id' => $contactWebForm3->id)); $this->runControllerWithNoExceptionsAndGetContent('contactWebForms/default/edit'); //Test userInChildGroup, access to edit should not fail. Yii::app()->user->userModel = $userInChildGroup; $this->logoutCurrentUserLoginNewUserAndGetByUsername($userInChildGroup->username); $this->setGetArray(array('id' => $contactWebForm3->id)); $this->runControllerWithNoExceptionsAndGetContent('contactWebForms/default/edit'); $contactWebFormId = $contactWebForm3->id; $contactWebForm3->forget(); $contactWebForm3 = ContactWebForm::getById($contactWebFormId); //revoke parentGroup access to read and write Yii::app()->user->userModel = $super; $contactWebForm3->removePermissions($parentGroup, Permission::READ_WRITE_CHANGE_PERMISSIONS); $this->assertTrue($contactWebForm3->save()); AllPermissionsOptimizationUtil::securableItemLostPermissionsForGroup($contactWebForm3, $parentGroup); //Test userInChildGroup, access to detail should fail. Yii::app()->user->userModel = $userInChildGroup; $this->setGetArray(array('id' => $contactWebForm3->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/details'); $this->setGetArray(array('id' => $contactWebForm3->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/edit'); //Test userInParentGroup, access to detail should fail. Yii::app()->user->userModel = $userInParentGroup; $this->setGetArray(array('id' => $contactWebForm3->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/details'); $this->setGetArray(array('id' => $contactWebForm3->id)); $this->runControllerShouldResultInAccessFailureAndGetContent('contactWebForms/default/edit'); //clear up the role relationships between users so not to effect next assertions $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $userInParentGroup->forget(); $userInChildGroup->forget(); $childGroup->forget(); $parentGroup->forget(); $userInParentGroup = User::getByUsername('nobody'); $userInChildGroup = User::getByUsername('confused'); $childGroup = Group::getByName('BBB'); $parentGroup = Group::getByName('AAA'); //clear up the role relationships between users so not to effect next assertions $parentGroup->users->remove($userInParentGroup); $parentGroup->groups->remove($childGroup); $this->assertTrue($parentGroup->save()); $childGroup->users->remove($userInChildGroup); $this->assertTrue($childGroup->save()); }
public function testSuperUserCreateAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); Yii::app()->user->userModel = $super; $this->resetGetArray(); $attributes = ContactWebFormTestHelper::getContactWebFormAttributes(); ContactsModule::loadStartingData(); $contactStates = ContactState::getByName('New'); $contactWebForm = array(); $contactWebForm['name'] = 'External Web Form (Drupal)'; $contactWebForm['redirectUrl'] = 'http://www.zurmo.com/'; $contactWebForm['submitButtonLabel'] = 'Save & Next'; $contactWebForm['defaultState'] = $contactStates[0]; $contactWebForm['defaultOwner'] = $super; $this->setPostArray(array('ContactWebForm' => $contactWebForm, 'ContactWebFormAttributeForm' => $attributes)); $redirectUrl = $this->runControllerWithRedirectExceptionAndGetUrl('contactWebForms/default/create'); $contactWebForms = ContactWebForm::getByName('External Web Form (Drupal)'); $this->assertEquals(1, count($contactWebForms)); $this->assertTrue($contactWebForms[0]->id > 0); $this->assertEquals('Save & Next', $contactWebForms[0]->submitButtonLabel); $this->assertEquals($attributes, unserialize($contactWebForms[0]->serializedData)); $compareRedirectUrl = Yii::app()->createUrl('contactWebForms/default/details', array('id' => $contactWebForms[0]->id)); $this->assertEquals($compareRedirectUrl, $redirectUrl); }
/** * @depends testCreateWebFormEntries */ public function testDeleteContactWebForm() { $contactWebForms = ContactWebForm::getAll(); $this->assertEquals(1, count($contactWebForms)); $contactWebForms[0]->delete(); $contactWebForms = ContactWebForm::getAll(); $this->assertEquals(0, count($contactWebForms)); }