|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright © Magento, Inc. All rights reserved. |
| 5 | + * See COPYING.txt for license details. |
| 6 | + */ |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\Framework\Indexer\Test\Unit; |
| 10 | + |
| 11 | +use Magento\Framework\Indexer\CacheContext; |
| 12 | +use PHPUnit\Framework\TestCase; |
| 13 | + |
| 14 | +class CacheContextTest extends TestCase |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var Batch |
| 18 | + */ |
| 19 | + private $object; |
| 20 | + |
| 21 | + protected function setUp(): void |
| 22 | + { |
| 23 | + $this->object = new CacheContext(); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @param array $tagsData |
| 28 | + * @param array $expected |
| 29 | + * @dataProvider getTagsDataProvider |
| 30 | + */ |
| 31 | + public function testUniqueTags($tagsData, $expected) |
| 32 | + { |
| 33 | + foreach ($tagsData as $tagSet) { |
| 34 | + foreach ($tagSet as $cacheTag => $ids) { |
| 35 | + $this->object->registerEntities($cacheTag, $ids); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + $this->assertEquals($this->object->getIdentities(), $expected); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @return array |
| 44 | + */ |
| 45 | + public function getTagsDataProvider() |
| 46 | + { |
| 47 | + return [ |
| 48 | + 'same entities and ids' => [ |
| 49 | + [['cat_p' => [1]], ['cat_p' => [1]]], |
| 50 | + ['cat_p_1'] |
| 51 | + ], |
| 52 | + 'same entities with overlapping ids' => [ |
| 53 | + [['cat_p' => [1, 2, 3]], ['cat_p' => [3]]], |
| 54 | + ['cat_p_1', 'cat_p_2', 'cat_p_3'] |
| 55 | + ] |
| 56 | + ]; |
| 57 | + } |
| 58 | +} |
| 59 | + |
0 commit comments