Skip to content

Commit 1f780e7

Browse files
authored
Merge branch 'develop' into remove_dead_code_v2
2 parents 58311da + bf2143d commit 1f780e7

File tree

12 files changed

+126
-17
lines changed

12 files changed

+126
-17
lines changed

dev/tests/verification/Resources/SectionReplacementTest.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,7 @@ class SectionReplacementTestCest
6868
$I->click("#stringLiteral1-" . PersistedObjectHandler::getInstance()->retrieveEntityField('createdData', 'firstname', 'test') . " .Doe" . msq("uniqueData"));
6969
$I->click("#element .1#element .2");
7070
$I->click("#element .1#element .{$data}");
71+
$I->click("(//div[@data-role='slide'])[1]/a[@data-element='link'][contains(@href,'')]");
72+
$I->click("(//div[@data-role='slide'])[1]/a[@data-element='link'][contains(@href,' ')]");
7173
}
7274
}

dev/tests/verification/Resources/functionalSuiteHooks.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class functionalSuiteHooks extends \Codeception\GroupObject
3030

3131
if ($this->preconditionFailure != null) {
3232
//if our preconditions fail, we need to mark all the tests as incomplete.
33-
$e->getTest()->getMetadata()->setIncomplete($this->preconditionFailure);
33+
$e->getTest()->getMetadata()->setIncomplete("SUITE PRECONDITION FAILED:" . PHP_EOL . $this->preconditionFailure);
3434
}
3535
}
3636

dev/tests/verification/TestModule/Section/SampleSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
<element name="threeOneDuplicateParamElement" type="button" selector="#{{var1}}-{{var2}} .{{var1}} [{{var3}}]" parameterized="true"/>
1919
<element name="timeoutElement" type="button" selector="#foo" timeout="30"/>
2020
<element name="mergeElement" type="button" selector="#unMerge"/>
21+
<element name="anotherTwoParamsElement" type="button" selector="(//div[@data-role='slide'])[{{arg1}}]/a[@data-element='link'][contains(@href,'{{arg2}}')]" parameterized="true"/>
2122
</section>
2223
</sections>

dev/tests/verification/TestModule/Test/SectionReplacementTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@
5050

5151
<click stepKey="selectorReplaceTwoParamElements" selector="{{SampleSection.oneParamElement('1')}}{{SampleSection.oneParamElement('2')}}"/>
5252
<click stepKey="selectorReplaceTwoParamMixedTypes" selector="{{SampleSection.oneParamElement('1')}}{{SampleSection.oneParamElement({$data})}}"/>
53+
54+
<click stepKey="selectorParamWithEmptyString" selector="{{SampleSection.anotherTwoParamsElement('1', '')}}"/>
55+
<click stepKey="selectorParamWithASpace" selector="{{SampleSection.anotherTwoParamsElement('1', ' ')}}"/>
5356
</test>
5457
</tests>

etc/config/codeception.dist.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ settings:
1212
memory_limit: 1024M
1313
extensions:
1414
enabled:
15-
- Codeception\Extension\RunFailed
1615
- Magento\FunctionalTestingFramework\Extension\TestContextExtension
1716
- Magento\FunctionalTestingFramework\Allure\Adapter\MagentoAllureAdapter
1817
config:

src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Yandex\Allure\Adapter\Event\StepStartedEvent;
1111
use Yandex\Allure\Adapter\Event\StepFinishedEvent;
1212
use Yandex\Allure\Adapter\Event\StepFailedEvent;
13+
use Yandex\Allure\Adapter\Event\TestCaseFailedEvent;
14+
use Codeception\Event\FailEvent;
1315
use Codeception\Event\SuiteEvent;
1416
use Codeception\Event\StepEvent;
1517

