public function testGetModelClassNames() { $modelClassNames = ZurmoModule::getModelClassNames(); $this->assertEquals(23, count($modelClassNames)); $this->assertEquals('Address', $modelClassNames[0]); $this->assertEquals('AuditEvent', $modelClassNames[1]); $this->assertEquals('Currency', $modelClassNames[2]); $this->assertEquals('CurrencyValue', $modelClassNames[3]); $this->assertEquals('Email', $modelClassNames[4]); $this->assertEquals('ExplicitReadWriteModelPermissions', $modelClassNames[5]); $this->assertEquals('FileModel', $modelClassNames[6]); $this->assertEquals('Group', $modelClassNames[7]); $this->assertEquals('Item', $modelClassNames[8]); $this->assertEquals('NamedSecurableItem', $modelClassNames[9]); $this->assertEquals('OwnedCustomField', $modelClassNames[10]); $this->assertEquals('OwnedModel', $modelClassNames[11]); $this->assertEquals('OwnedMultipleValuesCustomField', $modelClassNames[12]); $this->assertEquals('OwnedSecurableItem', $modelClassNames[13]); $this->assertEquals('Permission', $modelClassNames[14]); $this->assertEquals('Permitable', $modelClassNames[15]); $this->assertEquals('Person', $modelClassNames[16]); $this->assertEquals('Policy', $modelClassNames[17]); $this->assertEquals('Right', $modelClassNames[18]); $this->assertEquals('Role', $modelClassNames[19]); $this->assertEquals('SavedSearch', $modelClassNames[20]); $this->assertEquals('SecurableItem', $modelClassNames[21]); }
/** * @depends testGetAndSetForCurrentUser */ public function testGetAndSetByUser() { $metaData = ZurmoModule::getMetaData(); Yii::app()->user->userModel = User::getByUsername('super'); $this->assertEquals(null, Yii::app()->user->getState('language')); $this->assertEquals('en', Yii::app()->language); $billy = User::getByUsername('billy'); $this->assertEquals(null, $billy->language); $billy->language = 'de'; $this->assertTrue($billy->save()); $this->assertEquals(null, Yii::app()->user->getState('language')); Yii::app()->user->clearStates(); $this->assertEquals('de', $billy->language); $this->assertEquals(null, Yii::app()->user->getState('language')); $this->assertEquals('en', Yii::app()->language); }
/** * @param string $methodName * @param string $displayLabel * @return bool */ protected function checkServiceAndSetMessagesByMethodNameAndDisplayLabel($methodName, $displayLabel) { assert('$this->minimumVersion != null && (is_array($this->minimumVersion) || is_string($this->minimumVersion))'); assert('is_string($methodName)'); assert('is_string($displayLabel)'); $actualVersion = VERSION; $latestStableVersion = ZurmoModule::getLastZurmoStableVersion(); $this->minimumVersion = $latestStableVersion; $minimumVersionLabel = $this->getMinimumVersionLabel(); $passed = $this->checkServiceMethod($latestStableVersion, $actualVersion); if ($passed) { return true; } else { $this->message .= Zurmo::t('InstallModule', 'Your ZurmoCRM software is outdated, new stable release available:') . ' ' . $latestStableVersion; return false; } }
public static function resolveCustomMetadataAndLoad() { $shouldSaveZurmoModuleMetadata = false; $metadata = ZurmoModule::getMetadata(); //Add Material to Menu if it doesn't exist if (!in_array('costbook', $metadata['global']['tabMenuItemsModuleOrdering'])) { $metadata['global']['tabMenuItemsModuleOrdering'][] = 'costbook'; $shouldSaveZurmoModuleMetadata = true; } if (!in_array('departmentReferences', $metadata['global']['tabMenuItemsModuleOrdering'])) { $metadata['global']['tabMenuItemsModuleOrdering'][] = 'departmentReferences'; $shouldSaveZurmoModuleMetadata = true; } if (!in_array('agreements', $metadata['global']['tabMenuItemsModuleOrdering'])) { $metadata['global']['tabMenuItemsModuleOrdering'][] = 'agreements'; $shouldSaveZurmoModuleMetadata = true; } if (!in_array('agreementProducts', $metadata['global']['tabMenuItemsModuleOrdering'])) { $metadata['global']['tabMenuItemsModuleOrdering'][] = 'agreementProducts'; $shouldSaveZurmoModuleMetadata = true; } if (!in_array('opportunityProducts', $metadata['global']['tabMenuItemsModuleOrdering'])) { $metadata['global']['tabMenuItemsModuleOrdering'][] = 'opportunityProducts'; $shouldSaveZurmoModuleMetadata = true; } if (!in_array('categories', $metadata['global']['tabMenuItemsModuleOrdering'])) { $metadata['global']['tabMenuItemsModuleOrdering'][] = 'categories'; $shouldSaveZurmoModuleMetadata = true; } if ($shouldSaveZurmoModuleMetadata) { ZurmoModule::setMetadata($metadata); GeneralCache::forgetAll(); } Yii::import('application.extensions.zurmoinc.framework.data.*'); $defaultDataMaker = new AgreementsDefaultDataMaker(); $defaultDataMaker->make(); $defaultDataMaker = new CostbooksDefaultDataMaker(); $defaultDataMaker->make(); $defaultDataMaker = new OpportunitiesDefaultDataMaker(); $defaultDataMaker->make(); }
public function login() { if ($this->_identity === null) { $this->_identity = Yii::app()->authenticationHelper->makeIdentity($this->username, $this->password); $this->_identity->authenticate(); } if ($this->_identity->errorCode == UserIdentity::ERROR_NONE) { $duration = $this->rememberMe ? 3600 * 24 * 30 : 0; // 30 days Yii::app()->user->login($this->_identity, $duration); // If user is usper admin, check for last stable zurmo version. $group = Group::getByName(Group::SUPER_ADMINISTRATORS_GROUP_NAME); $user = User::getByUsername(Yii::app()->user->username); if ($group->contains($user)) { ZurmoModule::checkAndUpdateZurmoInfo(); } return true; } else { return false; } }
public function testGetAndSetByCurrentUserByModuleName() { Yii::app()->user->userModel = User::getByUsername('super'); $this->assertNull(ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'aKey')); ZurmoConfigurationUtil::setForCurrentUserByModuleName('ZurmoModule', 'aKey', 'aValue'); Yii::app()->user->userModel = User::getByUsername('billy'); $this->assertNull(ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'aKey')); ZurmoConfigurationUtil::setForCurrentUserByModuleName('ZurmoModule', 'aKey', 'bValue'); Yii::app()->user->userModel = User::getByUsername('sally'); $this->assertNull(ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'aKey')); ZurmoConfigurationUtil::setForCurrentUserByModuleName('ZurmoModule', 'aKey', 'cValue'); //now retrieve again. Yii::app()->user->userModel = User::getByUsername('super'); $this->assertEquals('aValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'aKey')); Yii::app()->user->userModel = User::getByUsername('billy'); $this->assertEquals('bValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'aKey')); Yii::app()->user->userModel = User::getByUsername('sally'); $this->assertEquals('cValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'aKey')); //Test retrieving a generic value that is set globally on ZurmoModule. The value returned should be the //same for all users. $metadata = ZurmoModule::getMetadata(); $this->assertTrue(!isset($metadata['global']['bKey'])); $metadata['global']['bKey'] = 'GlobalValue'; ZurmoModule::setMetadata($metadata); Yii::app()->user->userModel = User::getByUsername('super'); $this->assertEquals('GlobalValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'bKey')); Yii::app()->user->userModel = User::getByUsername('billy'); $this->assertEquals('GlobalValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'bKey')); Yii::app()->user->userModel = User::getByUsername('sally'); $this->assertEquals('GlobalValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'bKey')); //Now change the bKey value, just for billy and retrieve again for all users. Only billy's bKey value //should be different. ZurmoConfigurationUtil::setByUserAndModuleName(User::getByUsername('billy'), 'ZurmoModule', 'bKey', 'BillyBKey'); Yii::app()->user->userModel = User::getByUsername('super'); $this->assertEquals('GlobalValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'bKey')); Yii::app()->user->userModel = User::getByUsername('billy'); $this->assertEquals('BillyBKey', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'bKey')); Yii::app()->user->userModel = User::getByUsername('sally'); $this->assertEquals('GlobalValue', ZurmoConfigurationUtil::getForCurrentUserByModuleName('ZurmoModule', 'bKey')); }
public static function resolveCustomMetadataAndLoad() { $shouldSaveZurmoModuleMetadata = false; $metadata = ZurmoModule::getMetadata(); if (!in_array('animals', $metadata['global']['tabMenuItemsModuleOrdering'])) { $metadata['global']['tabMenuItemsModuleOrdering'][] = 'animals'; $shouldSaveZurmoModuleMetadata = true; } if ($shouldSaveZurmoModuleMetadata) { ZurmoModule::setMetadata($metadata); GeneralCache::forgetAll(); } $metadata = Activity::getMetadata(); if (!in_array('Animal', $metadata['Activity']['activityItemsModelClassNames'])) { $metadata['Activity']['activityItemsModelClassNames'][] = 'Animal'; Activity::setMetadata($metadata); GeneralCache::forgetAll(); } Yii::import('application.extensions.zurmoinc.framework.data.*'); Yii::import('application.modules.animals.data.*'); $defaultDataMaker = new AnimalsDefaultDataMaker(); $defaultDataMaker->make(); }
public function testGetModuleLabelByTypeAndLanguage() { $this->assertEquals('en', Yii::app()->languageHelper->getForCurrentUser()); $this->assertEquals('Tes', TestModule::getModuleLabelByTypeAndLanguage('Singular')); $this->assertEquals('Test', TestModule::getModuleLabelByTypeAndLanguage('Plural')); $this->assertEquals('tes', TestModule::getModuleLabelByTypeAndLanguage('SingularLowerCase')); $this->assertEquals('test', TestModule::getModuleLabelByTypeAndLanguage('PluralLowerCase')); $metadata = TestModule::getMetadata(); $metadata['global']['singularModuleLabels'] = array('en' => 'company', 'de' => 'gesellschaft'); $metadata['global']['pluralModuleLabels'] = array('en' => 'companies', 'de' => 'gesellschaften'); TestModule::setMetadata($metadata); $this->assertEquals('Company', TestModule::getModuleLabelByTypeAndLanguage('Singular')); $this->assertEquals('Companies', TestModule::getModuleLabelByTypeAndLanguage('Plural')); $this->assertEquals('company', TestModule::getModuleLabelByTypeAndLanguage('SingularLowerCase')); $this->assertEquals('companies', TestModule::getModuleLabelByTypeAndLanguage('PluralLowerCase')); Yii::app()->language = 'de'; $this->assertEquals('Gesellschaft', TestModule::getModuleLabelByTypeAndLanguage('Singular')); $this->assertEquals('Gesellschaften', TestModule::getModuleLabelByTypeAndLanguage('Plural')); $this->assertEquals('gesellschaft', TestModule::getModuleLabelByTypeAndLanguage('SingularLowerCase')); $this->assertEquals('gesellschaften', TestModule::getModuleLabelByTypeAndLanguage('PluralLowerCase')); Yii::app()->language = 'en'; //Demonstrate getSingularModuleLabel and getPluralModuleLabel and how if they are not overriden, they //will not necessarily produce desired results. $this->assertEquals('Zurmo', ZurmoModule::getModuleLabelByTypeAndLanguage('Singular')); $this->assertEquals('Zurmo', ZurmoModule::getModuleLabelByTypeAndLanguage('Plural')); }
public function testSetDefaultTestToAddress() { $content = Yii::app()->emailHelper->resolveAndGetDefaultTestToAddress(); $this->assertEquals('*****@*****.**', $content); EmailHelper::setDefaultTestToAddress($content); $metadata = ZurmoModule::getMetadata(); $this->assertEquals('*****@*****.**', $metadata['global']['defaultTestToAddress']); }
/** * Temporarily statically defined until we implement * module sorting/visibility for tab menu items. */ protected static function getModuleOrderingForAdminTabMenuByUser($user) { assert('$user instanceof User'); $metadata = ZurmoModule::getMetadata(); if (isset($metadata['global']['adminTabMenuItemsModuleOrdering'])) { assert('is_array($metadata["global"]["adminTabMenuItemsModuleOrdering"])'); $orderedModules = $metadata['global']['adminTabMenuItemsModuleOrdering']; } else { throw new NotSupportedException(); } return $orderedModules; }
public function testLogAuditEventForEachType() { Yii::app()->user->userModel = User::getByUsername('jimmy'); $beforeCount = AuditEvent::getCount(); $item = new AuditTestItem(); $this->assertTrue($item->save()); $this->assertEquals($beforeCount + 1, AuditEvent::getCount()); $auditEvents = AuditEvent::getTailEvents(1); $this->assertRegExp('/[0-9]+\\/[0-9]+\\/[0-9]+ [0-9]+:[0-9]+ [AP]M, ' . 'James Boondog, Item Created, ' . 'AuditTestItem\\([0-9]+\\), \\(None\\)/', ZurmoModule::stringifyAuditEvent($auditEvents[0])); $item->dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 120); $item->date = '2010-12-20'; $item->float = 3.14159; $item->integer = 666; $item->time = '11:59'; $this->assertTrue($item->save()); $this->assertEquals($beforeCount + 6, AuditEvent::getCount()); $auditEvents = AuditEvent::getTailEvents(5); $this->assertRegExp('/[0-9]+\\/[0-9]+\\/[0-9]+ [0-9]+:[0-9]+ [AP]M, ' . 'James Boondog, Item Modified, ' . 'AuditTestItem\\([0-9]+\\), \\(None\\), ' . 'Changed Date Time from \\(None\\) to [0-9]+/', ZurmoModule::stringifyAuditEvent($auditEvents[0])); $this->assertRegExp('/[0-9]+\\/[0-9]+\\/[0-9]+ [0-9]+:[0-9]+ [AP]M, ' . 'James Boondog, Item Modified, ' . 'AuditTestItem\\([0-9]+\\), \\(None\\), ' . 'Changed Date from \\(None\\) to 2010-12-20/', ZurmoModule::stringifyAuditEvent($auditEvents[1])); $this->assertRegExp('/[0-9]+\\/[0-9]+\\/[0-9]+ [0-9]+:[0-9]+ [AP]M, ' . 'James Boondog, Item Modified, ' . 'AuditTestItem\\([0-9]+\\), \\(None\\), ' . 'Changed Float from \\(None\\) to 3.14159/', ZurmoModule::stringifyAuditEvent($auditEvents[2])); $this->assertRegExp('/[0-9]+\\/[0-9]+\\/[0-9]+ [0-9]+:[0-9]+ [AP]M, ' . 'James Boondog, Item Modified, ' . 'AuditTestItem\\([0-9]+\\), \\(None\\), ' . 'Changed Integer from \\(None\\) to 666/', ZurmoModule::stringifyAuditEvent($auditEvents[3])); $this->assertRegExp('/[0-9]+\\/[0-9]+\\/[0-9]+ [0-9]+:[0-9]+ [AP]M, ' . 'James Boondog, Item Modified, ' . 'AuditTestItem\\([0-9]+\\), \\(None\\), ' . 'Changed Time from \\(None\\) to 11:59/', ZurmoModule::stringifyAuditEvent($auditEvents[4])); $item->dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $item->date = '2012-01-22'; $item->float = 6.626068E-34; $item->integer = 69; $item->time = '12:00'; $this->assertTrue($item->save()); $this->assertEquals($beforeCount + 11, AuditEvent::getCount()); $auditEvents = AuditEvent::getTailEvents(5); $this->assertRegExp('/[0-9]+\\/[0-9]+\\/[0-9]+ [0-9]+:[0-9]+ [AP]M, ' . 'James Boondog, Item Modified, ' . 'AuditTestItem\\([0-9]+\\), \\(None\\), ' . 'Changed Date from 2010-12-20 to 2012-01-22/', ZurmoModule::stringifyAuditEvent($auditEvents[1])); $this->assertRegExp('/[0-9]+\\/[0-9]+\\/[0-9]+ [0-9]+:[0-9]+ [AP]M, ' . 'James Boondog, Item Modified, ' . 'AuditTestItem\\([0-9]+\\), \\(None\\), ' . 'Changed Float from 3.14159 to 6.626068E-34/', ZurmoModule::stringifyAuditEvent($auditEvents[2])); $this->assertRegExp('/[0-9]+\\/[0-9]+\\/[0-9]+ [0-9]+:[0-9]+ [AP]M, ' . 'James Boondog, Item Modified, ' . 'AuditTestItem\\([0-9]+\\), \\(None\\), ' . 'Changed Integer from 666 to 69/', ZurmoModule::stringifyAuditEvent($auditEvents[3])); $this->assertRegExp('/[0-9]+\\/[0-9]+\\/[0-9]+ [0-9]+:[0-9]+ [AP]M, ' . 'James Boondog, Item Modified, ' . 'AuditTestItem\\([0-9]+\\), \\(None\\), ' . 'Changed Time from 11:59 to 12:00/', ZurmoModule::stringifyAuditEvent($auditEvents[4])); }
/** * Check if there are new zurmo updates. * Then delete these logs. * * @see BaseJob::run() */ public function run() { ZurmoModule::checkAndUpdateZurmoInfo(true); return true; }