3
3
namespace Algolia \AlgoliaSearch \Test \Integration \Product ;
4
4
5
5
use Algolia \AlgoliaSearch \Api \Product \ReplicaManagerInterface ;
6
+ use Algolia \AlgoliaSearch \Console \Command \ReplicaRebuildCommand ;
7
+ use Algolia \AlgoliaSearch \Console \Command \ReplicaSyncCommand ;
6
8
use Algolia \AlgoliaSearch \Helper \ConfigHelper ;
9
+ use Algolia \AlgoliaSearch \Service \Product \SortingTransformer ;
7
10
use Algolia \AlgoliaSearch \Test \Integration \MultiStoreTestCase ;
11
+ use Algolia \AlgoliaSearch \Test \Integration \Product \Traits \ReplicaAssertionsTrait ;
8
12
use Magento \Framework \Serialize \SerializerInterface ;
9
13
use Magento \Store \Api \Data \StoreInterface ;
14
+ use Symfony \Component \Console \Input \InputInterface ;
15
+ use Symfony \Component \Console \Output \OutputInterface ;
10
16
11
17
/**
12
18
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
@@ -53,6 +59,80 @@ public function testMultiStoreReplicaConfig()
53
59
// Check replica config for color asc
54
60
$ this ->checkReplicaIsStandard ($ defaultStore , self ::COLOR_ATTR , self ::ASC_DIR );
55
61
$ this ->checkReplicaIsVirtual ($ fixtureSecondStore , self ::COLOR_ATTR , self ::ASC_DIR );
62
+
63
+ $ this ->resetAllSortings ();
64
+ }
65
+
66
+ public function testReplicaCommands ()
67
+ {
68
+ $ defaultStore = $ this ->storeRepository ->get ('default ' );
69
+ $ fixtureSecondStore = $ this ->storeRepository ->get ('fixture_second_store ' );
70
+
71
+ $ defaultIndexName = $ this ->indexPrefix . $ defaultStore ->getCode () . '_products ' ;
72
+ $ fixtureIndexName = $ this ->indexPrefix . $ fixtureSecondStore ->getCode () . '_products ' ;
73
+
74
+ // Update store config for fixture only
75
+ $ this ->mockSortUpdate ('price ' , 'desc ' , ['virtualReplica ' => 1 ], $ fixtureSecondStore );
76
+
77
+ $ defaultSortings = $ this ->objectManager ->get (SortingTransformer::class)->getSortingIndices (
78
+ $ defaultStore ->getId (),
79
+ null ,
80
+ null ,
81
+ true
82
+ );
83
+
84
+ $ fixtureSortings = $ this ->objectManager ->get (SortingTransformer::class)->getSortingIndices (
85
+ $ fixtureSecondStore ->getId (),
86
+ null ,
87
+ null ,
88
+ true
89
+ );
90
+
91
+ // Executing commands - Start
92
+ $ syncCmd = $ this ->objectManager ->get (ReplicaSyncCommand::class);
93
+ $ this ->mockProperty ($ syncCmd , 'output ' , OutputInterface::class);
94
+ $ syncCmd ->syncReplicas ();
95
+ $ this ->algoliaHelper ->waitLastTask ($ defaultStore ->getId ());
96
+ $ this ->algoliaHelper ->waitLastTask ($ fixtureSecondStore ->getId ());
97
+
98
+ $ rebuildCmd = $ this ->objectManager ->get (ReplicaRebuildCommand::class);
99
+ $ this ->invokeMethod (
100
+ $ rebuildCmd ,
101
+ 'execute ' ,
102
+ [
103
+ $ this ->createMock (InputInterface::class),
104
+ $ this ->createMock (OutputInterface::class)
105
+ ]
106
+ );
107
+ $ this ->algoliaHelper ->waitLastTask ($ defaultStore ->getId ());
108
+ $ this ->algoliaHelper ->waitLastTask ($ fixtureSecondStore ->getId ());
109
+ // Executing commands - End
110
+
111
+ $ currentDefaultSettings = $ this ->algoliaHelper ->getSettings ($ defaultIndexName , $ defaultStore ->getId ());
112
+ $ currentFixtureSettings = $ this ->algoliaHelper ->getSettings ($ fixtureIndexName , $ fixtureSecondStore ->getId ());
113
+
114
+ $ this ->assertArrayHasKey ('replicas ' , $ currentDefaultSettings );
115
+ $ this ->assertArrayHasKey ('replicas ' , $ currentFixtureSettings );
116
+
117
+ $ defaultReplicas = $ currentDefaultSettings ['replicas ' ];
118
+ $ fixtureReplicas = $ currentFixtureSettings ['replicas ' ];
119
+
120
+ $ this ->assertEquals (count ($ defaultSortings ), count ($ defaultReplicas ));
121
+ $ this ->assertEquals (count ($ fixtureSortings ), count ($ fixtureReplicas ));
122
+
123
+ $ this ->assertSortToReplicaConfigParity (
124
+ $ defaultIndexName ,
125
+ $ defaultSortings ,
126
+ $ defaultReplicas ,
127
+ $ defaultStore ->getId ()
128
+ );
129
+
130
+ $ this ->assertSortToReplicaConfigParity (
131
+ $ fixtureIndexName ,
132
+ $ fixtureSortings ,
133
+ $ fixtureReplicas ,
134
+ $ fixtureSecondStore ->getId ()
135
+ );
56
136
}
57
137
58
138
protected function checkReplicaIsStandard (StoreInterface $ store , $ sortAttr , $ sortDir )
@@ -112,7 +192,7 @@ protected function addSortingByStore(StoreInterface $store, $attr, $dir, $isVir
112
192
$ this ->algoliaHelper ->waitLastTask ($ store ->getId ());
113
193
}
114
194
115
- protected function tearDown (): void
195
+ protected function resetAllSortings ()
116
196
{
117
197
$ stores = $ this ->storeManager ->getStores ();
118
198
@@ -139,6 +219,11 @@ protected function tearDown(): void
139
219
$ store ->getCode ()
140
220
);
141
221
}
222
+ }
223
+
224
+ protected function tearDown (): void
225
+ {
226
+ $ this ->resetAllSortings ();
142
227
143
228
parent ::tearDown ();
144
229
}
0 commit comments