diff --git a/app/Handlers/UlbXmlImportHandler.php b/app/Handlers/UlbXmlImportHandler.php index 853e2e6..dbcd3ea 100644 --- a/app/Handlers/UlbXmlImportHandler.php +++ b/app/Handlers/UlbXmlImportHandler.php @@ -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); } /** diff --git a/tests/Unit/UlbXmlImportHandlerTest.php b/tests/Unit/UlbXmlImportHandlerTest.php index d5738e0..e2cc9ef 100644 --- a/tests/Unit/UlbXmlImportHandlerTest.php +++ b/tests/Unit/UlbXmlImportHandlerTest.php @@ -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); + } + } }