Exemple #1
0
 /**
  * @link https://familysearch.org/developers/docs/api/memories/Upload_Photo_usecase
  * Use shows uploading a photo with an image content type. SDK only supports uploading
  *       via multi-part form uploads.
  */
 public function testUploadPhoto()
 {
     $filename = ArtifactBuilder::makeImage();
     $artifact = new DataSource();
     $artifact->setFile($filename);
     $artifact->setTitle(TestBuilder::faker()->sentence(4));
     $factory = new FamilySearchStateFactory();
     /** @var FamilySearchMemories $memories */
     $memories = $factory->newMemoriesState();
     $memories = $this->authorize($memories);
     $this->assertNotEmpty($memories->getAccessToken());
     $upload = $memories->addArtifact($artifact);
     $this->queueForDelete($upload);
     $this->assertEquals(HttpStatus::CREATED, $upload->getStatus(), $this->buildFailMessage(__METHOD__, $upload));
     $upload = $upload->get();
     $this->assertEquals(HttpStatus::OK, $upload->getStatus());
 }
Exemple #2
0
 /**
  * @vcr SpousesTests/testUpdateCoupleRelationshipConclusion.json
  * @link https://familysearch.org/developers/docs/api/tree/Update_Couple_Relationship_Conclusion_usecase
  */
 public function testUpdateCoupleRelationshipConclusion()
 {
     $factory = new FamilyTreeStateFactory();
     $this->collectionState($factory);
     list($husband, $family) = $this->initializeRelationship(array('husband', 'family'));
     /** @var FamilyTreePersonState $husband */
     $husband = $husband->get();
     $this->assertEquals(HttpStatus::OK, $husband->getStatus(), $this->buildFailMessage(__METHOD__ . "(getHusband)", $husband));
     $this->assertNotNull($husband->getEntity(), "Get failed. Husband entity is null.");
     /** @var RelationshipState $family */
     $family = $family->get();
     $this->assertEquals(HttpStatus::OK, $family->getStatus(), $this->buildFailMessage(__METHOD__ . "(getRelationship)", $family));
     $this->assertNotNull($family->getEntity(), "Get failed. Family entity is null.");
     //  Create Marriage Fact
     /** @var Fact $birth */
     $birth = $husband->getPerson()->getFactsOfType(FactType::BIRTH);
     $marriage = FactBuilder::marriage($birth->getDate()->getDateTime());
     $family = $family->addFact($marriage);
     $this->assertEquals(HttpStatus::NO_CONTENT, $family->getStatus(), $this->buildFailMessage(__METHOD__ . "(createSource)", $family));
     //  Alter Marriage Fact
     $marriage->setAttribution(new Attribution(array("changeMessage" => TestBuilder::faker()->sentence(6))));
     $currentDate = $marriage->getDate()->getDateTime();
     $newDate = new \DateTime($currentDate->format('Y-m-d') . " +5 days");
     $marriage->setDate(new DateInfo(array("original" => $newDate->format('F m, Y'))));
     $family = $family->addFact($marriage);
     $this->assertEquals(HttpStatus::NO_CONTENT, $family->getStatus(), $this->buildFailMessage(__METHOD__ . "(addFact)", $family));
 }
