diff --git a/src/Logic/HTMLDocumentProcessor.php b/src/Logic/HTMLDocumentProcessor.php index f4c63174..6078780d 100644 --- a/src/Logic/HTMLDocumentProcessor.php +++ b/src/Logic/HTMLDocumentProcessor.php @@ -44,6 +44,20 @@ function processPartialContent( $componentList = new LogicAssemblyComponentList(); + try { + $partial = new PartialContent(implode(DIRECTORY_SEPARATOR, [ + getcwd(), + $this->partialDirectory, + ])); + + $partialExpander = new PartialExpander( + $model, + $partial, + ); + $partialExpander->expand(); + } + catch(PartialContentDirectoryNotFoundException) {} + try { // TODO: Handle other model types in sub-functions. $partial = new PartialContent(implode(DIRECTORY_SEPARATOR, [ @@ -82,20 +96,6 @@ function processPartialContent( } catch(PartialContentDirectoryNotFoundException) {} - try { - $partial = new PartialContent(implode(DIRECTORY_SEPARATOR, [ - getcwd(), - $this->partialDirectory, - ])); - - $partialExpander = new PartialExpander( - $model, - $partial, - ); - $partialExpander->expand(); - } - catch(PartialContentDirectoryNotFoundException) {} - return $componentList; } diff --git a/test/phpunit/Logic/HTMLDocumentProcessorTest.php b/test/phpunit/Logic/HTMLDocumentProcessorTest.php index bf10ac0e..642da475 100644 --- a/test/phpunit/Logic/HTMLDocumentProcessorTest.php +++ b/test/phpunit/Logic/HTMLDocumentProcessorTest.php @@ -93,6 +93,36 @@ public function testProcessPartialContent_expandsComponentsAndPartialsAndRegiste self::assertSame("no-logic", TestLogHandler::$records[0]["context"]["component"]); } + public function testProcessPartialContent_expandsAndRegistersComponentsFromPartial():void { + file_put_contents( + $this->componentDir . "/site-card.html", + "
", + ); + file_put_contents($this->componentDir . "/site-card.php", "partialDir . "/layout.html", + "
", + ); + + $document = new HTMLDocument( + "

Page

" + ); + $processor = new HTMLDocumentProcessor( + ltrim(substr($this->componentDir, strlen(getcwd())), "/"), + ltrim(substr($this->partialDir, strlen(getcwd())), "/"), + ); + + $componentList = $processor->processPartialContent($document); + + self::assertCount(1, $componentList); + self::assertSame("site-card", strtolower($componentList[0]->component->tagName)); + self::assertSame( + "site-card", + $document->querySelector("site-card input[name='__component']")?->getAttribute("value"), + ); + self::assertStringContainsString("

Page

", (string)$document); + } + public function testProcessPartialContent_ignoresMissingDirectories():void { $document = new HTMLDocument(""); $processor = new HTMLDocumentProcessor(