当前位置: 首页>>代码示例>>PHP>>正文


PHP User::getByUsername方法代码示例

本文整理汇总了PHP中User::getByUsername方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getByUsername方法的具体用法?PHP User::getByUsername怎么用?PHP User::getByUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在User的用法示例。


在下文中一共展示了User::getByUsername方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAddingUserToRole

 public function testAddingUserToRole()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $role = new Role();
     $role->name = 'myRole';
     $role->validate();
     $saved = $role->save();
     $this->assertTrue($saved);
     $benny = User::getByUsername('benny');
     //Add the role to benny
     $benny->role = $role;
     $saved = $benny->save();
     $this->assertTrue($saved);
     $roleId = $role->id;
     unset($role);
     $role = Role::getById($roleId);
     $this->assertEquals(1, $role->users->count());
     $this->assertTrue($role->users[0]->isSame($benny));
     //Now try adding billy to the role but from the other side, from the role side.
     $billy = User::getByUsername('billy');
     $role->users->add($billy);
     $saved = $role->save();
     $this->assertTrue($saved);
     $billy->forget();
     //need to forget billy otherwise it won't pick up the change. i tried unset(), test fails
     $billy = User::getByUsername('billy');
     $this->assertTrue($billy->role->id > 0);
     $this->assertTrue($billy->role->isSame($role));
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:29,代码来源:RoleTest.php

示例2: testGetByType

 public function testGetByType()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $jobLog = new JobLog();
     $jobLog->type = 'Monitor';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog->isProcessed = false;
     $this->assertTrue($jobLog->save());
     $jobLog = new JobLog();
     $jobLog->type = 'Monitor';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog->isProcessed = false;
     $this->assertTrue($jobLog->save());
     $jobLog = new JobLog();
     $jobLog->type = 'SomethingElse';
     $jobLog->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->endDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $jobLog->status = JobLog::STATUS_COMPLETE_WITHOUT_ERROR;
     $jobLog->isProcessed = false;
     $this->assertTrue($jobLog->save());
     $jobLogs = JobLog::getByType('Monitor');
     $this->assertCount(2, $jobLogs);
     $jobLogs = JobLog::getByType('Monitor', 1);
     $this->assertCount(1, $jobLogs);
     $jobLogs = JobLog::getByType('SomethingElse');
     $this->assertCount(1, $jobLogs);
     $jobLogs = JobLog::getByType('SomethingElse', 1);
     $this->assertCount(1, $jobLogs);
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:33,代码来源:JobLogTest.php

示例3: testSequentialProcessViewFactory

 public function testSequentialProcessViewFactory()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'string', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_1' => array('attributeIndexOrDerivedType' => 'phone', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))));
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName());
     $config = array('pagination' => array('pageSize' => 2));
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     $sequentialProcess = new ImportDataAnalysisSequentialProcess($import, $dataProvider);
     $sequentialProcess->run(null, null);
     $route = 'default/someAction';
     $view = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     $content = $view->render();
     $this->assertNotNull($content);
     $this->assertEquals('SequentialProcessView', get_class($view));
     //Now process the first run. Will process page 0.
     $sequentialProcess = new ImportDataAnalysisSequentialProcess($import, $dataProvider);
     $sequentialProcess->run('processColumns', null);
     $route = 'default/someAction';
     $view = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     $content = $view->render();
     $this->assertNotNull($content);
     $this->assertEquals('SequentialProcessView', get_class($view));
     $this->assertEquals(array('columnNameToProcess' => 'column_1'), $sequentialProcess->getNextParams());
 }
开发者ID:sandeep1027,项目名称:zurmo_,代码行数:29,代码来源:ImportDataAnalysisSequentialProcessTest.php

示例4: setUp

 public function setUp()
 {
     EmailMessageTestHelper::purgeAllMessages();
     parent::setUp();
     $this->user = User::getByUsername('super');
     Yii::app()->user->userModel = $this->user;
 }
开发者ID:sandeep1027,项目名称:zurmo_,代码行数:7,代码来源:ZurmoImapTest.php

示例5: setUp

 public function setUp()
 {
     parent::setUp();
     $this->user = User::getByUsername('super');
     Yii::app()->user->userModel = $this->user;
     $this->purgeAllCampaigns();
 }
开发者ID:sandeep1027,项目名称:zurmo_,代码行数:7,代码来源:CampaignItemsUtilTest.php

