Skip to content

Commit

Permalink
Merge pull request #8999 from magento-gl/spartans_pr_12062024
Browse files Browse the repository at this point in the history
Spartans pr 12062024
  • Loading branch information
2 parents 35b1b1d + faa90bb commit 0c53bbf
Show file tree
Hide file tree
Showing 16 changed files with 365 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/
namespace Magento\Catalog\Controller\Product\Compare;

use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
use Magento\Framework\Data\Form\FormKey\Validator;
use Magento\Framework\View\Result\PageFactory;

Expand Down Expand Up @@ -81,6 +81,8 @@ public function execute()
$this->_catalogSession->setBeforeCompareUrl(
$this->urlDecoder->decode($beforeUrl)
);
} else {
$this->_catalogSession->unsBeforeCompareUrl();
}
return $this->resultPageFactory->create();
}
Expand Down
13 changes: 11 additions & 2 deletions app/code/Magento/Catalog/CustomerData/CompareProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
Expand Down Expand Up @@ -43,25 +44,33 @@ class CompareProducts implements SectionSourceInterface
*/
private $storeManager;

/**
* @var UrlInterface
*/
private $urlBuilder;

/**
* @param \Magento\Catalog\Helper\Product\Compare $helper
* @param \Magento\Catalog\Model\Product\Url $productUrl
* @param \Magento\Catalog\Helper\Output $outputHelper
* @param ScopeConfigInterface|null $scopeConfig
* @param StoreManagerInterface|null $storeManager
* @param UrlInterface|null $urlBuilder
*/
public function __construct(
\Magento\Catalog\Helper\Product\Compare $helper,
\Magento\Catalog\Model\Product\Url $productUrl,
\Magento\Catalog\Helper\Output $outputHelper,
?ScopeConfigInterface $scopeConfig = null,
?StoreManagerInterface $storeManager = null
?StoreManagerInterface $storeManager = null,
?UrlInterface $urlBuilder = null
) {
$this->helper = $helper;
$this->productUrl = $productUrl;
$this->outputHelper = $outputHelper;
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
$this->storeManager = $storeManager ?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
$this->urlBuilder = $urlBuilder ?? ObjectManager::getInstance()->get(UrlInterface::class);
}

/**
Expand All @@ -73,7 +82,7 @@ public function getSectionData()
return [
'count' => $count,
'countCaption' => $count == 1 ? __('1 item') : __('%1 items', $count),
'listUrl' => $this->helper->getListUrl(),
'listUrl' => $this->urlBuilder->getUrl('catalog/product_compare/index'),
'items' => $count ? $this->getItems() : [],
'websiteId' => $this->storeManager->getWebsite()->getId()
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
use Magento\Catalog\Model\ResourceModel\Product\Compare\Item\Collection;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Model\Website;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Magento\Store\Model\StoreManagerInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CompareProductsTest extends TestCase
{
/**
Expand Down Expand Up @@ -64,6 +68,11 @@ class CompareProductsTest extends TestCase
*/
private $websiteMock;

/**
* @var UrlInterface|MockObject
*/
private $urlBuilder;

/**
* @var array
*/
Expand All @@ -88,6 +97,9 @@ protected function setUp(): void
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->urlBuilder = $this->getMockBuilder(UrlInterface::class)
->disableOriginalConstructor()
->getMock();

$this->storeManagerMock = $this->getMockBuilder(
StoreManagerInterface::class
Expand All @@ -97,7 +109,7 @@ protected function setUp(): void
$this->websiteMock = $this->getMockBuilder(
Website::class
)->onlyMethods(
['getId',]
['getId']
)->disableOriginalConstructor()
->getMock();

Expand All @@ -110,8 +122,8 @@ protected function setUp(): void
'productUrl' => $this->productUrlMock,
'outputHelper' => $this->outputHelperMock,
'scopeConfig' => $this->scopeConfigMock,
'storeManager' => $this->storeManagerMock

'storeManager' => $this->storeManagerMock,
'urlBuilder' => $this->urlBuilder
]
);
}
Expand Down Expand Up @@ -219,9 +231,10 @@ public function testGetSectionData()
->method('getItemCollection')
->willReturn($itemCollectionMock);

$this->helperMock->expects($this->once())
->method('getListUrl')
$this->urlBuilder->expects($this->once())
->method('getUrl')
->willReturn('http://list.url');

