Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Fix EOF and indentation of xml processing #218

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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