Skip to content

Commit 8483e94

Browse files
committed
Add alt text to saved payment method for accessibility
Fixes #21089
1 parent 88d0413 commit 8483e94

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

app/code/Magento/Payment/Model/CcConfigProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getIcons()
6969
}
7070

7171
$types = $this->ccConfig->getCcAvailableTypes();
72-
foreach (array_keys($types) as $code) {
72+
foreach ($types as $code => $label) {
7373
if (!array_key_exists($code, $this->icons)) {
7474
$asset = $this->ccConfig->createAsset('Magento_Payment::images/cc/' . strtolower($code) . '.png');
7575
$placeholder = $this->assetSource->findSource($asset);
@@ -78,7 +78,8 @@ public function getIcons()
7878
$this->icons[$code] = [
7979
'url' => $asset->getUrl(),
8080
'width' => $width,
81-
'height' => $height
81+
'height' => $height,
82+
'title' => __($label),
8283
];
8384
}
8485
}

app/code/Magento/Payment/Test/Unit/Model/CcConfigProviderTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ public function testGetConfig()
4242
'vi' => [
4343
'url' => 'http://cc.card/vi.png',
4444
'width' => getimagesize($imagesDirectoryPath . 'vi.png')[0],
45-
'height' => getimagesize($imagesDirectoryPath . 'vi.png')[1]
45+
'height' => getimagesize($imagesDirectoryPath . 'vi.png')[1],
46+
'title' => __('Visa'),
4647
],
4748
'ae' => [
4849
'url' => 'http://cc.card/ae.png',
4950
'width' => getimagesize($imagesDirectoryPath . 'ae.png')[0],
50-
'height' => getimagesize($imagesDirectoryPath . 'ae.png')[1]
51+
'height' => getimagesize($imagesDirectoryPath . 'ae.png')[1],
52+
'title' => __('American Express'),
5153
]
5254
]
5355
]
@@ -56,19 +58,25 @@ public function testGetConfig()
5658

5759
$ccAvailableTypesMock = [
5860
'vi' => [
61+
'title' => 'Visa',
5962
'fileId' => 'Magento_Payment::images/cc/vi.png',
6063
'path' => $imagesDirectoryPath . 'vi.png',
6164
'url' => 'http://cc.card/vi.png'
6265
],
6366
'ae' => [
67+
'title' => 'American Express',
6468
'fileId' => 'Magento_Payment::images/cc/ae.png',
6569
'path' => $imagesDirectoryPath . 'ae.png',
6670
'url' => 'http://cc.card/ae.png'
6771
]
6872
];
6973
$assetMock = $this->createMock(\Magento\Framework\View\Asset\File::class);
7074

71-
$this->ccConfigMock->expects($this->once())->method('getCcAvailableTypes')->willReturn($ccAvailableTypesMock);
75+
$this->ccConfigMock->expects($this->once())->method('getCcAvailableTypes')
76+
->willReturn(array_combine(
77+
array_keys($ccAvailableTypesMock),
78+
array_column($ccAvailableTypesMock, 'title')
79+
));
7280

7381
$this->ccConfigMock->expects($this->atLeastOnce())
7482
->method('createAsset')

app/code/Magento/Vault/view/frontend/web/template/payment/form.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
<img data-bind="attr: {
2020
'src': getIcons(getCardType()).url,
2121
'width': getIcons(getCardType()).width,
22-
'height': getIcons(getCardType()).height
22+
'height': getIcons(getCardType()).height,
23+
'alt': getIcons(getCardType()).title
2324
}" class="payment-icon">
2425
<span translate="'ending'"></span>
2526
<span text="getMaskedCard()"></span>

0 commit comments

Comments
 (0)