Skip to content

Commit 03e3812

Browse files
committed
Merge remote-tracking branch 'origin/MC-34851' into 2.4-develop-pr120
2 parents b9758d6 + 00ec932 commit 03e3812

File tree

2 files changed

+118
-0
lines changed
  • app/code/Magento/Ui

2 files changed

+118
-0
lines changed

app/code/Magento/Ui/Controller/Adminhtml/Bookmark/Save.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public function __construct(
103103
*/
104104
public function execute()
105105
{
106+
if (!$this->userContext->getUserId()) {
107+
return;
108+
}
109+
106110
$bookmark = $this->bookmarkFactory->create();
107111
$jsonData = $this->_request->getParam('data');
108112
if (!$jsonData) {
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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\Ui\Test\Unit\Controller\Adminhtml\Bookmark;
9+
10+
use Magento\Authorization\Model\UserContextInterface;
11+
use Magento\Framework\Json\DecoderInterface;
12+
use Magento\Framework\View\Element\UiComponentFactory;
13+
use Magento\Ui\Api\BookmarkManagementInterface;
14+
use Magento\Ui\Api\BookmarkRepositoryInterface;
15+
use Magento\Ui\Api\Data\BookmarkInterfaceFactory;
16+
use Magento\Ui\Controller\Adminhtml\Bookmark\Save;
17+
use Magento\Backend\App\Action\Context;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Save controller test.
23+
*/
24+
class SaveTest extends TestCase
25+
{
26+
/**
27+
* @var MockObject|Context
28+
*/
29+
private $context;
30+
31+
/**
32+
* @var MockObject|UiComponentFactory
33+
*/
34+
private $factory;
35+
36+
/**
37+
* @var MockObject|BookmarkRepositoryInterface
38+
*/
39+
private $bookmarkRepository;
40+
41+
/**
42+
* @var MockObject|BookmarkManagementInterface
43+
*/
44+
private $bookmarkManagement;
45+
46+
/**
47+
* @var MockObject|BookmarkInterfaceFactory
48+
*/
49+
private $bookmarkFactory;
50+
51+
/**
52+
* @var MockObject|UserContextInterface
53+
*/
54+
private $userContext;
55+
56+
/**
57+
* @var MockObject|DecoderInterface
58+
*/
59+
private $jsonDecoder;
60+
61+
/**
62+
* @var Save
63+
*/
64+
private $model;
65+
66+
/**
67+
* @inheritDoc
68+
*/
69+
protected function setUp(): void
70+
{
71+
$this->context = $this->createMock(Context::class);
72+
$this->factory = $this->createMock(UiComponentFactory::class);
73+
$this->bookmarkRepository = $this->createMock(BookmarkRepositoryInterface::class);
74+
$this->bookmarkManagement = $this->createMock(BookmarkManagementInterface::class);
75+
$this->bookmarkFactory = $this->createMock(BookmarkInterfaceFactory::class);
76+
$this->userContext = $this->createMock(UserContextInterface::class);
77+
$this->jsonDecoder = $this->createMock(DecoderInterface::class);
78+
79+
$this->model = new Save(
80+
$this->context,
81+
$this->factory,
82+
$this->bookmarkRepository,
83+
$this->bookmarkManagement,
84+
$this->bookmarkFactory,
85+
$this->userContext,
86+
$this->jsonDecoder
87+
);
88+
}
89+
90+
/**
91+
* Tests execute method.
92+
* Test when User Context doesn't provide userId. In such a case the method should not be executed.
93+
*
94+
* @return void
95+
*/
96+
public function testExecuteWontBeExecutedWhenNoUserIdInContext(): void
97+
{
98+
$this->factory->expects($this->never())
99+
->method($this->anything());
100+
$this->bookmarkRepository->expects($this->never())
101+
->method($this->anything());
102+
$this->bookmarkManagement->expects($this->never())
103+
->method($this->anything());
104+
$this->bookmarkFactory->expects($this->never())
105+
->method($this->anything());
106+
$this->jsonDecoder->expects($this->never())
107+
->method($this->anything());
108+
109+
$this->userContext->method('getUserId')
110+
->willReturn(null);
111+
112+
$this->model->execute();
113+
}
114+
}

0 commit comments

Comments
 (0)