Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ThemeValidatorTest.php
Go to the documentation of this file.
1 <?php
11 
12 class ThemeValidatorTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $themeValidator;
18 
22  protected $storeManager;
23 
27  protected $themeProvider;
28 
32  protected $configData;
33 
34  protected function setUp()
35  {
36  $this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
37  $this->themeProvider = $this->createMock(\Magento\Framework\View\Design\Theme\ThemeProviderInterface::class);
38  $this->configData = $this->createPartialMock(
39  \Magento\Framework\App\Config\Value::class,
40  ['getCollection', 'addFieldToFilter']
41  );
42  $this->themeValidator = new \Magento\Theme\Model\ThemeValidator(
43  $this->storeManager,
44  $this->themeProvider,
45  $this->configData
46  );
47  }
48 
49  public function testValidateIsThemeInUse()
50  {
51  $theme = $this->createMock(\Magento\Theme\Model\Theme::class);
52  $theme->expects($this->once())->method('getId')->willReturn(6);
53  $defaultEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope' => 'default', 'scope_id' => 8]);
54  $websitesEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope' => 'websites', 'scope_id' => 8]);
55  $storesEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope' => 'stores', 'scope_id' => 8]);
56  $this->themeProvider->expects($this->once())->method('getThemeByFullPath')->willReturn($theme);
57  $this->configData->expects($this->once())->method('getCollection')->willReturn($this->configData);
58  $this->configData
59  ->expects($this->at(1))
60  ->method('addFieldToFilter')
61  ->willReturn($this->configData);
62  $this->configData
63  ->expects($this->at(2))
64  ->method('addFieldToFilter')
65  ->willReturn([$defaultEntity, $websitesEntity, $storesEntity]);
66  $website = $this->createPartialMock(\Magento\Store\Model\Website::class, ['getName']);
67  $website->expects($this->once())->method('getName')->willReturn('websiteA');
68  $store = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getName']);
69  $store->expects($this->once())->method('getName')->willReturn('storeA');
70  $this->storeManager->expects($this->once())->method('getWebsite')->willReturn($website);
71  $this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
72  $result = $this->themeValidator->validateIsThemeInUse(['frontend/Magento/a']);
73  $this->assertEquals(
74  [
75  '<error>frontend/Magento/a is in use in default config</error>',
76  '<error>frontend/Magento/a is in use in website websiteA</error>',
77  '<error>frontend/Magento/a is in use in store storeA</error>'
78  ],
79  $result
80  );
81  }
82 }
$theme