Skip to content

Commit 673d723

Browse files
authored
ENGCOM-6808: Set of fixes introduced during #CoreReview 31.01.2020 #26621
2 parents a84f785 + 3aa039e commit 673d723

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

app/code/Magento/CatalogWidget/Block/Product/ProductsList.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Catalog\Api\CategoryRepositoryInterface;
1010
use Magento\Catalog\Block\Product\AbstractProduct;
11+
use Magento\Catalog\Block\Product\Context;
1112
use Magento\Catalog\Block\Product\Widget\Html\Pager;
1213
use Magento\Catalog\Model\Product;
1314
use Magento\Catalog\Model\Product\Visibility;
@@ -16,7 +17,7 @@
1617
use Magento\Catalog\Pricing\Price\FinalPrice;
1718
use Magento\CatalogWidget\Model\Rule;
1819
use Magento\Framework\App\ActionInterface;
19-
use Magento\Framework\App\Http\Context;
20+
use Magento\Framework\App\Http\Context as HttpContext;
2021
use Magento\Framework\App\ObjectManager;
2122
use Magento\Framework\DataObject\IdentityInterface;
2223
use Magento\Framework\Exception\LocalizedException;
@@ -27,7 +28,7 @@
2728
use Magento\Framework\View\LayoutFactory;
2829
use Magento\Framework\View\LayoutInterface;
2930
use Magento\Rule\Model\Condition\Combine;
30-
use Magento\Rule\Model\Condition\Sql\Builder;
31+
use Magento\Rule\Model\Condition\Sql\Builder as SqlBuilder;
3132
use Magento\Widget\Block\BlockInterface;
3233
use Magento\Widget\Helper\Conditions;
3334

@@ -69,7 +70,7 @@ class ProductsList extends AbstractProduct implements BlockInterface, IdentityIn
6970
protected $pager;
7071

7172
/**
72-
* @var Context
73+
* @var HttpContext
7374
*/
7475
protected $httpContext;
7576

@@ -88,7 +89,7 @@ class ProductsList extends AbstractProduct implements BlockInterface, IdentityIn
8889
protected $productCollectionFactory;
8990

9091
/**
91-
* @var Builder
92+
* @var SqlBuilder
9293
*/
9394
protected $sqlBuilder;
9495

@@ -135,34 +136,34 @@ class ProductsList extends AbstractProduct implements BlockInterface, IdentityIn
135136
private $categoryRepository;
136137

137138
/**
138-
* @param \Magento\Catalog\Block\Product\Context $context
139+
* @param Context $context
139140
* @param CollectionFactory $productCollectionFactory
140141
* @param Visibility $catalogProductVisibility
141-
* @param Context $httpContext
142-
* @param Builder $sqlBuilder
142+
* @param HttpContext $httpContext
143+
* @param SqlBuilder $sqlBuilder
143144
* @param Rule $rule
144145
* @param Conditions $conditionsHelper
145-
* @param CategoryRepositoryInterface $categoryRepository
146146
* @param array $data
147147
* @param Json|null $json
148148
* @param LayoutFactory|null $layoutFactory
149149
* @param EncoderInterface|null $urlEncoder
150+
* @param CategoryRepositoryInterface|null $categoryRepository
150151
*
151152
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
152153
*/
153154
public function __construct(
154-
\Magento\Catalog\Block\Product\Context $context,
155+
Context $context,
155156
CollectionFactory $productCollectionFactory,
156157
Visibility $catalogProductVisibility,
157-
Context $httpContext,
158-
Builder $sqlBuilder,
158+
HttpContext $httpContext,
159+
SqlBuilder $sqlBuilder,
159160
Rule $rule,
160161
Conditions $conditionsHelper,
161-
CategoryRepositoryInterface $categoryRepository,
162162
array $data = [],
163163
Json $json = null,
164164
LayoutFactory $layoutFactory = null,
165-
EncoderInterface $urlEncoder = null
165+
EncoderInterface $urlEncoder = null,
166+
CategoryRepositoryInterface $categoryRepository = null
166167
) {
167168
$this->productCollectionFactory = $productCollectionFactory;
168169
$this->catalogProductVisibility = $catalogProductVisibility;
@@ -173,7 +174,8 @@ public function __construct(
173174
$this->json = $json ?: ObjectManager::getInstance()->get(Json::class);
174175
$this->layoutFactory = $layoutFactory ?: ObjectManager::getInstance()->get(LayoutFactory::class);
175176
$this->urlEncoder = $urlEncoder ?: ObjectManager::getInstance()->get(EncoderInterface::class);
176-
$this->categoryRepository = $categoryRepository;
177+
$this->categoryRepository = $categoryRepository ?? ObjectManager::getInstance()
178+
->get(CategoryRepositoryInterface::class);
177179
parent::__construct(
178180
$context,
179181
$data

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Category/Delete/DeleteCategoryWithEnabledFlatTest.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
class DeleteCategoryWithEnabledFlatTest extends AbstractBackendController
2626
{
27+
const STUB_CATEGORY_ID = 333;
28+
2729
/**
2830
* @var IndexerRegistry
2931
*/
@@ -79,13 +81,16 @@ protected function tearDown()
7981
*/
8082
public function testDeleteCategory(): void
8183
{
82-
$this->assertEquals(1, $this->getFlatCategoryCollectionSizeByCategoryId(333));
83-
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
84-
$this->getRequest()->setPostValue(['id' => 333]);
85-
$this->dispatch('backend/catalog/category/delete');
84+
// Given
85+
$this->assertEquals(1, $this->getFlatCategoryCollectionSizeByCategoryId(self::STUB_CATEGORY_ID));
86+
87+
// When
88+
$this->sendDeleteCategoryRequest(self::STUB_CATEGORY_ID);
89+
90+
// Then
8691
$this->assertSessionMessages($this->equalTo([(string)__('You deleted the category.')]));
87-
$this->assertEquals(0, $this->getFlatCategoryCollectionSizeByCategoryId(333));
88-
$this->checkCategoryIsDeleted(333);
92+
$this->assertEquals(0, $this->getFlatCategoryCollectionSizeByCategoryId(self::STUB_CATEGORY_ID));
93+
$this->checkCategoryIsDeleted(self::STUB_CATEGORY_ID);
8994
}
9095

9196
/**
@@ -106,10 +111,26 @@ private function getFlatCategoryCollectionSizeByCategoryId(int $categoryId): int
106111
* Assert that category is deleted.
107112
*
108113
* @param int $categoryId
114+
* @return void
109115
*/
110116
private function checkCategoryIsDeleted(int $categoryId): void
111117
{
112-
$this->expectExceptionObject(new NoSuchEntityException(__("No such entity with id = {$categoryId}")));
118+
$this->expectExceptionObject(
119+
new NoSuchEntityException(__("No such entity with id = %entityId", ['entityId' => $categoryId]))
120+
);
113121
$this->categoryRepository->get($categoryId);
114122
}
123+
124+
/**
125+
* Method passes the request to Backend to remove given category.
126+
*
127+
* @param int $categoryId
128+
* @return void
129+
*/
130+
private function sendDeleteCategoryRequest(int $categoryId): void
131+
{
132+
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
133+
$this->getRequest()->setPostValue(['id' => $categoryId]);
134+
$this->dispatch('backend/catalog/category/delete');
135+
}
115136
}

0 commit comments

Comments
 (0)