Strip usfm nodes from word elements and add a test for it

This commit is contained in:
Leonard Smith 2021-05-06 07:25:38 -05:00
parent 0e2b564a7d
commit ef26a212d0
2 changed files with 35 additions and 11 deletions

View File

@ -357,7 +357,7 @@ class UlbXmlImportHandler
$sub = $wordElem->getAttribute('sub');
// Does our content require a substitution?
$ulb = $this->replaceSub($wordElem);
$ulb = $this->replaceSub($this->stripUsfmMarkup($wordElem));
$word = Word::create([
'verse_code' => implode('-', [$verse_id, $ognt_sort]),
@ -365,7 +365,7 @@ class UlbXmlImportHandler
// 'ulb' => $wordElem->nodeValue,
'ulb' => $ulb,
'phrase_id' => $wordElem->hasAttribute('phraseId') ? $wordElem->getAttribute('phraseId') : null, // *** from buildVersePhrases()
'sub' => empty($sub),
'sub' => !empty($sub),
'greek' => $wordElem->getAttribute('text'),
'lemma' => $wordElem->getAttribute('lemma'),
'morph' => $wordElem->getAttribute('morph'),
@ -401,7 +401,25 @@ class UlbXmlImportHandler
return $results;
}
protected function getUlbSortNumber()
/**
* @param DOMElement $element
* @return DOMElement
*/
protected function stripUsfmMarkup(DOMElement $element) : DOMElement
{
$usfmNodes = $element->getElementsByTagName('usfm');
if (!empty($usfmNodes)) {
foreach ($usfmNodes as $node) {
$element->removeChild($node);
}
}
return $element;
}
/**
* @return int
*/
protected function getUlbSortNumber() : int
{
$chapterNumber = sprintf("%02d", $this->currentChapterNumber);
$verseNumber = sprintf("%03d", $this->currentVerseNumber);
@ -411,12 +429,12 @@ class UlbXmlImportHandler
}
/**
* Not all of the strongs numbers coming from the XML files are formatted the same. Let's fix that here.
* Not all of the strong's numbers coming from the XML files are formatted the same. Let's fix that here.
*
* @param string $strongsNumber
* @return string
* @return mixed
*/
protected function formatStrongsNumber(string $strongsNumber)
protected function formatStrongsNumber(string $strongsNumber) : ?string
{
if ($strongsNumber == -1) {
return $strongsNumber;
@ -462,10 +480,10 @@ class UlbXmlImportHandler
}
/**
* @param $filepath
* @param string $filepath
* @return DOMDocument
*/
protected function openBook($filepath) : DOMDocument
protected function openBook(string $filepath) : DOMDocument
{
$document = new \DOMDocument;
$document->load($filepath);
@ -473,14 +491,21 @@ class UlbXmlImportHandler
return $document;
}
protected function write($message, $newline)
/**
* @param string $message
* @param bool $newline
*/
protected function write(string $message, bool $newline) : void
{
if ($this->output !== null && $this->output instanceof OutputStyle) {
$this->output->write("<info>$message</info>", $newline, OutputInterface::VERBOSITY_NORMAL);
}
}
protected function writeln($message)
/**
* @param string $message
*/
protected function writeln(string $message) : void
{
if ($this->output !== null && $this->output instanceof OutputStyle) {
$this->output->writeln("<info>$message</info>", OutputInterface::VERBOSITY_NORMAL);

View File

@ -1,7 +1,6 @@
<?php
namespace Tests\Unit;
use App\Handlers\UlbXmlImportHandler;
use App\Helpers\Traits\BookTitleHelperTrait;
use Tests\TestCase;