Skip to content

Commit 6ef2a2e

Browse files
committed
Merge remote-tracking branch 'mainline/2.2-develop' into MAGETWO-94080
2 parents 0809bf3 + 369b5ce commit 6ef2a2e

File tree

10 files changed

+670
-10
lines changed

10 files changed

+670
-10
lines changed
Lines changed: 339 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,339 @@
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\Cms\Test\Unit\Model;
9+
10+
use Magento\Cms\Model\Block;
11+
use Magento\Cms\Model\ResourceModel\Block as BlockResource;
12+
use Magento\Framework\Event\ManagerInterface;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\Model\Context;
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
16+
17+
/**
18+
* @covers \Magento\Cms\Model\Block
19+
*/
20+
class BlockTest extends \PHPUnit\Framework\TestCase
21+
{
22+
/**
23+
* Testable Object
24+
*
25+
* @var Block
26+
*/
27+
private $blockModel;
28+
29+
/**
30+
* Object Manager
31+
*
32+
* @var ObjectManager
33+
*/
34+
private $objectManager;
35+
36+
/**
37+
* @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
private $eventManagerMock;
40+
41+
/**
42+
* @var Context|\PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
private $contextMock;
45+
46+
/**
47+
* @var BlockResource|\PHPUnit_Framework_MockObject_MockObject
48+
*/
49+
private $resourceMock;
50+
51+
/**
52+
* Set Up
53+
*
54+
* @return void
55+
*/
56+
protected function setUp()
57+
{
58+
$this->resourceMock = $this->createMock(BlockResource::class);
59+
$this->eventManagerMock = $this->createMock(ManagerInterface::class);
60+
$this->contextMock = $this->createMock(Context::class);
61+
$this->contextMock->expects($this->any())->method('getEventDispatcher')->willReturn($this->eventManagerMock);
62+
$this->objectManager = new ObjectManager($this);
63+
$this->blockModel = $this->objectManager->getObject(
64+
Block::class,
65+
[
66+
'context' => $this->contextMock,
67+
'resource' => $this->resourceMock,
68+
]
69+
);
70+
}
71+
72+
/**
73+
* Test beforeSave method
74+
*
75+
* @return void
76+
*
77+
* @throws LocalizedException
78+
*/
79+
public function testBeforeSave()
80+
{
81+
$blockId = 7;
82+
$this->blockModel->setData(Block::BLOCK_ID, $blockId);
83+
$this->blockModel->setData(Block::CONTENT, 'test');
84+
$this->objectManager->setBackwardCompatibleProperty($this->blockModel, '_hasDataChanges', true);
85+
$this->eventManagerMock->expects($this->atLeastOnce())->method('dispatch');
86+
87+
$expected = $this->blockModel;
88+
$actual = $this->blockModel->beforeSave();
89+
self::assertEquals($expected, $actual);
90+
}
91+
92+
/**
93+
* Test beforeSave method
94+
*
95+
* @return void
96+
*
97+
* @throws LocalizedException
98+
*/
99+
public function testBeforeSaveWithException()
100+
{
101+
$blockId = 10;
102+
$this->blockModel->setData(Block::BLOCK_ID, $blockId);
103+
$this->blockModel->setData(Block::CONTENT, 'Test block_id="' . $blockId . '".');
104+
$this->objectManager->setBackwardCompatibleProperty($this->blockModel, '_hasDataChanges', false);
105+
$this->eventManagerMock->expects($this->never())->method('dispatch');
106+
$this->expectException(LocalizedException::class);
107+
$this->blockModel->beforeSave();
108+
}
109+
110+
/**
111+
* Test getIdentities method
112+
*
113+
* @return void
114+
*/
115+
public function testGetIdentities()
116+
{
117+
$result = $this->blockModel->getIdentities();
118+
self::assertInternalType('array', $result);
119+
}
120+
121+
/**
122+
* Test getId method
123+
*
124+
* @return void
125+
*/
126+
public function testGetId()
127+
{
128+
$blockId = 12;
129+
$this->blockModel->setData(Block::BLOCK_ID, $blockId);
130+
$expected = $blockId;
131+
$actual = $this->blockModel->getId();
132+
self::assertEquals($expected, $actual);
133+
}
134+
135+
/**
136+
* Test getIdentifier method
137+
*
138+
* @return void
139+
*/
140+
public function testGetIdentifier()
141+
{
142+
$identifier = 'test01';
143+
$this->blockModel->setData(Block::IDENTIFIER, $identifier);
144+
145+
$expected = $identifier;
146+
$actual = $this->blockModel->getIdentifier();
147+
self::assertEquals($expected, $actual);
148+
}
149+
150+
/**
151+
* Test getTitle method
152+
*
153+
* @return void
154+
*/
155+
public function testGetTitle()
156+
{
157+
$title = 'test02';
158+
$this->blockModel->setData(Block::TITLE, $title);
159+
$expected = $title;
160+
$actual = $this->blockModel->getTitle();
161+
self::assertEquals($expected, $actual);
162+
}
163+
164+
/**
165+
* Test getContent method
166+
*
167+
* @return void
168+
*/
169+
public function testGetContent()
170+
{
171+
$content = 'test03';
172+
$this->blockModel->setData(Block::CONTENT, $content);
173+
$expected = $content;
174+
$actual = $this->blockModel->getContent();
175+
self::assertEquals($expected, $actual);
176+
}
177+
178+
/**
179+
* Test getCreationTime method
180+
*
181+
* @return void
182+
*/
183+
public function testGetCreationTime()
184+
{
185+
$creationTime = 'test04';
186+
$this->blockModel->setData(Block::CREATION_TIME, $creationTime);
187+
$expected = $creationTime;
188+
$actual = $this->blockModel->getCreationTime();
189+
self::assertEquals($expected, $actual);
190+
}
191+
192+
/**
193+
* Test getUpdateTime method
194+
*
195+
* @return void
196+
*/
197+
public function testGetUpdateTime()
198+
{
199+
$updateTime = 'test05';
200+
$this->blockModel->setData(Block::UPDATE_TIME, $updateTime);
201+
$expected = $updateTime;
202+
$actual = $this->blockModel->getUpdateTime();
203+
self::assertEquals($expected, $actual);
204+
}
205+
206+
/**
207+
* Test isActive method
208+
*
209+
* @return void
210+
*/
211+
public function testIsActive()
212+
{
213+
$isActive = true;
214+
$this->blockModel->setData(Block::IS_ACTIVE, $isActive);
215+
$result = $this->blockModel->isActive();
216+
self::assertTrue($result);
217+
}
218+
219+
/**
220+
* Test setId method
221+
*
222+
* @return void
223+
*/
224+
public function testSetId()
225+
{
226+
$blockId = 15;
227+
$this->blockModel->setId($blockId);
228+
$expected = $blockId;
229+
$actual = $this->blockModel->getData(Block::BLOCK_ID);
230+
self::assertEquals($expected, $actual);
231+
}
232+
233+
/**
234+
* Test setIdentifier method
235+
*
236+
* @return void
237+
*/
238+
public function testSetIdentifier()
239+
{
240+
$identifier = 'test06';
241+
$this->blockModel->setIdentifier($identifier);
242+
$expected = $identifier;
243+
$actual = $this->blockModel->getData(Block::IDENTIFIER);
244+
self::assertEquals($expected, $actual);
245+
}
246+
247+
/**
248+
* Test setTitle method
249+
*
250+
* @return void
251+
*/
252+
public function testSetTitle()
253+
{
254+
$title = 'test07';
255+
$this->blockModel->setTitle($title);
256+
$expected = $title;
257+
$actual = $this->blockModel->getData(Block::TITLE);
258+
self::assertEquals($expected, $actual);
259+
}
260+
261+
/**
262+
* Test setContent method
263+
*
264+
* @return void
265+
*/
266+
public function testSetContent()
267+
{
268+
$content = 'test08';
269+
$this->blockModel->setContent($content);
270+
$expected = $content;
271+
$actual = $this->blockModel->getData(Block::CONTENT);
272+
self::assertEquals($expected, $actual);
273+
}
274+
275+
/**
276+
* Test setCreationTime method
277+
*
278+
* @return void
279+
*/
280+
public function testSetCreationTime()
281+
{
282+
$creationTime = 'test09';
283+
$this->blockModel->setCreationTime($creationTime);
284+
$expected = $creationTime;
285+
$actual = $this->blockModel->getData(Block::CREATION_TIME);
286+
self::assertEquals($expected, $actual);
287+
}
288+
289+
/**
290+
* Test setUpdateTime method
291+
*
292+
* @return void
293+
*/
294+
public function testSetUpdateTime()
295+
{
296+
$updateTime = 'test10';
297+
$this->blockModel->setUpdateTime($updateTime);
298+
$expected = $updateTime;
299+
$actual = $this->blockModel->getData(Block::UPDATE_TIME);
300+
self::assertEquals($expected, $actual);
301+
}
302+
303+
/**
304+
* Test setIsActive method
305+
*
306+
* @return void
307+
*/
308+
public function testSetIsActive()
309+
{
310+
$this->blockModel->setIsActive(false);
311+
$result = $this->blockModel->getData(Block::IS_ACTIVE);
312+
self::assertFalse($result);
313+
}
314+
315+
/**
316+
* Test getStores method
317+
*
318+
* @return void
319+
*/
320+
public function testGetStores()
321+
{
322+
$stores = [1, 4, 9];
323+
$this->blockModel->setData('stores', $stores);
324+
$expected = $stores;
325+
$actual = $this->blockModel->getStores();
326+
self::assertEquals($expected, $actual);
327+
}
328+
329+
/**
330+
* Test getAvailableStatuses method
331+
*
332+
* @return void
333+
*/
334+
public function testGetAvailableStatuses()
335+
{
336+
$result = $this->blockModel->getAvailableStatuses();
337+
self::assertInternalType('array', $result);
338+
}
339+
}

0 commit comments

Comments
 (0)