Skip to content

Commit 501b642

Browse files
authored
Merge pull request #218 from andreaswolf/issue-198
[BUGFIX] Fix EOF and indentation of xml processing
2 parents fe989a9 + 50b6d67 commit 501b642

File tree

7 files changed

+104
-3
lines changed

7 files changed

+104
-3
lines changed

e2e/run-test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cd $TESTS_BASE_DIR
1010
rm -r composer.lock vendor || true
1111
composer install
1212

13-
for TEST_DIR in typo3-yaml typo3-typoscript
13+
for TEST_DIR in typo3-typoscript typo3-xml typo3-yaml
1414
do
1515
set +x
1616
echo

e2e/typo3-xml/expected-output.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
1 file with changes
3+
===================
4+
5+
1) typo3-xml/result/Fixture.xml:9
6+
7+
---------- begin diff ----------
8+
@@ @@
9+
<settings.nullable_field_trimmed>
10+
<label>Nullable field trimmed</label>
11+
<config>
12+
- <eval>null,trim</eval>
13+
+ <eval>trim</eval>
14+
+ <nullable>true</nullable>
15+
</config>
16+
</settings.nullable_field_trimmed>
17+
</el>
18+
----------- end diff -----------
19+
20+
Applied rules:
21+
* MigrateNullFlagFlexFormFractor (https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Deprecation-97384-TCAOptionNullable.html)
22+
23+
24+
[OK] 1 file has been changed by Fractor
25+
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<T3DataStructure>
3+
<sheets>
4+
<sDEF>
5+
<ROOT>
6+
<sheetTitle>sheetTitle</sheetTitle>
7+
<type>array</type>
8+
<el>
9+
<settings.nullable_field_trimmed>
10+
<label>Nullable field trimmed</label>
11+
<config>
12+
<eval>trim</eval>
13+
<nullable>true</nullable>
14+
</config>
15+
</settings.nullable_field_trimmed>
16+
</el>
17+
</ROOT>
18+
</sDEF>
19+
</sheets>
20+
</T3DataStructure>

e2e/typo3-xml/fixtures/Fixture.xml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<T3DataStructure>
3+
<sheets>
4+
<sDEF>
5+
<ROOT>
6+
<sheetTitle>sheetTitle</sheetTitle>
7+
<type>array</type>
8+
<el>
9+
<settings.nullable_field_trimmed>
10+
<label>Nullable field trimmed</label>
11+
<config>
12+
<eval>null,trim</eval>
13+
</config>
14+
</settings.nullable_field_trimmed>
15+
</el>
16+
</ROOT>
17+
</sDEF>
18+
</sheets>
19+
</T3DataStructure>

e2e/typo3-xml/fractor.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use a9f\Fractor\Configuration\FractorConfiguration;
6+
use a9f\Fractor\ValueObject\Indent;
7+
use a9f\FractorXml\Configuration\XmlProcessorOption;
8+
use a9f\Typo3Fractor\Set\Typo3LevelSetList;
9+
10+
return FractorConfiguration::configure()
11+
->withPaths([__DIR__ . '/result/'])
12+
->withSets([Typo3LevelSetList::UP_TO_TYPO3_13])
13+
->withOptions([
14+
XmlProcessorOption::INDENT_CHARACTER => Indent::STYLE_TAB,
15+
XmlProcessorOption::INDENT_SIZE => 1,
16+
]);

e2e/typo3-xml/result/Fixture.xml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<T3DataStructure>
3+
<sheets>
4+
<sDEF>
5+
<ROOT>
6+
<sheetTitle>sheetTitle</sheetTitle>
7+
<type>array</type>
8+
<el>
9+
<settings.nullable_field_trimmed>
10+
<label>Nullable field trimmed</label>
11+
<config>
12+
<eval>null,trim</eval>
13+
</config>
14+
</settings.nullable_field_trimmed>
15+
</el>
16+
</ROOT>
17+
</sDEF>
18+
</sheets>
19+
</T3DataStructure>

packages/fractor-xml/src/XmlFileProcessor.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ public function handle(File $file, iterable $appliedRules): void
4040
$document->loadXML($originalXml);
4141

4242
// This is a hacky trick to keep format and create a nice diff later
43-
$file->changeOriginalContent($this->saveXml($document));
43+
$oldXml = $this->saveXml($document);
44+
$oldXml = $this->formatter->format($this->indent, $oldXml) . "\n";
45+
$file->changeOriginalContent($oldXml);
4446

4547
$iterator = new DomDocumentIterator($appliedRules);
4648
$iterator->traverseDocument($file, $document);
4749

4850
$newXml = $this->saveXml($document);
49-
$newXml = $this->formatter->format($this->indent, $newXml);
51+
$newXml = $this->formatter->format($this->indent, $newXml) . "\n";
5052

5153
if ($newXml === $originalXml) {
5254
return;

0 commit comments

Comments
 (0)