$this->storeManagerMock->expects($this->any())->method('getWebsite')->willReturn($this->websiteMock);
$this->websiteMock->expects($this->any())->method('getId')->willReturn(1);
$this->assertEquals(
Expand Down Expand Up @@ -269,8 +282,8 @@ public function testGetSectionDataNoItems()
$this->helperMock->expects($this->never())
->method('getItemCollection');

$this->helperMock->expects($this->once())
->method('getListUrl')
$this->urlBuilder->expects($this->once())
->method('getUrl')
->willReturn('http://list.url');

$this->storeManagerMock->expects($this->any())->method('getWebsite')->willReturn($this->websiteMock);
Expand Down Expand Up @@ -314,8 +327,8 @@ public function testGetSectionDataSingleItem()
->method('getItemCollection')
->willReturn($itemCollectionMock);

$this->helperMock->expects($this->once())
->method('getListUrl')
$this->urlBuilder->expects($this->once())
->method('getUrl')
->willReturn('http://list.url');

$this->assertEquals(
Expand Down
21 changes: 12 additions & 9 deletions app/code/Magento/Developer/Console/Command/DiInfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
use Magento\Developer\Model\Di\Information;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Helper\Table;

class DiInfoCommand extends Command
{
/**
* Command name
*/
const COMMAND_NAME = 'dev:di:info';
public const COMMAND_NAME = 'dev:di:info';

/**
* input name
*/
const CLASS_NAME = 'class';
public const CLASS_NAME = 'class';

/**
* @var Information
Expand All @@ -42,7 +42,8 @@ public function __construct(
}

/**
* {@inheritdoc}
* Initialization of the command
*
* @throws InvalidArgumentException
*/
protected function configure()
Expand Down Expand Up @@ -93,7 +94,7 @@ private function printConstructorArguments($className, $output)
$paramsTableArray[] = $parameterRow;
}
$paramsTable->setRows($paramsTableArray);
$output->writeln($paramsTable->render());
$paramsTable->render();
}

/**
Expand Down Expand Up @@ -142,12 +143,14 @@ private function printPlugins($className, $output, $label)
->setHeaders(['Plugin', 'Method', 'Type'])
->setRows($parameters);

$output->writeln($table->render());
$table->render();
}

/**
* {@inheritdoc}
* @throws \InvalidArgumentException
* Displays dependency injection configuration information for a class.
*
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ class IdentifierForSave implements IdentifierInterface
* @param Http $request
* @param Context $context
* @param Json $serializer
* @param IdentifierStoreReader $identifierStoreReader
*/
public function __construct(
private Http $request,
private Context $context,
private Json $serializer
private Http $request,
private Context $context,
private Json $serializer,
private IdentifierStoreReader $identifierStoreReader,
) {
}

Expand All @@ -42,6 +44,8 @@ public function getValue()
$this->context->getVaryString()
];

$data = $this->identifierStoreReader->getPageTagsWithStoreCacheTags($data);

return sha1($this->serializer->serialize($data));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\PageCache\Model\App\Request\Http;

use Magento\Store\Model\StoreManager;

class IdentifierStoreReader
{
/**
* @var \Magento\Framework\View\DesignExceptions
*/
private $designExceptions;

/**
* @var \Magento\Framework\App\RequestInterface
*/
private $request;

/**
* @var \Magento\PageCache\Model\Config
*/
private $config;

/**
* @param \Magento\Framework\View\DesignExceptions $designExceptions
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\PageCache\Model\Config $config
*/
public function __construct(
\Magento\Framework\View\DesignExceptions $designExceptions,
\Magento\Framework\App\RequestInterface $request,
\Magento\PageCache\Model\Config $config
) {
$this->designExceptions = $designExceptions;
$this->request = $request;
$this->config = $config;
}

/**
* Adds a theme key to identifier for a built-in cache if user-agent theme rule is actual
*
* @param array $data
* @return array|null
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getPageTagsWithStoreCacheTags(array $data): ?array
{
if ($this->config->getType() === \Magento\PageCache\Model\Config::BUILT_IN && $this->config->isEnabled()) {
$ruleDesignException = $this->designExceptions->getThemeByRequest($this->request);
if ($ruleDesignException !== false) {
$data['DESIGN'] = $ruleDesignException;
}

if ($runType = $this->request->getServerValue(StoreManager::PARAM_RUN_TYPE)) {
$data[StoreManager::PARAM_RUN_TYPE] = $runType;
}

if ($runCode = $this->request->getServerValue(StoreManager::PARAM_RUN_CODE)) {
$data[StoreManager::PARAM_RUN_CODE] = $runCode;
}
}

return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Framework\App\Request\Http as HttpRequest;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\PageCache\Model\App\Request\Http\IdentifierForSave;
use Magento\PageCache\Model\App\Request\Http\IdentifierStoreReader;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -40,6 +41,10 @@ class IdentifierForSaveTest extends TestCase
* @var Json|MockObject
*/
private mixed $serializerMock;
/**
* @var IdentifierStoreReader|MockObject
*/
private $identifierStoreReader;

/**
* @inheritdoc
Expand All @@ -64,10 +69,16 @@ function ($value) {
}
);

$this->identifierStoreReader = $this->getMockBuilder(IdentifierStoreReader::class)
->onlyMethods(['getPageTagsWithStoreCacheTags'])
->disableOriginalConstructor()
->getMock();

$this->model = new IdentifierForSave(
$this->requestMock,
$this->contextMock,
$this->serializerMock
$this->serializerMock,
$this->identifierStoreReader
);
parent::setUp();
}
Expand All @@ -91,6 +102,12 @@ public function testGetValue(): void
->method('getVaryString')
->willReturn(self::VARY);

$this->identifierStoreReader->method('getPageTagsWithStoreCacheTags')->willReturnCallback(
function ($value) {
return $value;
}
);

$this->assertEquals(
sha1(
json_encode(
Expand Down
Loading

0 comments on commit 0c53bbf

Please sign in to comment.