Fix issue with formatting strongs numbers

This commit is contained in:
Leonard Smith 2021-05-06 12:09:16 -05:00
parent 82dcef8879
commit d9b6c65247
2 changed files with 33 additions and 1 deletions

View File

@ -4,6 +4,7 @@ namespace App\Handlers;
use App\Book;
use App\Chapter;
use App\Helpers\Traits\BookTitleHelperTrait;
use App\LexicalEntry;
use App\Word;
use App\Verse;
use DOMDocument;
@ -11,6 +12,7 @@ use DOMElement;
use DOMNodeList;
use Illuminate\Console\OutputStyle;
use Symfony\Component\Console\Output\OutputInterface;
use Illuminate\Support\Facades\Log;
/**
* UlbXmlImportHandler.php
@ -374,6 +376,14 @@ class UlbXmlImportHandler
'ulb_sort' => $this->getUlbSortNumber(),
]);
// While we are here, let's check for mismatched strongs entries and log them
if (!empty($word->strongs_number) && $word->strongs_number !== '-1') {
$lexicalEntry = LexicalEntry::find($word->strongs_number);
if (empty($lexicalEntry)) {
Log::info(self::class . ": No Lexical Entry found for $word->id | $word->strongs_number");
}
}
// Save this word object to the subs stack so that we can grab it when we need it.
if (!empty($sub)) {
$this->subs[$sub] = $word;
@ -441,7 +451,8 @@ class UlbXmlImportHandler
} elseif (empty($strongsNumber)) {
return null;
}
return 'G' . ltrim($strongsNumber, "Gg");
$strongsNumber = ltrim($strongsNumber, "Gg");
return sprintf("G%04d", $strongsNumber);
}
/**

View File

@ -75,4 +75,25 @@ END;
$this->assertInstanceOf(\DOMElement::class, $result);
$this->assertStringContainsString('Some test without markup', $result->nodeValue);
}
public function testThatStrongsNumbersGetFormattedCorrectly()
{
$numbersToTest = [
[ 'actual' => '1', 'expected' => 'G0001' ],
[ 'actual' => '11', 'expected' => 'G0011' ],
[ 'actual' => '111', 'expected' => 'G0111' ],
[ 'actual' => '1111', 'expected' => 'G1111' ],
];
$handler = new UlbXmlImportHandler;
$reflection_class = new \ReflectionClass(UlbXmlImportHandler::class);
$method = $reflection_class->getMethod('formatStrongsNumber');
$method->setAccessible(true);
foreach ($numbersToTest as $set) {
$result = $method->invoke($handler, $set['actual']);
$this->assertEquals($set['expected'], $result);
}
}
}