Skip to content

Commit 8ad9bea

Browse files
MC-37653: New/Edit Dynamic Block with Different User Role
1 parent 047995e commit 8ad9bea

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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\PageBuilder\Test\Unit\Model;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\State;
12+
use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
13+
use Magento\Framework\View\DesignInterface;
14+
use Magento\PageBuilder\Model\Stage\Preview;
15+
use Magento\Store\Model\App\Emulation;
16+
use Magento\Store\Model\Store;
17+
use Magento\Store\Model\StoreManagerInterface;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Test for Page Builder Stage Preview Model.
23+
*/
24+
class PreviewTest extends TestCase
25+
{
26+
/**
27+
* @var Preview
28+
*/
29+
private $model;
30+
31+
/**
32+
* @var Emulation|MockObject
33+
*/
34+
private $emulation;
35+
36+
/**
37+
* @var StoreManagerInterface|MockObject
38+
*/
39+
private $storeManagerInterface;
40+
41+
/**
42+
* @inheritdoc
43+
*/
44+
protected function setUp(): void
45+
{
46+
parent::setUp();
47+
48+
$this->storeManagerInterface = $this->createMock(StoreManagerInterface::class);
49+
$this->emulation = $this->createMock(Emulation::class);
50+
$this->model = new Preview(
51+
$this->emulation,
52+
$this->createMock(State::class),
53+
$this->createMock(DesignInterface::class),
54+
$this->createMock(ThemeProviderInterface::class),
55+
$this->storeManagerInterface,
56+
$this->createMock(ScopeConfigInterface::class)
57+
);
58+
}
59+
60+
/**
61+
* Checks that method works properly even if the getDefaultStoreView returns null
62+
*
63+
* @return void
64+
* @throws \Exception
65+
*/
66+
public function testStartPreviewModeWithEmptyDefaultStoreView(): void
67+
{
68+
$callback = function () {
69+
};
70+
$storeId = 2;
71+
$store = $this->createMock(Store::class);
72+
$store->method('getId')
73+
->willReturn($storeId);
74+
$this->storeManagerInterface->method('getDefaultStoreView')
75+
->willReturn(null);
76+
$this->storeManagerInterface->expects($this->once())
77+
->method('getStores')
78+
->willReturn([$store]);
79+
$this->emulation->expects($this->once())
80+
->method('startEnvironmentEmulation')
81+
->with($storeId);
82+
$this->model->startPreviewMode($callback);
83+
}
84+
}

0 commit comments

Comments
 (0)