* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -163,6 +165,11 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
*/
private $urlModel;
+ /**
+ * @var Database
+ */
+ private $fileStorageDatabase;
+
/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\View\DesignInterface $design
@@ -177,6 +184,7 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
* @param \Magento\Framework\Filter\FilterManager $filterManager
* @param \Magento\Framework\UrlInterface $urlModel
* @param array $data
+ * @param Database $fileStorageDatabase
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
@@ -193,7 +201,8 @@ public function __construct(
\Magento\Email\Model\TemplateFactory $templateFactory,
\Magento\Framework\Filter\FilterManager $filterManager,
\Magento\Framework\UrlInterface $urlModel,
- array $data = []
+ array $data = [],
+ Database $fileStorageDatabase = null
) {
$this->design = $design;
$this->area = isset($data['area']) ? $data['area'] : null;
@@ -207,6 +216,8 @@ public function __construct(
$this->templateFactory = $templateFactory;
$this->filterManager = $filterManager;
$this->urlModel = $urlModel;
+ $this->fileStorageDatabase = $fileStorageDatabase ?:
+ \Magento\Framework\App\ObjectManager::getInstance()->get(Database::class);
parent::__construct($context, $registry, null, null, $data);
}
@@ -394,6 +405,11 @@ protected function getLogoUrl($store)
if ($fileName) {
$uploadDir = \Magento\Email\Model\Design\Backend\Logo::UPLOAD_DIR;
$mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
+ if ($this->fileStorageDatabase->checkDbUsage() &&
+ !$mediaDirectory->isFile($uploadDir . '/' . $fileName)
+ ) {
+ $this->fileStorageDatabase->saveFileToFilesystem($uploadDir . '/' . $fileName);
+ }
if ($mediaDirectory->isFile($uploadDir . '/' . $fileName)) {
return $this->storeManager->getStore()->getBaseUrl(
\Magento\Framework\UrlInterface::URL_TYPE_MEDIA
@@ -490,7 +506,6 @@ protected function addEmailVariables($variables, $storeId)
/**
* Apply design config so that emails are processed within the context of the appropriate area/store/theme.
- * Can be called multiple times without issue.
*
* @return bool
*/
@@ -664,8 +679,7 @@ public function getTemplateFilter()
}
/**
- * Save current design config and replace with design config from specified store
- * Event is not dispatched.
+ * Save current design config and replace with design config from specified store. Event is not dispatched.
*
* @param null|bool|int|string $storeId
* @param string $area
diff --git a/app/code/Magento/Email/Test/Unit/Model/BackendTemplateTest.php b/app/code/Magento/Email/Test/Unit/Model/BackendTemplateTest.php
index 31a04b0b2bbd0..1ceccd4414cc0 100644
--- a/app/code/Magento/Email/Test/Unit/Model/BackendTemplateTest.php
+++ b/app/code/Magento/Email/Test/Unit/Model/BackendTemplateTest.php
@@ -12,6 +12,9 @@
use Magento\Email\Model\BackendTemplate;
use Magento\Framework\ObjectManagerInterface;
+/**
+ * Tests for adminhtml email template model.
+ */
class BackendTemplateTest extends \PHPUnit\Framework\TestCase
{
/**
@@ -46,6 +49,11 @@ class BackendTemplateTest extends \PHPUnit\Framework\TestCase
*/
private $serializerMock;
+ /**
+ * @var \Magento\MediaStorage\Helper\File\Storage\Database|\PHPUnit_Framework_MockObject_MockObject
+ */
+ private $databaseHelperMock;
+
protected function setUp()
{
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -56,6 +64,7 @@ protected function setUp()
$this->structureMock = $this->createMock(\Magento\Config\Model\Config\Structure::class);
$this->structureMock->expects($this->any())->method('getFieldPathsByAttribute')->willReturn(['path' => 'test']);
+ $this->databaseHelperMock = $this->createMock(\Magento\MediaStorage\Helper\File\Storage\Database::class);
$this->resourceModelMock = $this->createMock(\Magento\Email\Model\ResourceModel\Template::class);
$this->resourceModelMock->expects($this->any())
->method('getSystemConfigByPathsAndTemplateId')
@@ -64,8 +73,18 @@ protected function setUp()
$objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
$objectManagerMock->expects($this->any())
->method('get')
- ->with(\Magento\Email\Model\ResourceModel\Template::class)
- ->will($this->returnValue($this->resourceModelMock));
+ ->willReturnCallback(
+ function ($value) {
+ switch ($value) {
+ case \Magento\MediaStorage\Helper\File\Storage\Database::class:
+ return ($this->databaseHelperMock);
+ case \Magento\Email\Model\ResourceModel\Template::class:
+ return ($this->resourceModelMock);
+ default:
+ return(null);
+ }
+ }
+ );
\Magento\Framework\App\ObjectManager::setInstance($objectManagerMock);
diff --git a/app/code/Magento/Email/composer.json b/app/code/Magento/Email/composer.json
index 1011b16f8537d..e887adef1fbc9 100644
--- a/app/code/Magento/Email/composer.json
+++ b/app/code/Magento/Email/composer.json
@@ -12,6 +12,7 @@
"magento/module-config": "*",
"magento/module-store": "*",
"magento/module-theme": "*",
+ "magento/module-media-storage": "*",
"magento/module-variable": "*"
},
"suggest": {
diff --git a/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php b/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php
index 6143b8e659059..0848f566f67bb 100644
--- a/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php
+++ b/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php
@@ -182,6 +182,9 @@ public function getJsonSwatchConfig()
$attributeDataArray
);
}
+ if (isset($attributeDataArray['additional_data'])) {
+ $config[$attributeId]['additional_data'] = $attributeDataArray['additional_data'];
+ }
}
return $this->jsonEncoder->encode($config);
@@ -189,6 +192,7 @@ public function getJsonSwatchConfig()
/**
* Get number of swatches from config to show on product listing.
+ *
* Other swatches can be shown after click button 'Show more'
*
* @return string
@@ -228,6 +232,8 @@ public function getProduct()
}
/**
+ * Get swatch attributes data.
+ *
* @return array
*/
protected function getSwatchAttributesData()
@@ -236,6 +242,8 @@ protected function getSwatchAttributesData()
}
/**
+ * Init isProductHasSwatchAttribute.
+ *
* @deprecated 100.1.5 Method isProductHasSwatchAttribute() is used instead of this.
*
* @codeCoverageIgnore
@@ -364,6 +372,8 @@ protected function getVariationMedia($attributeCode, $optionId)
}
/**
+ * Get swatch product image.
+ *
* @param Product $childProduct
* @param string $imageType
* @return string
@@ -384,6 +394,8 @@ protected function getSwatchProductImage(Product $childProduct, $imageType)
}
/**
+ * Check if product have image.
+ *
* @param Product $product
* @param string $imageType
* @return bool
@@ -394,6 +406,8 @@ protected function isProductHasImage(Product $product, $imageType)
}
/**
+ * Get configurable options ids.
+ *
* @param array $attributeData
* @return array
* @since 100.0.3
@@ -453,8 +467,8 @@ protected function getRendererTemplate()
}
/**
+ * @inheritDoc
* @deprecated 100.1.5 Now is used _toHtml() directly
- * @return string
*/
protected function getHtmlOutput()
{
@@ -462,6 +476,8 @@ protected function getHtmlOutput()
}
/**
+ * Get media callback url.
+ *
* @return string
*/
public function getMediaCallback()
diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml
index 5347a1a1f870f..b1ae06428c0ab 100644
--- a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml
+++ b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml
@@ -41,6 +41,9 @@
+
+
+
diff --git a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js
index b0688f33aaef7..6e028ec53c122 100644
--- a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js
+++ b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js
@@ -713,7 +713,8 @@ define([
$wrapper = $this.parents('.' + $widget.options.classes.attributeOptionsWrapper),
$label = $parent.find('.' + $widget.options.classes.attributeSelectedOptionLabelClass),
attributeId = $parent.attr('attribute-id'),
- $input = $parent.find('.' + $widget.options.classes.attributeInput);
+ $input = $parent.find('.' + $widget.options.classes.attributeInput),
+ checkAdditionalData = JSON.parse(this.options.jsonSwatchConfig[attributeId]['additional_data']);
if ($widget.inProductList) {
$input = $widget.productForm.find(
@@ -753,7 +754,10 @@ define([
$widget.options.jsonConfig.optionPrices
]);
- $widget._loadMedia();
+ if (checkAdditionalData['update_product_preview_image'] === '1') {
+ $widget._loadMedia();
+ }
+
$input.trigger('change');
},
diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php
index 10b632c002475..898d3ff400b38 100644
--- a/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php
+++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php
@@ -15,17 +15,17 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Value;
use Magento\Framework\App\Http;
+use Magento\Framework\App\Request\Http as HttpRequest;
use Magento\Framework\Data\Form\FormKey;
use Magento\Framework\Message\MessageInterface;
+use Magento\Framework\Serialize\Serializer\Json;
+use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
+use Magento\TestFramework\Mail\Template\TransportBuilderMock;
use Magento\TestFramework\Request;
use Magento\TestFramework\Response;
-use Zend\Stdlib\Parameters;
-use Magento\Framework\App\Request\Http as HttpRequest;
-use Magento\TestFramework\Mail\Template\TransportBuilderMock;
-use Magento\Framework\Serialize\Serializer\Json;
-use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Theme\Controller\Result\MessagePlugin;
+use Zend\Stdlib\Parameters;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -169,6 +169,7 @@ public function testCreatepasswordActionWithDirectLink()
$token = Bootstrap::getObjectManager()->get(\Magento\Framework\Math\Random::class)
->getUniqueHash();
$customer->changeResetPasswordLinkToken($token);
+ $customer->setData('confirmation', 'confirmation');
$customer->save();
$this->getRequest()->setParam('token', $token);
@@ -187,6 +188,7 @@ public function testCreatepasswordActionWithDirectLink()
$session = Bootstrap::getObjectManager()->get(Session::class);
$this->assertEquals($token, $session->getRpToken());
$this->assertNotContains($token, $response->getHeader('Location')->getFieldValue());
+ $this->assertCustomerConfirmationEquals(1, null);
}
/**
@@ -201,6 +203,7 @@ public function testCreatepasswordActionWithSession()
$token = Bootstrap::getObjectManager()->get(\Magento\Framework\Math\Random::class)
->getUniqueHash();
$customer->changeResetPasswordLinkToken($token);
+ $customer->setData('confirmation', 'confirmation');
$customer->save();
/** @var \Magento\Customer\Model\Session $customer */
@@ -213,6 +216,7 @@ public function testCreatepasswordActionWithSession()
$response = $this->getResponse();
$text = $response->getBody();
$this->assertTrue((bool)preg_match('/' . $token . '/m', $text));
+ $this->assertCustomerConfirmationEquals(1, null);
}
/**
@@ -227,6 +231,7 @@ public function testCreatepasswordActionInvalidToken()
$token = Bootstrap::getObjectManager()->get(\Magento\Framework\Math\Random::class)
->getUniqueHash();
$customer->changeResetPasswordLinkToken($token);
+ $customer->setData('confirmation', 'confirmation');
$customer->save();
$this->getRequest()->setParam('token', 'INVALIDTOKEN');
@@ -238,6 +243,19 @@ public function testCreatepasswordActionInvalidToken()
$response = $this->getResponse();
$this->assertEquals(302, $response->getHttpResponseCode());
$this->assertContains('customer/account/forgotpassword', $response->getHeader('Location')->getFieldValue());
+ $this->assertCustomerConfirmationEquals(1, 'confirmation');
+ }
+
+ /**
+ * @param int $customerId
+ * @param string|null $confirmation
+ */
+ private function assertCustomerConfirmationEquals(int $customerId, string $confirmation = null)
+ {
+ /** @var \Magento\Customer\Model\Customer $customer */
+ $customer = Bootstrap::getObjectManager()
+ ->create(\Magento\Customer\Model\Customer::class)->load($customerId);
+ $this->assertEquals($confirmation, $customer->getConfirmation());
}
/**
@@ -297,11 +315,13 @@ public function testWithConfirmCreatePostAction()
$this->dispatch('customer/account/createPost');
$this->assertRedirect($this->stringContains('customer/account/index/'));
$this->assertSessionMessages(
- $this->equalTo([
- 'You must confirm your account. Please check your email for the confirmation link or '
+ $this->equalTo(
+ [
+ 'You must confirm your account. Please check your email for the confirmation link or '
. 'click here for a new link.'
- ]),
+ ]
+ ),
MessageInterface::TYPE_SUCCESS
);
}
@@ -315,10 +335,14 @@ public function testExistingEmailCreatePostAction()
$this->dispatch('customer/account/createPost');
$this->assertRedirect($this->stringContains('customer/account/create/'));
$this->assertSessionMessages(
- $this->equalTo(['There is already an account with this email address. ' .
- 'If you are sure that it is your email address, ' .
- 'click here' .
- ' to get your password and access your account.', ]),
+ $this->equalTo(
+ [
+ 'There is already an account with this email address. ' .
+ 'If you are sure that it is your email address, ' .
+ 'click here' .
+ ' to get your password and access your account.',
+ ]
+ ),
MessageInterface::TYPE_ERROR
);
}
@@ -330,7 +354,11 @@ public function testInactiveUserConfirmationAction()
{
$this->getRequest()
->setMethod('POST')
- ->setPostValue(['email' => 'customer@needAconfirmation.com']);
+ ->setPostValue(
+ [
+ 'email' => 'customer@needAconfirmation.com',
+ ]
+ );
$this->dispatch('customer/account/confirmation');
$this->assertRedirect($this->stringContains('customer/account/index'));
@@ -347,14 +375,20 @@ public function testActiveUserConfirmationAction()
{
$this->getRequest()
->setMethod('POST')
- ->setPostValue([
- 'email' => 'customer@example.com',
- ]);
+ ->setPostValue(
+ [
+ 'email' => 'customer@example.com',
+ ]
+ );
$this->dispatch('customer/account/confirmation');
$this->assertRedirect($this->stringContains('customer/account/index'));
$this->assertSessionMessages(
- $this->equalTo(['This email does not require confirmation.']),
+ $this->equalTo(
+ [
+ 'This email does not require confirmation.',
+ ]
+ ),
MessageInterface::TYPE_SUCCESS
);
}
@@ -395,9 +429,11 @@ public function testForgotPasswordPostWithBadEmailAction()
{
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
$this->getRequest()
- ->setPostValue([
- 'email' => 'bad@email',
- ]);
+ ->setPostValue(
+ [
+ 'email' => 'bad@email',
+ ]
+ );
$this->dispatch('customer/account/forgotPasswordPost');
$this->assertRedirect($this->stringContains('customer/account/forgotpassword'));
@@ -416,10 +452,12 @@ public function testResetPasswordPostNoTokenAction()
->setParam('id', 1)
->setParam('token', '8ed8677e6c79e68b94e61658bd756ea5')
->setMethod('POST')
- ->setPostValue([
- 'password' => 'new-password',
- 'password_confirmation' => 'new-password',
- ]);
+ ->setPostValue(
+ [
+ 'password' => 'new-password',
+ 'password_confirmation' => 'new-password',
+ ]
+ );
$this->dispatch('customer/account/resetPasswordPost');
$this->assertRedirect($this->stringContains('customer/account/'));
@@ -439,10 +477,12 @@ public function testResetPasswordPostAction()
->setQueryValue('id', 1)
->setQueryValue('token', '8ed8677e6c79e68b94e61658bd756ea5')
->setMethod('POST')
- ->setPostValue([
- 'password' => 'new-Password1',
- 'password_confirmation' => 'new-Password1',
- ]);
+ ->setPostValue(
+ [
+ 'password' => 'new-Password1',
+ 'password_confirmation' => 'new-Password1',
+ ]
+ );
$this->dispatch('customer/account/resetPasswordPost');
$this->assertRedirect($this->stringContains('customer/account/login'));
@@ -465,8 +505,11 @@ public function testEditAction()
$this->assertEquals(200, $this->getResponse()->getHttpResponseCode(), $body);
$this->assertContains('', $body);
// Verify the password check box is not checked
- $this->assertContains('
', $body);
+ $this->assertContains(
+ '
',
+ $body
+ );
}
/**
@@ -510,14 +553,16 @@ public function testEditPostAction()
$this->login(1);
$this->getRequest()
->setMethod('POST')
- ->setPostValue([
- 'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
- 'firstname' => 'John',
- 'lastname' => 'Doe',
- 'email' => 'johndoe@email.com',
- 'change_email' => 1,
- 'current_password' => 'password'
- ]);
+ ->setPostValue(
+ [
+ 'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
+ 'firstname' => 'John',
+ 'lastname' => 'Doe',
+ 'email' => 'johndoe@email.com',
+ 'change_email' => 1,
+ 'current_password' => 'password'
+ ]
+ );
$this->dispatch('customer/account/editPost');
@@ -648,16 +693,18 @@ public function testWrongConfirmationEditPostAction()
$this->login(1);
$this->getRequest()
->setMethod('POST')
- ->setPostValue([
- 'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
- 'firstname' => 'John',
- 'lastname' => 'Doe',
- 'email' => 'johndoe@email.com',
- 'change_password' => 1,
- 'current_password' => 'password',
- 'password' => 'new-password',
- 'password_confirmation' => 'new-password-no-match',
- ]);
+ ->setPostValue(
+ [
+ 'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
+ 'firstname' => 'John',
+ 'lastname' => 'Doe',
+ 'email' => 'johndoe@email.com',
+ 'change_password' => 1,
+ 'current_password' => 'password',
+ 'password' => 'new-password',
+ 'password_confirmation' => 'new-password-no-match',
+ ]
+ );
$this->dispatch('customer/account/editPost');
@@ -841,13 +888,15 @@ private function getCustomerByEmail($email)
*/
private function prepareRequest()
{
- $post = new Parameters([
- 'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
- 'login' => [
- 'username' => 'customer@example.com',
- 'password' => 'password'
+ $post = new Parameters(
+ [
+ 'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
+ 'login' => [
+ 'username' => 'customer@example.com',
+ 'password' => 'password'
+ ]
]
- ]);
+ );
$request = $this->getRequest();
$formKey = $this->_objectManager->get(FormKey::class);
$request->setParam('form_key', $formKey->getFormKey());
@@ -913,6 +962,7 @@ private function getConfirmationUrlFromMessageContent(string $content): string
if (preg_match('
.*?)".*>', $content, $matches)) {
$confirmationUrl = $matches['url'];
$confirmationUrl = str_replace('http://localhost/index.php/', '', $confirmationUrl);
+ // phpcs:ignore Magento2.Functions.DiscouragedFunction
$confirmationUrl = html_entity_decode($confirmationUrl);
}
diff --git a/lib/internal/Magento/Framework/App/Cache/FlushCacheByTags.php b/lib/internal/Magento/Framework/App/Cache/FlushCacheByTags.php
index e2392b198492b..8f8dfd3baf1b6 100644
--- a/lib/internal/Magento/Framework/App/Cache/FlushCacheByTags.php
+++ b/lib/internal/Magento/Framework/App/Cache/FlushCacheByTags.php
@@ -1,18 +1,24 @@
cachePool = $cachePool;
$this->cacheState = $cacheState;
@@ -54,17 +58,14 @@ public function __construct(
/**
* Clean cache on save object
*
- * @param \Magento\Framework\Model\ResourceModel\AbstractResource $subject
+ * @param AbstractResource $subject
* @param \Closure $proceed
- * @param \Magento\Framework\Model\AbstractModel $object
- * @return \Magento\Framework\Model\ResourceModel\AbstractResource
+ * @param AbstractModel $object
+ * @return AbstractResource
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
- public function aroundSave(
- \Magento\Framework\Model\ResourceModel\AbstractResource $subject,
- \Closure $proceed,
- \Magento\Framework\Model\AbstractModel $object
- ) {
+ public function aroundSave(AbstractResource $subject, \Closure $proceed, AbstractModel $object): AbstractResource
+ {
$result = $proceed($object);
$tags = $this->tagResolver->getTags($object);
$this->cleanCacheByTags($tags);
@@ -75,39 +76,37 @@ public function aroundSave(
/**
* Clean cache on delete object
*
- * @param \Magento\Framework\Model\ResourceModel\AbstractResource $subject
+ * @param AbstractResource $subject
* @param \Closure $proceed
- * @param \Magento\Framework\Model\AbstractModel $object
- * @return \Magento\Framework\Model\ResourceModel\AbstractResource
+ * @param AbstractModel $object
+ * @return AbstractResource
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
- public function aroundDelete(
- \Magento\Framework\Model\ResourceModel\AbstractResource $subject,
- \Closure $proceed,
- \Magento\Framework\Model\AbstractModel $object
- ) {
+ public function aroundDelete(AbstractResource $subject, \Closure $proceed, AbstractModel $object): AbstractResource
+ {
$tags = $this->tagResolver->getTags($object);
$result = $proceed($object);
$this->cleanCacheByTags($tags);
+
return $result;
}
/**
* Clean cache by tags
*
- * @param string[] $tags
+ * @param string[] $tags
* @return void
*/
- private function cleanCacheByTags($tags)
+ private function cleanCacheByTags(array $tags): void
{
- if (empty($tags)) {
+ if (!$tags) {
return;
}
foreach ($this->cacheList as $cacheType) {
if ($this->cacheState->isEnabled($cacheType)) {
$this->cachePool->get($cacheType)->clean(
- \Zend_Cache::CLEANING_MODE_MATCHING_TAG,
- array_unique($tags)
+ \Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG,
+ \array_unique($tags)
);
}
}
diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/FlushCacheByTagsTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/FlushCacheByTagsTest.php
index e05399cd0bfcb..60dba582177eb 100644
--- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/FlushCacheByTagsTest.php
+++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/FlushCacheByTagsTest.php
@@ -3,9 +3,20 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
+declare(strict_types=1);
namespace Magento\Framework\App\Test\Unit\Cache;
+use Magento\Framework\App\Cache\FlushCacheByTags;
+use Magento\Framework\App\Cache\StateInterface;
+use Magento\Framework\App\Cache\Tag\Resolver;
+use Magento\Framework\App\Cache\Type\FrontendPool;
+use Magento\Framework\Model\AbstractModel;
+use Magento\Framework\Model\ResourceModel\AbstractResource;
+
+/**
+ * Unit tests for the \Magento\Framework\App\Cache\FlushCacheByTags class.
+ */
class FlushCacheByTagsTest extends \PHPUnit\Framework\TestCase
{
/**
@@ -28,13 +39,16 @@ class FlushCacheByTagsTest extends \PHPUnit\Framework\TestCase
*/
private $plugin;
+ /**
+ * @inheritdoc
+ */
protected function setUp()
{
- $this->cacheState = $this->getMockForAbstractClass(\Magento\Framework\App\Cache\StateInterface::class);
- $this->frontendPool = $this->createMock(\Magento\Framework\App\Cache\Type\FrontendPool::class);
- $this->tagResolver = $this->createMock(\Magento\Framework\App\Cache\Tag\Resolver::class);
+ $this->cacheState = $this->getMockForAbstractClass(StateInterface::class);
+ $this->frontendPool = $this->createMock(FrontendPool::class);
+ $this->tagResolver = $this->createMock(Resolver::class);
- $this->plugin = new \Magento\Framework\App\Cache\FlushCacheByTags(
+ $this->plugin = new FlushCacheByTags(
$this->frontendPool,
$this->cacheState,
['test'],
@@ -42,14 +56,19 @@ protected function setUp()
);
}
- public function testAroundSave()
+ /**
+ * @return void
+ */
+ public function testAroundSave(): void
{
- $resource = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\AbstractResource::class)
+ $resource = $this->getMockBuilder(AbstractResource::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
- $model = $this->getMockBuilder(\Magento\Framework\Model\AbstractModel::class)
+ $model = $this->getMockBuilder(AbstractModel::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
+ $this->tagResolver->expects($this->atLeastOnce())->method('getTags')->with($model)->willReturn([]);
+
$result = $this->plugin->aroundSave(
$resource,
function () use ($resource) {
@@ -57,17 +76,23 @@ function () use ($resource) {
},
$model
);
+
$this->assertSame($resource, $result);
}
- public function testAroundDelete()
+ /**
+ * @return void
+ */
+ public function testAroundDelete(): void
{
- $resource = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\AbstractResource::class)
+ $resource = $this->getMockBuilder(AbstractResource::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
- $model = $this->getMockBuilder(\Magento\Framework\Model\AbstractModel::class)
+ $model = $this->getMockBuilder(AbstractModel::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
+ $this->tagResolver->expects($this->atLeastOnce())->method('getTags')->with($model)->willReturn([]);
+
$result = $this->plugin->aroundDelete(
$resource,
function () use ($resource) {
@@ -75,25 +100,7 @@ function () use ($resource) {
},
$model
);
- $this->assertSame($resource, $result);
- }
- public function testAroundSaveWithInterface()
- {
- $resource = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\AbstractResource::class)
-
- ->disableOriginalConstructor()
- ->getMockForAbstractClass();
- $model = $this->getMockBuilder(\Magento\Framework\Model\AbstractModel::class)
- ->disableOriginalConstructor()
- ->getMockForAbstractClass();
- $result = $this->plugin->aroundSave(
- $resource,
- function () use ($resource) {
- return $resource;
- },
- $model
- );
$this->assertSame($resource, $result);
}
}