public function testGetActivityForProject_DeletedUser_DtoAsExpected() { $e = new MongoTestEnvironment(); $e->clean(); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $text = new TextModel($project); $text->title = "Text 1"; $text->content = "text content"; $textId = $text->write(); ActivityCommands::addText($project, $textId, $text); $userId = $e->createUser("user1", "user1", "*****@*****.**"); ActivityCommands::addUserToProject($project, $userId); // 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(); ActivityCommands::addQuestion($project, $questionId, $question); // Then to add an answer to a question $answer = new AnswerModel(); $answer->content = "first answer"; $answer->score = 10; $answer->userRef->id = $userId; $answer->textHightlight = "text highlight"; $answerId = $question->writeAnswer($answer); $activityid = ActivityCommands::addAnswer($project, $questionId, $answer); // now delete the user $user = new UserModel($userId); $user->remove(); $dto = ActivityListDto::getActivityForProject($project); $this->assertEqual($dto[$activityid]['action'], 'add_answer'); $this->assertEqual($dto[$activityid]['projectRef'], array('id' => $project->id->asString(), 'type' => 'sfchecks')); $this->assertEqual($dto[$activityid]['content']['project'], $project->projectName); $this->assertEqual($dto[$activityid]['textRef'], $textId); $this->assertEqual($dto[$activityid]['content']['text'], $text->title); $this->assertEqual($dto[$activityid]['questionRef'], $questionId); $this->assertEqual($dto[$activityid]['content']['question'], $question->title); $this->assertEqual($dto[$activityid]['content']['answer'], $answer->content); $this->assertEqual($dto[$activityid]['userRef'], ''); $this->assertEqual($dto[$activityid]['content']['user'], 'user1'); }
/** * @param array $userIds * @return int Total number of users removed. */ public static function deleteUsers($userIds) { CodeGuard::checkTypeAndThrow($userIds, 'array'); $count = 0; foreach ($userIds as $userId) { CodeGuard::checkTypeAndThrow($userId, 'string'); $userModel = new \Api\Model\UserModel($userId); $userModel->remove(); $count++; } return $count; }
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)); }