5
5
*/
6
6
namespace Magento \Cms \Model ;
7
7
8
+ use Magento \Cms \Model \ResourceModel \Block ;
9
+ use Magento \Cms \Model \BlockFactory ;
10
+ use Magento \Framework \ObjectManagerInterface ;
11
+ use Magento \Framework \Stdlib \DateTime \DateTime ;
12
+ use Magento \TestFramework \Helper \Bootstrap ;
13
+ use PHPUnit \Framework \TestCase ;
14
+
8
15
/**
9
16
* @magentoAppArea adminhtml
10
17
*/
11
- class BlockTest extends \ PHPUnit \ Framework \ TestCase
18
+ class BlockTest extends TestCase
12
19
{
20
+
21
+ /**
22
+ * @var ObjectManagerInterface
23
+ */
24
+ private $ objectManager ;
25
+
26
+ /**
27
+ * @var Block
28
+ */
29
+ private $ blockResource ;
30
+
31
+ /**
32
+ * @var BlockFactory
33
+ */
34
+ private $ blockFactory ;
35
+
36
+ /**
37
+ * @var GetBlockByIdentifier
38
+ */
39
+ private $ blockIdentifier ;
40
+
41
+ protected function setUp ()
42
+ {
43
+ $ this ->objectManager = Bootstrap::getObjectManager ();
44
+
45
+ /** @var BlockFactory $blockFactory */
46
+ /** @var Block $blockResource */
47
+ /** @var GetBlockByIdentifier $getBlockByIdentifierCommand */
48
+ $ this ->blockResource = $ this ->objectManager ->create (Block::class);
49
+ $ this ->blockFactory = $ this ->objectManager ->create (BlockFactory::class);
50
+ $ this ->blockIdentifier = $ this ->objectManager ->create (GetBlockByIdentifier::class);
51
+ }
52
+
13
53
/**
14
54
* Tests the get by identifier command
15
55
* @param array $blockData
@@ -20,40 +60,55 @@ class BlockTest extends \PHPUnit\Framework\TestCase
20
60
*/
21
61
public function testGetByIdentifier (array $ blockData )
22
62
{
23
- $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
63
+ # Prepare and save the temporary block
64
+ $ tempBlock = $ this ->blockFactory ->create ();
65
+ $ tempBlock ->setData ($ blockData );
66
+ $ this ->blockResource ->save ($ tempBlock );
24
67
25
- /** @var \Magento\Cms\Model\BlockFactory $blockFactory */
26
- /** @var \Magento\Cms\Model\ResourceModel\Block $blockResource */
27
- /** @var \Magento\Cms\Model\GetBlockByIdentifier $getBlockByIdentifierCommand */
28
- $ blockResource = $ objectManager ->create (\Magento \Cms \Model \ResourceModel \Block::class);
29
- $ blockFactory = $ objectManager ->create (\Magento \Cms \Model \BlockFactory::class);
30
- $ getBlockByIdentifierCommand = $ objectManager ->create (\Magento \Cms \Model \GetBlockByIdentifier::class);
68
+ # Load previously created block and compare identifiers
69
+ $ storeId = reset ($ blockData ['stores ' ]);
70
+ $ block = $ this ->blockIdentifier ->execute ($ blockData ['identifier ' ], $ storeId );
71
+ $ this ->assertEquals ($ blockData ['identifier ' ], $ block ->getIdentifier ());
72
+ }
31
73
74
+ /**
75
+ * Tests the get by identifier command
76
+ * @param array $blockData
77
+ * @throws \Exception
78
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
79
+ * @magentoDbIsolation enabled
80
+ * @dataProvider testGetByIdentifierDataProvider
81
+ */
82
+ public function testUpdateTime (array $ blockData )
83
+ {
32
84
# Prepare and save the temporary block
33
- $ tempBlock = $ blockFactory ->create ();
85
+ $ tempBlock = $ this -> blockFactory ->create ();
34
86
$ tempBlock ->setData ($ blockData );
35
- $ blockResource ->save ($ tempBlock );
87
+ $ this -> blockResource ->save ($ tempBlock );
36
88
37
89
# Load previously created block and compare identifiers
38
90
$ storeId = reset ($ blockData ['stores ' ]);
39
- $ block = $ getBlockByIdentifierCommand ->execute ($ blockData ['identifier ' ], $ storeId );
40
- $ this ->assertEquals ($ blockData ['identifier ' ], $ block ->getIdentifier ());
91
+ $ block = $ this ->blockIdentifier ->execute ($ blockData ['identifier ' ], $ storeId );
92
+ $ date = $ this ->objectManager ->get (DateTime::class)->date ();
93
+ $ this ->assertEquals ($ date , $ block ->getUpdateTime ());
41
94
}
42
95
43
96
/**
44
- * Data provider for "testGetByIdentifier" method
97
+ * Data provider for "testGetByIdentifier" and "testUpdateTime" method
45
98
* @return array
46
99
*/
47
- public function testGetByIdentifierDataProvider () : array
100
+ public function testGetByIdentifierDataProvider (): array
48
101
{
49
102
return [
50
- ['data ' => [
51
- 'title ' => 'Test title ' ,
52
- 'stores ' => [0 ],
53
- 'identifier ' => 'test-identifier ' ,
54
- 'content ' => 'Test content ' ,
55
- 'is_active ' => 1
56
- ]]
103
+ [
104
+ 'data ' => [
105
+ 'title ' => 'Test title ' ,
106
+ 'stores ' => [0 ],
107
+ 'identifier ' => 'test-identifier ' ,
108
+ 'content ' => 'Test content ' ,
109
+ 'is_active ' => 1
110
+ ]
111
+ ]
57
112
];
58
113
}
59
114
}
0 commit comments