public function testHasRight_Ok()
 {
     $userId = MongoTestEnvironment::mockId();
     $project = new SfchecksProjectModel();
     $project->addUser($userId, ProjectRoles::MANAGER);
     $result = $project->hasRight($userId, Domain::QUESTIONS + Operation::CREATE);
     $this->assertTrue($result);
 }
 public function testCRUD_Works()
 {
     $e = new MongoTestEnvironment();
     $e->clean();
     $userId = $e->mockId();
     $projectId = $e->mockId();
     $questionId = $e->mockId();
     $answerId = $e->mockId();
     // Create
     $vote = new UserVoteModel($userId, $projectId, $questionId);
     $this->assertNotNull($vote);
     $this->assertTrue(empty($vote->id->id));
     // Has vote should fail, answer is not yet present.
     $result = $vote->hasVote($answerId);
     $this->assertFalse($result);
     // Add vote, should then be present.
     $vote->addVote($answerId);
     $result = $vote->hasVote($answerId);
     $this->assertTrue($result);
     $id = $vote->write();
     $this->assertNotNull($id);
     $this->assertIsA($id, 'string');
     $this->assertEqual($id, $vote->id->asString());
     // Read back
     $otherVote = new UserVoteModel($userId, $projectId, $questionId);
     $this->assertIsA($otherVote->id->id, 'string');
     $this->assertEqual($id, $vote->id->asString());
     $result = $otherVote->hasVote($answerId);
     $this->assertTrue($result);
     // Update
     $answer2Id = $e->mockId();
     $otherVote->addVote($answer2Id);
     $otherVote->write();
     // Read back
     $otherVote = new UserVoteModel($userId, $projectId, $questionId);
     $result = $otherVote->hasVote($answerId);
     $this->assertTrue($result);
     $result = $otherVote->hasVote($answer2Id);
     $this->assertTrue($result);
     // Remove vote, should no longer be present.
     $vote->removeVote($answerId);
     $result = $vote->hasVote($answerId);
     $this->assertFalse($result);
     // UserVoteModel::remove($projectModel->databaseName(), $id);
 }
 public function testAnswerCRUD_Works()
 {
     $e = new MongoTestEnvironment();
     $e->clean();
     $textRef = MongoTestEnvironment::mockId();
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     // Create Question
     $question = new QuestionModel($project);
     $question->title = "Some Question";
     $question->textRef->id = $textRef;
     $questionId = $question->write();
     // List
     $question->read($questionId);
     $count = count($question->answers);
     $this->assertEqual(0, $count);
     // Create
     $answer = new AnswerModel();
     $answer->content = 'Some answer';
     $id = $question->writeAnswer($answer);
     $comment = new CommentModel();
     $comment->content = 'Some comment';
     $commentId = QuestionModel::writeComment($project->databaseName(), $questionId, $id, $comment);
     $this->assertNotNull($id);
     $this->assertIsA($id, 'string');
     $this->assertEqual(24, strlen($id));
     $this->assertEqual($id, $answer->id->asString());
     // Read back
     $otherQuestion = new QuestionModel($project, $questionId);
     $otherAnswer = $otherQuestion->answers[$id];
     $this->assertEqual($id, $otherAnswer->id->asString());
     $this->assertEqual('Some answer', $otherAnswer->content);
     $this->assertEqual(1, count($otherAnswer->comments));
     // Update
     $otherAnswer->content = 'Other answer';
     // Note: Updates to the AnswerModel should not clobber child nodes such as comments. Hence this test.
     // See https://github.com/sillsdev/sfwebchecks/issues/39
     unset($otherAnswer->comments[$commentId]);
     $otherQuestion->read($otherQuestion->id->asString());
     $otherId = $otherQuestion->writeAnswer($otherAnswer);
     $this->assertEqual($id, $otherId);
     // Read back
     $otherQuestion = new QuestionModel($project, $questionId);
     $otherAnswer = $otherQuestion->answers[$id];
     $this->assertEqual($id, $otherAnswer->id->asString());
     $this->assertEqual('Other answer', $otherAnswer->content);
     $this->assertEqual(1, count($otherAnswer->comments));
     // List
     $this->assertEqual(1, count($otherQuestion->answers));
     // Delete
     QuestionModel::removeAnswer($project->databaseName(), $questionId, $id);
     // List
     $otherQuestion->read($questionId);
     $this->assertEqual(0, count($otherQuestion->answers));
 }
 public function testAnswerCRUD_Works()
 {
     $environ = new MongoTestEnvironment();
     $environ->clean();
     $textRef = MongoTestEnvironment::mockId();
     $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     // Create Question
     $question = new QuestionModel($project);
     $question->title = "Some Question";
     $question->textRef->id = $textRef;
     $questionId = $question->write();
     // Create Answer
     $answer = new AnswerModel();
     $answer->content = 'Some answer';
     $answerId = $question->writeAnswer($answer);
     // List
     $question->read($questionId);
     $count = count($question->answers[$answerId]->comments);
     $this->assertEquals(0, $count);
     // Create
     $comment = new CommentModel();
     $comment->content = 'Some comment';
     $id = QuestionModel::writeComment($project->databaseName(), $questionId, $answerId, $comment);
     $this->assertNotNull($id);
     $this->assertInternalType('string', $id);
     $this->assertEquals(24, strlen($id));
     $this->assertEquals($comment->id->asString(), $id);
     // Read back
     $otherQuestion = new QuestionModel($project, $questionId);
     $otherComment = $otherQuestion->answers[$answerId]->comments[$id];
     $this->assertEquals($id, $otherComment->id->asString());
     $this->assertEquals('Some comment', $otherComment->content);
     // Update
     $otherComment->content = 'Other comment';
     $otherId = $question->writeComment($project->databaseName(), $questionId, $answerId, $otherComment);
     $this->assertEquals($id, $otherId);
     // Read back
     $otherQuestion = new QuestionModel($project, $questionId);
     $otherComment = $otherQuestion->answers[$answerId]->comments[$id];
     $this->assertEquals($id, $otherComment->id->asString());
     $this->assertEquals('Other comment', $otherComment->content);
     // List
     $count = count($otherQuestion->answers[$answerId]->comments);
     $this->assertEquals(1, $count);
     // Delete
     QuestionModel::removeComment($project->databaseName(), $questionId, $answerId, $id);
     // List
     $otherQuestion->read($questionId);
     $count = count($otherQuestion->answers[$answerId]->comments);
     $this->assertEquals(0, $count);
 }
 public function testCRUD_Works()
 {
     $e = new MongoTestEnvironment();
     $e->clean();
     $textRef = MongoTestEnvironment::mockId();
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     // List
     $list = new QuestionListModel($project, $textRef);
     $list->read();
     $this->assertEqual(0, $list->count);
     // Create
     $question = new QuestionModel($project);
     $question->title = "SomeQuestion";
     $question->description = "SomeQuestion";
     $question->textRef->id = $textRef;
     $id = $question->write();
     $this->assertNotNull($id);
     $this->assertIsA($id, 'string');
     $this->assertEqual($id, $question->id->asString());
     // Read back
     $otherQuestion = new QuestionModel($project, $id);
     $this->assertEqual($id, $otherQuestion->id->asString());
     $this->assertEqual('SomeQuestion', $otherQuestion->title);
     $this->assertEqual($textRef, $otherQuestion->textRef->id);
     // Update
     $otherQuestion->description = 'OtherQuestion';
     $otherQuestion->write();
     // Read back
     $otherQuestion = new QuestionModel($project, $id);
     $this->assertEqual('OtherQuestion', $otherQuestion->description);
     // List
     $list->read();
     $this->assertEqual(1, $list->count);
     // Delete
     QuestionModel::remove($project->databaseName(), $id);
     // List
     $list->read();
     $this->assertEqual(0, $list->count);
 }
 /**
  * @expectedException Exception
  */
 public function testGetRightsArray_Exception()
 {
     $userId = MongoTestEnvironment::mockId();
     $project = new ProjectModel();
     $project->addUser($userId, ProjectRoles::MANAGER);
     // rolesClass undefined in base ProjectModel
     $project->getRightsArray($userId);
 }
 public function testGetRightsArray_Ok()
 {
     $userId = MongoTestEnvironment::mockId();
     $project = new SfchecksProjectModel();
     $project->addUser($userId, ProjectRoles::MANAGER);
     $result = $project->getRightsArray($userId);
     $this->assertIsA($result, 'array');
     $this->assertTrue(in_array(Domain::QUESTIONS + Operation::CREATE, $result));
 }