public function run($userId, $mode = 'test') { $testMode = $mode != 'run'; $message = ''; $userlist = new UserListModel(); $userlist->read(); $badAvatarLinks = 0; foreach ($userlist->entries as $userParams) { // foreach existing user $userId = $userParams['id']; $user = new UserProfileModel($userId); if (strpos($user->avatar_ref, '/') !== FALSE or strpos($user->avatar_ref, '\\') !== FALSE) { if ($user->avatar_color != '' && $user->avatar_shape != '') { $newRef = $user->avatar_color . '-' . $user->avatar_shape . '-128x128.png'; } else { $newRef = 'anonymoose.png'; } $message .= "Changed user {$userId} 's avatar from " . $user->avatar_ref . " to {$newRef}\n"; $user->avatar_ref = $newRef; $badAvatarLinks++; if (!$testMode) { $user->write(); } } } if ($badAvatarLinks > 0) { $message .= "\n\nFixed {$badAvatarLinks} bad avatar URLs\n\n"; } else { $message .= "\n\nNo bad avatar URLs were found\n\n"; } return $message; }
public function testEncode_userProjectHasNoUserProfileProperties_noProjectSettings() { $e = new MongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserProfileModel($userId); $user->role = SiteRoles::USER; $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $user->addProject($projectId); // user profile has data; but the encode method ignores it because the project has not enabled the 'city' property $projectUserProfile = new SfchecksUserProfile(); $projectUserProfile->city = 'myCity'; $user->projectUserProfiles[$projectId] = $projectUserProfile; $user->write(); $project->write(); $dto = UserProfileDto::encode($userId, $e->website); $this->assertIsA($dto['userProfile'], 'array'); $this->assertEqual($dto['userProfile']['id'], $userId); $this->assertEqual($dto['userProfile']['name'], 'Name'); $this->assertEqual($dto['userProfile']['role'], SiteRoles::USER); $this->assertTrue(array_key_exists('avatar_shape', $dto['userProfile'])); $this->assertTrue(array_key_exists('avatar_color', $dto['userProfile'])); $this->assertFalse(isset($dto['userProfile']['projects'])); $this->assertIsA($dto['projectsSettings'], 'array'); $this->assertEqual(count($dto['projectsSettings']), 0); }
public function testEncode_Project_DtoCorrect() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserProfileModel($userId); $user->role = SystemRoles::USER; $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $user->addProject($projectId); $user->interfaceLanguageCode = 'th'; $user->write(); $project->write(); $dto = LexBaseViewDto::encode($projectId, $userId); // test for a few default values $this->assertEqual($dto['config']['inputSystems']['en']['tag'], 'en'); $this->assertTrue($dto['config']['tasks']['dbe']['visible']); $this->assertEqual($dto['config']['entry']['type'], 'fields', 'dto config is not valid'); $this->assertEqual($dto['config']['entry']['fields']['lexeme']['label'], 'Word'); $this->assertEqual($dto['config']['entry']['fields']['lexeme']['label'], 'Word'); $this->assertEqual($dto['config']['entry']['fields']['senses']['fields']['partOfSpeech']['label'], 'Part of Speech'); $this->assertTrue($dto['config']['roleViews']['contributor']['fields']['lexeme']['show']); $this->assertTrue($dto['config']['roleViews']['contributor']['showTasks']['dbe']); // todo re-enable this after userLanguageCode feature is mature //$this->assertEqual($dto['interfaceConfig']['userLanguageCode'], 'th'); $this->assertEqual($dto['interfaceConfig']['selectLanguages']['options']['en'], 'English'); }