99
1010namespace OxidEsales \Twig \Tests \Unit \Resolver \TemplateChain ;
1111
12- use OxidEsales \EshopCommunity \Internal \Framework \Module \Configuration \Dao \ShopConfigurationDaoInterface ;
12+ use OxidEsales \EshopCommunity \Internal \Framework \Module \Configuration \Dao \Chain \ TemplateExtensionChainDaoInterface ;
1313use OxidEsales \EshopCommunity \Internal \Framework \Module \Configuration \DataObject \ModuleTemplateExtensionChain ;
14- use OxidEsales \EshopCommunity \Internal \Framework \Module \Configuration \DataObject \ShopConfiguration ;
1514use OxidEsales \EshopCommunity \Internal \Transition \Utility \ContextInterface ;
1615use OxidEsales \Twig \Resolver \TemplateChain \DataObject \TemplateChain ;
1716use OxidEsales \Twig \Resolver \TemplateChain \InvalidSortingConfigurationException ;
@@ -162,17 +161,49 @@ public function testSortWithADuplicatedModuleIdInConfigurationWillCallLogger():
162161 $ this ->logger ->error (Argument::type ('string ' ))->shouldHaveBeenCalled ();
163162 }
164163
164+ public function testSortWithMultipleCallsWillUseCachedShopConfiguration (): void
165+ {
166+ $ shopId = 1 ;
167+ $ templateModule1 = new ModuleTemplateType ('template1 ' , 'module1 ' );
168+ $ chain = new TemplateChain ();
169+ $ chain ->append ($ templateModule1 );
170+
171+ $ moduleTemplateExtensionsChain = new ModuleTemplateExtensionChain ([]);
172+
173+ $ templateExtensionChainDao = $ this ->prophesize (TemplateExtensionChainDaoInterface::class);
174+ $ templateExtensionChainDao ->getChain ($ shopId )->willReturn ($ moduleTemplateExtensionsChain )->shouldBeCalledOnce ();
175+
176+ $ context = $ this ->prophesize (ContextInterface::class);
177+ $ context ->getCurrentShopId ()->willReturn ($ shopId );
178+
179+ $ this ->sortingConfigurationValidator = $ this ->prophesize (SortingConfigurationValidatorInterface::class);
180+ $ this ->logger = $ this ->prophesize (LoggerInterface::class);
181+
182+ $ this ->chainSorter = new TemplateChainSorter (
183+ $ this ->sortingConfigurationValidator ->reveal (),
184+ $ templateExtensionChainDao ->reveal (),
185+ $ context ->reveal (),
186+ $ this ->logger ->reveal (),
187+ );
188+
189+ $ chain1 = new TemplateChain ();
190+ $ chain1 ->append ($ templateModule1 );
191+ $ this ->chainSorter ->sort ($ chain1 , $ templateModule1 );
192+
193+ $ chain2 = new TemplateChain ();
194+ $ chain2 ->append ($ templateModule1 );
195+ $ this ->chainSorter ->sort ($ chain2 , $ templateModule1 );
196+ }
197+
165198 private function prepareChainSortersConfiguration (string $ templateName , array $ loadOrder ): void
166199 {
167200 $ shopId = 1 ;
168201 $ moduleTemplateExtensionsChain = new ModuleTemplateExtensionChain ([$ templateName => $ loadOrder ]);
169202
170- $ shopConfiguration = $ this ->prophesize (ShopConfiguration::class);
171- $ shopConfigurationDao = $ this ->prophesize (ShopConfigurationDaoInterface::class);
203+ $ templateExtensionChainDao = $ this ->prophesize (TemplateExtensionChainDaoInterface::class);
172204 $ context = $ this ->prophesize (ContextInterface::class);
173205
174- $ shopConfiguration ->getModuleTemplateExtensionChain ()->willReturn ($ moduleTemplateExtensionsChain );
175- $ shopConfigurationDao ->get ($ shopId )->willReturn ($ shopConfiguration );
206+ $ templateExtensionChainDao ->getChain ($ shopId )->willReturn ($ moduleTemplateExtensionsChain );
176207 $ context ->getCurrentShopId ()->willReturn ($ shopId );
177208
178209 $ this ->logger = $ this ->prophesize (LoggerInterface::class);
@@ -181,7 +212,7 @@ private function prepareChainSortersConfiguration(string $templateName, array $l
181212
182213 $ this ->chainSorter = new TemplateChainSorter (
183214 $ this ->sortingConfigurationValidator ->reveal (),
184- $ shopConfigurationDao ->reveal (),
215+ $ templateExtensionChainDao ->reveal (),
185216 $ context ->reveal (),
186217 $ this ->logger ->reveal (),
187218 );
0 commit comments