Skip to content

Commit 99cf549

Browse files
Mohit.k.SharmaManjusha.S
authored andcommitted
MQE-3543 | Color code manipulation for chrome update
1 parent 92bbb4d commit 99cf549

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

app/code/Magento/Swatches/Test/Mftf/ActionGroup/AssertSwatchColorActionGroup.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
</arguments>
1919

2020
<grabAttributeFrom selector="{{AdminManageSwatchSection.nthSwatch(nthSwatch)}}" userInput="style" stepKey="grabStyle1"/>
21+
<helper class="Magento\Swatches\Test\Mftf\Helper\ColorCode" method="colorCode" stepKey="colorCode">
22+
<argument name="colorCode">{$grabStyle1}</argument>
23+
</helper>
2124
<assertEquals stepKey="assertStyle1">
22-
<actualResult type="string">{$grabStyle1}</actualResult>
25+
<actualResult type="string">{$colorCode}</actualResult>
2326
<expectedResult type="string">{{expectedStyle}}</expectedResult>
2427
</assertEquals>
2528
</actionGroup>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Magento\Swatches\Test\Mftf\Helper;
4+
5+
use Magento\FunctionalTestingFramework\Helper\Helper;
6+
7+
/**
8+
* Class ColorCode provides an ability to color code manipulation.
9+
*/
10+
class ColorCode extends Helper
11+
{
12+
/**
13+
* Color code check.
14+
*
15+
* @param string $colorCode
16+
* @return string
17+
*/
18+
public function colorCode(string $colorCode): string
19+
{
20+
$colorCode = str_replace('background: #', '', $colorCode);
21+
if (!preg_match('/^[a-f0-9]{6}$/i', $colorCode) ) {
22+
return $colorCode;
23+
}
24+
25+
$length = strlen($colorCode);
26+
$rgbColorCode['r'] = hexdec($length == 6 ? substr($colorCode, 0, 2) : ($length == 3 ? str_repeat(substr($colorCode, 0, 1), 2) : 0));
27+
$rgbColorCode['g'] = hexdec($length == 6 ? substr($colorCode, 2, 2) : ($length == 3 ? str_repeat(substr($colorCode, 1, 1), 2) : 0));
28+
$rgbColorCode['b'] = hexdec($length == 6 ? substr($colorCode, 4, 2) : ($length == 3 ? str_repeat(substr($colorCode, 2, 1), 2) : 0));
29+
30+
return 'background: rgb('.implode(', ', $rgbColorCode).');';
31+
}
32+
}

0 commit comments

Comments
 (0)