示例6: setUp

 public function setUp()
 {
     parent::setUp();
     Yii::app()->user->userModel = User::getByUsername('super');
     EmailMessage::deleteAll();
     Notification::deleteAll();
 }
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:7,代码来源:TaskNotificationUtilTest.php

示例7: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     //Setup test data owned by the super user.
     $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
     AccountTestHelper::createAccountByNameForOwner('superAccount2', $super);
     ContactTestHelper::createContactWithAccountByNameForOwner('superContact', $super, $account);
     ContactTestHelper::createContactWithAccountByNameForOwner('superContact2', $super, $account);
     OpportunityTestHelper::createOpportunityStagesIfDoesNotExist();
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp', $super, $account);
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp2', $super, $account);
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp3', $super, $account);
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp4', $super, $account);
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp5', $super, $account);
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp6', $super, $account);
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp7', $super, $account);
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp8', $super, $account);
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp9', $super, $account);
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp10', $super, $account);
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp11', $super, $account);
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp12', $super, $account);
     //Setup default dashboard.
     Dashboard::getByLayoutIdAndUser(Dashboard::DEFAULT_USER_LAYOUT_ID, $super);
 }
开发者ID:sandeep1027,项目名称:zurmo_,代码行数:27,代码来源:OpportunitiesSuperUserWalkthroughTest.php

示例8: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     SecurityTestHelper::createUsers();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     //Setup test data owned by the super user.
     $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
     $account2 = AccountTestHelper::createAccountByNameForOwner('superAccount2', $super);
     $contact1 = ContactTestHelper::createContactWithAccountByNameForOwner('superContact', $super, $account);
     $contact2 = ContactTestHelper::createContactWithAccountByNameForOwner('superContact2', $super, $account2);
     $contact3 = ContactTestHelper::createContactWithAccountByNameForOwner('superContact3', $super, $account);
     $contact4 = ContactTestHelper::createContactWithAccountByNameForOwner('superContact4', $super, $account2);
     $contact5 = ContactTestHelper::createContactWithAccountByNameForOwner('superContact5', $super, $account);
     $marketingList1 = MarketingListTestHelper::createMarketingListByName('MarketingList1', 'MarketingList Description1');
     $marketingList2 = MarketingListTestHelper::createMarketingListByName('MarketingList2', 'MarketingList Description2');
     MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList1, $contact1);
     MarketingListMemberTestHelper::createMarketingListMember(1, $marketingList1, $contact2);
     MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList1, $contact3);
     MarketingListMemberTestHelper::createMarketingListMember(1, $marketingList1, $contact4);
     MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList1, $contact5);
     MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList2, $contact1);
     MarketingListMemberTestHelper::createMarketingListMember(1, $marketingList2, $contact2);
     AllPermissionsOptimizationUtil::rebuild();
 }
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:26,代码来源:MarketingListDefaultPortletControllerSuperUserWalkthroughTest.php

示例9: testRun

 public function testRun()
 {
     $quote = DatabaseCompatibilityUtil::getQuote();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
     //Create 2 sent notifications, and set one with a date over a week ago (8 days ago) for the modifiedDateTime
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
     $emailMessage->folder = $folder;
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $modifiedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 8);
     $sql = "Update item set modifieddatetime = '" . $modifiedDateTime . "' where id = " . $emailMessage->getClassId('Item');
     ZurmoRedBean::exec($sql);
     $emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('My Email Message 2', $super);
     $emailMessage2->folder = $folder;
     $saved = $emailMessage2->save();
     $this->assertTrue($saved);
     $this->assertEquals(2, EmailMessage::getCount());
     $job = new ClearSentNotificationsEmailJob();
     $this->assertTrue($job->run());
     $emailMessages = EmailMessage::getAll();
     $this->assertEquals(1, count($emailMessages));
     $this->assertEquals($emailMessage2->id, $emailMessages[0]->id);
 }
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:26,代码来源:ClearSentNotificationsEmailJobTest.php

