Skip to content

Commit c4daea5

Browse files
authored
Make changes to pass new Marketplace test expectations (#906)
1 parent bd01918 commit c4daea5

File tree

8 files changed

+56
-24
lines changed

8 files changed

+56
-24
lines changed

Helper/ConfigHelper.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Framework\App\Filesystem\DirectoryList;
99
use Magento\Framework\DataObject;
1010
use Magento\Framework\Locale\Currency;
11+
use Magento\Framework\Serialize\SerializerInterface;
1112
use Magento\Store\Model\ScopeInterface;
1213
use Magento\Store\Model\StoreManagerInterface;
1314

@@ -119,6 +120,7 @@ class ConfigHelper
119120
private $productMetadata;
120121
private $eventManager;
121122
private $currencyManager;
123+
private $serializer;
122124
private $maxRecordSize;
123125

124126
public function __construct(
@@ -131,7 +133,8 @@ public function __construct(
131133
Magento\Framework\Module\ResourceInterface $moduleResource,
132134
Magento\Framework\App\ProductMetadataInterface $productMetadata,
133135
Magento\Framework\Event\ManagerInterface $eventManager,
134-
Magento\Directory\Model\Currency $currencyManager
136+
Magento\Directory\Model\Currency $currencyManager,
137+
SerializerInterface $serializer
135138
) {
136139
$this->objectManager = $objectManager;
137140
$this->configInterface = $configInterface;
@@ -143,6 +146,7 @@ public function __construct(
143146
$this->productMetadata = $productMetadata;
144147
$this->eventManager = $eventManager;
145148
$this->currencyManager = $currencyManager;
149+
$this->serializer = $serializer;
146150
}
147151

148152
public function indexOutOfStockOptions($storeId = null)
@@ -1063,13 +1067,17 @@ private function addIndexableAttributes(
10631067

10641068
private function unserialize($value)
10651069
{
1070+
if (false === $value || null === $value || '' === $value) {
1071+
return false;
1072+
}
1073+
10661074
$unserialized = json_decode($value, true);
10671075

10681076
if (json_last_error() === JSON_ERROR_NONE) {
10691077
return $unserialized;
10701078
}
10711079

1072-
return unserialize($value);
1080+
return $this->serializer->unserialize($value);
10731081
}
10741082

10751083
public function getDefaultMaxRecordSize()

Helper/Entity/PageHelper.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,22 +162,24 @@ private function strip($s, $completeRemoveTags = [])
162162
{
163163
if ($completeRemoveTags && $completeRemoveTags !== [] && $s) {
164164
$dom = new \DOMDocument();
165-
if (@$dom->loadHTML(mb_convert_encoding($s, 'HTML-ENTITIES', 'UTF-8'))) {
166-
$toRemove = [];
167-
foreach ($completeRemoveTags as $tag) {
168-
$removeTags = $dom->getElementsByTagName($tag);
169-
170-
foreach ($removeTags as $item) {
171-
$toRemove[] = $item;
172-
}
173-
}
165+
libxml_use_internal_errors(true);
166+
$dom->loadHTML(mb_convert_encoding($s, 'HTML-ENTITIES', 'UTF-8'));
167+
libxml_use_internal_errors(false);
168+
169+
$toRemove = [];
170+
foreach ($completeRemoveTags as $tag) {
171+
$removeTags = $dom->getElementsByTagName($tag);
174172

175-
foreach ($toRemove as $item) {
176-
$item->parentNode->removeChild($item);
173+
foreach ($removeTags as $item) {
174+
$toRemove[] = $item;
177175
}
176+
}
178177

179-
$s = $dom->saveHTML();
178+
foreach ($toRemove as $item) {
179+
$item->parentNode->removeChild($item);
180180
}
181+
182+
$s = $dom->saveHTML();
181183
}
182184

183185
$s = html_entity_decode($s, null, 'UTF-8');

Helper/Entity/SuggestionHelper.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Magento\Framework\DataObject;
88
use Magento\Framework\Event\ManagerInterface;
99
use Magento\Framework\ObjectManagerInterface;
10+
use Magento\Framework\Serialize\SerializerInterface;
1011
use Magento\Search\Model\Query;
1112

1213
class SuggestionHelper
@@ -19,18 +20,22 @@ class SuggestionHelper
1920

2021
private $configHelper;
2122

23+
private $serializer;
24+
2225
private $popularQueriesCacheId = 'algoliasearch_popular_queries_cache_tag';
2326

2427
public function __construct(
2528
ManagerInterface $eventManager,
2629
ObjectManagerInterface $objectManager,
2730
ConfigCache $cache,
28-
ConfigHelper $configHelper
31+
ConfigHelper $configHelper,
32+
SerializerInterface $serializer
2933
) {
3034
$this->eventManager = $eventManager;
3135
$this->objectManager = $objectManager;
3236
$this->cache = $cache;
3337
$this->configHelper = $configHelper;
38+
$this->serializer = $serializer;
3439
}
3540

3641
public function getIndexNameSuffix()
@@ -81,7 +86,7 @@ public function getPopularQueries($storeId)
8186
{
8287
$queries = $this->cache->load($this->popularQueriesCacheId);
8388
if ($queries !== false) {
84-
return unserialize($queries);
89+
return $this->serializer->unserialize($queries);
8590
}
8691

8792
$collection = $this->objectManager->create('\Magento\Search\Model\ResourceModel\Query\Collection');
@@ -111,7 +116,7 @@ public function getPopularQueries($storeId)
111116

112117
$queries = array_slice($suggestions, 0, 9);
113118

114-
$this->cache->save(serialize($queries), $this->popularQueriesCacheId, [], 24*3600);
119+
$this->cache->save($this->serializer->serialize($queries), $this->popularQueriesCacheId, [], 24*3600);
115120

116121
return $queries;
117122
}

Test/Integration/CategoriesIndexingTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ public function testCategories()
1515

1616
public function testDefaultIndexableAttributes()
1717
{
18-
$this->setConfig('algoliasearch_categories/categories/category_additional_attributes', serialize([]));
18+
$this->setConfig(
19+
'algoliasearch_categories/categories/category_additional_attributes',
20+
$this->getSerializer()->serialize([])
21+
);
1922

2023
/** @var Category $categoriesIndexer */
2124
$categoriesIndexer = $this->getObjectManager()->create('\Algolia\AlgoliaSearch\Model\Indexer\Category');

Test/Integration/ConfigTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testAutomaticalSetOfCategoriesFacet()
6565
}
6666
}
6767

68-
$this->setConfig('algoliasearch_instant/instant/facets', serialize($facets));
68+
$this->setConfig('algoliasearch_instant/instant/facets', $this->getSerializer()->serialize($facets));
6969

7070
// Set don't replace category pages with Algolia - categories attribute shouldn't be included in facets
7171
$this->setConfig('algoliasearch_instant/instant/replace_categories', '0');
@@ -172,7 +172,7 @@ private function replicaCreationTest($withCustomerGroups = false)
172172
];
173173

174174
$this->setConfig('algoliasearch_instant/instant/is_instant_enabled', '1'); // Needed to set replicas to Algolia
175-
$this->setConfig('algoliasearch_instant/instant/sorts', serialize($sortingIndicesData));
175+
$this->setConfig('algoliasearch_instant/instant/sorts', $this->getSerializer()->serialize($sortingIndicesData));
176176
$this->setConfig('algoliasearch_advanced/advanced/customer_groups_enable', $enableCustomGroups);
177177

178178
$sortingIndicesWithRankingWhichShouldBeCreated = [

Test/Integration/PagesIndexingTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ class PagesIndexingTest extends IndexingTestCase
99
{
1010
public function testOnlyOnStockProducts()
1111
{
12-
$this->setConfig('algoliasearch_autocomplete/autocomplete/excluded_pages', serialize([]));
12+
$this->setConfig(
13+
'algoliasearch_autocomplete/autocomplete/excluded_pages',
14+
$this->getSerializer()->serialize([])
15+
);
1316

1417
/** @var Page $indexer */
1518
$indexer = $this->getObjectManager()->create('\Algolia\AlgoliaSearch\Model\Indexer\Page');
@@ -23,7 +26,10 @@ public function testExcludedPages()
2326
['attribute' => 'no-route'],
2427
['attribute' => 'home'],
2528
];
26-
$this->setConfig('algoliasearch_autocomplete/autocomplete/excluded_pages', serialize($excludedPages));
29+
$this->setConfig(
30+
'algoliasearch_autocomplete/autocomplete/excluded_pages',
31+
$this->getSerializer()->serialize($excludedPages)
32+
);
2733

2834
/** @var Page $indexer */
2935
$indexer = $this->getObjectManager()->create('\Algolia\AlgoliaSearch\Model\Indexer\Page');

Test/Integration/ProductsIndexingTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testIncludingOutOfStock()
3333

3434
public function testDefaultIndexableAttributes()
3535
{
36-
$empty = serialize([]);
36+
$empty = $this->getSerializer()->serialize([]);
3737

3838
$this->setConfig('algoliasearch_products/products/product_additional_attributes', $empty);
3939
$this->setConfig('algoliasearch_instant/instant/facets', $empty);
@@ -89,7 +89,10 @@ public function testNoProtocolImageUrls()
8989
'order' => 'unordered',
9090
];
9191

92-
$this->setConfig('algoliasearch_products/products/product_additional_attributes', serialize($additionAttributes));
92+
$this->setConfig(
93+
'algoliasearch_products/products/product_additional_attributes',
94+
$this->getSerializer()->serialize($additionAttributes)
95+
);
9396

9497
/** @var Product $indexer */
9598
$indexer = $this->getObjectManager()->create('\Algolia\AlgoliaSearch\Model\Indexer\Product');

Test/Integration/TestCase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,9 @@ private function getMagentoVersion()
149149

150150
return $productMetadata->getVersion();
151151
}
152+
153+
protected function getSerializer()
154+
{
155+
return $this->getObjectManager()->get('Magento\Framework\Serialize\SerializerInterface');
156+
}
152157
}

0 commit comments

Comments
 (0)