Exemple #3
0
 /**
  * @vcr SourcesTests/testDeleteCoupleRelationshipSourceReference.json
  * @link https://familysearch.org/developers/docs/api/tree/Delete_Couple_Relationship_Source_Reference_usecase
  */
 public function testDeleteCoupleRelationshipSourceReference()
 {
     $factory = new FamilyTreeStateFactory();
     $this->collectionState($factory);
     /** @var FamilyTreePersonState $husband */
     $husband = $this->createPerson('male');
     $this->assertEquals(HttpStatus::CREATED, $husband->getStatus(), $this->buildFailMessage(__METHOD__ . ':' . __LINE__, $husband));
     $husband = $husband->get();
     $this->assertEquals(HttpStatus::OK, $husband->getStatus(), $this->buildFailMessage(__METHOD__ . ':' . __LINE__, $husband));
     /** @var FamilyTreePersonState $wife */
     $wife = $this->createPerson('female');
     $this->assertEquals(HttpStatus::CREATED, $wife->getStatus(), $this->buildFailMessage(__METHOD__ . ':' . __LINE__, $wife));
     /** @var FamilyTreeRelationshipState $relationship */
     $relationship = $husband->addSpouse($wife);
     $this->assertEquals(HttpStatus::CREATED, $relationship->getStatus(), $this->buildFailMessage(__METHOD__ . ':' . __LINE__, $relationship));
     $this->queueForDelete($relationship);
     $relationship = $relationship->get();
     $this->assertEquals(HttpStatus::OK, $relationship->getStatus(), $this->buildFailMessage(__METHOD__ . ':' . __LINE__, $relationship));
     $sourceState = $this->createSource();
     $reference = new SourceReference();
     $reference->setDescriptionRef($sourceState->getSelfUri());
     $reference->setAttribution(new Attribution(array("changeMessage" => TestBuilder::faker()->sentence(6))));
     $sourceRef = $relationship->addSourceReference($reference);
     $this->assertEquals(HttpStatus::CREATED, $sourceRef->getStatus(), $this->buildFailMessage(__METHOD__ . ':' . __LINE__, $sourceRef));
     $relationship->loadSourceReferences();
     $this->assertNotEmpty($relationship->getRelationship()->getSources());
     $state = $relationship->deleteSourceReference($relationship->getSourceReference());
     $this->AssertNotNull($state->ifSuccessful());
     $this->assertEquals(HttpStatus::NO_CONTENT, $state->getStatus());
     $relationship = $relationship->get();
     $relationship->loadSourceReferences($this->createCacheBreakerQueryParam());
     $this->assertEmpty($relationship->getRelationship()->getSources());
 }
 /**
  * @vcr DiscussionsTests/testUpdateComment.json
  * @link https://familysearch.org/developers/docs/api/discussions/Update_Comment_usecase
  */
 public function testUpdateComment()
 {
     $factory = new FamilySearchStateFactory();
     $this->collectionState($factory);
     $userState = $this->collectionState()->readCurrentUser();
     $discussion = DiscussionBuilder::createDiscussion($userState->getUser()->getTreeUserId());
     /** @var DiscussionState $state */
     $state = $this->collectionState()->addDiscussion($discussion);
     $this->queueForDelete($state);
     $state = $state->get();
     $comment = DiscussionBuilder::createComment($userState);
     $state->addComment($comment);
     $comment = DiscussionBuilder::createComment($userState);
     $state->addComment($comment);
     $state = $state->get();
     $state->loadComments();
     $comments = $state->getDiscussion()->getComments();
     $comment = $comments[0];
     $newText = TestBuilder::faker()->paragraph();
     $comment->setText($newText);
     $updated = $state->updateComment($comment);
     $this->assertAttributeEquals(HttpStatus::NO_CONTENT, "statusCode", $updated->getResponse(), $this->buildFailMessage(__METHOD__, $updated));
     $state->loadComments();
     $this->assertEquals(2, count($comments));
     $pass = false;
     $comments = $state->getDiscussion()->getComments();
     foreach ($comments as $c) {
         if ($c->getId() == $comment->getId() & $c->getText() == $newText) {
             $pass = true;
         }
     }
     $this->assertTrue($pass);
 }
Exemple #5
0
 /**
  * @vcr PersonTests/testUpdatePersonLifeSketch.json
  * @link https://familysearch.org/developers/docs/api/tree/Update_Person_Life_Sketch_usecase
  */
 public function testUpdatePersonLifeSketch()
 {
     $factory = new FamilyTreeStateFactory();
     $this->collectionState($factory);
     /** @var FamilyTreePersonState $personState */
     $personState = $this->createPerson();
     $fact = FactBuilder::lifeSketch();
     $personState = $personState->addFact($fact)->get();
     $sketch = $personState->getPerson()->getFactsOfType(FactType::LIFE_SKETCH);
     if (is_array($sketch)) {
         $sketch = array_shift($sketch);
     }
     $sketch->setValue(TestBuilder::faker()->paragraph(3));
     $newState = $personState->updateFact($sketch);
     $this->assertEquals(HttpStatus::NO_CONTENT, $newState->getStatus(), $this->buildFailMessage(__METHOD__, $newState));
 }
