3
3
namespace Algolia \AlgoliaSearch \Test \Unit \Plugin ;
4
4
5
5
use Algolia \AlgoliaSearch \Helper \ConfigHelper ;
6
+ use Algolia \AlgoliaSearch \Helper \Configuration \InstantSearchHelper ;
6
7
use Algolia \AlgoliaSearch \Plugin \RenderingCacheContextPlugin ;
7
8
use Magento \Framework \App \Http \Context as HttpContext ;
8
9
use Magento \Framework \App \Request \Http ;
9
10
use Magento \Store \Api \Data \StoreInterface ;
10
11
use Magento \Store \Model \StoreManagerInterface ;
11
12
use Magento \UrlRewrite \Model \UrlFinderInterface ;
12
13
use PHPUnit \Framework \TestCase ;
13
-
14
14
class RenderingCacheContextPluginTest extends TestCase
15
15
{
16
16
protected ?RenderingCacheContextPlugin $ plugin ;
17
17
protected ?ConfigHelper $ configHelper ;
18
+
19
+ protected ?InstantSearchHelper $ instantSearchHelper ;
18
20
protected ?StoreManagerInterface $ storeManager ;
19
21
protected ?Http $ request ;
20
22
protected ?UrlFinderInterface $ urlFinder ;
21
-
22
23
protected function setUp (): void
23
24
{
24
25
$ this ->configHelper = $ this ->createMock (ConfigHelper::class);
26
+ $ this ->instantSearchHelper = $ this ->createMock (InstantSearchHelper::class);
25
27
$ this ->storeManager = $ this ->createMock (StoreManagerInterface::class);
26
28
$ this ->request = $ this ->createMock (Http::class);
27
29
$ this ->urlFinder = $ this ->createMock (UrlFinderInterface::class);
28
30
29
31
$ this ->plugin = new RenderingCacheContextPluginTestable (
30
32
$ this ->configHelper ,
33
+ $ this ->instantSearchHelper ,
31
34
$ this ->storeManager ,
32
35
$ this ->request ,
33
36
$ this ->urlFinder
@@ -47,7 +50,7 @@ public function testAfterGetDataAddsRenderingContextNoBackendRender(): void
47
50
$ this ->storeManager ->method ('getStore ' )->willReturn ($ this ->getStoreMock ());
48
51
49
52
$ this ->request ->method ('getControllerName ' )->willReturn ('category ' );
50
- $ this ->configHelper ->method ('replaceCategories ' )->willReturn (true );
53
+ $ this ->instantSearchHelper ->method ('shouldReplaceCategories ' )->willReturn (true );
51
54
52
55
$ result = $ this ->plugin ->afterGetData (
53
56
$ this ->createMock (HttpContext::class),
@@ -66,7 +69,7 @@ public function testAfterGetDataAddsRenderingContextWithBackendRender(): void
66
69
$ this ->storeManager ->method ('getStore ' )->willReturn ($ this ->getStoreMock ());
67
70
68
71
$ this ->request ->method ('getControllerName ' )->willReturn ('category ' );
69
- $ this ->configHelper ->method ('replaceCategories ' )->willReturn (true );
72
+ $ this ->instantSearchHelper ->method ('shouldReplaceCategories ' )->willReturn (true );
70
73
71
74
$ result = $ this ->plugin ->afterGetData (
72
75
$ this ->createMock (HttpContext::class),
@@ -86,7 +89,7 @@ public function testAfterGetDataDoesNotModifyDataIfNotApplicable(): void
86
89
87
90
$ this ->request ->method ('getControllerName ' )->willReturn ('product ' );
88
91
$ this ->request ->method ('getRequestUri ' )->willReturn ('some-product.html ' );
89
- $ this ->configHelper ->method ('replaceCategories ' )->willReturn (false );
92
+ $ this ->instantSearchHelper ->method ('shouldReplaceCategories ' )->willReturn (false );
90
93
91
94
$ data = ['existing_key ' => 'existing_value ' ];
92
95
$ result = $ this ->plugin ->afterGetData ($ subject , $ data );
@@ -121,7 +124,7 @@ public function testShouldApplyCacheContext(): void
121
124
$ this ->storeManager ->method ('getStore ' )->willReturn ($ this ->getStoreMock ());
122
125
123
126
$ this ->request ->method ('getControllerName ' )->willReturn ('category ' );
124
- $ this ->configHelper ->method ('replaceCategories ' )->willReturn (true );
127
+ $ this ->instantSearchHelper ->method ('shouldReplaceCategories ' )->willReturn (true );
125
128
126
129
$ this ->assertTrue ($ this ->plugin ->shouldApplyCacheContext ());
127
130
}
0 commit comments