Skip to content

Commit

Permalink
Merge pull request #218 from andreaswolf/issue-198
Browse files Browse the repository at this point in the history
[BUGFIX] Fix EOF and indentation of xml processing
  • Loading branch information
simonschaufi authored Aug 28, 2024
2 parents fe989a9 + 50b6d67 commit 501b642
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 3 deletions.
2 changes: 1 addition & 1 deletion e2e/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions e2e/typo3-xml/expected-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

1 file with changes
===================

1) typo3-xml/result/Fixture.xml:9

---------- begin diff ----------
@@ @@
<settings.nullable_field_trimmed>
<label>Nullable field trimmed</label>
<config>
- <eval>null,trim</eval>
+ <eval>trim</eval>
+ <nullable>true</nullable>
</config>
</settings.nullable_field_trimmed>
</el>
----------- 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

20 changes: 20 additions & 0 deletions e2e/typo3-xml/expected-result/Fixture.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<T3DataStructure>
<sheets>
<sDEF>
<ROOT>
<sheetTitle>sheetTitle</sheetTitle>
<type>array</type>
<el>
<settings.nullable_field_trimmed>
<label>Nullable field trimmed</label>
<config>
<eval>trim</eval>
<nullable>true</nullable>
</config>
</settings.nullable_field_trimmed>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
19 changes: 19 additions & 0 deletions e2e/typo3-xml/fixtures/Fixture.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<T3DataStructure>
<sheets>
<sDEF>
<ROOT>
<sheetTitle>sheetTitle</sheetTitle>
<type>array</type>
<el>
<settings.nullable_field_trimmed>
<label>Nullable field trimmed</label>
<config>
<eval>null,trim</eval>
</config>
</settings.nullable_field_trimmed>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
16 changes: 16 additions & 0 deletions e2e/typo3-xml/fractor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use a9f\Fractor\Configuration\FractorConfiguration;
use a9f\Fractor\ValueObject\Indent;
use a9f\FractorXml\Configuration\XmlProcessorOption;
use a9f\Typo3Fractor\Set\Typo3LevelSetList;

return FractorConfiguration::configure()
->withPaths([__DIR__ . '/result/'])
->withSets([Typo3LevelSetList::UP_TO_TYPO3_13])
->withOptions([
XmlProcessorOption::INDENT_CHARACTER => Indent::STYLE_TAB,
XmlProcessorOption::INDENT_SIZE => 1,
]);
19 changes: 19 additions & 0 deletions e2e/typo3-xml/result/Fixture.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<T3DataStructure>
<sheets>
<sDEF>
<ROOT>
<sheetTitle>sheetTitle</sheetTitle>
<type>array</type>
<el>
<settings.nullable_field_trimmed>
<label>Nullable field trimmed</label>
<config>
<eval>null,trim</eval>
</config>
</settings.nullable_field_trimmed>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
6 changes: 4 additions & 2 deletions packages/fractor-xml/src/XmlFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 501b642

Please sign in to comment.