ThemeValidatorTest.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test theme model
  8. */
  9. namespace Magento\Theme\Test\Unit\Model;
  10. class ThemeValidatorTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Theme\Model\ThemeValidator
  14. */
  15. protected $themeValidator;
  16. /**
  17. * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $storeManager;
  20. /**
  21. * @var \Magento\Framework\View\Design\Theme\ThemeProviderInterface|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $themeProvider;
  24. /**
  25. * @var \Magento\Framework\App\Config\Value|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. protected $configData;
  28. protected function setUp()
  29. {
  30. $this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
  31. $this->themeProvider = $this->createMock(\Magento\Framework\View\Design\Theme\ThemeProviderInterface::class);
  32. $this->configData = $this->createPartialMock(
  33. \Magento\Framework\App\Config\Value::class,
  34. ['getCollection', 'addFieldToFilter']
  35. );
  36. $this->themeValidator = new \Magento\Theme\Model\ThemeValidator(
  37. $this->storeManager,
  38. $this->themeProvider,
  39. $this->configData
  40. );
  41. }
  42. public function testValidateIsThemeInUse()
  43. {
  44. $theme = $this->createMock(\Magento\Theme\Model\Theme::class);
  45. $theme->expects($this->once())->method('getId')->willReturn(6);
  46. $defaultEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope' => 'default', 'scope_id' => 8]);
  47. $websitesEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope' => 'websites', 'scope_id' => 8]);
  48. $storesEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope' => 'stores', 'scope_id' => 8]);
  49. $this->themeProvider->expects($this->once())->method('getThemeByFullPath')->willReturn($theme);
  50. $this->configData->expects($this->once())->method('getCollection')->willReturn($this->configData);
  51. $this->configData
  52. ->expects($this->at(1))
  53. ->method('addFieldToFilter')
  54. ->willReturn($this->configData);
  55. $this->configData
  56. ->expects($this->at(2))
  57. ->method('addFieldToFilter')
  58. ->willReturn([$defaultEntity, $websitesEntity, $storesEntity]);
  59. $website = $this->createPartialMock(\Magento\Store\Model\Website::class, ['getName']);
  60. $website->expects($this->once())->method('getName')->willReturn('websiteA');
  61. $store = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getName']);
  62. $store->expects($this->once())->method('getName')->willReturn('storeA');
  63. $this->storeManager->expects($this->once())->method('getWebsite')->willReturn($website);
  64. $this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
  65. $result = $this->themeValidator->validateIsThemeInUse(['frontend/Magento/a']);
  66. $this->assertEquals(
  67. [
  68. '<error>frontend/Magento/a is in use in default config</error>',
  69. '<error>frontend/Magento/a is in use in website websiteA</error>',
  70. '<error>frontend/Magento/a is in use in store storeA</error>'
  71. ],
  72. $result
  73. );
  74. }
  75. }