Skip to content

Commit 89e789a

Browse files
Fix #567
- fix selector for widget config
1 parent 7fd0116 commit 89e789a

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

app/code/Magento/PageBuilder/Model/WidgetInitializerConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function getConfig(): array
4747
{
4848
$resultConfig = [];
4949
foreach ($this->config as $contentTypeName => $config) {
50-
$selector = sprintf('[data-content-type="%s"]', $contentTypeName);
5150
foreach ($config as $item) {
51+
$selector = sprintf('[data-content-type="%s"]', $contentTypeName);
5252
if (!isset($item['component'])) {
5353
continue;
5454
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\Test\Unit\Model;
9+
10+
use Magento\PageBuilder\Model\WidgetInitializerConfig;
11+
use PHPUnit\Framework\TestCase;
12+
13+
/**
14+
* Test for WidgetInitializerConfig
15+
*/
16+
class WidgetInitializerConfigTest extends TestCase
17+
{
18+
/**
19+
* Test different config variation.
20+
*
21+
* @dataProvider configProvider
22+
* @param array $config
23+
* @param array $expectedConfig
24+
*/
25+
public function testGetConfig(array $config, array $expectedConfig): void
26+
{
27+
$model = new WidgetInitializerConfig(
28+
$config
29+
);
30+
31+
$actualConfig = $model->getConfig();
32+
$this->assertEquals($expectedConfig, $actualConfig);
33+
}
34+
35+
/**
36+
* @return array
37+
*/
38+
public function configProvider(): array
39+
{
40+
return [
41+
[
42+
[
43+
'products' => [
44+
'default' => [
45+
'component' => 'test',
46+
'appearance' => 'default',
47+
'config' => [
48+
'a' => true
49+
]
50+
]
51+
]
52+
],
53+
[
54+
'[data-content-type="products"][data-appearance="default"]' => [
55+
'test' => [
56+
'a' => true
57+
]
58+
]
59+
]
60+
],
61+
[
62+
[
63+
'products' => [
64+
'default' => [
65+
'component' => 'test-component',
66+
'appearance' => 'default',
67+
'config' => [
68+
'a' => true
69+
]
70+
],
71+
'another' => [
72+
'component' => 'another-test-component',
73+
'appearance' => 'not_default',
74+
'config' => [
75+
'b' => false
76+
]
77+
]
78+
]
79+
],
80+
[
81+
'[data-content-type="products"][data-appearance="default"]' => [
82+
'test-component' => [
83+
'a' => true
84+
]
85+
],
86+
'[data-content-type="products"][data-appearance="not_default"]' => [
87+
'another-test-component' => [
88+
'b' => false
89+
]
90+
]
91+
]
92+
]
93+
];
94+
}
95+
}

0 commit comments

Comments
 (0)