public function testUserEngagementReport_simpleProjectWithQuestionsAndAnswers_AsExpected() { $e = new MongoTestEnvironment(); $e->clean(); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $text = new TextModel($project); $text->title = "Text 1"; $usx = MongoTestEnvironment::usxSample(); $text->content = $usx; $textId = $text->write(); $user1Id = $e->createUser("user1", "user1", "*****@*****.**"); $user2Id = $e->createUser("user2", "user2", "*****@*****.**"); $user3Id = $e->createUser("user3", "user3", "*****@*****.**"); ProjectCommands::updateUserRole($project->id->asString(), $user1Id); ProjectCommands::updateUserRole($project->id->asString(), $user2Id); ProjectCommands::updateUserRole($project->id->asString(), $user3Id); // Workflow is first to create a question $question = new QuestionModel($project); $question->title = "the question"; $question->description = "question description"; $question->textRef->id = $textId; $questionId = $question->write(); // Then to add an answer to a question $answer = new AnswerModel(); $answer->content = "first answer"; $answer->score = 10; $answer->userRef->id = $user3Id; $answer->textHightlight = "text highlight"; $answerId = $question->writeAnswer($answer); // Followed by comments $comment1 = new CommentModel(); $comment1->content = "first comment"; $comment1->userRef->id = $user1Id; $comment1Id = QuestionModel::writeComment($project->databaseName(), $questionId, $answerId, $comment1); $comment2 = new CommentModel(); $comment2->content = "second comment"; $comment2->userRef->id = $user2Id; $comment2Id = QuestionModel::writeComment($project->databaseName(), $questionId, $answerId, $comment2); $data = SfchecksReports::UserEngagementReport($project->id->asString()); $this->assertTrue($data['output']); }
public function testUpdateUserRole_JoinTwice_JoinedOnce() { $this->environ->clean(); // setup user and project $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $userId = $this->environ->createUser("existinguser", "Existing Name", "*****@*****.**"); $params = array('id' => $userId); // update user role in project once $updatedUserId = ProjectCommands::updateUserRole($projectId, $userId); // read from disk $sameUser = new UserModel($updatedUserId); $sameProject = new ProjectModel($projectId); // user in project once and project has one user $this->assertEqual($sameProject->listUsers()->count, 1); $this->assertEqual($sameUser->listProjects($this->environ->website->domain)->count, 1); // update user role in project again $updatedUserId = ProjectCommands::updateUserRole($projectId, $userId); // read from disk again $sameProject->read($projectId); $sameUser->read($updatedUserId); // user still in project once and project still has one user $this->assertEqual($sameProject->listUsers()->count, 1); $this->assertEqual($sameUser->listProjects($this->environ->website->domain)->count, 1); }
/** * * @param string $projectId * @param string $userId * @param string $website * @param role $role * @param DeliveryInterface $delivery * @return \Api\Model\Mapper\IdReference|\Api\Model\UserModel */ public static function acceptJoinRequest($projectId, $userId, $website, $role, DeliveryInterface $delivery = null) { $newUser = new UserModel($userId); $project = new ProjectModel(); $project->read($projectId); ProjectCommands::updateUserRole($projectId, $userId, $role); // 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; } $admin = new UserModel($project->ownerRef->asString()); if ($admin->email != '') { Communicate::sendJoinRequestAccepted($newUser, $project, $website, $delivery); } return $admin; }
public function project_updateUserRole($userId, $role) { return ProjectCommands::updateUserRole($this->_projectId, $userId, $role); }
} } $testProject = ProjectCommands::createProject($constants['testProjectName'], $constants['testProjectCode'], $projectType, $adminUserId, $website); $testProjectModel = new ProjectModel($testProject); $testProjectModel->projectCode = $constants['testProjectCode']; $testProjectModel->allowInviteAFriend = $constants['testProjectAllowInvites']; $testProjectModel->write(); $otherProject = ProjectCommands::createProject($constants['otherProjectName'], $constants['otherProjectCode'], $projectType, $managerUserId, $website); $otherProjectModel = new ProjectModel($otherProject); $otherProjectModel->projectCode = $constants['otherProjectCode']; $otherProjectModel->allowInviteAFriend = $constants['otherProjectAllowInvites']; $otherProjectModel->write(); ProjectCommands::updateUserRole($testProject, $managerUserId, ProjectRoles::MANAGER); ProjectCommands::updateUserRole($testProject, $memberUserId, ProjectRoles::CONTRIBUTOR); ProjectCommands::updateUserRole($testProject, $resetUserId, ProjectRoles::CONTRIBUTOR); ProjectCommands::updateUserRole($otherProject, $adminUserId, ProjectRoles::MANAGER); if ($site == 'scriptureforge') { $text1 = TextCommands::updateText($testProject, array('id' => '', 'title' => $constants['testText1Title'], 'content' => $constants['testText1Content'])); $text2 = TextCommands::updateText($testProject, array('id' => '', 'title' => $constants['testText2Title'], 'content' => $constants['testText2Content'])); $question1 = QuestionCommands::updateQuestion($testProject, array('id' => '', 'textRef' => $text1, 'title' => $constants['testText1Question1Title'], 'description' => $constants['testText1Question1Content'])); $question2 = QuestionCommands::updateQuestion($testProject, array('id' => '', 'textRef' => $text1, 'title' => $constants['testText1Question2Title'], 'description' => $constants['testText1Question2Content'])); $template1 = QuestionTemplateCommands::updateTemplate($testProject, array('id' => '', 'title' => 'first template', 'description' => 'not particularly interesting')); $template2 = QuestionTemplateCommands::updateTemplate($testProject, array('id' => '', 'title' => 'second template', 'description' => 'not entirely interesting')); $answer1 = QuestionCommands::updateAnswer($testProject, $question1, array('id' => '', 'content' => $constants['testText1Question1Answer']), $managerUserId); $answer1Id = array_keys($answer1)[0]; $answer2 = QuestionCommands::updateAnswer($testProject, $question2, array('id' => '', 'content' => $constants['testText1Question2Answer']), $managerUserId); $answer2Id = array_keys($answer2)[0]; $comment1 = QuestionCommands::updateComment($testProject, $question1, $answer1Id, array('id' => '', 'content' => $constants['testText1Question1Answer1Comment']), $managerUserId); $comment2 = QuestionCommands::updateComment($testProject, $question2, $answer2Id, array('id' => '', 'content' => $constants['testText1Question2Answer2Comment']), $managerUserId); } elseif ($site == 'languageforge') { // Set up LanguageForge E2E test envrionment here
public function testSessionData_userIsPartOfProject() { $e = new SessionTestEnvironment(); $e->create(); ProjectCommands::updateUserRole($e->projectId, $e->userId); $data = SessionCommands::getSessionData($e->projectId, $e->userId, $e->website); // Session data should contain user project rights, an array of integers $this->assertTrue(array_key_exists('userProjectRights', $data)); $this->assertTrue(is_array($data['userProjectRights'])); // ... which should not be empty once the user has been assigned to the project $this->assertFalse(empty($data['userProjectRights'])); $this->assertTrue(is_integer($data['userProjectRights'][0])); }