|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * Copyright © Magento, Inc. All rights reserved. |
4 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2015 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */
|
6 | 6 |
|
7 | 7 | declare(strict_types=1);
|
|
15 | 15 | use Magento\Framework\App\Area;
|
16 | 16 | use Magento\Framework\App\Config\ScopeConfigInterface;
|
17 | 17 | use Magento\Framework\App\Filesystem\DirectoryList;
|
18 |
| -use Magento\Framework\DataObject; |
19 |
| -use Magento\Framework\Exception\MailException; |
20 |
| -use Magento\Framework\Exception\NoSuchEntityException; |
21 | 18 | use Magento\Framework\App\State;
|
22 | 19 | use Magento\Framework\Css\PreProcessor\Adapter\CssInliner;
|
| 20 | +use Magento\Framework\DataObject; |
23 | 21 | use Magento\Framework\Escaper;
|
| 22 | +use Magento\Framework\Exception\MailException; |
| 23 | +use Magento\Framework\Exception\NoSuchEntityException; |
24 | 24 | use Magento\Framework\Filesystem;
|
25 | 25 | use Magento\Framework\Filesystem\Directory\Read;
|
26 | 26 | use Magento\Framework\Filter\DirectiveProcessor\DependDirective;
|
|
34 | 34 | use Magento\Framework\View\Asset\File;
|
35 | 35 | use Magento\Framework\View\Asset\File\FallbackContext;
|
36 | 36 | use Magento\Framework\View\Asset\Repository;
|
| 37 | +use Magento\Framework\View\Element\AbstractBlock; |
37 | 38 | use Magento\Framework\View\LayoutFactory;
|
38 | 39 | use Magento\Framework\View\LayoutInterface;
|
| 40 | +use Magento\Store\Model\Information as StoreInformation; |
39 | 41 | use Magento\Store\Model\Store;
|
40 | 42 | use Magento\Store\Model\StoreManagerInterface;
|
41 | 43 | use Magento\Variable\Model\Source\Variables;
|
42 | 44 | use Magento\Variable\Model\VariableFactory;
|
43 | 45 | use PHPUnit\Framework\MockObject\MockObject;
|
44 | 46 | use PHPUnit\Framework\TestCase;
|
45 | 47 | use Psr\Log\LoggerInterface;
|
46 |
| -use Magento\Store\Model\Information as StoreInformation; |
47 | 48 |
|
48 | 49 | /**
|
49 | 50 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
@@ -623,4 +624,81 @@ public static function dataProviderUrlModelCompanyRedirect(): array
|
623 | 624 | ]
|
624 | 625 | ];
|
625 | 626 | }
|
| 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 | + } |
626 | 704 | }
|
0 commit comments