Exemple #6
0
 protected function createCacheBreakerQueryParam()
 {
     return new QueryParameter(true, '_', TestBuilder::faker()->randomNumber);
 }
Exemple #7
0
 /**
  * @vcr NotesTests/testUpdateCoupleRelationshipNote.json
  * @link https://familysearch.org/developers/docs/api/tree/Update_Couple_Relationship_Note_usecase
  */
 public function testUpdateCoupleRelationshipNote()
 {
     $factory = new FamilyTreeStateFactory();
     $this->collectionState($factory);
     $person1 = $this->createPerson('male')->get();
     $this->assertAttributeEquals(HttpStatus::OK, "statusCode", $person1->getResponse());
     $person2 = $this->createPerson('female')->get();
     $this->assertAttributeEquals(HttpStatus::OK, "statusCode", $person2->getResponse());
     /* Create Relationship */
     /** @var $relation RelationshipState */
     $relation = $this->collectionState()->addSpouseRelationship($person1, $person2)->get();
     $this->assertAttributeEquals(HttpStatus::OK, "statusCode", $relation->getResponse(), $this->buildFailMessage(__METHOD__ . "(addSpouse)", $relation));
     $note = NoteBuilder::createNote();
     $noted = $relation->addNote($note);
     $this->assertAttributeEquals(HttpStatus::CREATED, "statusCode", $noted->getResponse(), $this->buildFailMessage(__METHOD__ . "(addSpouse)", $noted));
     $relation->loadNotes();
     $notes = $relation->getRelationship()->getNotes();
     $notes[0]->setText(TestBuilder::faker()->sentence(12));
     $noted = $relation->updateNote($notes[0]);
     $this->assertAttributeEquals(HttpStatus::NO_CONTENT, "statusCode", $noted->getResponse(), $this->buildFailMessage(__METHOD__ . "(addSpouse)", $noted));
     $relation->delete();
     $person1->delete();
     $person2->delete();
 }
Exemple #8
0
 public function setUp()
 {
     parent::setUp();
     TestBuilder::seed(20125032);
 }
 /**
  * @vcr SourceBoxTests/testMoveSourcesToAUserDefinedCollection.json
  * @link https://familysearch.org/developers/docs/api/sources/Move_Sources_to_a_User-Defined_Collection_usecase
  */
 public function testMoveSourcesToAUserDefinedCollection()
 {
     $factory = new FamilySearchStateFactory();
     /** @var FamilySearchCollectionState $collection */
     $collection = $this->collectionState($factory, "https://sandbox.familysearch.org/platform/collections/sources");
     $sd = SourceBuilder::newSource();
     /** @var FamilySearchSourceDescriptionState $description */
     $description = $collection->addSourceDescription($sd);
     $this->queueForDelete($description);
     $this->assertEquals(HttpStatus::CREATED, $description->getStatus());
     $description = $description->get();
     $this->assertEquals(HttpStatus::OK, $description->getStatus());
     /** @var CollectionState $subcollection */
     $c = new Collection();
     $c->setTitle(TestBuilder::faker()->sha1);
     $subcollection = $collection->addCollection($c)->get();
     $this->queueForDelete($subcollection);
     /** @var FamilySearchSourceDescriptionState $state */
     $state = $description->moveToCollection($subcollection);
     $this->assertNotNull($state->ifSuccessful());
     $this->assertEquals(HttpStatus::NO_CONTENT, $state->getStatus());
     // Ensure it doesn't exist in the old collection
     $rootCollection = $this->getRootCollection($collection);
     $found = $this->findInCollection($description->getSourceDescription(), $rootCollection->readSourceDescriptions()->getEntity()->getSourceDescriptions());
     $this->assertFalse($found);
     // Ensure it exists in the new collection
     $found = $this->findInCollection($description->getSourceDescription(), $subcollection->readSourceDescriptions()->getEntity()->getSourceDescriptions());
     $this->assertTrue($found);
 }