public function testLexEntryCrud_CreateUpdateDeleteListOk()
 {
     $e = new LexiconMongoTestEnvironment();
     $e->clean();
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     // create an user and add to the project
     $userId = $e->getProjectMember($projectId, 'user1');
     $entry = new LexEntryModel($project);
     $entry->lexeme->form('th', 'SomeEntry');
     $sense = new Sense();
     $sense->definition->form('en', 'red fruit');
     $sense->partOfSpeech->value = 'noun';
     $example = new Example();
     $example->sentence->form('th', 'example1');
     $example->translation->form('en', 'trans1');
     $sense->examples[] = $example;
     $entry->senses[] = $sense;
     // List
     $dto = LexEntryCommands::listEntries($projectId);
     $this->assertEqual($dto->count, 0);
     // Create
     $params = JsonEncoder::encode($entry);
     $result1 = LexEntryCommands::updateEntry($projectId, $params, $userId);
     $entryId = $result1['id'];
     $this->assertNotNull($entryId);
     $this->assertEqual(24, strlen($entryId));
     // Read
     $result2 = LexEntryCommands::readEntry($projectId, $entryId);
     $this->assertNotNull($result2['id']);
     $this->assertEqual('SomeEntry', $result2['lexeme']['th']['value']);
     // Update
     $result2['lexeme']['th']['value'] = 'OtherEntry';
     $result3 = LexEntryCommands::updateEntry($projectId, $result2, $userId);
     $this->assertNotNull($result3);
     $this->assertEqual($result3['id'], $entryId);
     // Read back
     $result4 = LexEntryCommands::readEntry($projectId, $entryId);
     $this->assertNotNull($result4['id']);
     $this->assertEqual('OtherEntry', $result4['lexeme']['th']['value']);
     // List
     $dto = LexEntryCommands::listEntries($projectId);
     $this->assertEqual($dto->count, 1);
     // Delete
     $result5 = LexEntryCommands::removeEntry($projectId, $entryId, $userId);
     $this->assertTrue($result5);
     // List to confirm delete
     $dto = LexEntryCommands::listEntries($projectId);
     $this->assertEqual($dto->count, 0);
     // Clean up after ourselves
     ProjectCommands::deleteProjects(array($projectId));
 }
 private static function _createEmptyProject($languageCode, $languageName, $userId)
 {
     $website = Website::get();
     $projectCode = SemDomTransProjectModel::projectCode($languageCode);
     $projectName = SemDomTransProjectModel::projectName($languageCode, $languageName);
     $projectID = ProjectCommands::createProject($projectName, $projectCode, LfProjectModel::SEMDOMTRANS_APP, $userId, $website);
     $project = new SemDomTransProjectModel($projectID);
     $project->languageIsoCode = $languageCode;
     $project->isSourceLanguage = false;
     $project->semdomVersion = SemDomTransProjectModel::SEMDOM_VERSION;
     // by default all created projects have English as their source.  A future feature would allow creating projects off of other source languages
     $englishProject = SemDomTransProjectModel::getEnglishProject();
     $project->sourceLanguageProjectId->id = $englishProject->id->asString();
     return $project->write();
 }
 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']);
 }
 /**
  * Creates a semdomtrans project and prefills it (using Google Translate data if appropriate flag is set)
  * @param string $languageCode
  * @param string $languageName
  * @param bool $useGoogleTranslateData
  * @param string $userId
  * @param Website $website
  * @param int $semdomVersion
  * @return string
  */
 public static function createProject($languageCode, $languageName, $useGoogleTranslateData, $userId, $website, $semdomVersion = SemDomTransProjectModel::SEMDOM_VERSION)
 {
     $projectCode = SemDomTransProjectModel::projectCode($languageCode, $semdomVersion);
     $projectName = SemDomTransProjectModel::projectName($languageCode, $languageName, $semdomVersion);
     $projectID = ProjectCommands::createProject($projectName, $projectCode, LfProjectModel::SEMDOMTRANS_APP, $userId, $website);
     $project = new SemDomTransProjectModel($projectID);
     $project->languageIsoCode = $languageCode;
     $project->isSourceLanguage = false;
     $project->semdomVersion = $semdomVersion;
     $project->languageName = $languageName;
     // by default all created projects have English as their source.  A future feature would allow creating projects off of other source languages
     $englishProject = SemDomTransProjectModel::getEnglishProject($semdomVersion);
     $project->sourceLanguageProjectId->id = $englishProject->id->asString();
     // prefill project with semdom items
     $project->preFillFromSourceLanguage($useGoogleTranslateData);
     return $project->write();
 }
