Skip to content

Commit 93e9698

Browse files
committed
MAGE-1044 Test sorting attribute via ConfigHelper
1 parent f675d31 commit 93e9698

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

Test/Integration/Product/ReplicaIndexingTest.php

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
class ReplicaIndexingTest extends IndexingTestCase
1212
{
13-
protected ?ReplicaManagerInterface $replicaManager;
14-
protected ?ProductIndexer $productIndexer;
13+
protected ?ReplicaManagerInterface $replicaManager = null;
14+
protected ?ProductIndexer $productIndexer = null;
1515

16-
protected ?IndicesConfigurator $indicesConfigurator;
16+
protected ?IndicesConfigurator $indicesConfigurator = null;
1717

18-
protected ?string $indexSuffix;
18+
protected ?string $indexSuffix = null;
1919

20-
protected ?array $ogSortingState;
20+
protected ?array $ogSortingState = null;
2121

2222
public function setUp(): void
2323
{
@@ -107,6 +107,7 @@ function($replica) use ($sortIndexName) {
107107

108108
/**
109109
* @magentoDbIsolation disabled
110+
* @group virtual
110111
*/
111112
public function testVirtualReplicaConfig(): void
112113
{
@@ -124,33 +125,13 @@ public function testVirtualReplicaConfig(): void
124125
'sort' => $sortDir,
125126
'sortLabel' => $sortAttr
126127
];
127-
$encoded = json_encode($sorting);
128-
// $this->setConfig('algoliasearch_instant/instant_sorts/sorts', $encoded);
129128
$this->configHelper->setSorting($sorting);
130129

131-
$connection = $this->objectManager->create(\Magento\Framework\App\ResourceConnection::class)
132-
->getConnection();
133-
// $connection->beginTransaction();
134-
// $this->objectManager->get(\Magento\Framework\App\Config\Storage\WriterInterface::class)->save(
135-
// \Algolia\AlgoliaSearch\Helper\ConfigHelper::SORTING_INDICES,
136-
// $encoded,
137-
// 'default'
138-
// );
139-
// $connection->commit();
130+
$this->assertConfigInDb('algoliasearch_instant/instant_sorts/sorts', json_encode($sorting));
140131

132+
$this->refreshConfigFromDb();
141133

142-
$select = $connection->select()
143-
->from('core_config_data', 'value')
144-
->where('path = ?', 'algoliasearch_instant/instant_sorts/sorts')
145-
->where('scope = ?', 'default')
146-
->where('scope_id = ?', 0);
147-
148-
$configValue = $connection->fetchOne($select);
149-
150-
// Assert that the correct value was written to the database
151-
$this->assertEquals($encoded, $configValue);
152-
153-
// $this->assertSortingAttribute($sortAttr, $sortDir);
134+
$this->assertSortingAttribute($sortAttr, $sortDir);
154135

155136
}
156137

Test/Integration/TestCase.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Algolia\AlgoliaSearch\Setup\Patch\Schema\ConfigPatch;
99
use Algolia\AlgoliaSearch\Test\Integration\AssertValues\Magento246;
1010
use Algolia\AlgoliaSearch\Test\Integration\AssertValues\Magento247;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1112
use Magento\Framework\App\ProductMetadataInterface;
1213
use Magento\Framework\ObjectManagerInterface;
1314
use Magento\Store\Model\ScopeInterface;
@@ -78,6 +79,32 @@ protected function setConfig(
7879
);
7980
}
8081

82+
protected function assertConfigInDb(
83+
string $path,
84+
mixed $value,
85+
string $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
86+
int $scopeId = 0
87+
): void
88+
{
89+
$connection = $this->objectManager->create(\Magento\Framework\App\ResourceConnection::class)
90+
->getConnection();
91+
92+
$select = $connection->select()
93+
->from('core_config_data', 'value')
94+
->where('path = ?', $path)
95+
->where('scope = ?', $scope)
96+
->where('scope_id = ?', $scopeId);
97+
98+
$configValue = $connection->fetchOne($select);
99+
100+
$this->assertEquals($value, $configValue);
101+
}
102+
103+
protected function refreshConfigFromDb(): void
104+
{
105+
$this->objectManager->get(\Magento\Framework\App\Config\ReinitableConfigInterface::class)->reinit();
106+
}
107+
81108
protected function clearIndices()
82109
{
83110
$indices = $this->algoliaHelper->listIndexes();
@@ -107,7 +134,7 @@ private function bootstrap()
107134
return;
108135
}
109136

110-
$this->objectManager = Bootstrap::getObjectManager();
137+
$this->objectManager = $this->getObjectManager();
111138

112139
if (version_compare($this->getMagentoVersion(), '2.4.7', '<')) {
113140
$this->assertValues = new Magento246();

0 commit comments

Comments
 (0)