Add the test left out in the previous commit :-(

This commit is contained in:
Leonard Smith 2021-05-06 07:27:45 -05:00
parent ef26a212d0
commit dec8b69c7e
1 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,78 @@
<?php
namespace Tests\Unit;
use App\Handlers\UlbXmlImportHandler;
use Tests\TestCase;
/**
* UlbXmlImportHandlerTest.php
*
* @author: Leonard Smith <leonard@acornwebconsultants.com>
* Date: 5/6/21
* Time: 6:52 AM
*/
class UlbXmlImportHandlerTest extends TestCase
{
public function testStripUsfmMarkupRemovesUsfmNode()
{
$xml = <<<'END'
<xml>
<book>
<chapter >
<verse>
<w>Some test with markup <usfm>\f the markup \f*</usfm></w>
</verse>
</chapter>
</book>
</xml>
END;
/** @var \DOMDocument $doc */
$doc = new \DOMDocument;
$doc->loadXML($xml);
$element = $doc->getElementsByTagName('w');
$handler = new UlbXmlImportHandler;
$reflection_class = new \ReflectionClass(UlbXmlImportHandler::class);
$method = $reflection_class->getMethod('stripUsfmMarkup');
$method->setAccessible(true);
$result = $method->invoke($handler, $element[0]);
$this->assertInstanceOf(\DOMElement::class, $result);
$this->assertStringNotContainsString('\f the markup \f*', $result->nodeValue);
$this->assertStringContainsString('Some test with markup', $result->nodeValue);
}
public function testStripUsfmMarkupWorksWhenNoUsfmNode()
{
$xml = <<<'END'
<xml>
<book>
<chapter >
<verse>
<w>Some test without markup</w>
</verse>
</chapter>
</book>
</xml>
END;
/** @var \DOMDocument $doc */
$doc = new \DOMDocument;
$doc->loadXML($xml);
$element = $doc->getElementsByTagName('w');
$handler = new UlbXmlImportHandler;
$reflection_class = new \ReflectionClass(UlbXmlImportHandler::class);
$method = $reflection_class->getMethod('stripUsfmMarkup');
$method->setAccessible(true);
$result = $method->invoke($handler, $element[0]);
$this->assertInstanceOf(\DOMElement::class, $result);
$this->assertStringContainsString('Some test without markup', $result->nodeValue);
}
}