Skip to content

Commit 214a5df

Browse files
committed
ACP2E-3324: added unit test
1 parent e8c140a commit 214a5df

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Unit\Plugin\Data;
9+
10+
use PHPUnit\Framework\MockObject\Exception;
11+
use PHPUnit\Framework\MockObject\MockObject;
12+
use PHPUnit\Framework\TestCase;
13+
use Magento\Theme\Plugin\DesignProcessorFacade;
14+
use Magento\Config\Console\Command\ConfigSet\ProcessorFacade;
15+
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Theme\Model\Data\Design\ConfigFactory;
17+
use Magento\Theme\Model\Design\Config\Validator;
18+
use Magento\Theme\Api\Data\DesignConfigInterface;
19+
20+
class DesignProcessorFacadeTest extends TestCase
21+
{
22+
/**
23+
* @var Validator|MockObject
24+
*/
25+
private $validator;
26+
27+
/**
28+
* @var ConfigFactory|MockObject
29+
*/
30+
private $configFactory;
31+
32+
/**
33+
* @var DesignProcessorFacade
34+
*/
35+
private $designProcessorFacade;
36+
37+
protected function setUp(): void
38+
{
39+
$this->validator = $this->createMock(Validator::class);
40+
$this->configFactory = $this->createMock(ConfigFactory::class);
41+
42+
$this->designProcessorFacade = new DesignProcessorFacade(
43+
$this->validator,
44+
$this->configFactory
45+
);
46+
}
47+
48+
/**
49+
* @return void
50+
* @throws Exception
51+
* @throws LocalizedException
52+
*/
53+
public function testBeforeProcessWithLockTargetValidDesignPath()
54+
{
55+
$processorFacade = $this->createMock(ProcessorFacade::class);
56+
$path = 'design/theme/custom';
57+
$value = 'custom_value';
58+
$scope = 'default';
59+
$scopeCode = null;
60+
$lock = false;
61+
$lockTarget = 'app_env';
62+
63+
$designConfig = $this->createMock(DesignConfigInterface::class);
64+
$this->configFactory->expects($this->once())
65+
->method('create')
66+
->with($scope, $scopeCode, ['theme_custom' => $value])
67+
->willReturn($designConfig);
68+
69+
$this->validator->expects($this->once())
70+
->method('validate')
71+
->with($designConfig);
72+
73+
$result = $this->designProcessorFacade->beforeProcessWithLockTarget(
74+
$processorFacade,
75+
$path,
76+
$value,
77+
$scope,
78+
$scopeCode,
79+
$lock,
80+
$lockTarget
81+
);
82+
83+
$this->assertEquals([$path, $value, $scope, $scopeCode, $lock, $lockTarget], $result);
84+
}
85+
86+
/**
87+
* @return void
88+
* @throws LocalizedException
89+
* @throws Exception
90+
*/
91+
public function testBeforeProcessWithLockTargetNonDesignPath()
92+
{
93+
$processorFacade = $this->createMock(ProcessorFacade::class);
94+
$path = 'non_design/path';
95+
$value = 'value';
96+
$scope = 'default';
97+
$scopeCode = null;
98+
$lock = false;
99+
$lockTarget = 'app_env';
100+
101+
$this->configFactory->expects($this->never())
102+
->method('create');
103+
104+
$this->validator->expects($this->never())
105+
->method('validate');
106+
107+
$result = $this->designProcessorFacade->beforeProcessWithLockTarget(
108+
$processorFacade,
109+
$path,
110+
$value,
111+
$scope,
112+
$scopeCode,
113+
$lock,
114+
$lockTarget
115+
);
116+
117+
$this->assertEquals([$path, $value, $scope, $scopeCode, $lock, $lockTarget], $result);
118+
}
119+
120+
/**
121+
* @return void
122+
* @throws LocalizedException
123+
* @throws Exception
124+
*/
125+
public function testBeforeProcessWithLockTargetThrowsException()
126+
{
127+
$this->expectException(LocalizedException::class);
128+
129+
$processorFacade = $this->createMock(ProcessorFacade::class);
130+
$path = 'design/theme/custom';
131+
$value = 'custom_value';
132+
$scope = 'default';
133+
$scopeCode = null;
134+
$lock = false;
135+
$lockTarget = 'app_env';
136+
137+
$designConfig = $this->createMock(DesignConfigInterface::class);
138+
$this->configFactory->expects($this->once())
139+
->method('create')
140+
->with($scope, $scopeCode, ['theme_custom' => $value])
141+
->willReturn($designConfig);
142+
143+
$this->validator->expects($this->once())
144+
->method('validate')
145+
->with($designConfig)
146+
->willThrowException(new LocalizedException(__('Validation error')));
147+
148+
$this->designProcessorFacade->beforeProcessWithLockTarget(
149+
$processorFacade,
150+
$path,
151+
$value,
152+
$scope,
153+
$scopeCode,
154+
$lock,
155+
$lockTarget
156+
);
157+
}
158+
}

0 commit comments

Comments
 (0)