public function init()
 {
     if (ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted()) {
         $eventHandler = array($this, 'updateContactLatestActivityDateTimeByTask');
         Task::model()->attachEventHandler('onAfterSave', $eventHandler);
         $this->attachedEventHandlersIndexedByModelClassName['Task'] = array('onAfterSave', $eventHandler);
     }
     if (ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated()) {
         $eventHandler = array($this, 'updateContactLatestActivityDateTimeByNote');
         Note::model()->attachEventHandler('onAfterSave', $eventHandler);
         $this->attachedEventHandlersIndexedByModelClassName['Note'] = array('onAfterSave', $eventHandler);
     }
     if (ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived()) {
         $eventHandler = array($this, 'updateContactLatestActivityDateTimeByEmailMessage');
         EmailMessage::model()->attachEventHandler('onAfterSave', $eventHandler);
         $this->attachedEventHandlersIndexedByModelClassName['EmailMessage'] = array('onAfterSave', $eventHandler);
     }
     if (ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast()) {
         $eventHandler = array($this, 'resolveModelLatestActivityDateTimeProcessFlagByMeeting');
         Meeting::model()->attachEventHandler('onBeforeSave', $eventHandler);
         $this->attachedEventHandlersIndexedByModelClassName['Meeting'] = array('onBeforeSave', $eventHandler);
     }
 }
 public function testSuperUserContactDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     //Default Controller actions requiring some sort of parameter via POST or GET
     //Load Conatct Modules Menu.
     $this->resetPostArray();
     $this->setGetArray(array('moduleClassName' => 'ContactsModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/modulesMenu');
     //Load AttributesList for Contacts module.
     $this->setGetArray(array('moduleClassName' => 'ContactsModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/attributesList');
     //Load ModuleLayoutsList for Conatct module.
     $this->setGetArray(array('moduleClassName' => 'ContactsModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/moduleLayoutsList');
     //Load ModuleEdit view for each applicable module.
     $this->setGetArray(array('moduleClassName' => 'ContactsModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/moduleEdit');
     //Now validate save with failed validation.
     $this->setGetArray(array('moduleClassName' => 'ContactsModule'));
     $this->setPostArray(array('ajax' => 'edit-form', 'ContactsModuleForm' => $this->createModuleEditBadValidationPostData()));
     $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/moduleEdit');
     $this->assertTrue(strlen($content) > 50);
     //approximate, but should definetely be larger than 50.
     //Now validate save with successful validation.
     $this->setGetArray(array('moduleClassName' => 'ContactsModule'));
     $this->setPostArray(array('ajax' => 'edit-form', 'ContactsModuleForm' => $this->createModuleEditGoodValidationPostData('con new name')));
     $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/moduleEdit');
     $this->assertEquals('[]', $content);
     //Now save successfully.
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted();
     $this->assertTrue($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated();
     $this->assertTrue($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived();
     $this->assertTrue($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast();
     $this->assertTrue($value);
     $postDataForForm = $this->createModuleEditGoodValidationPostData('con new name');
     $postDataForForm['updateLatestActivityDateTimeWhenATaskIsCompleted'] = '';
     $postDataForForm['updateLatestActivityDateTimeWhenANoteIsCreated'] = '';
     $postDataForForm['updateLatestActivityDateTimeWhenAnEmailIsSentOrArchived'] = '';
     $postDataForForm['updateLatestActivityDateTimeWhenAMeetingIsInThePast'] = '';
     $this->setGetArray(array('moduleClassName' => 'ContactsModule'));
     $this->setPostArray(array('save' => 'Save', 'ContactsModuleForm' => $postDataForForm));
     $this->runControllerWithRedirectExceptionAndGetContent('designer/default/moduleEdit');
     //Now confirm everything did in fact save correctly.
     $this->assertEquals('Con New Name', ContactsModule::getModuleLabelByTypeAndLanguage('Singular'));
     $this->assertEquals('Con New Names', ContactsModule::getModuleLabelByTypeAndLanguage('Plural'));
     $this->assertEquals('con new name', ContactsModule::getModuleLabelByTypeAndLanguage('SingularLowerCase'));
     $this->assertEquals('con new names', ContactsModule::getModuleLabelByTypeAndLanguage('PluralLowerCase'));
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted();
     $this->assertFalse($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated();
     $this->assertFalse($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived();
     $this->assertFalse($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast();
     $this->assertFalse($value);
     //Load LayoutEdit for each applicable module and applicable layout
     $this->resetPostArray();
     $this->setGetArray(array('moduleClassName' => 'ContactsModule', 'viewClassName' => 'ContactEditAndDetailsView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'ContactsModule', 'viewClassName' => 'ContactsListView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'ContactsModule', 'viewClassName' => 'ContactsModalListView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'ContactsModule', 'viewClassName' => 'ContactsModalSearchView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'ContactsModule', 'viewClassName' => 'ContactsMassEditView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'ContactsModule', 'viewClassName' => 'ContactsRelatedListView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'ContactsModule', 'viewClassName' => 'ContactsSearchView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
 }
 public function testUpdateLatestActivityDateTimeMethods()
 {
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted();
     $this->assertTrue($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated();
     $this->assertTrue($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived();
     $this->assertTrue($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast();
     $this->assertTrue($value);
     $metadata = ContactsModule::getMetadata();
     $metadata['global']['updateLatestActivityDateTimeWhenATaskIsCompleted'] = false;
     ContactsModule::setMetadata($metadata);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted();
     $this->assertFalse($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated();
     $this->assertTrue($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived();
     $this->assertTrue($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast();
     $this->assertTrue($value);
     $metadata = ContactsModule::getMetadata();
     $metadata['global']['updateLatestActivityDateTimeWhenANoteIsCreated'] = false;
     ContactsModule::setMetadata($metadata);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted();
     $this->assertFalse($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated();
     $this->assertFalse($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived();
     $this->assertTrue($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast();
     $this->assertTrue($value);
     $metadata = ContactsModule::getMetadata();
     $metadata['global']['updateLatestActivityDateTimeWhenAnEmailIsSentOrArchived'] = false;
     ContactsModule::setMetadata($metadata);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted();
     $this->assertFalse($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated();
     $this->assertFalse($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived();
     $this->assertFalse($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast();
     $this->assertTrue($value);
     $metadata = ContactsModule::getMetadata();
     $metadata['global']['updateLatestActivityDateTimeWhenAMeetingIsInThePast'] = false;
     ContactsModule::setMetadata($metadata);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted();
     $this->assertFalse($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated();
     $this->assertFalse($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived();
     $this->assertFalse($value);
     $value = ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast();
     $this->assertFalse($value);
 }