Skip to content

Commit

Permalink
Fix for multi-level xml tags (lvl 3+) (#32)
Browse files Browse the repository at this point in the history
* Fix for multi-level xml tags (lvl 3+)

* added test for multi-level tag fix

* typo fix

* test case array fix

* final test array fix

* ...
  • Loading branch information
BigOHenry authored Apr 12, 2022
1 parent cac6349 commit 5368a00
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Xml/Concerns/SupportMultiLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ protected function parseAdvancedUses(string $value): MultiLevel
$uses[$current] = '';
--$level;
break;
} else {
$uses[$current] .= '}';
--$level;
break;
}
// no break
default:
Expand Down
100 changes: 100 additions & 0 deletions tests/Xml/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,106 @@ public function testParseValueCollectionMultiLevels()
'product' => ['uses' => 'T_NEW_CATALOG.PRODUCT[NODE_ID>node_id,PRODUCT_FEATURES{FEATURE{FNAME>name,FVALUE>value,TRANSLATION_US.FNAME>feature_translation_name,TRANSLATION_US.FVALUE>feature_translation_value}>feature}>product_features,MIME_INFO{MIME{property(::id=@),MIME_TYPE>mime_type,MIME_SOURCE>mime_source,MIME_DESCRIPTION>mime_description}>mime}>mime_info]'],
]);

$this->assertEquals($expected, $data);
}

/** @test */
public function testParseValueCollectionMultiLevelsPartTwo()
{
$expected = [
'errors' => [
[
'ErrorItem' => [
[
'DataArea' => 'AREA1',
'DynPar' => 'T0019:1,R0109:,R0108:,R0107:,T0025:X',
'StatusItem' => 'REJECTED',
'Error' => [
[
'Code' => 'ERR_2059',
'Severity' => 'Critical',
'Text' => 'Error message ERR_2059.',
'Localization' => [
[
'DataAreaCode' => 'AREA1_CODE',
'Detail' => [
'DynPar' => 'T0019:1,R0109:test1,R0108:,R0107:,T0025:X',
],
],
],
],
],
],
[
'DataArea' => 'AREA2',
'DynPar' => 'T0019:2,R0109:test2,R0108:,R0107:,T0025:X',
'StatusItem' => 'REJECTED',
'Error' => [
[
'Code' => 'ERR_2060',
'Severity' => 'Warning',
'Text' => 'Error message ERR_2060.',
'Localization' => [
[
'DataAreaCode' => 'AREA2_CODE',
'Detail' => [
'DynPar' => 'T0019:2,R0109:test2,R0108:,R0107:,T0025:X',
],
],
],
],
],
],
],
],
],
];

$stub = new DocumentStub();

$stub->setContent(simplexml_load_string("<StepProcess>
<StepName>FORMAT_CONTROL</StepName>
<Result>NOT_ACCEPTED</Result>
<ErrorsProcess>
<ErrorItem>
<DataArea>AREA1</DataArea>
<DynPar>T0019:1,R0109:,R0108:,R0107:,T0025:X</DynPar>
<StatusItem>REJECTED</StatusItem>
<Error>
<Code>ERR_2059</Code>
<Severity>Critical</Severity>
<Text>Error message ERR_2059.</Text>
<Localization>
<DataAreaCode>AREA1_CODE</DataAreaCode>
<Detail>
<DynPar>T0019:1,R0109:test1,R0108:,R0107:,T0025:X</DynPar>
</Detail>
</Localization>
</Error>
</ErrorItem>
<ErrorItem>
<DataArea>AREA2</DataArea>
<DynPar>T0019:2,R0109:test2,R0108:,R0107:,T0025:X</DynPar>
<StatusItem>REJECTED</StatusItem>
<Error>
<Code>ERR_2060</Code>
<Severity>Warning</Severity>
<Text>Error message ERR_2060.</Text>
<Localization>
<DataAreaCode>AREA2_CODE</DataAreaCode>
<Detail>
<DynPar>T0019:2,R0109:test2,R0108:,R0107:,T0025:X</DynPar>
</Detail>
</Localization>
</Error>
</ErrorItem>
</ErrorsProcess>
</StepProcess>"));

$data = $stub->parse([
'errors' => ['uses' => 'ErrorsProcess[ErrorItem{DataArea,DynPar,StatusItem,Error{Code,Severity,Text,Localization{DataAreaCode,Detail.DynPar}}}]'],
]);

$this->assertEquals($expected, $data);
}
}
Expand Down

0 comments on commit 5368a00

Please sign in to comment.