Skip to content

Commit e7ffb9e

Browse files
AC-6897 Template improvements
1 parent 03d4aa5 commit e7ffb9e

File tree

5 files changed

+112
-32
lines changed

5 files changed

+112
-32
lines changed

app/code/Magento/Catalog/Test/Unit/Pricing/Render/FinalPriceBoxTest.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Framework\App\State;
2020
use Magento\Framework\Config\ConfigOptionsListConstants;
2121
use Magento\Framework\Event\Test\Unit\ManagerStub;
22+
use Magento\Framework\ObjectManagerInterface;
2223
use Magento\Framework\Pricing\Amount\AmountInterface;
2324
use Magento\Framework\Pricing\Price\PriceInterface;
2425
use Magento\Framework\Pricing\PriceInfoInterface;
@@ -98,11 +99,27 @@ class FinalPriceBoxTest extends TestCase
9899
*/
99100
private $minimalPriceCalculator;
100101

102+
/**
103+
* @var DeploymentConfig|MockObject
104+
*/
105+
private $deploymentConfig;
106+
107+
/**
108+
* @var ObjectManagerInterface|MockObject
109+
*/
110+
private $objectManagerMock;
111+
101112
/**
102113
* @inheritDoc
114+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
103115
*/
104116
protected function setUp(): void
105117
{
118+
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
119+
->disableOriginalConstructor()
120+
->onlyMethods(['get'])
121+
->getMockForAbstractClass();
122+
\Magento\Framework\App\ObjectManager::setInstance($this->objectManagerMock);
106123
$this->product = $this->getMockBuilder(Product::class)
107124
->addMethods(['getCanShowPrice'])
108125
->onlyMethods(['getPriceInfo', 'isSalable', 'getId'])
@@ -185,16 +202,11 @@ protected function setUp(): void
185202
->disableOriginalConstructor()
186203
->getMockForAbstractClass();
187204

188-
$deploymentConfig = $this->createPartialMock(
205+
$this->deploymentConfig = $this->createPartialMock(
189206
DeploymentConfig::class,
190207
['get']
191208
);
192209

193-
$deploymentConfig->expects($this->any())
194-
->method('get')
195-
->with(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY)
196-
->willReturn('448198e08af35844a42d3c93c1ef4e03');
197-
198210
$this->minimalPriceCalculator = $this->getMockForAbstractClass(MinimalPriceCalculatorInterface::class);
199211
$this->object = $objectManager->getObject(
200212
FinalPriceBox::class,
@@ -205,8 +217,7 @@ protected function setUp(): void
205217
'price' => $this->price,
206218
'data' => ['zone' => 'test_zone', 'list_category_page' => true],
207219
'salableResolver' => $this->salableResolverMock,
208-
'minimalPriceCalculator' => $this->minimalPriceCalculator,
209-
'deploymentConfig' => $deploymentConfig,
220+
'minimalPriceCalculator' => $this->minimalPriceCalculator
210221
]
211222
);
212223
}
@@ -468,6 +479,15 @@ public function testHidePrice(): void
468479
*/
469480
public function testGetCacheKey(): void
470481
{
482+
$this->objectManagerMock->expects($this->any())
483+
->method('get')
484+
->with(DeploymentConfig::class)
485+
->willReturn($this->deploymentConfig);
486+
487+
$this->deploymentConfig->expects($this->any())
488+
->method('get')
489+
->with(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY)
490+
->willReturn('448198e08af35844a42d3c93c1ef4e03');
471491
$result = $this->object->getCacheKey();
472492
$this->assertStringEndsWith('list-category-page', $result);
473493
}

app/code/Magento/Email/Model/Template/Filter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ class Filter extends Template
6969
/**
7070
* @var bool
7171
* @deprecated SID is not being used as query parameter anymore.
72+
* @see Session ID's in URL
7273
*/
7374
protected $_useSessionInUrl = false;
7475

7576
/**
7677
* @var array
7778
* @deprecated 101.0.4 Use the new Directive Processor interfaces
79+
* @see Directive Processor interfaces
7880
*/
7981
protected $_modifiers = ['nl2br' => ''];
8082

