Skip to content

Commit

Permalink
WIP: test coverage for parser.
Browse files Browse the repository at this point in the history
applied formatting fixes to other tests while at it.
  • Loading branch information
stopfstedt committed Dec 10, 2016
1 parent 3ac2187 commit 3936e09
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 3 deletions.
1 change: 0 additions & 1 deletion tests/Ilios/MeSH/Model/DescriptorSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public function testAddGetDescriptors()
$this->object->addDescriptor($descriptor3);
$this->assertEquals(count($this->object->getDescriptors()), 2);
$this->assertEquals($this->object->getDescriptors()[1], $descriptor3);

}

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/Ilios/MeSH/Model/DescriptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public function testGetSetPublicMeshNote()
public function testAddGetPreviousIndexing()
{
$this->addTextToListTest($this->object, 'previousIndexing', 'getPreviousIndexing');

}

/**
Expand Down Expand Up @@ -175,7 +174,6 @@ public function testAddGetPharmacologicalAction()
public function testAddGetTreeNumbers()
{
$this->addTextToListTest($this->object, 'treeNumber');

}

/**
Expand Down
108 changes: 108 additions & 0 deletions tests/Ilios/MeSH/ParserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace Ilios\MeSH;

class ParserTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Parser
*/
protected $parser;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->parser = new Parser();
}

/**
* @inheritdoc
*/
protected function tearDown()
{
unset($this->parser);
}

/**
* @covers Parser:test
*/
public function testForInvalidInputUriFailure()
{
$uri = 'this/is/a/path/that/does/not/exist/desc.xml';
try {
$this->parser->parse($uri);
} catch (\Exception $e) {
$this->assertSame("XML reader failed to open ${uri}.", $e->getMessage());
}
}

/**
* @covers Parser:test
*/
public function testForIncompleteDateFailure()
{
$xml =<<<EOL
<?xml version="1.0"?>
<!DOCTYPE DescriptorRecordSet SYSTEM "https://www.nlm.nih.gov/databases/dtd/nlmdescriptorrecordset_20170101.dtd">
<DescriptorRecordSet LanguageCode="eng">
<DescriptorRecord DescriptorClass="1">
<DescriptorUI>D000000</DescriptorUI>
<DescriptorName>
<String>a descriptor</String>
</DescriptorName>
<DateCreated>
<Year>2016</Year>
<Month>12</Month>
</DateCreated>
</DescriptorRecord>
</DescriptorRecordSet>
EOL;
try {
/* @link http://php.net/manual/en/wrappers.data.php */
$this->parser->parse('data://text/plain;base64,' . base64_encode($xml));
} catch (\Exception $e) {
$this->assertSame('Could not retrieve Year/Month/Day info from node "DateCreated".', $e->getMessage());
}
}

/**
* @covers Parser:test
*/
public function testForInvalidStringNodeFailure()
{
$xml =<<<EOL
<?xml version="1.0"?>
<!DOCTYPE DescriptorRecordSet SYSTEM "https://www.nlm.nih.gov/databases/dtd/nlmdescriptorrecordset_20170101.dtd">
<DescriptorRecordSet LanguageCode="eng">
<DescriptorRecord DescriptorClass="1">
<DescriptorUI>D000000</DescriptorUI>
<AllowableQualifiersList>
<AllowableQualifier>
<QualifierReferredTo>
<QualifierUI>Q000001</QualifierUI>
<QualifierName>
this should be wrapped in a "String" element, but isn't.
</QualifierName>
</QualifierReferredTo>
</AllowableQualifier>
</AllowableQualifiersList>
</DescriptorRecord>
</DescriptorRecordSet>
EOL;
try {
$this->parser->parse('data://text/plain;base64,' . base64_encode($xml));
} catch (\Exception $e) {
$this->assertSame('Node "QualifierName" does not contain a child node of type "String".', $e->getMessage());
}
}

/**
* @covers Parser:test
*/
public function testParse()
{
$this->markTestIncomplete('To be implemented.');
}
}

0 comments on commit 3936e09

Please sign in to comment.