Exemplo n.º 1
0
 /**
  * @link https://familysearch.org/developers/docs/api/memories/Update_Memories_Comment_usecase
  */
 public function testCreateUpdateDeleteMemoriesComment()
 {
     $factory = new FamilySearchStateFactory();
     /** @var FamilySearchMemories $memories */
     $memories = $factory->newMemoriesState();
     $this->authorize($memories);
     $this->assertNotEmpty($memories->getAccessToken());
     $ds = new DataSource();
     $ds->setTitle("Sample Memory");
     $ds->setFile(ArtifactBuilder::makeTextFile());
     /** @var FamilySearchSourceDescriptionState $artifact */
     $artifact = $memories->addArtifact($ds);
     $this->queueForDelete($artifact);
     $this->assertEquals(HttpStatus::CREATED, $artifact->getStatus());
     $artifact = $artifact->get();
     $this->assertEquals(HttpStatus::OK, $artifact->getStatus());
     $comments = $artifact->readComments();
     $comment = new Comment();
     $comment->setText("Test comment.");
     $comments->addComment($comment);
     $comments = $artifact->readComments();
     $this->assertEquals(HttpStatus::OK, $comments->getStatus());
     $this->assertNotNull($comments->getDiscussion());
     // UPDATE
     $entities = $comments->getDiscussion()->getComments();
     $this->assertNotEmpty($entities);
     $update = array_shift($entities);
     $commentText = "Updated comment";
     $update->setText($commentText);
     $state = $comments->updateComment($update);
     $this->assertNotNull($state->ifSuccessful());
     $this->assertEquals(HttpStatus::NO_CONTENT, $state->getStatus());
     $comments = $artifact->readComments();
     $this->assertEquals(HttpStatus::OK, $comments->getStatus());
     $this->assertNotNull($comments->getDiscussion());
     $entities = $comments->getDiscussion()->getComments();
     $this->assertNotEmpty($entities);
     $update = array_shift($entities);
     $this->assertEquals($commentText, $update->getText());
     // DELETE
     $state = $comments->deleteComment($update);
     $this->assertNotNull($state->ifSuccessful());
     $this->assertEquals(HttpStatus::NO_CONTENT, $state->getStatus());
     $comments = $artifact->readComments();
     $this->assertEquals(HttpStatus::OK, $comments->getStatus());
     $this->assertNotNull($comments->getDiscussion());
     $entities = $comments->getDiscussion()->getComments();
     $this->assertEmpty($entities);
 }
Exemplo n.º 2
0
 /**
  * Deletes the specified comment from the current discussion.
  *
  * @param Comment               $comment
  * @param StateTransitionOption $option,...
  *
  * @return DiscussionState
  * @throws GedcomxApplicationException
  */
 public function deleteComment(Comment $comment, StateTransitionOption $option = null)
 {
     $link = $comment->getLink(Rel::COMMENT);
     $link = $link == null ? $comment->getLink(Rel::SELF) : $link;
     if ($link == null || $link->getHref() == null) {
         throw new GedcomxApplicationException("Comment cannot be deleted: missing {$link}.");
     }
     $request = $this->createAuthenticatedGedcomxRequest('DELETE', $link->getHref(), FamilySearchRequest::getMediaTypes());
     return $this->stateFactory->createState('DiscussionState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken);
 }