Skip to content

Commit c261905

Browse files
committed
[Unit Test] ActionObject.php
- Brought Code Coverage up to 90% - Deleted some TODOs that didn't make sense
1 parent 7563d0a commit c261905

File tree

1 file changed

+144
-11
lines changed

1 file changed

+144
-11
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Test/Objects/ActionObjectTest.php

Lines changed: 144 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,125 @@ public function testResolveElementInSelector()
6868
}
6969

7070
/**
71-
* {{Section.element(param)}} should be replaced
71+
* {{Section.element(param)}} should replace correctly with 'stringLiterals'
7272
*/
73-
public function testResolveSelectorWithOneParam()
73+
public function testResolveSelectorWithOneStringLiteral()
7474
{
75-
$this->markTestIncomplete('TODO');
75+
$actionObject = new ActionObject('key123', 'fillField', [
76+
'selector' => "{{SectionObject.elementObject('stringliteral')}}",
77+
'userInput' => 'Input'
78+
]);
79+
$elementObject = new ElementObject('elementObject', 'button', '#{{var1}}', null, '42', true);
80+
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
81+
$instance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
82+
->make(); // bypass the private constructor
83+
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $instance]);
84+
85+
// Call the method under test
86+
$actionObject->resolveReferences();
87+
88+
// Verify
89+
$expected = [
90+
'selector' => '#stringliteral',
91+
'userInput' => 'Input'
92+
];
93+
$this->assertEquals($expected, $actionObject->getCustomActionAttributes());
94+
}
95+
96+
/**
97+
* {{Section.element(param)}} should replace correctly with {{data.key}} references
98+
*/
99+
public function testResolveSelectorWithOneDataReference()
100+
{
101+
$actionObject = new ActionObject('key123', 'fillField', [
102+
'selector' => "{{SectionObject.elementObject(dataObject.key)}}",
103+
'userInput' => 'Input'
104+
]);
105+
106+
// Mock SectionHandler
107+
$elementObject = new ElementObject('elementObject', 'button', '#{{var1}}', null, '42', true);
108+
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
109+
$sectionInstance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
110+
->make(); // bypass the private constructor
111+
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $sectionInstance]);
112+
113+
// Mock DataHandler
114+
$dataObject = new EntityDataObject('dataObject', 'dataType', ["key" => 'myValue'], null, null, null);
115+
$dataInstance = AspectMock::double(DataObjectHandler::class, ['getObject' => $dataObject])
116+
->make();
117+
AspectMock::double(DataObjectHandler::class, ['getInstance' => $dataInstance]);
118+
119+
// Call the method under test
120+
$actionObject->resolveReferences();
121+
122+
// Verify
123+
$expected = [
124+
'selector' => '#myValue',
125+
'userInput' => 'Input'
126+
];
127+
$this->assertEquals($expected, $actionObject->getCustomActionAttributes());
128+
}
129+
130+
/**
131+
* {{Section.element(param)}} should replace correctly with $data.key$ references
132+
*/
133+
public function testResolveSelectorWithOnePersistedReference()
134+
{
135+
$actionObject = new ActionObject('key123', 'fillField', [
136+
'selector' => '{{SectionObject.elementObject($data.key$)}}',
137+
'userInput' => 'Input'
138+
]);
139+
140+
// Mock SectionHandler
141+
$elementObject = new ElementObject('elementObject', 'button', '#{{var1}}', null, '42', true);
142+
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
143+
$sectionInstance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
144+
->make(); // bypass the private constructor
145+
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $sectionInstance]);
146+
147+
// Call the method under test
148+
$actionObject->resolveReferences();
149+
150+
// Verify
151+
$expected = [
152+
'selector' => '#$data.key$',
153+
'userInput' => 'Input'
154+
];
155+
$this->assertEquals($expected, $actionObject->getCustomActionAttributes());
76156
}
77157

