Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CacheContextTest.php
Go to the documentation of this file.
1 <?php
8 
9 class CacheContextTest extends \PHPUnit\Framework\TestCase
10 {
14  protected $context;
15 
19  protected function setUp()
20  {
21  $this->context = new \Magento\Framework\Indexer\CacheContext();
22  }
23 
27  public function testRegisterEntities()
28  {
29  $cacheTag = 'tag';
30  $expectedIds = [1, 2, 3];
31  $this->context->registerEntities($cacheTag, $expectedIds);
32  $actualIds = $this->context->getRegisteredEntity($cacheTag);
33  $this->assertEquals($expectedIds, $actualIds);
34  }
35 
39  public function testGetIdentities()
40  {
41  $expectedIdentities = [
42  'product_1', 'product_2', 'product_3', 'category_5', 'category_6', 'category_7',
43  ];
44  $productTag = 'product';
45  $categoryTag = 'category';
46  $productIds = [1, 2, 3];
47  $categoryIds = [5, 6, 7];
48  $this->context->registerEntities($productTag, $productIds);
49  $this->context->registerEntities($categoryTag, $categoryIds);
50  $actualIdentities = $this->context->getIdentities();
51  $this->assertEquals($expectedIdentities, $actualIdentities);
52  }
53 }