public function testUpdateConfig_ConfigPersists() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserModel($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->write(); $project->write(); $config = json_decode(json_encode(LexBaseViewDto::encode($projectId, $userId)['config']), true); $this->assertTrue($config['tasks']['addMeanings']['visible']); $this->assertEqual($config['entry']['fields']['lexeme']['inputSystems'][0], 'th'); $config['tasks']['addMeanings']['visible'] = false; $config['entry']['fields']['lexeme']['inputSystems'] = array('my', 'th'); LexProjectCommands::updateConfig($projectId, $config); $project2 = new LexiconProjectModel($projectId); // test for a few default values $this->assertEqual($project2->inputSystems['en']->tag, 'en'); $this->assertTrue($project2->config->tasks['dbe']->visible); $this->assertEqual($project2->config->entry->fields['lexeme']->label, 'Word'); // test for updated values $this->assertFalse($project2->config->tasks['addMeanings']->visible); $this->assertEqual($project2->config->entry->fields['lexeme']->inputSystems[0], 'my'); $this->assertEqual($project2->config->entry->fields['lexeme']->inputSystems[1], 'th'); }
function testEncode_EntriesAndLoadPartial_PartialOk() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserModel($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->write(); $project->write(); $sense = new Sense(); $sense->definition->form('en', 'apple'); for ($i = 9; $i >= 0; $i--) { $entry = new LexEntryModel($project); $entry->lexeme->form('th', 'Apfel' . $i); $entry->senses[] = $sense; $entry->write(); } $result = LexDbeDto::encode($projectId, $userId, null, 5); $this->assertEqual(count($result['entries']), 5); $this->assertEqual($result['itemCount'], 5); $this->assertEqual($result['itemTotalCount'], 10); $this->assertEqual($result['entries'][0]['lexeme']['th']['value'], 'Apfel0', 'Apfel0 should sort first'); $this->assertEqual($result['entries'][4]['lexeme']['th']['value'], 'Apfel4', 'Apfel4 should sort first'); $result = LexDbeDto::encode($projectId, $userId, null, 9); $this->assertEqual(count($result['entries']), 1); $this->assertEqual($result['itemCount'], 1); $this->assertEqual($result['itemTotalCount'], 10); $this->assertEqual($result['entries'][0]['lexeme']['th']['value'], 'Apfel0', 'Apfel0 should sort first'); }
public function getProjectMember($projectId, $userName) { $userId = $this->e->createUser($userName, $userName, '*****@*****.**'); $user = new UserModel($userId); $user->addProject($projectId); $user->write(); $project = new ProjectModel($projectId); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $project->write(); return $userId; }
public function testUserCanAccessMethod_projectSettings_projectMember_false() { $userId = $this->environ->createUser('user', 'user', '*****@*****.**', SystemRoles::USER); $user = new UserModel($userId); $project = $this->environ->createProject('projectForTest', 'projTestCode'); $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $project->appName = 'sfchecks'; $project->write(); $user->addProject($projectId); $user->write(); $project = ProjectModel::getById($projectId); $rh = new RightsHelper($userId, $project, $this->environ->website); $result = $rh->userCanAccessMethod('project_settings', array()); $this->assertFalse($result); }
public function testEncode_ProjectWithUser_DtoCorrect() { $e = new MongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserModel($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->write(); $project->write(); $dto = ManageUsersDto::encode($projectId); $this->assertEqual($dto['userCount'], 1); $this->assertIsA($dto['users'], 'array'); $this->assertEqual($dto['users'][0]['id'], $userId); $this->assertEqual($dto['users'][0]['name'], 'Name'); $this->assertEqual($dto['users'][0]['role'], ProjectRoles::CONTRIBUTOR); }
public function testEncode_ProjectWith2Users1Unvalidated_DtoCorrect1User() { $e = new MongoTestEnvironment(); $e->clean(); $user1Id = $e->createUser("", "", ""); $user1 = new UserModel($user1Id); $user1->role = SystemRoles::USER; $user2Id = $e->createUser("User", "Name", "*****@*****.**"); $user2 = new UserModel($user2Id); $user2->role = SystemRoles::USER; $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $project->addUser($user1Id, ProjectRoles::CONTRIBUTOR); $user1->addProject($projectId); $user1->write(); $project->addUser($user2Id, ProjectRoles::CONTRIBUTOR); $user2->addProject($projectId); $user2->write(); $project->write(); $text1 = new TextModel($project); $text1->title = "Some Title"; $text1->write(); $text2 = new TextModel($project); $text2->title = "Archived Title"; $text2->isArchived = true; $text2->write(); $dto = ProjectSettingsDto::encode($projectId, $user2Id); $this->assertEqual($dto['count'], 1); $this->assertIsA($dto['entries'], 'array'); $this->assertEqual($dto['entries'][0]['id'], $user2Id); $this->assertEqual($dto['entries'][0]['name'], 'Name'); $this->assertEqual($dto['entries'][0]['role'], ProjectRoles::CONTRIBUTOR); $this->assertEqual(count($dto['archivedTexts']), 1); $this->assertEqual($dto['archivedTexts'][0]['title'], 'Archived Title'); $this->assertTrue(count($dto['rights']) > 0, "No rights in dto"); $this->assertEqual($dto['bcs']['op'], 'settings'); $this->assertEqual($dto['bcs']['project'], array('id' => $projectId, 'crumb' => SF_TESTPROJECT)); $this->assertFalse(isset($dto['project']['users'])); $this->assertEqual($dto['project']['id'], $projectId); }
public function testEncode_ProjectWithUser_DtoCorrect() { $e = new MongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserModel($userId); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE, 'sfchecks'); $project->ownerRef->id = $userId; $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $user->addProject($projectId); $user->write(); $project->write(); $dto = ProjectManagementDto::encode($projectId); $this->assertTrue(count($dto['reports']) > 0); $foundUserEngagementReport = false; foreach ($dto['reports'] as $report) { if ($report['id'] == 'sfchecks_userEngagementReport') { $foundUserEngagementReport = true; } } $this->assertTrue($foundUserEngagementReport); }
public function testEncode_2Questions1Archived_DtoCorrect1ArchivedQuestion() { $e = new MongoTestEnvironment(); $e->clean(); $userId = $e->createUser("User", "Name", "*****@*****.**"); $user = new UserModel($userId); $user->role = SystemRoles::USER; $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $project->addUser($userId, ProjectRoles::MANAGER); $user->addProject($projectId); $user->write(); $project->write(); $text = new TextModel($project); $text->title = "Text Title"; $textId = $text->write(); $question1 = new QuestionModel($project); $question1->title = "Some Title"; $question1->textRef->id = $textId; $question1->write(); $question2 = new QuestionModel($project); $question2->title = "Archived Title"; $question2->textRef->id = $textId; $question2->isArchived = true; $question2->write(); $dto = TextSettingsDto::encode($projectId, $textId, $userId); $this->assertIsA($dto['text'], 'array'); $this->assertEqual($dto['text']['id'], $textId); $this->assertEqual($dto['text']['title'], 'Text Title'); $this->assertIsA($dto['archivedQuestions'], 'array'); $this->assertEqual(count($dto['archivedQuestions']), 1); $this->assertEqual($dto['archivedQuestions'][0]['title'], 'Archived Title'); $this->assertTrue(count($dto['rights']) > 0, "No rights in dto"); $this->assertEqual($dto['bcs']['op'], 'settings'); $this->assertEqual($dto['bcs']['project'], array('id' => $projectId, 'crumb' => SF_TESTPROJECT)); }
public function testSendJoinRequest_PropertiesFromToBodyOk() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $adminId = $e->createUser('admin', 'Admin', '*****@*****.**'); $admin = new UserModel($adminId); $userId = $e->createUser('User', 'Name', '*****@*****.**'); $user = new UserModel($userId); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $delivery = new MockCommunicateDelivery(); $project->addUser($adminId, $e->website->userDefaultSiteRole); $project->write(); $admin->addProject($project->id->asString()); $admin->write(); Communicate::sendJoinRequest($user, $admin, $project, $e->website, $delivery); // What's in the delivery? $senderEmail = 'no-reply@' . $e->website->domain; $expectedFrom = array($senderEmail => $e->website->name); $expectedTo = array($admin->email => $admin->name); $this->assertEqual($expectedFrom, $delivery->from); $this->assertEqual($expectedTo, $delivery->to); $this->assertPattern('/' . $user->name . '/', $delivery->subject); $this->assertPattern('/' . $e->website->domain . '\\/app\\/usermanagement/', $delivery->content); }
public function testMultipleUnreadModels_multipleUsers_multipleUpdates_multipleVisitsToQuestionPage_usersHaveDifferentUnreadStates() { $e = new MongoTestEnvironment(); $e->clean(); $project = $e->createProject("unread_test", "unreadCode"); $projectId = $project->id->asString(); $userId1 = $e->createUser('user1', 'user1', 'user1'); $user1 = new UserModel($userId1); $user1->addProject($project->id->asString()); $user1->write(); $userId2 = $e->createUser('user2', 'user2', 'user2'); $user2 = new UserModel($userId2); $user2->addProject($project->id->asString()); $user2->write(); $userId3 = $e->createUser('user3', 'user3', 'user3'); $user3 = new UserModel($userId3); $user3->addProject($project->id->asString()); $user3->write(); $answer1 = array('content' => "test answer 1", 'id' => ''); $answer2 = array('content' => "test answer 2", 'id' => ''); $text = new TextModel($project); $text->title = "Text 1"; $usx = MongoTestEnvironment::usxSample(); $text->content = $usx; $textId = $text->write(); $question = new QuestionModel($project); $question->title = "test question"; $question->textRef->id = $textId; $questionId = $question->write(); $answer1Dto = QuestionCommands::updateAnswer($projectId, $questionId, $answer1, $userId1); $answer2Dto = QuestionCommands::updateAnswer($projectId, $questionId, $answer2, $userId2); $answer1 = array_pop($answer1Dto); $answer1Id = $answer1['id']; $answer2 = array_pop($answer2Dto); $answer2Id = $answer2['id']; // the answer author does NOT get their answer marked as unread $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 1); // the answer author does NOT get their answer marked as unread $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 1); $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 2); // user1 visits question page $pageDto = QuestionCommentDto::encode($projectId, $questionId, $userId1); $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 0); $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 1); $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 2); // user2 visits question page $pageDto = QuestionCommentDto::encode($projectId, $questionId, $userId2); $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 0); $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 0); $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 2); // user2 visits question page $pageDto = QuestionCommentDto::encode($projectId, $questionId, $userId3); $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 0); $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 0); $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId); $this->assertEqual(count($unreadModel->unreadItems()), 0); }
public function testRemoveUsers_ProjectOwner_NotRemovedFromProject() { $this->environ->clean(); // setup project and users. user1 is the project owner $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $user1Id = $this->environ->createUser("user1name", "User1 Name", "*****@*****.**"); $user2Id = $this->environ->createUser("user2name", "User2 Name", "*****@*****.**"); $user1 = new UserModel($user1Id); $user2 = new UserModel($user2Id); $project->addUser($user1->id->asString(), ProjectRoles::CONTRIBUTOR); $project->addUser($user2->id->asString(), ProjectRoles::CONTRIBUTOR); $project->ownerRef = $user2Id; $project->write(); $user1->addProject($project->id->asString()); $user1->write(); $user2->addProject($project->id->asString()); $user2->write(); // save data for rest of this test $this->save['projectId'] = $projectId; $this->save['user1Id'] = $user1Id; $this->save['user2Id'] = $user2Id; // remove users from project. user1 still remains as project owner $userIds = array($user1->id->asString(), $user2->id->asString()); $this->expectException(); $this->environ->inhibitErrorDisplay(); ProjectCommands::removeUsers($projectId, $userIds); // nothing runs in the current test function after an exception. IJH 2014-11 }
/** * Update the user project role in the project * @param string $projectId * @param string $userId * @param string $projectRole * @return string - userId */ public static function updateUserRole($projectId, $userId, $projectRole = ProjectRoles::CONTRIBUTOR) { CodeGuard::checkNotFalseAndThrow($projectId, '$projectId'); CodeGuard::checkNotFalseAndThrow($userId, 'userId'); //CodeGuard::assertInArrayOrThrow($role, array(ProjectRoles::CONTRIBUTOR, ProjectRoles::MANAGER)); // Add the user to the project $user = new UserModel($userId); $project = ProjectModel::getById($projectId); if ($userId == $project->ownerRef->asString()) { throw new \Exception("Cannot update role for project owner"); } // TODO: Only trigger activity if this is the first time they have been added to project $usersDto = ProjectCommands::usersDto($projectId); if (!$project->users->offsetExists($userId)) { ActivityCommands::addUserToProject($project, $userId); } $project->addUser($userId, $projectRole); $user->addProject($projectId); $project->write(); $user->write(); return $userId; }
/** * Sends an email to invite emailee to join the project * @param string $projectId * @param string $inviterUserId * @param Website $website * @param string $toEmail * @param DeliveryInterface $delivery * @throws \Exception * @return string $userId */ public static function sendInvite($projectId, $inviterUserId, $website, $toEmail, DeliveryInterface $delivery = null) { $newUser = new UserModel(); $inviterUser = new UserModel($inviterUserId); $project = new ProjectModel($projectId); $newUser->emailPending = $toEmail; // Check if email already exists in an account $identityCheck = UserCommands::checkIdentity('', $toEmail, $website); if ($identityCheck->emailExists) { $newUser->readByProperty('email', $toEmail); } // Make sure the user exists on the site if (!$newUser->hasRoleOnSite($website)) { $newUser->siteRole[$website->domain] = $website->userDefaultSiteRole; } // Determine if user is already a member of the project if ($project->userIsMember($newUser->id->asString())) { return $newUser->id; } // Add the user to the project $newUser->addProject($project->id->asString()); $userId = $newUser->write(); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $project->write(); if (!$identityCheck->emailExists) { // Email communication with new user Communicate::sendInvite($inviterUser, $newUser, $project, $website, $delivery); } else { // Tell existing user they're now part of the project Communicate::sendAddedToProject($inviterUser, $newUser, $project, $website, $delivery); } return $userId; }
public function testUserRemove_UserMemberOfProject_ProjectLinkRemovedAsWell() { $e = new MongoTestEnvironment(); $e->clean(); $userId = $e->createUser('user1', 'user1', 'user1'); $user = new UserModel($userId); $project = $e->createProject('testProject', 'testProjectCode'); $project->addUser($userId, ProjectRoles::CONTRIBUTOR); $project->write(); $user->addProject($project->id->asString()); $user->write(); // delete the user $user->remove(); // re-read the project $project->read($project->id->asString()); $this->assertFalse($project->userIsMember($userId)); }
public function testGetActivityForUser_TwoProjectsTwoDomains_UnreadHasOneProject() { $e = new MongoTestEnvironment('scriptureforge.org'); $e->clean(); $project1 = $e->createProject(SF_TESTPROJECTCODE, SF_TESTPROJECTCODE); $project2 = $e->createProject(SF_TESTPROJECTCODE2, SF_TESTPROJECTCODE2); $project2->siteName = 'languageforge.org'; $project2->write(); $userId = $e->createUser('joe', 'joe', 'joe'); $user = new UserModel($userId); $user->addProject($project1->id->asString()); $user->addProject($project2->id->asString()); $project1->addUser($userId, ProjectRoles::CONTRIBUTOR); $project2->addUser($userId, ProjectRoles::CONTRIBUTOR); $user->write(); $project1->write(); $project2->write(); $text = new TextModel($project1); $text->title = "Text 1"; $text->content = "text content"; $textId = $text->write(); $a1 = ActivityCommands::addText($project1, $textId, $text); $text = new TextModel($project2); $text->title = "Text 2"; $text->content = "text content"; $textId = $text->write(); $a2 = ActivityCommands::addText($project2, $textId, $text); $dto = ActivityListDto::getActivityForUser($project1->siteName, $userId); $this->assertEqual(count($dto['unread']), 1); }