@@ -17,6 +17,8 @@ class Dom extends \Magento\FunctionalTestingFramework\Config\Dom
17
17
const TEST_META_FILENAME_ATTRIBUTE = 'filename ' ;
18
18
const TEST_META_NAME_ATTRIBUTE = 'name ' ;
19
19
const TEST_HOOK_NAMES = ["after " , "before " ];
20
+ const TEST_MERGE_POINTER_BEFORE = "before " ;
21
+ const TEST_MERGE_POINTER_AFTER = "after " ;
20
22
21
23
/**
22
24
* TestDom constructor.
@@ -63,6 +65,23 @@ public function initDom($xml, $filename = null, $exceptionCollector = null)
63
65
/** @var \DOMElement $testNode */
64
66
$ testNode ->setAttribute (self ::TEST_META_FILENAME_ATTRIBUTE , $ filename );
65
67
$ this ->validateDomStepKeys ($ testNode , $ filename , 'Test ' , $ exceptionCollector );
68
+ if ($ testNode ->getAttribute (self ::TEST_MERGE_POINTER_AFTER ) !== "" ) {
69
+ $ this ->appendMergePointerToActions (
70
+ $ testNode ,
71
+ self ::TEST_MERGE_POINTER_AFTER ,
72
+ $ testNode ->getAttribute (self ::TEST_MERGE_POINTER_AFTER ),
73
+ $ filename ,
74
+ $ exceptionCollector
75
+ );
76
+ } elseif ($ testNode ->getAttribute (self ::TEST_MERGE_POINTER_BEFORE ) !== "" ) {
77
+ $ this ->appendMergePointerToActions (
78
+ $ testNode ,
79
+ self ::TEST_MERGE_POINTER_BEFORE ,
80
+ $ testNode ->getAttribute (self ::TEST_MERGE_POINTER_BEFORE ),
81
+ $ filename ,
82
+ $ exceptionCollector
83
+ );
84
+ }
66
85
}
67
86
}
68
87
@@ -83,6 +102,36 @@ public function merge($xml, $filename = null, $exceptionCollector = null)
83
102
$ this ->mergeNode ($ dom ->documentElement , '' );
84
103
}
85
104
105
+ /**
106
+ * Parses DOM Structure's actions and appends a before/after attribute along with the parent's stepkey reference.
107
+ *
108
+ * @param \DOMElement $testNode
109
+ * @param string $pointerType
110
+ * @param string $pointerKey
111
+ * @param string $filename
112
+ * @param ExceptionCollector $exceptionCollector
113
+ * @return void
114
+ */
115
+ protected function appendMergePointerToActions ($ testNode , $ pointerType , $ pointerKey , $ filename , $ exceptionCollector )
116
+ {
117
+ $ childNodes = $ testNode ->childNodes ;
118
+ for ($ i = 0 ; $ i < $ childNodes ->length ; $ i ++) {
119
+ $ currentNode = $ childNodes ->item ($ i );
120
+ if (!is_a ($ currentNode , \DOMElement::class)) {
121
+ continue ;
122
+ }
123
+ if ($ currentNode ->hasAttribute ('stepKey ' )) {
124
+ if ($ currentNode ->hasAttribute ($ pointerType ) && $ testNode ->hasAttribute ($ pointerType )) {
125
+ $ errorMsg = "Actions cannot have a before/after pointer if they are in a test that provides a merge pointer. " ;
126
+ $ errorMsg .= "\n\tstepKey: {$ currentNode ->getAttribute ('stepKey ' )}\tin file: {$ filename }" ;
127
+ $ exceptionCollector ->addError ($ filename , $ errorMsg );
128
+ continue ;
129
+ }
130
+ $ currentNode ->setAttribute ($ pointerType , $ pointerKey );
131
+ }
132
+ }
133
+ }
134
+
86
135
/**
87
136
* Parses an individual DOM structure for repeated stepKey attributes
88
137
*
0 commit comments