@@ -132,4 +134,18 @@ public function stepAfter(StepEvent $stepEvent = null)
132134
}
133135
$this->getLifecycle()->fire(new StepFinishedEvent());
134136
}
137+
138+
/**
139+
* Override of parent method, fires a TestCaseFailedEvent if a test is marked as incomplete.
140+
*
141+
* @param FailEvent $failEvent
142+
* @return void
143+
*/
144+
public function testIncomplete(FailEvent $failEvent)
145+
{
146+
$event = new TestCaseFailedEvent();
147+
$e = $failEvent->getFail();
148+
$message = $e->getMessage();
149+
$this->getLifecycle()->fire($event->withException($e)->withMessage($message));
150+
}
135151
}

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,33 @@ private function resolveUrlReference($urlIn, $entityObjects)
197197
{
198198
$urlOut = $urlIn;
199199
$matchedParams = [];
200+
// Find all the params ({}) references
200201
preg_match_all("/[{](.+?)[}]/", $urlIn, $matchedParams);
201202

202203
if (!empty($matchedParams)) {
203204
foreach ($matchedParams[0] as $paramKey => $paramValue) {
205+
$paramEntityParent = "";
206+
$matchedParent = [];
207+
$dataItem = $matchedParams[1][$paramKey];
208+
// Find all the parent property (Type.key) references, assuming there will be only one
209+
// parent property reference within one param
210+
preg_match_all("/(.+?)\./", $dataItem, $matchedParent);
211+
212+
if (!empty($matchedParent) && !empty($matchedParent[0])) {
213+
$paramEntityParent = $matchedParent[1][0];
214+
$dataItem = preg_replace('/^'.$matchedParent[0][0].'/', '', $dataItem);
215+
}
216+
204217
foreach ($entityObjects as $entityObject) {
205-
$param = $entityObject->getDataByName(
206-
$matchedParams[1][$paramKey],
207-
EntityDataObject::CEST_UNIQUE_VALUE
208-
);
218+
$param = null;
219+
220+
if ($paramEntityParent === "" || $entityObject->getType() == $paramEntityParent) {
221+
$param = $entityObject->getDataByName(
222+
$dataItem,
223+
EntityDataObject::CEST_UNIQUE_VALUE
224+
);
225+
}
226+
209227
if (null !== $param) {
210228
$urlOut = str_replace($paramValue, $param, $urlOut);
211229
continue;

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/OperationDataArrayResolver.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function __construct($dependentEntities = null)
6666
* @return array
6767
* @throws \Exception
6868
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
69+
* @SuppressWarnings(PHPMD.NPathComplexity)
70+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
6971
*/
7072
public function resolveOperationDataArray($entityObject, $operationMetadata, $operation, $fromArray = false)
7173
{
@@ -134,6 +136,13 @@ public function resolveOperationDataArray($entityObject, $operationMetadata, $op
134136
));
135137
}
136138
} else {
139+
$operationElementProperty = null;
140+
if (strpos($operationElementType, '.') !== false) {
141+
$operationElementComponents = explode('.', $operationElementType);
142+
$operationElementType = $operationElementComponents[0];
143+
$operationElementProperty = $operationElementComponents[1];
144+
}
145+
137146
$entityNamesOfType = $entityObject->getLinkedEntitiesOfType($operationElementType);
138147

139148
// If an element is required by metadata, but was not provided in the entity, throw an exception
@@ -146,12 +155,23 @@ public function resolveOperationDataArray($entityObject, $operationMetadata, $op
146155
));
147156
}
148157
foreach ($entityNamesOfType as $entityName) {
149-
$operationDataSubArray = $this->resolveNonPrimitiveElement(
150-
$entityName,
151-
$operationElement,
152-
$operation,
153-
$fromArray
154-
);
158+
if ($operationElementProperty === null) {
159+
$operationDataSubArray = $this->resolveNonPrimitiveElement(
160+
$entityName,
161+
$operationElement,
162+
$operation,
163+
$fromArray
164+
);
165+
} else {
166+
$linkedEntityObj = $this->resolveLinkedEntityObject($entityName);
167+
$operationDataSubArray = $linkedEntityObj->getDataByName($operationElementProperty, 0);
168+
169+
if ($operationDataSubArray === null) {
170+
throw new \Exception(
171+
sprintf('Property %s not found in entity %s \n', $operationElementProperty, $entityName)
172+
);
173+
}
174+
}
155175

156176
if ($operationElement->getType() == OperationDefinitionObjectHandler::ENTITY_OPERATION_ARRAY) {
157177
$operationDataArray[$operationElement->getKey()][] = $operationDataSubArray;

src/Magento/FunctionalTestingFramework/Extension/TestContextExtension.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
class TestContextExtension extends BaseExtension
1717
{
1818
const TEST_PHASE_AFTER = "_after";
19+
const TEST_FAILED_FILE = 'failed';
1920

2021
/**
2122
* Codeception Events Mapping to methods
@@ -35,7 +36,8 @@ public function _initialize()
3536
Events::TEST_START => 'testStart',
3637
Events::TEST_FAIL => 'testFail',
3738
Events::STEP_AFTER => 'afterStep',
38-
Events::TEST_END => 'testEnd'
39+
Events::TEST_END => 'testEnd',
40+
Events::RESULT_PRINT_AFTER => 'saveFailed'
3941
];
4042
self::$events = array_merge(parent::$events, $events);
4143
parent::_initialize();
@@ -170,4 +172,52 @@ public function afterStep(\Codeception\Event\StepEvent $e)
170172
{
171173
ErrorLogger::getInstance()->logErrors($this->getDriver(), $e);
172174
}
175+
176+
/**
177+
* Saves failed tests from last codecept run command into a file in _output directory
178+
* Removes file if there were no failures in last run command
179+
* @param \Codeception\Event\PrintResultEvent $e
180+
* @return void
181+
*/
182+
public function saveFailed(\Codeception\Event\PrintResultEvent $e)
183+
{
184+
$file = $this->getLogDir() . self::TEST_FAILED_FILE;
185+
$result = $e->getResult();
186+
$output = [];
187+
188+
// Remove previous file regardless if we're writing a new file
189+
if (is_file($file)) {
190+
unlink($file);
191+
}
192+
193+
foreach ($result->failures() as $fail) {
194+
$output[] = $this->localizePath(\Codeception\Test\Descriptor::getTestFullName($fail->failedTest()));
195+
}
196+
foreach ($result->errors() as $fail) {
197+
$output[] = $this->localizePath(\Codeception\Test\Descriptor::getTestFullName($fail->failedTest()));
198+
}
199+
foreach ($result->notImplemented() as $fail) {
200+
$output[] = $this->localizePath(\Codeception\Test\Descriptor::getTestFullName($fail->failedTest()));
201+
}
202+
203+
if (empty($output)) {
204+
return;
205+
}
206+
207+
file_put_contents($file, implode("\n", $output));
208+
}
209+
210+
/**
211+
* Returns localized path to string, for writing failed file.
212+
* @param string $path
213+
* @return string
214+
*/
215+
protected function localizePath($path)
216+
{
217+
$root = realpath($this->getRootDir()) . DIRECTORY_SEPARATOR;
218+
if (substr($path, 0, strlen($root)) == $root) {
219+
return substr($path, strlen($root));
220+
}
221+
return $path;
222+
}
173223
}

src/Magento/FunctionalTestingFramework/Suite/views/SuiteClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class {{suiteName}} extends \Codeception\GroupObject
3131
3232
if ($this->preconditionFailure != null) {
3333
//if our preconditions fail, we need to mark all the tests as incomplete.
34-
$e->getTest()->getMetadata()->setIncomplete($this->preconditionFailure);
34+
$e->getTest()->getMetadata()->setIncomplete("SUITE PRECONDITION FAILED:" . PHP_EOL . $this->preconditionFailure);
3535
}
3636
}
3737

src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ private function matchParameterReferences($reference, $parameters)
691691
$resolvedParameters = [];
692692
foreach ($parameters as $parameter) {
693693
$parameter = trim($parameter);
694-
preg_match_all("/[$'][\w\D]+[$']/", $parameter, $stringOrPersistedMatch);
694+
preg_match_all("/[$'][\w\D]*[$']/", $parameter, $stringOrPersistedMatch);
695695
preg_match_all('/{\$[a-z][a-zA-Z\d]+}/', $parameter, $variableMatch);
696696
if (!empty($stringOrPersistedMatch[0])) {
697697
$resolvedParameters[] = ltrim(rtrim($parameter, "'"), "'");

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ private function globRelevantPaths($testPath, $pattern)
276276
// Symlinks must be resolved otherwise they will not match Magento's filepath to the module
277277
$potentialSymlink = str_replace(DIRECTORY_SEPARATOR . $pattern, "", $codePath);
278278
if (is_link($potentialSymlink)) {
279-
$codePath = readlink($potentialSymlink) . DIRECTORY_SEPARATOR . $pattern;
279+
$codePath = realpath($potentialSymlink) . DIRECTORY_SEPARATOR . $pattern;
280280
}
281281

282282
$mainModName = array_search($codePath, $allComponents) ?: basename(str_replace($pattern, '', $codePath));
@@ -554,8 +554,8 @@ private function getRegisteredModuleList()
554554
}
555555
array_walk($allComponents, function (&$value) {
556556
// Magento stores component paths with unix DIRECTORY_SEPARATOR, need to stay uniform and convert
557-
$value .= '/Test/Mftf';
558557
$value = realpath($value);
558+
$value .= '/Test/Mftf';
559559
});
560560
return $allComponents;
561561
} catch (TestFrameworkException $e) {

0 commit comments

Comments
 (0)