Skip to content

Commit aa3f758

Browse files
committed
Merge remote-tracking branch 'origin/develop' into MQE-1711
2 parents 0f7bd4a + e4499a3 commit aa3f758

39 files changed

+775
-190
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Allure/AllureHelperTest.php

+39-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Tests\unit\Magento\FunctionalTestingFramework\Allure;
77

88
use Magento\FunctionalTestingFramework\Allure\AllureHelper;
9+
use Magento\FunctionalTestingFramework\Allure\Event\AddUniqueAttachmentEvent;
910
use Yandex\Allure\Adapter\Allure;
1011
use Yandex\Allure\Adapter\Event\AddAttachmentEvent;
1112
use Yandex\Allure\Adapter\Event\StepFinishedEvent;
@@ -24,6 +25,7 @@ class AllureHelperTest extends TestCase
2425
public function tearDown()
2526
{
2627
Allure::setDefaultLifecycle();
28+
AspectMock::clean();
2729
}
2830

2931
/**
@@ -85,13 +87,48 @@ public function testAddAttachmentToLastStep()
8587
}
8688

8789
/**
88-
* Mock file system manipulation function
90+
* AddAttachment actions should have files with different attachment names
91+
* @throws \Yandex\Allure\Adapter\AllureException
92+
*/
93+
public function testAddAttachementUniqueName()
94+
{
95+
$this->mockCopyFile();
96+
$expectedData = "string";
97+
$expectedCaption = "caption";
98+
99+
//Prepare Allure lifecycle
100+
Allure::lifecycle()->fire(new StepStartedEvent('firstStep'));
101+
102+
//Call function twice
103+
AllureHelper::addAttachmentToCurrentStep($expectedData, $expectedCaption);
104+
AllureHelper::addAttachmentToCurrentStep($expectedData, $expectedCaption);
105+
106+
// Assert file names for both attachments are not the same.
107+
$step = Allure::lifecycle()->getStepStorage()->pollLast();
108+
$attachmentOne = $step->getAttachments()[0]->getSource();
109+
$attachmentTwo = $step->getAttachments()[1]->getSource();
110+
$this->assertNotEquals($attachmentOne, $attachmentTwo);
111+
}
112+
113+
/**
114+
* Mock entire attachment writing mechanisms
89115
* @throws \Exception
90116
*/
91117
public function mockAttachmentWriteEvent()
92118
{
93-
AspectMock::double(AddAttachmentEvent::class, [
119+
AspectMock::double(AddUniqueAttachmentEvent::class, [
94120
"getAttachmentFileName" => self::MOCK_FILENAME
95121
]);
96122
}
123+
124+
/**
125+
* Mock only file writing mechanism
126+
* @throws \Exception
127+
*/
128+
public function mockCopyFile()
129+
{
130+
AspectMock::double(AddUniqueAttachmentEvent::class, [
131+
"copyFile" => true
132+
]);
133+
}
97134
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Tests\unit\Magento\FunctionalTestFramework\Util\Path;
7+
8+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
9+
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
10+
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
11+
12+
class FilePathFormatterTest extends MagentoTestCase
13+
{
14+
/**
15+
* Test file format
16+
*
17+
* @dataProvider formatDataProvider
18+
* @param string $path
19+
* @param boolean $withTrailingSeparator
20+
* @param mixed string|boolean $expectedPath
21+
* @return void
22+
* @throws TestFrameworkException
23+
*/
24+
public function testFormat($path, $withTrailingSeparator, $expectedPath)
25+
{
26+
if (null !== $expectedPath) {
27+
$this->assertEquals($expectedPath, FilePathFormatter::format($path, $withTrailingSeparator));
28+
} else {
29+
// Assert no exception
30+
FilePathFormatter::format($path, $withTrailingSeparator);
31+
$this->assertTrue(true);
32+
}
33+
}
34+
35+
/**
36+
* Test file format with exception
37+
*
38+
* @dataProvider formatExceptionDataProvider
39+
* @param string $path
40+
* @param boolean $withTrailingSeparator
41+
* @return void
42+
* @throws TestFrameworkException
43+
*/
44+
public function testFormatWithException($path, $withTrailingSeparator)
45+
{
46+
$this->expectException(TestFrameworkException::class);
47+
$this->expectExceptionMessage("Invalid or non-existing file: $path\n");
48+
FilePathFormatter::format($path, $withTrailingSeparator);
49+
}
50+
51+
/**
52+
* Data input
53+
*
54+
* @return array
55+
*/
56+
public function formatDataProvider()
57+
{
58+
$path1 = rtrim(TESTS_BP, '/');
59+
$path2 = $path1 . DIRECTORY_SEPARATOR;
60+
return [
61+
[$path1, null, $path1],
62+
[$path1, false, $path1],
63+
[$path1, true, $path2],
64+
[$path2, null, $path1],
65+
[$path2, false, $path1],
66+
[$path2, true, $path2],
67+
[__DIR__. DIRECTORY_SEPARATOR . basename(__FILE__), null, __FILE__],
68+
['', null, null] // Empty string is valid
69+
];
70+
}
71+
72+
/**
73+
* Invalid data input
74+
*
75+
* @return array
76+
*/
77+
public function formatExceptionDataProvider()
78+
{
79+
return [
80+
['abc', null],
81+
['X://some\dir/@', null],
82+
];
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Tests\unit\Magento\FunctionalTestFramework\Util\Path;
7+
8+
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
9+
use Magento\FunctionalTestingFramework\Util\Path\UrlFormatter;
10+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
11+
12+
class UrlFormatterTest extends MagentoTestCase
13+
{
14+
/**
15+
* Test url format
16+
*
17+
* @dataProvider formatDataProvider
18+
* @param string $path
19+
* @param boolean $withTrailingSeparator
20+
* @param mixed string|boolean $expectedPath
21+
* @return void
22+
* @throws TestFrameworkException
23+
*/
24+
public function testFormat($path, $withTrailingSeparator, $expectedPath)
25+
{
26+
$this->assertEquals($expectedPath, UrlFormatter::format($path, $withTrailingSeparator));
27+
}
28+
29+
/**
30+
* Test url format with exception
31+
*
32+
* @dataProvider formatExceptionDataProvider
33+
* @param string $path
34+
* @param boolean $withTrailingSeparator
35+
* @return void
36+
* @throws TestFrameworkException
37+
*/
38+
public function testFormatWithException($path, $withTrailingSeparator)
39+
{
40+
$this->expectException(TestFrameworkException::class);
41+
$this->expectExceptionMessage("Invalid url: $path\n");
42+
UrlFormatter::format($path, $withTrailingSeparator);
43+
}
44+
45+
/**
46+
* Data input
47+
*
48+
* @return array
49+
*/
50+
public function formatDataProvider()
51+
{
52+
$url1 = 'http://magento.local/index.php';
53+
$url2 = $url1 . '/';
54+
$url3 = 'https://www.example.com/index.php/admin';
55+
$url4 = $url3 . '/';
56+
$url5 = 'www.google.com';
57+
$url6 = 'http://www.google.com/';
58+
$url7 = 'http://127.0.0.1:8200';
59+
$url8 = 'wwøw.goåoøgle.coøm';
60+
$url9 = 'http://www.google.com';
61+
return [
62+
[$url1, null, $url1],
63+
[$url1, false, $url1],
64+
[$url1, true, $url2],
65+
[$url2, null, $url1],
66+
[$url2, false, $url1],
67+
[$url2, true, $url2],
68+
[$url3, null, $url3],
69+
[$url3, false, $url3],
70+
[$url3, true, $url4],
71+
[$url4, null, $url3],
72+
[$url4, false, $url3],
73+
[$url4, true, $url4],
74+
[$url5, true, $url6],
75+
[$url7, false, $url7],
76+
[$url8, false, $url9],
77+
];
78+
}
79+
80+
/**
81+
* Invalid data input
82+
*
83+
* @return array
84+
*/
85+
public function formatExceptionDataProvider()
86+
{
87+
return [
88+
['', null],
89+
];
90+
}
91+
}

dev/tests/verification/Resources/PersistenceCustomFieldsTest.txt

+31
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,36 @@ class PersistenceCustomFieldsTestCest
111111
);
112112

113113
$I->comment("Exiting Action Group [createdAG] PersistenceActionGroup");
114+
$I->comment("Entering Action Group [AGKEY] DataPersistenceSelfReferenceActionGroup");
115+
$I->comment("[createData1AGKEY] create 'entity1' entity");
116+
PersistedObjectHandler::getInstance()->createEntity(
117+
"createData1AGKEY",
118+
"test",
119+
"entity1",
120+
[],
121+
[]
122+
);
123+
124+
$I->comment("[createData2AGKEY] create 'entity2' entity");
125+
PersistedObjectHandler::getInstance()->createEntity(
126+
"createData2AGKEY",
127+
"test",
128+
"entity2",
129+
[],
130+
[]
131+
);
132+
133+
$createData3AGKEYFields['key1'] = PersistedObjectHandler::getInstance()->retrieveEntityField('createData1AGKEY', 'field', 'test');
134+
$createData3AGKEYFields['key2'] = PersistedObjectHandler::getInstance()->retrieveEntityField('createData2AGKEY', 'field', 'test');
135+
$I->comment("[createData3AGKEY] create 'entity3' entity");
136+
PersistedObjectHandler::getInstance()->createEntity(
137+
"createData3AGKEY",
138+
"test",
139+
"entity3",
140+
[],
141+
$createData3AGKEYFields
142+
);
143+
144+
$I->comment("Exiting Action Group [AGKEY] DataPersistenceSelfReferenceActionGroup");
114145
}
115146
}

dev/tests/verification/TestModule/ActionGroup/PersistenceActionGroup.xml

+8
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@
3030
<getData entity="someEneity" stepKey="getData"/>
3131
<comment userInput="$createData.field$" stepKey="comment"/>
3232
</actionGroup>
33+
<actionGroup name="DataPersistenceSelfReferenceActionGroup">
34+
<createData entity="entity1" stepKey="createData1"/>
35+
<createData entity="entity2" stepKey="createData2"/>
36+
<createData entity="entity3" stepKey="createData3">
37+
<field key="key1">$createData1.field$</field>
38+
<field key="key2">$createData2.field$</field>
39+
</createData>
40+
</actionGroup>
3341
</actionGroups>

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

+1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@
3333
<argument name="arg2" value="DefaultPerson.firstname"/>
3434
<argument name="arg3" value="$createdData3.firstname$"/>
3535
</actionGroup>
36+
<actionGroup ref="DataPersistenceSelfReferenceActionGroup" stepKey="AGKEY"/>
3637
</test>
3738
</tests>

dev/tests/verification/Tests/SuiteGenerationTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
namespace tests\verification\Tests;
88

9+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
910
use Magento\FunctionalTestingFramework\Suite\SuiteGenerator;
1011
use Magento\FunctionalTestingFramework\Util\Filesystem\DirSetupUtil;
1112
use Magento\FunctionalTestingFramework\Util\Manifest\DefaultTestManifest;
1213
use Magento\FunctionalTestingFramework\Util\Manifest\ParallelTestManifest;
1314
use Magento\FunctionalTestingFramework\Util\Manifest\TestManifestFactory;
15+
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
1416
use PHPUnit\Util\Filesystem;
1517
use Symfony\Component\Yaml\Yaml;
1618
use tests\unit\Util\TestLoggingUtil;
@@ -413,11 +415,11 @@ public static function tearDownAfterClass()
413415
* Getter for manifest file path
414416
*
415417
* @return string
418+
* @throws TestFrameworkException
416419
*/
417420
private static function getManifestFilePath()
418421
{
419-
return TESTS_BP .
420-
DIRECTORY_SEPARATOR .
422+
return FilePathFormatter::format(TESTS_BP) .
421423
"verification" .
422424
DIRECTORY_SEPARATOR .
423425
"_generated" .

src/Magento/FunctionalTestingFramework/Allure/AllureHelper.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\FunctionalTestingFramework\Allure;
77

8+
use Magento\FunctionalTestingFramework\Allure\Event\AddUniqueAttachmentEvent;
89
use Yandex\Allure\Adapter\Allure;
910
use Yandex\Allure\Adapter\Event\AddAttachmentEvent;
1011

@@ -19,7 +20,7 @@ class AllureHelper
1920
*/
2021
public static function addAttachmentToCurrentStep($data, $caption)
2122
{
22-
Allure::lifecycle()->fire(new AddAttachmentEvent($data, $caption));
23+
Allure::lifecycle()->fire(new AddUniqueAttachmentEvent($data, $caption));
2324
}
2425

2526
/**
@@ -34,7 +35,7 @@ public static function addAttachmentToLastStep($data, $caption)
3435
$rootStep = Allure::lifecycle()->getStepStorage()->getLast();
3536
$trueLastStep = array_last($rootStep->getSteps());
3637

37-
$attachmentEvent = new AddAttachmentEvent($data, $caption);
38+
$attachmentEvent = new AddUniqueAttachmentEvent($data, $caption);
3839
$attachmentEvent->process($trueLastStep);
3940
}
4041
}

0 commit comments

Comments
 (0)