PHP User::getByUsername Examples

PHP User::getByUsername - 30 examples found. These are the top rated real world PHP examples of User::getByUsername extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
 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));
 }
Example #2
0
 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);
 }
 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());
 }
Example #4
0
 public function setUp()
 {
     EmailMessageTestHelper::purgeAllMessages();
     parent::setUp();
     $this->user = User::getByUsername('super');
     Yii::app()->user->userModel = $this->user;
 }
 public function setUp()
 {
     parent::setUp();
     $this->user = User::getByUsername('super');
     Yii::app()->user->userModel = $this->user;
     $this->purgeAllCampaigns();
 }
 public function setUp()
 {
     parent::setUp();
     Yii::app()->user->userModel = User::getByUsername('super');
     EmailMessage::deleteAll();
     Notification::deleteAll();
 }
 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);
 }
 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();
 }
 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);
 }
 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());
 }
 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();
     }
 }
 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();
     }
 }
 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);
 }
 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);
 }
 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);
 }
Example #16
0
 public function testSubmitNonCritical()
 {
     $super = User::getByUsername('super');
     $emailAddress = new Email();
     $emailAddress->emailAddress = 'sometest@zurmoalerts.com';
     $super->primaryEmail = $emailAddress;
     $saved = $super->save();
     $this->assertTrue($saved);
     $billy = User::getByUsername('billy');
     $emailAddress = new Email();
     $emailAddress->emailAddress = 'sometest2@zurmoalerts.com';
     $billy->primaryEmail = $emailAddress;
     $saved = $billy->save();
     $this->assertTrue($saved);
     $notifications = Notification::getAll();
     $this->assertEquals(0, count($notifications));
     $message = new NotificationMessage();
     $message->textContent = 'text content';
     $message->htmlContent = 'html content';
     $rules = new SimpleNotificationRules();
     $rules->addUser($super);
     $rules->addUser($billy);
     NotificationsUtil::submit($message, $rules);
     //It should not send an email because it is non-critical
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $notifications = Notification::getAll();
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
 }
 public function testSendSystemEmail()
 {
     if (!EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
         $this->markTestSkipped(Zurmo::t('EmailMessagesModule', 'Test email settings are not configured in perInstanceTest.php file.'));
     }
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     Yii::app()->imap->connect();
     EmailMessage::deleteAll();
     // Expunge all emails from dropbox
     Yii::app()->imap->deleteMessages(true);
     $this->assertEquals(0, EmailMessage::getCount());
     $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed();
     $this->assertEquals(0, $imapStats->Nmsgs);
     $subject = "System Message";
     $textMessage = "System message content.";
     $htmlMessage = "<strong>System</strong> message content.";
     EmailMessageHelper::sendSystemEmail($subject, array(Yii::app()->imap->imapUsername), $textMessage, $htmlMessage);
     sleep(30);
     Yii::app()->imap->connect();
     $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed();
     $this->assertEquals(1, $imapStats->Nmsgs);
     $this->assertEquals(1, EmailMessage::getCount());
     $emailMessages = EmailMessage::getAll();
     $emailMessage = $emailMessages[0];
     $this->assertEquals('System Message', $emailMessage->subject);
     $this->assertEquals('System message content.', trim($emailMessage->content->textContent));
     $this->assertEquals('<strong>System</strong> message content.', trim($emailMessage->content->htmlContent));
     $this->assertEquals(1, count($emailMessage->recipients));
     foreach ($emailMessage->recipients as $recipient) {
         $this->assertEquals($recipient->toAddress, Yii::app()->imap->imapUsername);
         $this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipient->type);
     }
 }
 public function testImportDataAnalysisResults()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $import = new Import();
     $serializedData['importRulesType'] = 'Users';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.users.tests.unit.files'));
     $mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'username', 'type' => 'importColumn', 'mappingRulesData' => array()), 'column_1' => array('attributeIndexOrDerivedType' => 'Password', 'type' => 'importColumn', 'mappingRulesData' => array('PasswordDefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_2' => array('attributeIndexOrDerivedType' => 'UserStatus', 'type' => 'importColumn', 'mappingRulesData' => array('UserStatusDefaultValueMappingRuleForm' => array('defaultValue' => UserStatusUtil::ACTIVE))));
     $serializedData = unserialize($import->serializedData);
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $importRules = ImportRulesUtil::makeImportRulesByType('Users');
     $config = array('pagination' => array('pageSize' => 2));
     //This test csv has a header row.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     //Run data analyzer
     $importDataAnalyzer = new ImportDataAnalyzer($importRules, $dataProvider);
     foreach ($mappingData as $columnName => $columnMappingData) {
         $importDataAnalyzer->analyzeByColumnNameAndColumnMappingData($columnName, $columnMappingData);
     }
     $messagesData = $importDataAnalyzer->getMessagesData();
     $compareData = array('column_0' => array(array('message' => '1 value(s) are too large for this field. These values will be truncated to a length of 64 upon import.', 'sanitizerUtilType' => 'Truncate', 'moreAvailable' => false)), 'column_1' => array(array('message' => '1 value(s) are too large for this field. These values will be truncated to a length of 32 upon import.', 'sanitizerUtilType' => 'Truncate', 'moreAvailable' => false)), 'column_2' => array(array('message' => '2 user status value(s) are not valid. Users that have these values will be set to active upon import.', 'sanitizerUtilType' => 'UserStatus', 'moreAvailable' => false)));
     $this->assertEquals($compareData, $messagesData);
     $importInstructionsData = $importDataAnalyzer->getImportInstructionsData();
     $compareInstructionsData = array();
     $this->assertEquals($compareInstructionsData, $importInstructionsData);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $super = User::getByUsername('super');
     $super = User::getByUsername('super');
     $super->primaryEmail = new Email();
     $super->primaryEmail->emailAddress = 'super@zurmo.com';
     assert($super->save());
     // Not Coding Standard
     $bobby = UserTestHelper::createBasicUserWithEmailAddress('bobby');
     $sarah = UserTestHelper::createBasicUserWithEmailAddress('sarah');
     self::$superUserId = $super->id;
     self::$bobbyUserId = $bobby->id;
     self::$sarahUserId = $sarah->id;
     $emailTemplate = new EmailTemplate();
     $emailTemplate->modelClassName = 'WorkflowModelTestItem';
     $emailTemplate->type = 1;
     $emailTemplate->name = 'some template';
     $emailTemplate->subject = 'some subject [[LAST^NAME]]';
     $emailTemplate->htmlContent = 'html content [[STRING]]';
     $emailTemplate->textContent = 'text content [[PHONE]]';
     $saved = $emailTemplate->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     self::$emailTemplate = $emailTemplate;
 }
 public function testResolvePortletsForCurrentUser()
 {
     $betty = User::getByUsername('betty');
     $this->assertFalse(RightsUtil::canUserAccessModule('AccountsModule', $betty));
     $this->assertFalse(RightsUtil::canUserAccessModule('ContactsModule', $betty));
     $this->assertFalse(RightsUtil::canUserAccessModule('TasksModule', $betty));
     Yii::app()->user->userModel = $betty;
     $portlet1 = new Portlet();
     $portlet1->viewType = 'AccountsRelatedList';
     $portlet2 = new Portlet();
     $portlet2->viewType = 'ContactsRelatedList';
     $portlet3 = new Portlet();
     $portlet3->viewType = 'TasksMyList';
     $portlets = array();
     $portlets[0][0] = $portlet1;
     $portlets[0][1] = $portlet2;
     $portlets[0][2] = $portlet3;
     $portlets[1][0] = $portlet3;
     $portlets[1][1] = $portlet1;
     $portlets[1][2] = $portlet3;
     $this->assertEquals(2, count($portlets));
     $resolvedPortlets = PortletsSecurityUtil::resolvePortletsForCurrentUser($portlets);
     $comparePortlets = array();
     $comparePortlets[0][0] = $portlet3;
     $comparePortlets[1][0] = $portlet3;
     $comparePortlets[1][1] = $portlet3;
     $this->assertEquals(0, count($resolvedPortlets));
     Yii::app()->user->userModel = User::getByUsername('super');
     $resolvedPortlets = PortletsSecurityUtil::resolvePortletsForCurrentUser($portlets);
     $this->assertEquals($portlets, $resolvedPortlets);
 }
 public function setup()
 {
     parent::setUp();
     Yii::app()->user->userModel = User::getByUsername('super');
     Yii::app()->user->userModel->timeZone = 'America/Chicago';
     DisplayAttributeForReportForm::resetCount();
 }
 public function testCreateActionSecurityFromActionType()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $object = ActionSecurityFactory::createActionSecurityFromActionType('Delete', new Account(), $super);
     $this->assertTrue($object instanceof ActionSecurity);
 }
 public function testProcessStatusAndMessagesForEachRow()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $testTableName = $import->getTempTableName();
     $this->assertTrue(ImportTestHelper::createTempTableByFileNameAndTableName('importTest.csv', $testTableName));
     $count = ImportDatabaseUtil::getCount($testTableName);
     $this->assertEquals(5, $count);
     //Now add import results.
     $resultsUtil = new ImportResultsUtil($import);
     $rowDataResultsUtil = new ImportRowDataResultsUtil(2);
     $rowDataResultsUtil->setStatusToUpdated();
     $rowDataResultsUtil->addMessage('the first message');
     $resultsUtil->addRowDataResults($rowDataResultsUtil);
     $rowDataResultsUtil = new ImportRowDataResultsUtil(3);
     $rowDataResultsUtil->setStatusToCreated();
     $rowDataResultsUtil->addMessage('the second message');
     $resultsUtil->addRowDataResults($rowDataResultsUtil);
     $rowDataResultsUtil = new ImportRowDataResultsUtil(4);
     $rowDataResultsUtil->setStatusToError();
     $rowDataResultsUtil->addMessage('the third message');
     $resultsUtil->addRowDataResults($rowDataResultsUtil);
     $resultsUtil->processStatusAndMessagesForEachRow();
     $sql = 'select * from ' . $testTableName . ' where id != 1';
     $tempTableData = R::getAll($sql);
     $compareData = array(array('id' => 2, 'column_0' => 'abc', 'column_1' => '123', 'column_2' => 'a', 'status' => 1, 'serializedmessages' => serialize(array('the first message'))), array('id' => 3, 'column_0' => 'def', 'column_1' => '563', 'column_2' => 'b', 'status' => 2, 'serializedmessages' => serialize(array('the second message'))), array('id' => 4, 'column_0' => 'efg', 'column_1' => '456', 'column_2' => 'a', 'status' => 3, 'serializedmessages' => serialize(array('the third message'))), array('id' => 5, 'column_0' => 'we1s', 'column_1' => null, 'column_2' => 'b', 'status' => null, 'serializedmessages' => null));
     $this->assertEquals($compareData, $tempTableData);
 }
 public function testProperlyDeletingActivityItems()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $count = ZurmoRedBean::getRow('select count(*) count from activity_item');
     $this->assertEquals(0, $count['count']);
     $account = AccountTestHelper::createAccountByNameForOwner('anAccount', Yii::app()->user->userModel);
     $deleted = $account->delete();
     $this->assertTrue($deleted);
     $count = ZurmoRedBean::getRow('select count(*) count from activity_item');
     $this->assertEquals(0, $count['count']);
     $account2 = AccountTestHelper::createAccountByNameForOwner('anAccount2', Yii::app()->user->userModel);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('anOpp', Yii::app()->user->userModel);
     $task = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('aTask', Yii::app()->user->userModel, $account2);
     $task->activityItems->add($opportunity);
     $this->assertTrue($task->save());
     $taskId = $task->id;
     $task->forget();
     RedBeansCache::forgetAll();
     $count = ZurmoRedBean::getRow('select count(*) count from activity_item');
     $this->assertEquals(2, $count['count']);
     $deleted = $account2->delete();
     $this->assertTrue($deleted);
     $account2->forget();
     $count = ZurmoRedBean::getRow('select count(*) count from activity_item');
     $this->assertEquals(1, $count['count']);
     RedBeansCache::forgetAll();
     //Make sure things render ok even with the account deleted.
     $content = ActivitiesUtil::renderSummaryContent(Task::getById($taskId), 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'HomeModule');
 }
 public function setUp()
 {
     parent::setUp();
     Yii::app()->user->userModel = User::getByUsername('super');
     DisplayAttributeForReportForm::resetCount();
     DrillDownDisplayAttributeForReportForm::resetCount();
 }
 /**
  * @depends testResolveByTypeAndPerson
  */
 public function testProcessBonusPointsOnLevelChange()
 {
     Yii::app()->user->userModel = User::getByUsername('steven');
     $gamePoint = GamePoint::resolveToGetByTypeAndPerson(GamePoint::TYPE_USER_ADOPTION, Yii::app()->user->userModel);
     $this->assertEquals(GamePoint::TYPE_USER_ADOPTION, $gamePoint->type);
     $this->assertEquals(0, $gamePoint->value);
     //Testing a level that does not give bonus points.
     $gameLevel = new GameLevel();
     $gameLevel->person = Yii::app()->user->userModel;
     $gameLevel->type = GameLevel::TYPE_SALES;
     $gameLevel->value = 1;
     $this->assertTrue($gameLevel->save());
     GameLevel::processBonusPointsOnLevelChange($gameLevel, Yii::app()->user->userModel);
     //Test that bonus points were actually received.
     $gamePoint = GamePoint::resolveToGetByTypeAndPerson(GamePoint::TYPE_USER_ADOPTION, Yii::app()->user->userModel);
     $this->assertEquals(GamePoint::TYPE_USER_ADOPTION, $gamePoint->type);
     $this->assertEquals(100, $gamePoint->value);
     //Now get the GameLevel again, and make sure it works for level 2
     $gameLevel = GameLevel::resolveByTypeAndPerson(GameLevel::TYPE_SALES, Yii::app()->user->userModel);
     $gameLevel->person = Yii::app()->user->userModel;
     $gameLevel->type = GameLevel::TYPE_SALES;
     $gameLevel->value = 2;
     $this->assertTrue($gameLevel->save());
     GameLevel::processBonusPointsOnLevelChange($gameLevel, Yii::app()->user->userModel);
     //Test that bonus points were actually received.
     $gamePoint = GamePoint::resolveToGetByTypeAndPerson(GamePoint::TYPE_USER_ADOPTION, Yii::app()->user->userModel);
     $this->assertEquals(GamePoint::TYPE_USER_ADOPTION, $gamePoint->type);
     $this->assertEquals(210, $gamePoint->value);
 }
 public function testGetExportValue()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $data = array();
     $contactStates = ContactState::getByName('Qualified');
     $contact = new Contact();
     $contact->owner = $super;
     $contact->firstName = 'Super';
     $contact->lastName = 'Man';
     $contact->jobTitle = 'Superhero';
     $contact->description = 'Some Description';
     $contact->department = 'Red Tape';
     $contact->officePhone = '1234567890';
     $contact->mobilePhone = '0987654321';
     $contact->officeFax = '1222222222';
     $contact->state = $contactStates[0];
     $this->assertTrue($contact->save());
     $adapter = new ContactStateRedBeanModelAttributeValueToExportValueAdapter($contact, 'state');
     $adapter->resolveData($data);
     $compareData = array($contactStates[0]->name);
     $this->assertEquals($compareData, $data);
     $data = array();
     $adapter->resolveHeaderData($data);
     $compareData = array($contact->getAttributeLabel('state'));
     $this->assertEquals($compareData, $data);
 }
