1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Magento. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ namespace Magento \Catalog \Test \Unit \Model \System \Config \Backend \Catalog \Url \Rewrite ;
7
+
8
+ class SuffixTest extends \PHPUnit_Framework_TestCase
9
+ {
10
+ /**
11
+ * @var \Magento\Framework\Model\Context
12
+ */
13
+ protected $ context ;
14
+
15
+ /**
16
+ * @var \Magento\Framework\Event\ManagerInterface
17
+ */
18
+ protected $ eventDispatcher ;
19
+
20
+ /**
21
+ * @var \Magento\Framework\Registry
22
+ */
23
+ protected $ registry ;
24
+
25
+ /**
26
+ * @var \Magento\Framework\App\Config\ScopeConfigInterface
27
+ */
28
+ protected $ config ;
29
+
30
+ /**
31
+ * @var \Magento\Framework\App\Cache\TypeListInterface
32
+ */
33
+ protected $ cacheTypeList ;
34
+
35
+ /**
36
+ * @var \Magento\UrlRewrite\Helper\UrlRewrite
37
+ */
38
+ protected $ urlRewriteHelper ;
39
+
40
+ /**
41
+ * @var \Magento\Store\Model\StoreManagerInterface
42
+ */
43
+ protected $ storeManager ;
44
+
45
+ /**
46
+ * @var \Magento\Framework\App\ResourceConnection
47
+ */
48
+ protected $ appResource ;
49
+
50
+ /**
51
+ * @var \Magento\UrlRewrite\Model\UrlFinderInterface
52
+ */
53
+ protected $ urlFinder ;
54
+
55
+ /**
56
+ * @var \Magento\Catalog\Model\System\Config\Backend\Catalog\Url\Rewrite\Suffix
57
+ */
58
+ protected $ suffixModel ;
59
+
60
+ public function setUp ()
61
+ {
62
+ $ this ->eventDispatcher = $ this ->getMockBuilder ('\Magento\Framework\Event\ManagerInterface ' )
63
+ ->disableOriginalConstructor ()
64
+ ->setMethods (['dispatch ' ])
65
+ ->getMock ();
66
+ $ this ->eventDispatcher ->method ('dispatch ' )->willReturnSelf ();
67
+ $ this ->context = $ this ->getMockBuilder ('\Magento\Framework\Model\Context ' )
68
+ ->disableOriginalConstructor ()
69
+ ->setMethods (['getEventDispatcher ' ])
70
+ ->getMock ();
71
+ $ this ->context ->method ('getEventDispatcher ' )->willReturn ($ this ->eventDispatcher );
72
+
73
+ $ this ->registry = $ this ->getMock ('\Magento\Framework\Registry ' );
74
+ $ this ->config = $ this ->getMock ('\Magento\Framework\App\Config\ScopeConfigInterface ' );
75
+ $ this ->cacheTypeList = $ this ->getMockBuilder ('\Magento\Framework\App\Cache\TypeList ' )
76
+ ->disableOriginalConstructor ()
77
+ ->setMethods (['invalidate ' ])
78
+ ->getMock ();
79
+
80
+ $ this ->urlRewriteHelper = $ this ->getMockBuilder ('\Magento\UrlRewrite\Helper\UrlRewrite ' )
81
+ ->disableOriginalConstructor ()
82
+ ->getMock ();
83
+ $ this ->storeManager = $ this ->getMockBuilder ('\Magento\Store\Model\StoreManager ' )
84
+ ->disableOriginalConstructor ()
85
+ ->setMethods (['getStores ' ])
86
+ ->getMock ();
87
+ $ this ->storeManager ->method ('getStores ' )->willReturn ([]);
88
+
89
+ $ this ->appResource =$ this ->getMockBuilder ('\Magento\Framework\App\ResourceConnection ' )
90
+ ->disableOriginalConstructor ()
91
+ ->getMock ();
92
+ $ this ->urlFinder =$ this ->getMockBuilder ('\Magento\UrlRewrite\Model\UrlFinderInterface ' )
93
+ ->setMethods (['findAllByData ' , 'findOneByData ' ])
94
+ ->getMock ();
95
+ $ this ->urlFinder ->method ('findAllByData ' )->willReturn ([]);
96
+
97
+ $ this ->suffixModel = new \Magento \Catalog \Model \System \Config \Backend \Catalog \Url \Rewrite \Suffix (
98
+ $ this ->context ,
99
+ $ this ->registry ,
100
+ $ this ->config ,
101
+ $ this ->cacheTypeList ,
102
+ $ this ->urlRewriteHelper ,
103
+ $ this ->storeManager ,
104
+ $ this ->appResource ,
105
+ $ this ->urlFinder
106
+ );
107
+ }
108
+
109
+ public function testAfterSaveCleanCache ()
110
+ {
111
+ $ this ->suffixModel ->setValue ('new ' );
112
+ $ this ->suffixModel ->setPath (\Magento \CatalogUrlRewrite \Model \CategoryUrlPathGenerator::XML_PATH_CATEGORY_URL_SUFFIX );
113
+ $ this ->cacheTypeList ->expects ($ this ->exactly (2 ))->method ('invalidate ' )->withConsecutive (
114
+ [$ this ->equalTo ([
115
+ \Magento \Framework \App \Cache \Type \Block::TYPE_IDENTIFIER ,
116
+ \Magento \Framework \App \Cache \Type \Collection::TYPE_IDENTIFIER
117
+ ])],
118
+ [$ this ->equalTo ('config ' )]
119
+ );
120
+ $ this ->suffixModel ->afterSave ();
121
+ }
122
+
123
+ public function testAfterSaveWithoutChanges ()
124
+ {
125
+ $ this ->suffixModel ->setValue ('' );
126
+ $ this ->suffixModel ->setPath (\Magento \CatalogUrlRewrite \Model \CategoryUrlPathGenerator::XML_PATH_CATEGORY_URL_SUFFIX );
127
+ $ this ->cacheTypeList ->expects ($ this ->never ())->method ('invalidate ' );
128
+ $ this ->suffixModel ->afterSave ();
129
+ }
130
+
131
+ public function testAfterSaveProduct ()
132
+ {
133
+ $ this ->suffixModel ->setValue ('new ' );
134
+ $ this ->suffixModel ->setPath (\Magento \CatalogUrlRewrite \Model \ProductUrlPathGenerator::XML_PATH_PRODUCT_URL_SUFFIX );
135
+ $ this ->cacheTypeList ->expects ($ this ->once ())->method ('invalidate ' )->with ('config ' );
136
+ $ this ->suffixModel ->afterSave ();
137
+ }
138
+ }
0 commit comments