Exemplo n.º 5
0
$changeDatabase = false;
// process xml into a php data structure, organized by language
$xml = simplexml_load_file($xmlFilePath);
$lang = $argv[2];
$version = $argv[3];
$projectCode = "semdom-{$lang}-{$semdomVersion}";
$projectName = "Semdom {$lang} Project";
$appName = LfProjectModel::SEMDOMTRANS_APP;
$website = new Website($domain, Website::LANGUAGEFORGE);
// if a previous project for that language and semantic domain version exists, DO NOT IMPORT
$previousProject = new SemDomTransProjectModel();
$previousProject->readByProperties(array("languageIsoCode" => $lang, "semdomVersion" => $semdomVersion));
if ($previousProject->id->asString() == "") {
    $sourceProject = new SemDomTransProjectModel();
    $sourceProject->readByCode("en");
    $projectID = ProjectCommands::createProject($projectName, $projectCode, $appName, $userId, $website);
    $projectModel = new SemDomTransProjectModel($projectID);
    $newXmlFilePath = $projectModel->getAssetsFolderPath() . '/' . basename($xmlFilePath);
    FileUtilities::createAllFolders($projectModel->getAssetsFolderPath());
    print "copying {$xmlFilePath} to  {$newXmlFilePath}\n";
    copy($xmlFilePath, $newXmlFilePath);
    $projectModel->xmlFilePath = $newXmlFilePath;
    $projectModel->languageIsoCode = $lang;
    $projectModel->semdomVersion = $semdomVersion;
    $projectModel->sourceLanguageProjectId = $sourceProject->id->asString();
    $projectModel->write();
    $importer = new SemDomXMLImporter($xmlFilePath, $projectModel, false, $isEnglish);
    $importer->run();
} else {
    echo "Project exists already" . "\n";
}
Exemplo n.º 6
0
 /**
  * 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;
 }
 public function testCreateProject_newProject_projectOwnerSet()
 {
     $this->environ->clean();
     $user1Id = $this->environ->createUser("user1name", "User1 Name", "*****@*****.**");
     $user1 = new UserModel($user1Id);
     $projectID = ProjectCommands::createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE, 'sfchecks', $user1->id->asString(), $this->environ->website);
     $projectModel = new ProjectModel($projectID);
     $this->assertTrue($projectModel->ownerRef->asString() == $user1->id->asString());
 }
Exemplo n.º 8
0
 /**
  * 
  * @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;
 }
Exemplo n.º 9
0
 public function project_readSettings()
 {
     return ProjectCommands::readProjectSettings($this->_projectId);
 }
    }
}
$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
Exemplo n.º 11
0
 public function testUserCRUD_CRUDOK()
 {
     $e = new ApiCrudTestEnvironment();
     // initial list
     $result = $e->json(UserCommands::listUsers());
     $count = $result['count'];
     // Create
     $userId = $e->e->createUser('someuser', 'SomeUser', '*****@*****.**');
     $someUser = new UserModel($userId);
     $this->assertNotNull($someUser);
     $this->assertEqual(24, strlen($someUser->id->asString()));
     // create project
     $projectId = ProjectCommands::createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE, 'sfchecks', $someUser->id->asString(), $e->e->website);
     // list
     $result = $e->json(UserCommands::listUsers());
     $this->assertEqual($count + 1, $result['count']);
     // Read
     $result = $e->json(UserCommands::readUser($someUser->id->asString()));
     $this->assertNotNull($result['id']);
     $this->assertEqual('someuser', $result['username']);
     $this->assertEqual('*****@*****.**', $result['email']);
     // Update
     $result['username'] = '******';
     $result['email'] = '*****@*****.**';
     $id = UserCommands::updateUser($result);
     $this->assertNotNull($id);
     $this->assertEqual($result['id'], $id);
     // typeahead
     $result = $e->json(UserCommands::userTypeaheadList('ome', '', $e->e->website));
     $this->assertTrue($result['count'] > 0);
     // change password
     UserCommands::changePassword($id, 'newpassword', $id);
     // Delete
     $result = UserCommands::deleteUsers(array($id));
     $this->assertTrue($result);
 }
 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]));
 }