コード例 #1
0
ファイル: MemoriesTests.php プロジェクト: BRGWeb/gedcomx-php
 /**
  * @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);
 }