diff --git a/lib/internal/Magento/Framework/Indexer/CacheContext.php b/lib/internal/Magento/Framework/Indexer/CacheContext.php index 4a6964477ebd5..b29aafa054997 100644 --- a/lib/internal/Magento/Framework/Indexer/CacheContext.php +++ b/lib/internal/Magento/Framework/Indexer/CacheContext.php @@ -73,6 +73,6 @@ public function getIdentities() $identities[] = $cacheTag . '_' . $id; } } - return array_merge($identities, array_unique($this->tags)); + return array_unique(array_merge($identities, array_unique($this->tags))); } } diff --git a/lib/internal/Magento/Framework/Indexer/Test/Unit/CacheContextTest.php b/lib/internal/Magento/Framework/Indexer/Test/Unit/CacheContextTest.php new file mode 100644 index 0000000000000..a13d5d54aafe7 --- /dev/null +++ b/lib/internal/Magento/Framework/Indexer/Test/Unit/CacheContextTest.php @@ -0,0 +1,58 @@ +object = new CacheContext(); + } + + /** + * @param array $tagsData + * @param array $expected + * @dataProvider getTagsDataProvider + */ + public function testUniqueTags($tagsData, $expected) + { + foreach ($tagsData as $tagSet) { + foreach ($tagSet as $cacheTag => $ids) { + $this->object->registerEntities($cacheTag, $ids); + } + } + + $this->assertEquals($this->object->getIdentities(), $expected); + } + + /** + * @return array + */ + public function getTagsDataProvider() + { + return [ + 'same entities and ids' => [ + [['cat_p' => [1]], ['cat_p' => [1]]], + ['cat_p_1'] + ], + 'same entities with overlapping ids' => [ + [['cat_p' => [1, 2, 3]], ['cat_p' => [3]]], + ['cat_p_1', 'cat_p_2', 'cat_p_3'] + ] + ]; + } +}