Example #28
0
 public function testGetUserRankingData()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $data = GamePointUtil::getUserRankingData($super);
     $this->assertEquals(3, count($data));
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
 }
 /**
  * Execute the action.
  * @param array command line parameters specific for this command
  */
 public function run($args)
 {
     set_time_limit('900');
     if (!isset($args[0])) {
         $this->usageError('A username must be specified.');
     }
     try {
         Yii::app()->user->userModel = User::getByUsername($args[0]);
     } catch (NotFoundException $e) {
         $this->usageError('The specified username does not exist.');
     }
     $group = Group::getByName(Group::SUPER_ADMINISTRATORS_GROUP_NAME);
     if (!$group->users->contains(Yii::app()->user->userModel)) {
         $this->usageError('The specified user is not a super administrator.');
     }
     if (User::getRootUserCount() > 0) {
         echo 'There is already a root user. A new one cannot be specified.';
         Yii::app()->end();
     }
     Yii::app()->user->userModel->setIsRootUser();
     Yii::app()->user->userModel->hideFromSelecting = true;
     Yii::app()->user->userModel->hideFromLeaderboard = true;
     $saved = Yii::app()->user->userModel->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     $template = "{message}\n";
     $messageStreamer = new MessageStreamer($template);
     $messageStreamer->setExtraRenderBytes(0);
     $messageStreamer->add('');
     $messageStreamer->add(Zurmo::t('Commands', 'User with username {username} elevated to root.', array('{username}' => Yii::app()->user->userModel->username)));
 }