@@ -286,6 +288,7 @@ public function setUseAbsoluteLinks($flag)
286288
* @return $this
287289
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
288290
* @deprecated SID query parameter is not used in URLs anymore.
291+
* @see SessionId's in URL
289292
*/
290293
public function setUseSessionInUrl($flag)
291294
{
@@ -698,6 +701,7 @@ public function varDirective($construction)
698701
* @param string $default assumed modifier if none present
699702
* @return array
700703
* @deprecated 101.0.4 Use the new FilterApplier or Directive Processor interfaces
704+
* @see Directive Processor Interfaces
701705
*/
702706
protected function explodeModifiers($value, $default = null)
703707
{
@@ -717,6 +721,7 @@ protected function explodeModifiers($value, $default = null)
717721
* @param string $modifiers
718722
* @return string
719723
* @deprecated 101.0.4 Use the new FilterApplier or Directive Processor interfaces
724+
* @see Directive Processor Interfaces
720725
*/
721726
protected function applyModifiers($value, $modifiers)
722727
{
@@ -746,6 +751,7 @@ protected function applyModifiers($value, $modifiers)
746751
* @param string $type
747752
* @return string
748753
* @deprecated 101.0.4 Use the new FilterApplier or Directive Processor interfaces
754+
* @see Directive Processor Interfacees
749755
*/
750756
public function modifierEscape($value, $type = 'html')
751757
{

app/code/Magento/Swatches/Test/Unit/Block/Product/Renderer/Listing/ConfigurableTest.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
use Magento\Eav\Api\Data\AttributeInterface;
2222
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
2323
use Magento\Framework\App\Config\ScopeConfigInterface;
24-
use Magento\Framework\App\DeploymentConfig;
2524
use Magento\Framework\App\Request\Http;
2625
use Magento\Framework\App\RequestInterface;
26+
use Magento\Framework\App\DeploymentConfig;
2727
use Magento\Framework\Config\ConfigOptionsListConstants;
2828
use Magento\Framework\Json\EncoderInterface;
2929
use Magento\Framework\Model\AbstractModel;
30+
use Magento\Framework\ObjectManagerInterface;
3031
use Magento\Framework\Pricing\PriceCurrencyInterface;
3132
use Magento\Framework\Pricing\PriceInfo\Base;
3233
use Magento\Framework\Stdlib\ArrayUtils;
@@ -97,8 +98,23 @@ class ConfigurableTest extends TestCase
9798
*/
9899
private $request;
99100

101+
/**
102+
* @var ObjectManagerInterface|MockObject
103+
*/
104+
private $objectManagerMock;
105+
106+
/**
107+
* @var DeploymentConfig|MockObject
108+
*/
109+
private $deploymentConfig;
110+
100111
protected function setUp(): void
101112
{
113+
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
114+
->disableOriginalConstructor()
115+
->onlyMethods(['get'])
116+
->getMockForAbstractClass();
117+
\Magento\Framework\App\ObjectManager::setInstance($this->objectManagerMock);
102118
$this->arrayUtils = $this->createMock(ArrayUtils::class);
103119
$this->jsonEncoder = $this->getMockForAbstractClass(EncoderInterface::class);
104120
$this->helper = $this->createMock(Data::class);
@@ -129,12 +145,12 @@ protected function setUp(): void
129145
$context = $this->getContextMock();
130146
$context->method('getRequest')->willReturn($this->request);
131147

132-
$deploymentConfig = $this->createPartialMock(
148+
$this->deploymentConfig = $this->createPartialMock(
133149
DeploymentConfig::class,
134150
['get']
135151
);
136152

137-
$deploymentConfig->expects($this->any())
153+
$this->deploymentConfig->expects($this->any())
138154
->method('get')
139155
->with(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY)
140156
->willReturn('448198e08af35844a42d3c93c1ef4e03');
@@ -158,8 +174,7 @@ protected function setUp(): void
158174
'configurableAttributeData' => $this->configurableAttributeData,
159175
'data' => [],
160176
'variationPrices' => $this->variationPricesMock,
161-
'customerSession' => $customerSession,
162-
'deploymentConfig' => $deploymentConfig,
177+
'customerSession' => $customerSession
163178
]
164179
);
165180
}
@@ -321,6 +336,10 @@ public function testGetCacheKey()
321336
->willReturn($configurableAttributes);
322337

323338
$this->request->method('toArray')->willReturn($requestParams);
339+
$this->objectManagerMock->expects($this->any())
340+
->method('get')
341+
->with(DeploymentConfig::class)
342+
->willReturn($this->deploymentConfig);
324343
$this->assertStringContainsString(
325344
sha1(json_encode(['color' => 59, 'size' => 1])),
326345
$this->configurable->getCacheKey()

lib/internal/Magento/Framework/View/Element/AbstractBlock.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ abstract class AbstractBlock extends \Magento\Framework\DataObject implements Bl
5454
/**
5555
* @var \Magento\Framework\Session\SidResolverInterface
5656
* @deprecated 102.0.5 Not used anymore.
57+
* @see Session Id's In URL
5758
*/
5859
protected $_sidResolver;
5960

@@ -184,12 +185,10 @@ abstract class AbstractBlock extends \Magento\Framework\DataObject implements Bl
184185
*
185186
* @param \Magento\Framework\View\Element\Context $context
186187
* @param array $data
187-
* @param DeploymentConfig $deploymentConfig
188188
*/
189189
public function __construct(
190190
\Magento\Framework\View\Element\Context $context,
191-
array $data = [],
192-
DeploymentConfig $deploymentConfig = null
191+
array $data = []
193192
) {
194193
$this->_request = $context->getRequest();
195194
$this->_layout = $context->getLayout();
@@ -210,9 +209,6 @@ public function __construct(
210209
$this->inlineTranslation = $context->getInlineTranslation();
211210
$this->lockQuery = $context->getLockGuardedCacheLoader();
212211

213-
$this->deploymentConfig = $deploymentConfig ?? ObjectManager::getInstance()
214-
->get(DeploymentConfig::class);
215-
216212
if (isset($data['jsLayout'])) {
217213
$this->jsLayout = $data['jsLayout'];
218214
unset($data['jsLayout']);
@@ -894,6 +890,7 @@ public static function extractModuleName($className)
894890
* @param array|null $allowedTags
895891
* @return string
896892
* @deprecated 103.0.0 Use $escaper directly in templates and in blocks.
893+
* @see Escaper Usage
897894
*/
898895
public function escapeHtml($data, $allowedTags = null)
899896
{
@@ -907,6 +904,7 @@ public function escapeHtml($data, $allowedTags = null)
907904
* @return string
908905
* @since 101.0.0
909906
* @deprecated 103.0.0 Use $escaper directly in templates and in blocks.
907+
* @see Escaper Usage
910908
*/
911909
public function escapeJs($string)
912910
{
@@ -921,6 +919,7 @@ public function escapeJs($string)
921919
* @return string
922920
* @since 101.0.0
923921
* @deprecated 103.0.0 Use $escaper directly in templates and in blocks.
922+
* @see Escaper Usage
924923
*/
925924
public function escapeHtmlAttr($string, $escapeSingleQuote = true)
926925
{
@@ -934,6 +933,7 @@ public function escapeHtmlAttr($string, $escapeSingleQuote = true)
934933
* @return string
935934
* @since 101.0.0
936935
* @deprecated 103.0.0 Use $escaper directly in templates and in blocks.
936+
* @see Escaper Usage
937937
*/
938938
public function escapeCss($string)
939939
{
@@ -961,6 +961,7 @@ public function stripTags($data, $allowableTags = null, $allowHtmlEntities = fal
961961
* @param string $string
962962
* @return string
963963
* @deprecated 103.0.0 Use $escaper directly in templates and in blocks.
964+
* @see Escaper Usage
964965
*/
965966
public function escapeUrl($string)
966967
{
@@ -973,6 +974,7 @@ public function escapeUrl($string)
973974
* @param string $data
974975
* @return string
975976
* @deprecated 101.0.0
977+
* @see Escaper Usage
976978
*/
977979
public function escapeXssInUrl($data)
978980
{
@@ -988,6 +990,7 @@ public function escapeXssInUrl($data)
988990
* @param bool $addSlashes
989991
* @return string
990992
* @deprecated 101.0.0
993+
* @see Escaper Usage
991994
*/
992995
public function escapeQuote($data, $addSlashes = false)
993996
{
@@ -1002,6 +1005,7 @@ public function escapeQuote($data, $addSlashes = false)
10021005
*
10031006
* @return string|array
10041007
* @deprecated 101.0.0
1008+
* @see Escaper Usage
10051009
*/
10061010
public function escapeJsQuote($data, $quote = '\'')
10071011
{
@@ -1049,7 +1053,9 @@ public function getCacheKey()
10491053

10501054
$key = array_values($key); // ignore array keys
10511055

1052-
$key[] = (string)$this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY);
1056+
$key[] = (string)$this->getDeploymentConfig()->get(
1057+
ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY
1058+
);
10531059

10541060
$key = implode('|', $key);
10551061
$key = hash('sha256', $key); // use hashing to hide potentially private data
@@ -1191,10 +1197,25 @@ public function getVar($name, $module = null)
11911197
*
11921198
* @return bool
11931199
* @deprecated
1200+
* @see https://developer.adobe.com/commerce/php/development/cache/page/private-content
11941201
* @since 103.0.1
11951202
*/
11961203
public function isScopePrivate()
11971204
{
11981205
return $this->_isScopePrivate;
11991206
}
1207+
1208+
/**
1209+
* Get DeploymentConfig
1210+
*
1211+
* @return DeploymentConfig
1212+
*/
1213+
private function getDeploymentConfig() : DeploymentConfig
1214+
{
1215+
if ($this->deploymentConfig === null) {
1216+
$this->deploymentConfig = ObjectManager::getInstance()
1217+
->get(DeploymentConfig::class);
1218+
}
1219+
return $this->deploymentConfig;
1220+
}
12001221
}

0 commit comments

Comments
 (0)