FamilySearch / gedcomx-php

PHP SDK for GEDCOM X Processing. See the documentation at
http://familysearch.github.io/gedcomx-php/
Other
35 stars 15 forks source link

Bug in deserializing extensionElements #61

Closed dyeshurun closed 8 years ago

dyeshurun commented 8 years ago
  1. “Preserving” namespace for extensions
  2. Handling of empty child elements
  3. Getting all child elements
justincy commented 8 years ago

Thanks for the PR. Could you also provide a test that demonstrates the issue?

dyeshurun commented 8 years ago

Here is a test, before the change you will see an exception "Namespace error" in line #163 (new GedcomX)

<?php
/**
 * Created by PhpStorm.
 * User: danny
 * Date: 05/09/2016
 * Time: 9:08 AM
 */

namespace Gedcomx\Tests;

use Gedcomx\Gedcomx;

class XMLTest extends \PHPUnit_Framework_TestCase
{
    public function testDeserialize()
    {
        $xml = '
        <record xmlns="http://gedcomx.org/v1/" description="#SD-L2KF-NLB" id="http://familysearch.org/platform/tree/persons-with-relationships?person=L2KF-NLB">
    <person sortKey="0000000000" id="L2KF-NLB">
      <source description="http://familysearch.org/platform/sources/descriptions/9XC2-MW3" id="24ee625a-1465-48dd-887d-e11a662bb8f7">
        <fs:tag xmlns:atom="http://www.w3.org/2005/Atom" xmlns:fs="http://familysearch.org/v1/" resource="http://gedcomx.org/Gender"/>
        <fs:tag xmlns:atom="http://www.w3.org/2005/Atom" xmlns:fs="http://familysearch.org/v1/" resource="http://gedcomx.org/Name"/>
        <fs:tag xmlns:atom="http://www.w3.org/2005/Atom" xmlns:fs="http://familysearch.org/v1/" resource="http://gedcomx.org/Birth"/>
        <attribution>
          <contributor resource="http://familysearch.org/platform/users/agents/MMXX-M7Q" resourceId="MMXX-M7Q"/>
          <modified>2016-03-12T03:23:01.569Z</modified>
          <changeMessage>same</changeMessage>
        </attribution>
      </source>
      <identifier type="http://gedcomx.org/Persistent">https://familysearch.org/ark:/61903/4:1:L2KF-NLB</identifier>
      <living>false</living>
      <gender type="http://gedcomx.org/Female" id="4d6d2211-2c19-4c86-8954-8c2061de445b">
        <link rel="conclusion" href="http://familysearch.org/platform/tree/persons/L2KF-NLB/conclusions/4d6d2211-2c19-4c86-8954-8c2061de445b"/>
        <attribution>
          <contributor resource="http://familysearch.org/platform/users/agents/MMXX-M7Q" resourceId="MMXX-M7Q"/>
          <modified>2016-03-12T03:22:44.419Z</modified>
        </attribution>
      </gender>
      <name type="http://gedcomx.org/BirthName" id="ddfa08c7-905a-4cbf-b994-9d4514d2af50">
        <link rel="conclusion" href="http://familysearch.org/platform/tree/persons/L2KF-NLB/conclusions/ddfa08c7-905a-4cbf-b994-9d4514d2af50"/>
        <attribution>
          <contributor resource="http://familysearch.org/platform/users/agents/MM7Y-G9J" resourceId="MM7Y-G9J"/>
          <modified>2016-05-18T23:28:33.853Z</modified>
          <changeMessage>Middle name used in Ancestry Family Tree</changeMessage>
        </attribution>
        <preferred>true</preferred>
        <nameForm>
          <fullText>Dora Iucho Morrell</fullText>
          <part type="http://gedcomx.org/Given" value="Dora Iucho"/>
          <part type="http://gedcomx.org/Surname" value="Morrell"/>
        </nameForm>
      </name>
      <fact type="http://gedcomx.org/Birth" id="ebe0d4fe-20f8-4dad-b4b8-c69c03d0f100">
        <link rel="conclusion" href="http://familysearch.org/platform/tree/persons/L2KF-NLB/conclusions/ebe0d4fe-20f8-4dad-b4b8-c69c03d0f100"/>
        <attribution>
          <contributor resource="http://familysearch.org/platform/users/agents/MM7Y-G9J" resourceId="MM7Y-G9J"/>
          <modified>2016-05-18T23:29:58.013Z</modified>
          <changeMessage>Age in 1860 New York City census</changeMessage>
        </attribution>
        <date>
          <original>1856</original>
          <formal>+1856</formal>
          <normalized xml:lang="en-US">1856</normalized>
          <normalized>1856</normalized>
        </date>
        <place description="#1024916608">
          <original>New York, United States</original>
          <normalized xml:lang="en-US">New York, United States</normalized>
          <normalized xml:lang="und">New York, United States</normalized>
        </place>
      </fact>
      <fact type="http://gedcomx.org/Death" id="f1e514fe-d22c-45c0-ae4b-c14cb21b15a0">
        <link rel="conclusion" href="http://familysearch.org/platform/tree/persons/L2KF-NLB/conclusions/f1e514fe-d22c-45c0-ae4b-c14cb21b15a0"/>
        <attribution>
          <contributor resource="http://familysearch.org/platform/users/agents/MM7Y-G9J" resourceId="MM7Y-G9J"/>
          <modified>2016-05-20T01:56:16.996Z</modified>
          <changeMessage>Ancestry Family Tree; New York, New York City Municipal Deaths</changeMessage>
        </attribution>
        <date>
          <original>27 December 1899</original>
          <formal>+1899-12-27</formal>
          <normalized xml:lang="en-US">27 December 1899</normalized>
          <normalized>27 December 1899</normalized>
        </date>
        <place description="#1375628896">
          <original>Manhattan, New York County, New York, United States</original>
          <normalized xml:lang="en-US">Manhattan, New York County, New York, United States</normalized>
          <normalized xml:lang="und">Manhattan, New York County, New York, United States</normalized>
        </place>
      </fact>
      <fact type="http://gedcomx.org/Residence" id="272688ba-9db5-4a83-94df-1744d94ed9fd">
        <link rel="conclusion" href="http://familysearch.org/platform/tree/persons/L2KF-NLB/conclusions/272688ba-9db5-4a83-94df-1744d94ed9fd"/>
        <attribution>
          <contributor resource="http://familysearch.org/platform/users/agents/MMXX-M7Q" resourceId="MMXX-M7Q"/>
          <modified>2016-03-12T03:23:05.419Z</modified>
          <changeMessage>same</changeMessage>
        </attribution>
        <date>
          <original>1880</original>
          <formal>+1880</formal>
          <normalized xml:lang="en-US">1880</normalized>
          <normalized>1880</normalized>
        </date>
        <place description="#1879384345">
          <original>New York, New York, New York, United States</original>
          <normalized xml:lang="en-US">New York City, New York County, New York, United States</normalized>
          <normalized xml:lang="und">New York, New York, New York, United States</normalized>
        </place>
      </fact>
      <display>
        <ascendancyNumber>1</ascendancyNumber>
        <birthDate>1856</birthDate>
        <birthPlace>New York, United States</birthPlace>
        <deathDate>27 December 1899</deathDate>
        <deathPlace>Manhattan, New York County, New York, United States</deathPlace>
        <descendancyNumber>1</descendancyNumber>
        <familyAsChild>
          <parent1 resource="https://familysearch.org/ark:/61903/4:1:KCQM-418" resourceId="KCQM-418"/>
          <parent2 resource="https://familysearch.org/ark:/61903/4:1:KCJV-Z4S" resourceId="KCJV-Z4S"/>
          <child resource="#L2KF-NLB" resourceId="L2KF-NLB"/>
        </familyAsChild>
        <gender>Female</gender>
        <lifespan>1856-1899</lifespan>
        <name>Dora Iucho Morrell</name>
      </display>
    </person>
    <relationship type="http://gedcomx.org/ParentChild" id="FMT5B-VYX">
      <identifier type="http://familysearch.org/v1/ChildAndParentsRelationship">http://familysearch.org/platform/tree/child-and-parents-relationships/MT5B-VYX</identifier>
      <person1 resource="https://familysearch.org/ark:/61903/4:1:KCQM-418" resourceId="KCQM-418"/>
      <person2 resource="#L2KF-NLB" resourceId="L2KF-NLB"/>
    </relationship>
    <relationship type="http://gedcomx.org/ParentChild" id="MMT5B-VYX">
      <identifier type="http://familysearch.org/v1/ChildAndParentsRelationship">http://familysearch.org/platform/tree/child-and-parents-relationships/MT5B-VYX</identifier>
      <person1 resource="https://familysearch.org/ark:/61903/4:1:KCJV-Z4S" resourceId="KCJV-Z4S"/>
      <person2 resource="#L2KF-NLB" resourceId="L2KF-NLB"/>
    </relationship>
    <sourceDescription about="#L2KF-NLB" resourceType="http://gedcomx.org/Person" version="136870634522800000" id="SD-L2KF-NLB">
      <citation xml:lang="en">
        <value>"Family Tree," database, &lt;i&gt;FamilySearch&lt;/i&gt; (http://familysearch.org : modified 06 July 2016, 02:04), entry for Dora Iucho Morrell(PID https://familysearch.org/ark:/61903/4:1:L2KF-NLB); contributed by various users.</value>
      </citation>
      <componentOf description="http://familysearch.org/platform/collections/tree"/>
      <title>Dora Iucho Morrell</title>
      <identifier type="http://gedcomx.org/Persistent">https://familysearch.org/ark:/61903/4:1:L2KF-NLB</identifier>
      <modified>2016-07-06T02:04:12Z</modified>
    </sourceDescription>
    <place id="1024916608">
      <name xml:lang="en-US">New York, United States</name>
      <name xml:lang="und">New York, United States</name>
    </place>
    <place id="1375628896">
      <name xml:lang="en-US">Manhattan, New York County, New York, United States</name>
      <name xml:lang="und">Manhattan, New York County, New York, United States</name>
    </place>
    <place id="1879384345">
      <name xml:lang="en-US">New York City, New York County, New York, United States</name>
      <name xml:lang="und">New York, New York, New York, United States</name>
    </place>
  </record>
        ';
        $xmlReader = new \XMLReader();
        $xmlReader->XML($xml);
        $gedcomX = new Gedcomx($xmlReader);
        $extenstions = $gedcomX->getPersons()[0]->getSources()[0]->getExtensionElements();
        $this->assertEquals(3, count($extenstions));

    }
}
dyeshurun commented 8 years ago

Is the test above sufficient?

justincy commented 8 years ago

@dyeshurun Likely, though I'm not sure. I haven't had time to look at it yet. I hope to get around to it this week.

justincy commented 8 years ago

This has been merged and released in version 2.3.3