Skip to content

Commit 5e3202c

Browse files
committed
ACP2E-1508: Elastic search CRITICAL errors
1 parent 7cf0256 commit 5e3202c

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

app/code/Magento/Catalog/Model/System/Config/Backend/Rss/Category.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ class Category extends ConfigValue
2525
*/
2626
private $productAttributeRepository;
2727

28+
/**
29+
* @param Context $context
30+
* @param Registry $registry
31+
* @param ScopeConfigInterface $config
32+
* @param TypeListInterface $cacheTypeList
33+
* @param AbstractResource|null $resource
34+
* @param AbstractDb|null $resourceCollection
35+
* @param array $data
36+
* @param ProductAttributeRepositoryInterface|null $productAttributeRepository
37+
*/
2838
public function __construct(
2939
Context $context,
3040
Registry $registry,
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Model\System\Config\Backend\Rss;
9+
10+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
11+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
12+
use Magento\Catalog\Model\System\Config\Backend\Rss\Category;
13+
use Magento\Framework\App\Cache\TypeListInterface;
14+
use Magento\Framework\App\Config\ScopeConfigInterface;
15+
use Magento\Framework\Data\Collection\AbstractDb;
16+
use Magento\Framework\Event\ManagerInterface as EventManager;
17+
use Magento\Framework\Model\Context;
18+
use Magento\Framework\Model\ResourceModel\AbstractResource;
19+
use Magento\Framework\Registry;
20+
use PHPUnit\Framework\MockObject\MockObject;
21+
use PHPUnit\Framework\TestCase;
22+
23+
class CategoryTest extends TestCase
24+
{
25+
/**
26+
* @var ScopeConfigInterface|MockObject
27+
*/
28+
private $configMock;
29+
30+
/**
31+
* @var ProductAttributeRepositoryInterface|MockObject
32+
*/
33+
private $productAttributeRepositoryMock;
34+
35+
/**
36+
* @var Category
37+
*/
38+
private $model;
39+
40+
protected function setUp(): void
41+
{
42+
$contextMock = $this->createMock(Context::class);
43+
$eventManagerMock = $this->createMock(EventManager::class);
44+
$contextMock->method('getEventDispatcher')
45+
->willReturn($eventManagerMock);
46+
$registryMock = $this->createMock(Registry::class);
47+
$this->configMock = $this->createMock(ScopeConfigInterface::class);
48+
$cacheTypeListMock = $this->createMock(TypeListInterface::class);
49+
$resourceMock = $this->createMock(AbstractResource::class);
50+
$resourceCollectionMock = $this->createMock(AbstractDb::class);
51+
$this->productAttributeRepositoryMock = $this->createMock(ProductAttributeRepositoryInterface::class);
52+
$this->model = new Category(
53+
$contextMock,
54+
$registryMock,
55+
$this->configMock,
56+
$cacheTypeListMock,
57+
$resourceMock,
58+
$resourceCollectionMock,
59+
['path' => 'rss/catalog/category'],
60+
$this->productAttributeRepositoryMock
61+
);
62+
}
63+
64+
/**
65+
* @dataProvider afterSaveDataProvider
66+
* @param string $oldValue
67+
* @param string $newValue
68+
* @param bool $isUsedForSort
69+
* @param bool $isUpdateNeeded
70+
*/
71+
public function testAfterSave(string $oldValue, string $newValue, bool $isUsedForSort, bool $isUpdateNeeded): void
72+
{
73+
$this->configMock->expects($this->atLeastOnce())
74+
->method('getValue')
75+
->with('rss/catalog/category', 'default', null)
76+
->willReturn($oldValue);
77+
78+
$productAttributeMock = $this->createMock(ProductAttributeInterface::class);
79+
$productAttributeMock->method('getUsedForSortBy')
80+
->willReturn($isUsedForSort);
81+
$this->productAttributeRepositoryMock->method('get')
82+
->with('updated_at')
83+
->willReturn($productAttributeMock);
84+
85+
$productAttributeMock->expects($this->exactly((int) $isUpdateNeeded))
86+
->method('setUsedForSortBy')
87+
->with(true)
88+
->willReturnSelf();
89+
$this->productAttributeRepositoryMock->expects($this->exactly((int) $isUpdateNeeded))
90+
->method('save')
91+
->with($productAttributeMock)
92+
->willReturn($productAttributeMock);
93+
94+
$this->model->setValue($newValue);
95+
$this->model->afterSave();
96+
}
97+
98+
public function afterSaveDataProvider(): array
99+
{
100+
return [
101+
['0', '1', false, true],
102+
['0', '0', false, false],
103+
['1', '0', false, false],
104+
['0', '1', true, false],
105+
];
106+
}
107+
}

0 commit comments

Comments
 (0)