示例10: testCanCurrentUserPerformAction

 public function testCanCurrentUserPerformAction()
 {
     Yii::app()->user->userModel = User::getByUsername('billy');
     $leadForBilly = LeadTestHelper::createLeadbyNameForOwner("billy's lead", User::getByUsername('billy'));
     $betty = User::getByUsername('betty');
     Yii::app()->user->userModel = $betty;
     $leadForBetty = LeadTestHelper::createLeadbyNameForOwner("betty's lead", User::getByUsername('betty'));
     $betty->setRight('LeadsModule', LeadsModule::RIGHT_ACCESS_LEADS, Right::ALLOW);
     $saved = $betty->save();
     $this->assertTrue($saved);
     //make sure betty doesnt have write on billy's lead
     $this->assertEquals(Permission::NONE, $leadForBilly->getEffectivePermissions($betty));
     //make sure betty doesnt have convert lead right already
     $this->assertEquals(Right::DENY, $betty->getEffectiveRight('LeadsModule', LeadsModule::RIGHT_CONVERT_LEADS));
     //test Betty has no right to convert leads
     $actionSecurity = ActionSecurityFactory::createActionSecurityFromActionType('ConvertLead', $leadForBilly, $betty);
     $this->assertFalse($actionSecurity->canUserPerformAction());
     //test Betty has right to convert leads but cant write the lead she doesn't own
     $betty->setRight('LeadsModule', LeadsModule::RIGHT_CONVERT_LEADS, Right::ALLOW);
     $this->assertTrue($betty->save());
     $actionSecurity = ActionSecurityFactory::createActionSecurityFromActionType('ConvertLead', $leadForBilly, $betty);
     $this->assertFalse($actionSecurity->canUserPerformAction());
     //test Betty has right to convert and to write a lead she owns.
     $actionSecurity = ActionSecurityFactory::createActionSecurityFromActionType('ConvertLead', $leadForBetty, $betty);
     $this->assertTrue($actionSecurity->canUserPerformAction());
 }
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:26,代码来源:ConvertLeadActionSecurityTest.php

示例11: testSavingTwiceWithAModelThatHasACurrencyValueAsARelation

 public function testSavingTwiceWithAModelThatHasACurrencyValueAsARelation()
 {
     if (!RedBeanDatabase::isFrozen()) {
         Yii::app()->user->userModel = User::getByUsername('super');
         $testItem = new OwnedSecurableTestItem();
         $testItem->member = 'test';
         $saved = $testItem->save();
         $this->assertTrue($saved);
         //Because OwnedSecurableTestItem as a relatedCurrency, there are some strange issues with saving again.
         //It creates currency validation issues for any of the related users like owner, modifiedUser etc.
         //Need to investigate further to fix.
         //$testItem->forget();
         //$testItem = OwnedSecurableTestItem::getById($testItem->id);
         //Save again immediately after.
         $validated = $testItem->validate();
         // echo "<pre>";
         // print_r($testItem->getErrors());
         // echo "</pre>";
         $this->assertTrue($validated);
         $saved = $testItem->save();
         $this->assertTrue($saved);
         //Reset count of test items to 0.
         $testItem->delete();
     }
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:25,代码来源:OwnedSecurableTestItemTest.php

示例12: testSaveModelFromPostSuccessfulSave

 public function testSaveModelFromPostSuccessfulSave()
 {
     //Unfreeze since the test model is not part of the standard schema.
     $freezeWhenComplete = false;
     if (RedBeanDatabase::isFrozen()) {
         RedBeanDatabase::unfreeze();
         $freezeWhenComplete = true;
     }
     Yii::app()->user->userModel = User::getByUsername('super');
     $savedSuccessfully = false;
     $modelToStringValue = null;
     $postData = array('member' => 'abc');
     $model = new OwnedSecurableTestItem();
     $this->assertFalse($model->hasErrors());
     $controllerUtil = new ZurmoControllerUtil();
     $model = $controllerUtil->saveModelFromPost($postData, $model, $savedSuccessfully, $modelToStringValue);
     $this->assertTrue($savedSuccessfully);
     $this->assertEquals('abc', $modelToStringValue);
     $this->assertFalse($model->hasErrors());
     $this->assertTrue($model->id > 0);
     //Re-freeze if needed.
     if ($freezeWhenComplete) {
         RedBeanDatabase::freeze();
     }
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:25,代码来源:ZurmoControllerUtilTest.php

示例13: testSaveAllMetadata

 public function testSaveAllMetadata()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $this->assertTrue(ContactsModule::loadStartingData());
     $messageLogger = new MessageLogger();
     InstallUtil::autoBuildDatabase($messageLogger, true);
     chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands');
     $command = "php zurmocTest.php manageMetadata super saveAllMetadata";
     if (!IS_WINNT) {
         $command .= ' 2>&1';
     }
     exec($command, $output);
     // Check if data are saved for some specific View
     $moduleMetadata = ZurmoRedBean::getRow("SELECT * FROM globalmetadata WHERE classname='NotesModule'");
     $this->assertTrue($moduleMetadata['id'] > 0);
     $this->assertTrue(strlen($moduleMetadata['serializedmetadata']) > 0);
     // Check if data are saved for some specific View
     $modelMetadata = ZurmoRedBean::getRow("SELECT * FROM globalmetadata WHERE classname='Note'");
     $this->assertTrue($modelMetadata['id'] > 0);
     $this->assertTrue(strlen($modelMetadata['serializedmetadata']) > 0);
     // Check if data are saved for some specific View
     $viewMetadata = ZurmoRedBean::getRow("SELECT * FROM globalmetadata WHERE classname='ContactsListView'");
     $this->assertTrue($viewMetadata['id'] > 0);
     $this->assertTrue(strlen($viewMetadata['serializedmetadata']) > 0);
 }
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:26,代码来源:ManageMetadataCommandTest.php

示例14: testGetExportValue

 public function testGetExportValue()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $currencies = Currency::getAll();
     $currencyValue = new CurrencyValue();
     $currencyValue->value = 100;
     $currencyValue->currency = $currencies[0];
     $this->assertEquals('USD', $currencyValue->currency->code);
     $data = array();
     $model = new ExportTestModelItem();
     $model->currencyValue = $currencyValue;
     $model->lastName = "Smith";
     $model->string = "Some Test String";
     // We have to save model, to get correct currencyValue id.
     $this->assertTrue($model->save());
     $adapter = new CurrencyValueRedBeanModelAttributeValueToExportValueAdapter($model, 'currencyValue');
     $adapter->resolveData($data);
     $compareData = array($currencyValue->value, $currencyValue->currency->code);
     $this->assertEquals($compareData, $data);
     $data = array();
     $adapter->resolveHeaderData($data);
     $compareData = array($model->getAttributeLabel('currencyValue'), $model->getAttributeLabel('currencyValue') . " " . Zurmo::t('ZurmoModule', 'Currency'));
     $this->assertEquals($compareData, $data);
     $data = array();
     $model = new ExportTestModelItem();
     $adapter = new CurrencyValueRedBeanModelAttributeValueToExportValueAdapter($model, 'currencyValue');
     $adapter->resolveData($data);
     $compareData = array('', '');
     $this->assertEquals($compareData, $data);
     $data = array();
     $adapter->resolveHeaderData($data);
     $compareData = array($model->getAttributeLabel('currencyValue'), $model->getAttributeLabel('currencyValue') . " " . Zurmo::t('ZurmoModule', 'Currency'));
     $this->assertEquals($compareData, $data);
 }
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:35,代码来源:CurrencyValueRedBeanModelAttributeValueToExportValueAdapterTest.php

