Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CacheInvalidateTest.php
Go to the documentation of this file.
1 <?php
7 
8 class CacheInvalidateTest extends \PHPUnit\Framework\TestCase
9 {
13  private $typeList;
14 
18  private $swatchHelper;
19 
23  private $attribute;
24 
28  private $cacheInvalidate;
29 
30  protected function setUp()
31  {
32  $this->typeList = $this->createMock(\Magento\Framework\App\Cache\TypeListInterface::class);
33  $this->swatchHelper = $this->createMock(\Magento\Swatches\Helper\Data::class);
34  $this->attribute = $this->createMock(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class);
35 
36  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
37  $this->cacheInvalidate = $objectManager->getObject(
38  \Magento\Swatches\Plugin\Catalog\CacheInvalidate::class,
39  [
40  'typeList' => $this->typeList,
41  'swatchHelper' => $this->swatchHelper
42  ]
43  );
44  }
45 
46  public function testAfterSaveSwatch()
47  {
48  $this->swatchHelper->expects($this->atLeastOnce())->method('isSwatchAttribute')->with($this->attribute)
49  ->willReturn(true);
50  $this->typeList->expects($this->at(0))->method('invalidate')->with('block_html');
51  $this->typeList->expects($this->at(1))->method('invalidate')->with('collections');
52  $this->assertSame($this->attribute, $this->cacheInvalidate->afterSave($this->attribute, $this->attribute));
53  }
54 
55  public function testAfterSaveNotSwatch()
56  {
57  $this->swatchHelper->expects($this->atLeastOnce())->method('isSwatchAttribute')->with($this->attribute)
58  ->willReturn(false);
59  $this->typeList->expects($this->never())->method('invalidate');
60  $this->assertSame($this->attribute, $this->cacheInvalidate->afterSave($this->attribute, $this->attribute));
61  }
62 }
$objectManager
Definition: bootstrap.php:17