public static function buildPerson($gender) { /* * Can't use faker for dates. It doesn't deal well with negative timestamps. */ switch ($gender) { case 'male': $gender = GenderType::MALE; break; case 'female': $gender = GenderType::FEMALE; break; default: $gender = self::faker()->boolean() ? GenderType::FEMALE : GenderType::MALE; } $birth = FactBuilder::birth(); $death = FactBuilder::death($birth); $facts = array(); $facts[] = $birth; $living = false; if ($death->getDate()->getDateTime()->getTimestamp() > time()) { $living = true; } else { $facts[] = $death; } $person = new Person(); $person->setGender(new Gender(array("type" => $gender))); $person->setLiving($living); $person->setPrincipal(false); $name = self::birthName($gender); $person->setNames(array($name)); $person->setFacts($facts); $display = new DisplayProperties(array("birthDate" => $birth->getDate()->getDateTime()->format("d M Y"), "birthPlace" => $birth->getPlace()->getOriginal(), "gender" => $gender, "lifespan" => $birth->getDate()->getDateTime()->format("d M Y") . " - " . ($living ? '' : $death->getDate()->getDateTime()->format("d M Y")), "name" => $name->toString())); $person->setDisplayExtension($display); return $person; }
/** * @vcr SpousesTests/testDeleteCoupleRelationshipConclusion.json * @link https://familysearch.org/developers/docs/api/tree/Delete_Couple_Relationship_Conclusion_usecase */ public function testDeleteCoupleRelationshipConclusion() { $factory = new FamilyTreeStateFactory(); $this->collectionState($factory); /** @var FamilyTreePersonState $husband */ /** @var RelationshipState $family */ list($husband, $family) = $this->initializeRelationship(array('husband', 'family')); $husband = $husband->get(); $this->assertEquals(HttpStatus::OK, $husband->getStatus(), $this->buildFailMessage(__METHOD__ . "(getHusband)", $husband)); $this->assertNotNull($husband->getEntity(), "Get failed. Husband 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)); /** @var RelationshipState $family */ $family = $family->get(); $this->assertEquals(HttpStatus::OK, $family->getStatus(), $this->buildFailMessage(__METHOD__ . "(getRelationship)", $family)); $family->loadConclusions(); $this->assertNotNull($family->getEntity(), "Family entity is null."); $this->assertGreaterThan(0, count($family->getRelationship()->getFacts()), "Fact count should be greater than zero."); $marriage = $family->getRelationship()->getFactsOfType(FactType::MARRIAGE); /** @var RelationshipState $deleted */ $deleted = $family->deleteFact($marriage); $this->assertEquals(HttpStatus::NO_CONTENT, $deleted->getStatus(), $this->buildFailMessage(__METHOD__ . "(deleteSource)", $deleted)); $family = $family->get($this->createCacheBreakerQueryParam()); $this->assertEquals(HttpStatus::OK, $family->getStatus(), $this->buildFailMessage(__METHOD__ . "(getRelationship)", $family)); $this->assertNotNull($family->getEntity(), "Family entity is null."); $this->assertEquals(0, count($family->getRelationship()->getFacts()), "Fact count should be zero."); }
/** * @vcr ParentsAndChildrenTests/testDeleteChildAndParentsRelationshipConclusion.json * @link https://familysearch.org/developers/docs/api/tree/Delete_Child-and-Parents_Relationship_Conclusion_usecase */ public function testDeleteChildAndParentsRelationshipConclusion() { $factory = new FamilyTreeStateFactory(); $this->collectionState($factory); /** @var ChildAndParentsRelationshipState $relation */ $relation = $this->createRelationship(); $fact = FactBuilder::adoptiveParent(); $relation = $relation->addFatherFact($fact); $this->assertEquals(HttpStatus::NO_CONTENT, $relation->getStatus(), $this->buildFailMessage(__METHOD__ . "(addFact)", $relation)); $relation = $relation->get(); $this->assertEquals(HttpStatus::OK, $relation->getStatus(), $this->buildFailMessage(__METHOD__ . "(readRelationship)", $relation)); $this->assertNotNull($relation->getEntity(), "Relationship entity is null."); $facts = $relation->getRelationship()->getFatherFacts(); $this->assertNotEmpty($facts, "FatherFacts are empty."); $factState = $relation->deleteFact($facts[0]); $this->assertEquals(HttpStatus::NO_CONTENT, $factState->getStatus(), $this->buildFailMessage(__METHOD__ . "(deleteFact)", $factState)); }
/** * @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)); }