10
10
use Magento \Cms \Api \Data \BlockInterface ;
11
11
use Magento \Cms \Api \GetBlockByIdentifierInterface ;
12
12
use Magento \Cms \Block \BlockByIdentifier ;
13
+ use Magento \Cms \Model \Block ;
13
14
use Magento \Cms \Model \Template \FilterProvider ;
14
15
use Magento \Framework \App \Config \ScopeConfigInterface ;
15
16
use Magento \Framework \Event \ManagerInterface ;
21
22
use PHPUnit \Framework \MockObject \MockObject ;
22
23
use PHPUnit \Framework \TestCase ;
23
24
25
+ /**
26
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27
+ */
24
28
class BlockByIdentifierTest extends TestCase
25
29
{
26
30
private const STUB_MODULE_OUTPUT_DISABLED = false ;
@@ -37,6 +41,8 @@ class BlockByIdentifierTest extends TestCase
37
41
BlockByIdentifier::CACHE_KEY_PREFIX . '_ ' . self ::STUB_UNAVAILABLE_IDENTIFIER ,
38
42
BlockByIdentifier::CACHE_KEY_PREFIX . '_ ' . self ::STUB_UNAVAILABLE_IDENTIFIER . '_ ' . self ::STUB_DEFAULT_STORE
39
43
];
44
+ private const STUB_CMS_BLOCK_IDENTITY_BY_ID = 'CMS_BLOCK_ ' . self ::STUB_CMS_BLOCK_ID ;
45
+ private const STUB_CMS_BLOCK_IDENTITY_BY_IDENTIFIER = 'CMS_BLOCK_ ' . self ::STUB_EXISTING_IDENTIFIER ;
40
46
41
47
/** @var MockObject|GetBlockByIdentifierInterface */
42
48
private $ getBlockByIdentifierMock ;
@@ -108,14 +114,19 @@ public function testBlockReturnsCmsContentsWhenIdentifierFound(): void
108
114
$ this ->assertSame (self ::ASSERT_CONTENT_HTML , $ block ->toHtml ());
109
115
}
110
116
111
- public function testBlockCacheIdentitiesContainExplicitScopeInformation (): void
117
+ public function testBlockCacheIdentitiesContainCmsBlockIdentities (): void
112
118
{
113
119
// Given
114
- $ cmsBlockMock = $ this ->getCmsBlockMock (
115
- self ::STUB_CMS_BLOCK_ID ,
116
- self ::STUB_EXISTING_IDENTIFIER ,
117
- self ::STUB_CONTENT
120
+ $ cmsBlockMock = $ this ->createMock (Block::class);
121
+ $ cmsBlockMock ->method ('getId ' )->willReturn (self ::STUB_CMS_BLOCK_ID );
122
+ $ cmsBlockMock ->method ('getIdentifier ' )->willReturn (self ::STUB_EXISTING_IDENTIFIER );
123
+ $ cmsBlockMock ->method ('getIdentities ' )->willReturn (
124
+ [
125
+ self ::STUB_CMS_BLOCK_IDENTITY_BY_ID ,
126
+ self ::STUB_CMS_BLOCK_IDENTITY_BY_IDENTIFIER
127
+ ]
118
128
);
129
+
119
130
$ this ->storeMock ->method ('getId ' )->willReturn (self ::STUB_DEFAULT_STORE );
120
131
$ this ->getBlockByIdentifierMock ->method ('execute ' )
121
132
->with (self ::STUB_EXISTING_IDENTIFIER , self ::STUB_DEFAULT_STORE )
@@ -127,10 +138,8 @@ public function testBlockCacheIdentitiesContainExplicitScopeInformation(): void
127
138
128
139
// Then
129
140
$ this ->assertContains ($ this ->getIdentityStubById (self ::STUB_CMS_BLOCK_ID ), $ identities );
130
- $ this ->assertContains (
131
- $ this ->getIdentityStubByIdentifier (self ::STUB_EXISTING_IDENTIFIER , self ::STUB_DEFAULT_STORE ),
132
- $ identities
133
- );
141
+ $ this ->assertContains (self ::STUB_CMS_BLOCK_IDENTITY_BY_ID , $ identities );
142
+ $ this ->assertContains (self ::STUB_CMS_BLOCK_IDENTITY_BY_IDENTIFIER , $ identities );
134
143
}
135
144
136
145
/**
0 commit comments