From 50b6d67caf63286302f1050f2d5d66f1893e5110 Mon Sep 17 00:00:00 2001 From: Simon Schaufelberger Date: Wed, 28 Aug 2024 17:08:49 +0200 Subject: [PATCH] [BUGFIX] Fix EOF and indentation of xml processing Fixes: #198 --- e2e/run-test.sh | 2 +- e2e/typo3-xml/expected-output.txt | 25 +++++++++++++++++++ e2e/typo3-xml/expected-result/Fixture.xml | 20 +++++++++++++++ e2e/typo3-xml/fixtures/Fixture.xml | 19 ++++++++++++++ e2e/typo3-xml/fractor.php | 16 ++++++++++++ e2e/typo3-xml/result/Fixture.xml | 19 ++++++++++++++ packages/fractor-xml/src/XmlFileProcessor.php | 6 +++-- 7 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 e2e/typo3-xml/expected-output.txt create mode 100644 e2e/typo3-xml/expected-result/Fixture.xml create mode 100644 e2e/typo3-xml/fixtures/Fixture.xml create mode 100644 e2e/typo3-xml/fractor.php create mode 100644 e2e/typo3-xml/result/Fixture.xml diff --git a/e2e/run-test.sh b/e2e/run-test.sh index 0073f06..3e97f93 100755 --- a/e2e/run-test.sh +++ b/e2e/run-test.sh @@ -10,7 +10,7 @@ cd $TESTS_BASE_DIR rm -r composer.lock vendor || true composer install -for TEST_DIR in typo3-yaml typo3-typoscript +for TEST_DIR in typo3-typoscript typo3-xml typo3-yaml do set +x echo diff --git a/e2e/typo3-xml/expected-output.txt b/e2e/typo3-xml/expected-output.txt new file mode 100644 index 0000000..6c9f88e --- /dev/null +++ b/e2e/typo3-xml/expected-output.txt @@ -0,0 +1,25 @@ + +1 file with changes +=================== + +1) typo3-xml/result/Fixture.xml:9 + + ---------- begin diff ---------- +@@ @@ + + + +- null,trim ++ trim ++ true + + + + ----------- end diff ----------- + +Applied rules: + * MigrateNullFlagFlexFormFractor (https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Deprecation-97384-TCAOptionNullable.html) + + + [OK] 1 file has been changed by Fractor + diff --git a/e2e/typo3-xml/expected-result/Fixture.xml b/e2e/typo3-xml/expected-result/Fixture.xml new file mode 100644 index 0000000..e9d5e75 --- /dev/null +++ b/e2e/typo3-xml/expected-result/Fixture.xml @@ -0,0 +1,20 @@ + + + + + + sheetTitle + array + + + + + trim + true + + + + + + + diff --git a/e2e/typo3-xml/fixtures/Fixture.xml b/e2e/typo3-xml/fixtures/Fixture.xml new file mode 100644 index 0000000..784ce96 --- /dev/null +++ b/e2e/typo3-xml/fixtures/Fixture.xml @@ -0,0 +1,19 @@ + + + + + + sheetTitle + array + + + + + null,trim + + + + + + + diff --git a/e2e/typo3-xml/fractor.php b/e2e/typo3-xml/fractor.php new file mode 100644 index 0000000..09b8984 --- /dev/null +++ b/e2e/typo3-xml/fractor.php @@ -0,0 +1,16 @@ +withPaths([__DIR__ . '/result/']) + ->withSets([Typo3LevelSetList::UP_TO_TYPO3_13]) + ->withOptions([ + XmlProcessorOption::INDENT_CHARACTER => Indent::STYLE_TAB, + XmlProcessorOption::INDENT_SIZE => 1, + ]); diff --git a/e2e/typo3-xml/result/Fixture.xml b/e2e/typo3-xml/result/Fixture.xml new file mode 100644 index 0000000..784ce96 --- /dev/null +++ b/e2e/typo3-xml/result/Fixture.xml @@ -0,0 +1,19 @@ + + + + + + sheetTitle + array + + + + + null,trim + + + + + + + diff --git a/packages/fractor-xml/src/XmlFileProcessor.php b/packages/fractor-xml/src/XmlFileProcessor.php index 3a25360..728bdd5 100644 --- a/packages/fractor-xml/src/XmlFileProcessor.php +++ b/packages/fractor-xml/src/XmlFileProcessor.php @@ -40,13 +40,15 @@ public function handle(File $file, iterable $appliedRules): void $document->loadXML($originalXml); // This is a hacky trick to keep format and create a nice diff later - $file->changeOriginalContent($this->saveXml($document)); + $oldXml = $this->saveXml($document); + $oldXml = $this->formatter->format($this->indent, $oldXml) . "\n"; + $file->changeOriginalContent($oldXml); $iterator = new DomDocumentIterator($appliedRules); $iterator->traverseDocument($file, $document); $newXml = $this->saveXml($document); - $newXml = $this->formatter->format($this->indent, $newXml); + $newXml = $this->formatter->format($this->indent, $newXml) . "\n"; if ($newXml === $originalXml) { return;