-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation for basic custom tags.
Custom tags can be registered with the parser for a given Record object. So far, basic, single tag => value tags are implemented. Issue #6
- Loading branch information
Showing
5 changed files
with
260 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,11 @@ | |
*/ | ||
class Gedcom55ParserTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $vfsFile; | ||
|
||
/** | ||
* @var Gedcom55Parser | ||
*/ | ||
|
@@ -25,14 +30,12 @@ public function setUp() | |
vfsStreamWrapper::register(); | ||
vfsStreamWrapper::setRoot(new vfsStreamDirectory('test')); | ||
|
||
$vfsFile = vfsStream::url('test/file.ged'); | ||
file_put_contents($vfsFile, "0 HEAD\n1 SOUR PhpGedcom\n0 TRLF\n"); | ||
$this->vfsFile = vfsStream::url('test/file.ged'); | ||
file_put_contents($this->vfsFile, "0 HEAD\n1 SOUR PhpGedcom\n0 TRLF\n"); | ||
|
||
$this->tester = $this->getMockForAbstractClass( | ||
'PhpGedcom\Parser\Gedcom55Parser', | ||
array( | ||
$vfsFile | ||
) | ||
array($this->vfsFile) | ||
); | ||
} | ||
|
||
|
@@ -69,6 +72,90 @@ public function testLogUnhandledRecord() | |
$this->assertEquals('1: (Unhandled) 0|HEAD - info', current($this->tester->getErrors())); | ||
} | ||
|
||
/** | ||
* Tests registering a simple custom tag. | ||
*/ | ||
public function testRegisterSimpleCustomTag() | ||
{ | ||
$this->tester->registerCustomTag( | ||
'PhpGedcom\Record\Subm', | ||
'Email' | ||
); | ||
|
||
$tags = $this->tester->getCustomTags(); | ||
|
||
$this->assertCount(1, $tags); | ||
$this->assertEquals( | ||
array( | ||
'PhpGedcom\Record\Subm' => array( | ||
'email' => array( | ||
'nodeClass' => 'PhpGedcom\Record\Subm', 'tag' => 'Email', 'valueObject' => null | ||
) | ||
) | ||
), | ||
$tags | ||
); | ||
} | ||
|
||
/** | ||
* Tests registering a custom tag with a value object. | ||
*/ | ||
public function testRegisterCustomTagWithValueObject() | ||
{ | ||
$this->tester->registerCustomTag( | ||
'PhpGedcom\Record\Indi', | ||
'Map', | ||
'PhpGedcomTest\Parser\TestCustomTag' | ||
); | ||
|
||
$tags = $this->tester->getCustomTags(); | ||
|
||
$this->assertCount(1, $tags); | ||
$this->assertEquals( | ||
array( | ||
'PhpGedcom\Record\Indi' => array( | ||
'map' => array( | ||
'nodeClass' => 'PhpGedcom\Record\Indi', | ||
'tag' => 'Map', | ||
'valueObject' => 'PhpGedcomTest\Parser\TestCustomTag' | ||
) | ||
) | ||
), | ||
$tags | ||
); | ||
} | ||
|
||
/** | ||
* Test parsing a simple custom tag. | ||
*/ | ||
public function testParsingSimpleCustomTag() | ||
{ | ||
file_put_contents( | ||
$this->vfsFile, | ||
"0 HEAD\n1 SOUR PhpGedcom\n0 @SUBMITTER@ SUBM\n" . | ||
"1 NAME John A. Nairn\n1 EMAIL [email protected]\n0 TRLF" | ||
); | ||
|
||
$parser = new Gedcom55Parser($this->vfsFile); | ||
$parser->registerCustomTag( | ||
'PhpGedcom\Record\Subm', | ||
'Email' | ||
); | ||
|
||
$gedcom = $parser->parse(); | ||
$subm = current($gedcom->getSubm()); | ||
|
||
$this->assertEquals('[email protected]', $subm->getCustomTagValue('email')); | ||
} | ||
|
||
/** | ||
* Tests parsing a custom tag with a value object. | ||
*/ | ||
public function testParsingCustomTagWithValueObject() | ||
{ | ||
$this->markTestIncomplete(); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace PhpGedcomTest\Parser; | ||
|
||
use PhpGedcom\Record; | ||
|
||
/** | ||
* Class TestCustomTag | ||
* @package PhpGedcom\Parser | ||
*/ | ||
class TestCustomTag extends Record | ||
{ | ||
/** | ||
* @var float | ||
*/ | ||
protected $long; | ||
|
||
/** | ||
* @var float | ||
*/ | ||
protected $lat; | ||
|
||
/** | ||
* @param float $long | ||
* @return $this | ||
*/ | ||
public function setLong($long) | ||
{ | ||
$this->long = $long; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getLong() | ||
{ | ||
return $this->long; | ||
} | ||
|
||
/** | ||
* @param float $lat | ||
* @return $this | ||
*/ | ||
public function setLat($lat) | ||
{ | ||
$this->lat = $lat; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getLat() | ||
{ | ||
return $this->lat; | ||
} | ||
} |