1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Magento. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ namespace Magento \Swatches \Test \Unit \Plugin \Catalog ;
7
+
8
+ class CacheInvalidateTest extends \PHPUnit_Framework_TestCase
9
+ {
10
+ /**
11
+ * @var \Magento\Framework\App\Cache\TypeListInterface | \PHPUnit_Framework_MockObject_MockObject
12
+ */
13
+ private $ typeList ;
14
+
15
+ /**
16
+ * @var \Magento\Swatches\Helper\Data | \PHPUnit_Framework_MockObject_MockObject
17
+ */
18
+ private $ swatchHelper ;
19
+
20
+ /**
21
+ * @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute | \PHPUnit_Framework_MockObject_MockObject
22
+ */
23
+ private $ attribute ;
24
+
25
+ /**
26
+ * @var \Magento\Swatches\Plugin\Catalog\CacheInvalidate
27
+ */
28
+ private $ cacheInvalidate ;
29
+
30
+ protected function setUp ()
31
+ {
32
+ $ this ->typeList = $ this ->getMock (
33
+ '\Magento\Framework\App\Cache\TypeListInterface ' ,
34
+ [],
35
+ [],
36
+ '' ,
37
+ false
38
+ );
39
+ $ this ->swatchHelper = $ this ->getMock (
40
+ '\Magento\Swatches\Helper\Data ' ,
41
+ [],
42
+ [],
43
+ '' ,
44
+ false
45
+ );
46
+ $ this ->attribute = $ this ->getMock (
47
+ '\Magento\Catalog\Model\ResourceModel\Eav\Attribute ' ,
48
+ [],
49
+ [],
50
+ '' ,
51
+ false
52
+ );
53
+
54
+ $ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
55
+ $ this ->cacheInvalidate = $ objectManager ->getObject (
56
+ 'Magento\Swatches\Plugin\Catalog\CacheInvalidate ' ,
57
+ [
58
+ 'typeList ' => $ this ->typeList ,
59
+ 'swatchHelper ' => $ this ->swatchHelper
60
+ ]
61
+ );
62
+ }
63
+
64
+ public function testAfterSaveSwatch ()
65
+ {
66
+ $ this ->swatchHelper ->expects ($ this ->atLeastOnce ())->method ('isSwatchAttribute ' )->with ($ this ->attribute )
67
+ ->willReturn (true );
68
+ $ this ->typeList ->expects ($ this ->at (0 ))->method ('invalidate ' )->with ('block_html ' );
69
+ $ this ->typeList ->expects ($ this ->at (1 ))->method ('invalidate ' )->with ('collections ' );
70
+ $ this ->typeList ->expects ($ this ->at (2 ))->method ('invalidate ' )->with ('full_page ' );
71
+ $ this ->assertSame ($ this ->attribute , $ this ->cacheInvalidate ->afterSave ($ this ->attribute , $ this ->attribute ));
72
+ }
73
+
74
+ public function testAfterSaveNotSwatch ()
75
+ {
76
+ $ this ->swatchHelper ->expects ($ this ->atLeastOnce ())->method ('isSwatchAttribute ' )->with ($ this ->attribute )
77
+ ->willReturn (false );
78
+ $ this ->typeList ->expects ($ this ->never ())->method ('invalidate ' );
79
+ $ this ->assertSame ($ this ->attribute , $ this ->cacheInvalidate ->afterSave ($ this ->attribute , $ this ->attribute ));
80
+ }
81
+ }
0 commit comments