Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigTest.php
Go to the documentation of this file.
1 <?php
11 
12 class ConfigTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $_themeMock;
18 
22  protected $_configData;
23 
27  protected $_storeManagerMock;
28 
32  protected $_configCacheMock;
33 
37  protected $_layoutCacheMock;
38 
43 
47  protected $_model;
48 
49  protected function setUp()
50  {
52  $this->_themeMock = $this->createMock(\Magento\Theme\Model\Theme::class);
53  $this->_storeManagerMock = $this->getMockForAbstractClass(
54  \Magento\Store\Model\StoreManagerInterface::class,
55  [],
56  '',
57  true,
58  true,
59  true,
60  ['getStores', 'isSingleStoreMode']
61  );
62  $this->_configData = $this->createPartialMock(
63  \Magento\Framework\App\Config\Value::class,
64  ['getCollection', 'addFieldToFilter', '__wakeup']
65  );
66  $this->_configCacheMock = $this->getMockForAbstractClass(\Magento\Framework\Cache\FrontendInterface::class);
67  $this->_layoutCacheMock = $this->getMockForAbstractClass(\Magento\Framework\Cache\FrontendInterface::class);
68 
69  $this->_scopeConfigWriter = $this->createPartialMock(
70  \Magento\Framework\App\Config\Storage\WriterInterface::class,
71  ['save', 'delete']
72  );
73 
74  $this->_model = new \Magento\Theme\Model\Config(
75  $this->_configData,
76  $this->_scopeConfigWriter,
77  $this->_storeManagerMock,
78  $this->createMock(\Magento\Framework\Event\ManagerInterface::class),
79  $this->_configCacheMock,
80  $this->_layoutCacheMock
81  );
82  }
83 
84  protected function tearDown()
85  {
86  $this->_themeMock = null;
87  $this->_configData = null;
88  $this->_themeFactoryMock = null;
89  $this->_configCacheMock = null;
90  $this->_layoutCacheMock = null;
91  $this->_model = null;
92  }
93 
98  {
99  $this->_storeManagerMock->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true));
100 
101  $themePath = 'Magento/blank';
103  $configEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope_id' => 8]);
104 
105  $this->_configData->expects(
106  $this->once()
107  )->method(
108  'getCollection'
109  )->will(
110  $this->returnValue($this->_configData)
111  );
112 
113  $this->_configData->expects(
114  $this->at(1)
115  )->method(
116  'addFieldToFilter'
117  )->with(
118  'scope',
119  \Magento\Store\Model\ScopeInterface::SCOPE_STORES
120  )->will(
121  $this->returnValue($this->_configData)
122  );
123 
124  $this->_configData->expects(
125  $this->at(2)
126  )->method(
127  'addFieldToFilter'
128  )->with(
129  'path',
130  \Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID
131  )->will(
132  $this->returnValue([$configEntity])
133  );
134 
135  $this->_themeMock->expects($this->any())->method('getId')->will($this->returnValue(6));
136  $this->_themeMock->expects($this->any())->method('getThemePath')->will($this->returnValue($themePath));
137 
138  $this->_scopeConfigWriter->expects($this->once())->method('delete');
139 
140  $this->_scopeConfigWriter->expects($this->once())->method('save');
141 
142  $this->_model->assignToStore($this->_themeMock, [2, 3, 5]);
143  }
144 
149  {
150  $this->_storeManagerMock->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(false));
151 
152  $themePath = 'Magento/blank';
154  $configEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope_id' => 8]);
155 
156  $this->_configData->expects(
157  $this->once()
158  )->method(
159  'getCollection'
160  )->will(
161  $this->returnValue($this->_configData)
162  );
163 
164  $this->_configData->expects(
165  $this->at(1)
166  )->method(
167  'addFieldToFilter'
168  )->with(
169  'scope',
170  \Magento\Store\Model\ScopeInterface::SCOPE_STORES
171  )->will(
172  $this->returnValue($this->_configData)
173  );
174 
175  $this->_configData->expects(
176  $this->at(2)
177  )->method(
178  'addFieldToFilter'
179  )->with(
180  'path',
181  \Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID
182  )->will(
183  $this->returnValue([$configEntity])
184  );
185 
186  $this->_themeMock->expects($this->any())->method('getId')->will($this->returnValue(6));
187  $this->_themeMock->expects($this->any())->method('getThemePath')->will($this->returnValue($themePath));
188 
189  $this->_scopeConfigWriter->expects($this->once())->method('delete');
190 
191  $this->_scopeConfigWriter->expects($this->exactly(3))->method('save');
192 
193  $this->_model->assignToStore($this->_themeMock, [2, 3, 5]);
194  }
195 }