示例15: testRegularUserAllControllerActionsNoElevation

 public function testRegularUserAllControllerActionsNoElevation()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $superAccount = AccountTestHelper::createAccountByNameForOwner('accountOwnedBySuper', $super);
     //Create address array for the account owned by super user.
     $address = array('street1' => '123 Knob Street', 'street2' => 'Apartment 4b', 'city' => 'Chicago', 'state' => 'Illinois', 'postalCode' => '60606', 'country' => 'USA');
     //Assign Address to the user account.
     AddressGeoCodeTestHelper::updateTestAccountsWithBillingAddress($superAccount->id, $address, $super);
     //Fetch Latitute and Longitude values for address and save in Address.
     AddressMappingUtil::updateChangedAddresses();
     $accounts = Account::getByName('accountOwnedBySuper');
     $this->assertEquals(1, count($accounts));
     $this->assertEquals(round('42.11529', 4), round($accounts[0]->billingAddress->latitude, 4));
     $this->assertEquals(round('-87.976399', 4), round($accounts[0]->billingAddress->longitude, 4));
     $this->assertEquals(0, $accounts[0]->billingAddress->invalid);
     $addressString = $accounts[0]->billingAddress->makeAddress();
     $this->setGetArray(array('addressString' => $addressString, 'latitude' => $accounts[0]->billingAddress->latitude, 'longitude' => $accounts[0]->billingAddress->longitude));
     Yii::app()->user->userModel = User::getByUsername('nobody');
     //Now test account details portlet controller actions
     $this->setGetArray(array('id' => $superAccount->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('accounts/default/details');
     //The map should always be available.  Not controlled by rights.
     $this->setGetArray(array('addressString' => 'anAddress String', 'latitude' => '45.00', 'longitude' => '45.00'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('maps/default/mapAndPoint');
     $this->assertNotContains('Access Failure', $content);
 }
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:27,代码来源:MapsRegularUserWalkthroughTest.php


注:本文中的User::getByUsername方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。