78158
/**
79-
* {{Section.element(param1,param2)}} should be replaced
159+
* {{Section.element(param1,param2,param3)}} should replace correctly with all 3 data types.
80160
*/
81161
public function testResolveSelectorWithManyParams()
82162
{
83-
$this->markTestIncomplete('TODO');
163+
$actionObject = new ActionObject('key123', 'fillField', [
164+
'selector' => "{{SectionObject.elementObject('stringLiteral', data.key, \$data.key\$)}}",
165+
'userInput' => 'Input'
166+
]);
167+
168+
// Mock SectionHandler
169+
$elementObject = new ElementObject('elementObject', 'button', '#{{var1}}[{{var2}}, {{var3}}]', null, '42', true);
170+
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
171+
$sectionInstance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
172+
->make(); // bypass the private constructor
173+
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $sectionInstance]);
174+
175+
// Mock DataHandler
176+
$dataObject = new EntityDataObject('dataObject', 'dataType', ["key" => 'myValue'], null, null, null);
177+
$dataInstance = AspectMock::double(DataObjectHandler::class, ['getObject' => $dataObject])
178+
->make();
179+
AspectMock::double(DataObjectHandler::class, ['getInstance' => $dataInstance]);
180+
181+
// Call the method under test
182+
$actionObject->resolveReferences();
183+
184+
// Verify
185+
$expected = [
186+
'selector' => '#stringLiteral[myValue, $data.key$]',
187+
'userInput' => 'Input'
188+
];
189+
$this->assertEquals($expected, $actionObject->getCustomActionAttributes());
84190
}
85191

86192
/**
@@ -173,19 +279,46 @@ public function testResolveDataInUserInput()
173279
$this->assertEquals($expected, $actionObject->getCustomActionAttributes());
174280
}
175281

282+
176283
/**
177-
* $testScopeData$ (single dollar sign) should be replaced
284+
* Action object should throw an exception if a reference to a parameterized selector has too few given args.
178285
*/
179-
public function testTestScopeDataResolution()
286+
public function testTooFewArgumentException()
180287
{
181-
$this->markTestIncomplete('TODO');
288+
$this->expectException('Magento\FunctionalTestingFramework\Exceptions\TestReferenceException');
289+
290+
$actionObject = new ActionObject('key123', 'fillField', [
291+
'selector' => "{{SectionObject.elementObject('arg1')}}",
292+
'userInput' => 'Input'
293+
]);
294+
$elementObject = new ElementObject('elementObject', 'button', '#{{var1}} {{var2}}', null, '42', true);
295+
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
296+
$instance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
297+
->make(); // bypass the private constructor
298+
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $instance]);
299+
300+
// Call the method under test
301+
$actionObject->resolveReferences();
182302
}
183303

184304
/**
185-
* $$cestScopeData$$ (double dollar sign) should be replaced
305+
* Action object should throw an exception if a reference to a parameterized selector has too many given args.
186306
*/
187-
public function testCestScopeDataResolution()
307+
public function testTooManyArgumentException()
188308
{
189-
$this->markTestIncomplete('TODO');
309+
$this->expectException('Magento\FunctionalTestingFramework\Exceptions\TestReferenceException');
310+
311+
$actionObject = new ActionObject('key123', 'fillField', [
312+
'selector' => "{{SectionObject.elementObject('arg1', 'arg2', 'arg3')}}",
313+
'userInput' => 'Input'
314+
]);
315+
$elementObject = new ElementObject('elementObject', 'button', '#{{var1}}', null, '42', true);
316+
$sectionObject = new SectionObject('SectionObject', ['elementObject' => $elementObject]);
317+
$instance = AspectMock::double(SectionObjectHandler::class, ['getObject' => $sectionObject])
318+
->make(); // bypass the private constructor
319+
AspectMock::double(SectionObjectHandler::class, ['getInstance' => $instance]);
320+
321+
// Call the method under test
322+
$actionObject->resolveReferences();
190323
}
191324
}

0 commit comments

Comments
 (0)