14
14
use Magento \Cms \Model \Template \FilterProvider ;
15
15
use Magento \Framework \App \Config \ScopeConfigInterface ;
16
16
use Magento \Framework \Event \ManagerInterface ;
17
+ use Magento \Framework \Exception \NoSuchEntityException ;
17
18
use Magento \Framework \Filter \Template ;
18
19
use Magento \Framework \View \Element \Context ;
19
20
use Magento \Store \Api \Data \StoreInterface ;
@@ -25,13 +26,18 @@ class BlockByIdentifierTest extends TestCase
25
26
{
26
27
private const STUB_MODULE_OUTPUT_DISABLED = false ;
27
28
private const STUB_EXISTING_IDENTIFIER = 'existingOne ' ;
29
+ private const STUB_UNAVAILABLE_IDENTIFIER = 'notExists ' ;
28
30
private const STUB_DEFAULT_STORE = 1 ;
29
31
private const STUB_CMS_BLOCK_ID = 1 ;
30
32
private const STUB_CONTENT = 'Content ' ;
31
33
32
34
private const ASSERT_EMPTY_BLOCK_HTML = '' ;
33
35
private const ASSERT_CONTENT_HTML = self ::STUB_CONTENT ;
34
36
private const ASSERT_NO_CACHE_IDENTITIES = [];
37
+ private const ASSERT_UNAVAILABLE_IDENTIFIER_BASED_IDENTITIES = [
38
+ BlockByIdentifier::CACHE_KEY_PREFIX . '_ ' . self ::STUB_UNAVAILABLE_IDENTIFIER ,
39
+ BlockByIdentifier::CACHE_KEY_PREFIX . '_ ' . self ::STUB_UNAVAILABLE_IDENTIFIER . '_ ' . self ::STUB_DEFAULT_STORE
40
+ ];
35
41
36
42
/** @var MockObject|GetBlockByIdentifierInterface */
37
43
private $ getBlockByIdentifierMock ;
@@ -61,12 +67,30 @@ public function testBlockReturnsEmptyStringWhenNoIdentifierProvided(): void
61
67
{
62
68
// Given
63
69
$ missingIdentifierBlock = $ this ->getTestedBlockUsingIdentifier (null );
70
+ $ this ->storeMock ->method ('getId ' )->willReturn (self ::STUB_DEFAULT_STORE );
64
71
65
72
// Expect
66
73
$ this ->assertSame (self ::ASSERT_EMPTY_BLOCK_HTML , $ missingIdentifierBlock ->toHtml ());
67
74
$ this ->assertSame (self ::ASSERT_NO_CACHE_IDENTITIES , $ missingIdentifierBlock ->getIdentities ());
68
75
}
69
76
77
+ public function testBlockReturnsEmptyStringWhenIdentifierProvidedNotFound (): void
78
+ {
79
+ // Given
80
+ $ this ->getBlockByIdentifierMock ->method ('execute ' )->willThrowException (
81
+ new NoSuchEntityException (__ ('NoSuchEntityException ' ))
82
+ );
83
+ $ missingIdentifierBlock = $ this ->getTestedBlockUsingIdentifier (self ::STUB_UNAVAILABLE_IDENTIFIER );
84
+ $ this ->storeMock ->method ('getId ' )->willReturn (self ::STUB_DEFAULT_STORE );
85
+
86
+ // Expect
87
+ $ this ->assertSame (self ::ASSERT_EMPTY_BLOCK_HTML , $ missingIdentifierBlock ->toHtml ());
88
+ $ this ->assertSame (
89
+ self ::ASSERT_UNAVAILABLE_IDENTIFIER_BASED_IDENTITIES ,
90
+ $ missingIdentifierBlock ->getIdentities ()
91
+ );
92
+ }
93
+
70
94
public function testBlockReturnsCmsContentsWhenIdentifierFound (): void
71
95
{
72
96
// Given
0 commit comments