public function testSessionData_userIsPartOfProject()
 {
     $environ = new SessionTestEnvironment();
     $environ->create();
     ProjectCommands::updateUserRole($environ->projectId, $environ->userId);
     $data = SessionCommands::getSessionData($environ->projectId, $environ->userId, $environ->website);
     // Session data should contain user project rights, an array of integers
     $this->assertArrayHasKey('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]));
 }
 public function testUserEngagementReport_simpleProjectWithQuestionsAndAnswers_AsExpected()
 {
     $environ = new MongoTestEnvironment();
     $environ->clean();
     $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $text = new TextModel($project);
     $text->title = "Text 1";
     $usx = MongoTestEnvironment::usxSample();
     $text->content = $usx;
     $textId = $text->write();
     $user1Id = $environ->createUser("user1", "user1", "*****@*****.**");
     $user2Id = $environ->createUser("user2", "user2", "*****@*****.**");
     $user3Id = $environ->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;
     QuestionModel::writeComment($project->databaseName(), $questionId, $answerId, $comment1);
     $comment2 = new CommentModel();
     $comment2->content = "second comment";
     $comment2->userRef->id = $user2Id;
     QuestionModel::writeComment($project->databaseName(), $questionId, $answerId, $comment2);
     $data = SfchecksReports::UserEngagementReport($project->id->asString());
     $this->assertNotEmpty($data['output']);
 }
 public function project_updateUserRole($userId, $role)
 {
     return ProjectCommands::updateUserRole($this->projectId, $userId, $role);
 }
 public function testUpdateUserRole_JoinTwice_JoinedOnce()
 {
     self::$environ->clean();
     // setup user and project
     $project = self::$environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     $userId = self::$environ->createUser("existinguser", "Existing Name", "*****@*****.**");
     // 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->assertEquals(1, $sameProject->listUsers()->count);
     $this->assertEquals(1, $sameUser->listProjects(self::$environ->website->domain)->count);
     // 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->assertEquals(1, $sameProject->listUsers()->count);
     $this->assertEquals(1, $sameUser->listProjects(self::$environ->website->domain)->count);
 }
if ($site == 'scriptureforge') {
    $text1 = TextCommands::updateText($testProjectId, array('id' => '', 'title' => $constants['testText1Title'], 'content' => $constants['testText1Content']));
    $text2 = TextCommands::updateText($testProjectId, array('id' => '', 'title' => $constants['testText2Title'], 'content' => $constants['testText2Content']));
    $question1 = QuestionCommands::updateQuestion($testProjectId, array('id' => '', 'textRef' => $text1, 'title' => $constants['testText1Question1Title'], 'description' => $constants['testText1Question1Content']));
    $question2 = QuestionCommands::updateQuestion($testProjectId, array('id' => '', 'textRef' => $text1, 'title' => $constants['testText1Question2Title'], 'description' => $constants['testText1Question2Content']));
    $template1 = QuestionTemplateCommands::updateTemplate($testProjectId, array('id' => '', 'title' => 'first template', 'description' => 'not particularly interesting'));
    $template2 = QuestionTemplateCommands::updateTemplate($testProjectId, array('id' => '', 'title' => 'second template', 'description' => 'not entirely interesting'));
    $answer1 = QuestionCommands::updateAnswer($testProjectId, $question1, array('id' => '', 'content' => $constants['testText1Question1Answer']), $managerUserId);
    $answer1Id = array_keys($answer1)[0];
    $answer2 = QuestionCommands::updateAnswer($testProjectId, $question2, array('id' => '', 'content' => $constants['testText1Question2Answer']), $managerUserId);
    $answer2Id = array_keys($answer2)[0];
    $comment1 = QuestionCommands::updateComment($testProjectId, $question1, $answer1Id, array('id' => '', 'content' => $constants['testText1Question1Answer1Comment']), $managerUserId);
    $comment2 = QuestionCommands::updateComment($testProjectId, $question2, $answer2Id, array('id' => '', 'content' => $constants['testText1Question2Answer2Comment']), $managerUserId);
} elseif ($site == 'languageforge') {
    // Set up LanguageForge E2E test envrionment here
    ProjectCommands::updateUserRole($testProjectId, $observerUserId, LexRoles::OBSERVER);
    $testProjectModel = new LexProjectModel($testProjectId);
    $testProjectModel->addInputSystem('th-fonipa', 'tipa', 'Thai');
    $testProjectModel->config->entry->fields[LexConfig::LEXEME]->inputSystems[] = 'th-fonipa';
    $testProjectModel->addInputSystem('th-Zxxx-x-audio', 'taud', 'Thai Voice');
    $testProjectModel->config->entry->fields[LexConfig::LEXEME]->inputSystems[] = 'th-Zxxx-x-audio';
    $testProjectId = $testProjectModel->write();
    // setup to mimic file upload
    $fileName = $constants['testEntry1']['lexeme']['th-Zxxx-x-audio']['value'];
    $file = array();
    $file['name'] = $fileName;
    $_FILES['file'] = $file;
    // put a copy of the test file in tmp
    $tmpFilePath = sys_get_temp_dir() . "/CopyOf{$fileName}";
    copy(TestPath . "php/common/{$fileName}", $tmpFilePath);
    $response = LexUploadCommands::uploadAudioFile($testProjectId, 'audio', $tmpFilePath);
 /**
  * @param string $projectId
  * @param string $userId
  * @param Website $website
  * @param ProjectRoles $role
  * @param DeliveryInterface $delivery
  * @return IdReference|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;
 }