1414use Magento \Cms \Model \Template \FilterProvider ;
1515use Magento \Framework \App \Config \ScopeConfigInterface ;
1616use Magento \Framework \Event \ManagerInterface ;
17+ use Magento \Framework \Exception \NoSuchEntityException ;
1718use Magento \Framework \Filter \Template ;
1819use Magento \Framework \View \Element \Context ;
1920use Magento \Store \Api \Data \StoreInterface ;
@@ -25,13 +26,18 @@ class BlockByIdentifierTest extends TestCase
2526{
2627 private const STUB_MODULE_OUTPUT_DISABLED = false ;
2728 private const STUB_EXISTING_IDENTIFIER = 'existingOne ' ;
29+ private const STUB_UNAVAILABLE_IDENTIFIER = 'notExists ' ;
2830 private const STUB_DEFAULT_STORE = 1 ;
2931 private const STUB_CMS_BLOCK_ID = 1 ;
3032 private const STUB_CONTENT = 'Content ' ;
3133
3234 private const ASSERT_EMPTY_BLOCK_HTML = '' ;
3335 private const ASSERT_CONTENT_HTML = self ::STUB_CONTENT ;
3436 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+ ];
3541
3642 /** @var MockObject|GetBlockByIdentifierInterface */
3743 private $ getBlockByIdentifierMock ;
@@ -61,12 +67,30 @@ public function testBlockReturnsEmptyStringWhenNoIdentifierProvided(): void
6167 {
6268 // Given
6369 $ missingIdentifierBlock = $ this ->getTestedBlockUsingIdentifier (null );
70+ $ this ->storeMock ->method ('getId ' )->willReturn (self ::STUB_DEFAULT_STORE );
6471
6572 // Expect
6673 $ this ->assertSame (self ::ASSERT_EMPTY_BLOCK_HTML , $ missingIdentifierBlock ->toHtml ());
6774 $ this ->assertSame (self ::ASSERT_NO_CACHE_IDENTITIES , $ missingIdentifierBlock ->getIdentities ());
6875 }
6976
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+
7094 public function testBlockReturnsCmsContentsWhenIdentifierFound (): void
7195 {
7296 // Given
0 commit comments