From 11586a51649d11b41940c1d62dcbdfada30d00c0 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Mon, 19 Jun 2017 12:24:17 +0200 Subject: [PATCH] TASK: Handle empty nodeLists properly If a node only contained children that were ignored the returned fusion code was invalid. This case is fixed by creating an empty string for NodeLists that do not contain meaningful items. --- Classes/Service/AfxService.php | 4 ++-- Tests/Functional/AfxServiceTest.php | 34 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Classes/Service/AfxService.php b/Classes/Service/AfxService.php index f64dc60..0481660 100644 --- a/Classes/Service/AfxService.php +++ b/Classes/Service/AfxService.php @@ -178,7 +178,7 @@ protected static function astNodeToFusion($payload, $indentation = '') $childrenPropertyName = 'content'; } $childFusion = self::astNodeListToFusion($payload['children'], $indentation . self::INDENTATION); - if ($childFusion !== null) { + if ($childFusion) { $fusion .= $indentation . self::INDENTATION . $childrenPropertyName . ' = ' . $childFusion . PHP_EOL; } } @@ -215,7 +215,7 @@ protected static function astNodeListToFusion($payload, $indentation = '') }); if (count($payload) == 0) { - return ''; + return '\'\''; } elseif (count($payload) == 1) { return self::astToFusion(array_shift($payload), $indentation); } else { diff --git a/Tests/Functional/AfxServiceTest.php b/Tests/Functional/AfxServiceTest.php index 9cc5017..6b2c742 100644 --- a/Tests/Functional/AfxServiceTest.php +++ b/Tests/Functional/AfxServiceTest.php @@ -14,6 +14,7 @@ public function emptyCodeConvertedToEmptyFusion() { $afxCode = ''; $expectedFusion = <<<'EOF' +'' EOF; $this->assertEquals($expectedFusion, AfxService::convertAfxToFusion($afxCode)); } @@ -25,6 +26,7 @@ public function whitepaceCodeIsConvertedToEmptyFusion() { $afxCode = ' '; $expectedFusion = <<<'EOF' +'' EOF; $this->assertEquals($expectedFusion, AfxService::convertAfxToFusion($afxCode)); } @@ -43,6 +45,38 @@ public function htmlTagsAreConvertedToFusionTags() $this->assertEquals($expectedFusion, AfxService::convertAfxToFusion($afxCode)); } + /** + * @test + */ + public function htmlTagsWithSpaceContentAreConvertedToFusionTags() + { + $afxCode = '

'; + $expectedFusion = <<<'EOF' +Neos.Fusion:Tag { + tagName = 'h1' + content = ' ' +} +EOF; + $this->assertEquals($expectedFusion, AfxService::convertAfxToFusion($afxCode)); + } + + /** + * @test + */ + public function htmlTagsWithIgnoredContentAreConvertedToFusionTags() + { + $afxCode = '

+ +

'; + $expectedFusion = <<<'EOF' +Neos.Fusion:Tag { + tagName = 'h1' + content = '' +} +EOF; + $this->assertEquals($expectedFusion, AfxService::convertAfxToFusion($afxCode)); + } + /** * @test */