Skip to content

Commit b535da7

Browse files
tranthienbinh1989nishant04412
authored andcommitted
AC-14694:: Update template rendering
1 parent 54c59cf commit b535da7

File tree

2 files changed

+90
-8
lines changed

2 files changed

+90
-8
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -432,6 +432,10 @@ public function blockDirective($construction)
432432
$block->setDataUsingMethod($k, $v);
433433
}
434434

435+
if (!$block->hasData('cache_key')) {
436+
$block->setDataUsingMethod('cache_key', $block->getCacheKey());
437+
}
438+
435439
if (isset($blockParameters['output'])) {
436440
$method = $blockParameters['output'];
437441
}

app/code/Magento/Email/Test/Unit/Model/Template/FilterTest.php

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66

77
declare(strict_types=1);
@@ -15,12 +15,12 @@
1515
use Magento\Framework\App\Area;
1616
use Magento\Framework\App\Config\ScopeConfigInterface;
1717
use Magento\Framework\App\Filesystem\DirectoryList;
18-
use Magento\Framework\DataObject;
19-
use Magento\Framework\Exception\MailException;
20-
use Magento\Framework\Exception\NoSuchEntityException;
2118
use Magento\Framework\App\State;
2219
use Magento\Framework\Css\PreProcessor\Adapter\CssInliner;
20+
use Magento\Framework\DataObject;
2321
use Magento\Framework\Escaper;
22+
use Magento\Framework\Exception\MailException;
23+
use Magento\Framework\Exception\NoSuchEntityException;
2424
use Magento\Framework\Filesystem;
2525
use Magento\Framework\Filesystem\Directory\Read;
2626
use Magento\Framework\Filter\DirectiveProcessor\DependDirective;
@@ -34,16 +34,17 @@
3434
use Magento\Framework\View\Asset\File;
3535
use Magento\Framework\View\Asset\File\FallbackContext;
3636
use Magento\Framework\View\Asset\Repository;
37+
use Magento\Framework\View\Element\AbstractBlock;
3738
use Magento\Framework\View\LayoutFactory;
3839
use Magento\Framework\View\LayoutInterface;
40+
use Magento\Store\Model\Information as StoreInformation;
3941
use Magento\Store\Model\Store;
4042
use Magento\Store\Model\StoreManagerInterface;
4143
use Magento\Variable\Model\Source\Variables;
4244
use Magento\Variable\Model\VariableFactory;
4345
use PHPUnit\Framework\MockObject\MockObject;
4446
use PHPUnit\Framework\TestCase;
4547
use Psr\Log\LoggerInterface;
46-
use Magento\Store\Model\Information as StoreInformation;
4748

4849
/**
4950
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -623,4 +624,81 @@ public static function dataProviderUrlModelCompanyRedirect(): array
623624
]
624625
];
625626
}
627+
628+
/**
629+
* Test block directive cache key functionality
630+
*
631+
* @param bool $hasCacheKey
632+
* @param bool $expectGetCacheKey
633+
* @param bool $expectSetData
634+
* @dataProvider blockDirectiveCacheKeyDataProvider
635+
*/
636+
public function testBlockDirectiveCacheKey($hasCacheKey, $expectGetCacheKey, $expectSetData)
637+
{
638+
$block = $this->getMockBuilder(AbstractBlock::class)
639+
->disableOriginalConstructor()
640+
->getMock();
641+
642+
$this->layout->expects($this->once())
643+
->method('createBlock')
644+
->willReturn($block);
645+
646+
$block->expects($this->once())
647+
->method('hasData')
648+
->with('cache_key')
649+
->willReturn($hasCacheKey);
650+
651+
if ($expectGetCacheKey) {
652+
$block->expects($this->once())
653+
->method('getCacheKey')
654+
->willReturn('test_cache_key');
655+
} else {
656+
$block->expects($this->never())
657+
->method('getCacheKey');
658+
}
659+
660+
if ($expectSetData) {
661+
$block->expects($this->once())
662+
->method('setDataUsingMethod')
663+
->with('cache_key', 'test_cache_key');
664+
} else {
665+
$block->expects($this->never())
666+
->method('setDataUsingMethod');
667+
}
668+
669+
$block->expects($this->once())
670+
->method('toHtml')
671+
->willReturn('block html');
672+
673+
$construction = [
674+
'{{block class="Magento\\Framework\\View\\Element\\AbstractBlock"}}',
675+
'block',
676+
' class="Magento\\Framework\\View\\Element\\AbstractBlock"'
677+
];
678+
679+
$filter = $this->getModel();
680+
$result = $filter->blockDirective($construction);
681+
$this->assertEquals('block html', $result);
682+
}
683+
684+
/**
685+
* Data provider for testBlockDirectiveCacheKey
686+
*
687+
* @return array
688+
*/
689+
public static function blockDirectiveCacheKeyDataProvider()
690+
{
691+
return [
692+
'block without cache key' => [
693+
'hasCacheKey' => false,
694+
'expectGetCacheKey' => true,
695+
'expectSetData' => true
696+
],
697+
'block with existing cache key' => [
698+
'hasCacheKey' => true,
699+
'expectGetCacheKey' => false,
700+
'expectSetData' => false
701+
]
702+
];
703+
}
626704
}

0 commit comments

Comments
 (0)