ThemeDependencyCheckerTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Test\Unit\Model\Theme;
  7. use Magento\Theme\Model\Theme\ThemeDependencyChecker;
  8. class ThemeDependencyCheckerTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var ThemeDependencyChecker
  12. */
  13. private $themeDependencyChecker;
  14. /**
  15. * @var \Magento\Theme\Model\Theme\Data\Collection|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. private $themeCollection;
  18. /**
  19. * @var \Magento\Theme\Model\Theme\ThemeProvider|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. private $themeProvider;
  22. /**
  23. * @var \Magento\Theme\Model\Theme\ThemePackageInfo|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. private $themePackageInfo;
  26. public function setup()
  27. {
  28. $this->themePackageInfo = $this->createMock(\Magento\Theme\Model\Theme\ThemePackageInfo::class);
  29. $this->themeCollection = $this->createMock(\Magento\Theme\Model\Theme\Data\Collection::class);
  30. $this->themeProvider = $this->createMock(\Magento\Theme\Model\Theme\ThemeProvider::class);
  31. $this->themeDependencyChecker = new ThemeDependencyChecker(
  32. $this->themeCollection,
  33. $this->themeProvider,
  34. $this->themePackageInfo
  35. );
  36. }
  37. public function testCheckChildThemeByPackagesName()
  38. {
  39. $packages = [
  40. 'vendor/package1',
  41. 'vendor/package2'
  42. ];
  43. $this->themePackageInfo->expects($this->exactly(2))->method('getFullThemePath')->willReturn(null);
  44. $this->themeDependencyChecker->checkChildThemeByPackagesName($packages);
  45. }
  46. /**
  47. * @dataProvider executeFailedChildThemeCheckDataProvider
  48. * @param bool $hasVirtual
  49. * @param bool $hasPhysical
  50. * @param array $input
  51. * @param string $expected
  52. * @return void
  53. */
  54. public function testExecuteFailedChildThemeCheck($hasVirtual, $hasPhysical, array $input, $expected)
  55. {
  56. $theme = $this->createMock(\Magento\Theme\Model\Theme::class);
  57. $theme->expects($this->any())->method('hasChildThemes')->willReturn($hasVirtual);
  58. $parentThemeA = $this->createMock(\Magento\Theme\Model\Theme::class);
  59. $parentThemeA->expects($this->any())->method('getFullPath')->willReturn('frontend/Magento/a');
  60. $parentThemeB = $this->createMock(\Magento\Theme\Model\Theme::class);
  61. $parentThemeB->expects($this->any())->method('getFullPath')->willReturn('frontend/Magento/b');
  62. $childThemeC = $this->createMock(\Magento\Theme\Model\Theme::class);
  63. $childThemeC->expects($this->any())->method('getFullPath')->willReturn('frontend/Magento/c');
  64. $childThemeD = $this->createMock(\Magento\Theme\Model\Theme::class);
  65. $childThemeD->expects($this->any())->method('getFullPath')->willReturn('frontend/Magento/d');
  66. if ($hasPhysical) {
  67. $childThemeC->expects($this->any())->method('getParentTheme')->willReturn($parentThemeA);
  68. $childThemeD->expects($this->any())->method('getParentTheme')->willReturn($parentThemeB);
  69. }
  70. $this->themeProvider->expects($this->any())->method('getThemeByFullPath')->willReturn($theme);
  71. $this->themeCollection->expects($this->any())
  72. ->method('getIterator')
  73. ->willReturn(new \ArrayIterator([$childThemeC, $childThemeD]));
  74. $this->assertEquals($expected, $this->themeDependencyChecker->checkChildTheme($input));
  75. }
  76. /**
  77. * @return array
  78. */
  79. public function executeFailedChildThemeCheckDataProvider()
  80. {
  81. return [
  82. [
  83. true,
  84. false,
  85. ['frontend/Magento/a'],
  86. ['frontend/Magento/a is a parent of virtual theme. Parent themes cannot be uninstalled.']
  87. ],
  88. [
  89. true,
  90. false,
  91. ['frontend/Magento/a', 'frontend/Magento/b'],
  92. ['frontend/Magento/a, frontend/Magento/b are parents of virtual theme.'
  93. . ' Parent themes cannot be uninstalled.']
  94. ],
  95. [
  96. false,
  97. true,
  98. ['frontend/Magento/a'],
  99. ['frontend/Magento/a is a parent of physical theme. Parent themes cannot be uninstalled.']
  100. ],
  101. [
  102. false,
  103. true,
  104. ['frontend/Magento/a', 'frontend/Magento/b'],
  105. ['frontend/Magento/a, frontend/Magento/b are parents of physical theme.'
  106. . ' Parent themes cannot be uninstalled.']
  107. ],
  108. [
  109. true,
  110. true,
  111. ['frontend/Magento/a'],
  112. ['frontend/Magento/a is a parent of virtual theme. Parent themes cannot be uninstalled.',
  113. 'frontend/Magento/a is a parent of physical theme. Parent themes cannot be uninstalled.']
  114. ],
  115. [
  116. true,
  117. true,
  118. ['frontend/Magento/a', 'frontend/Magento/b'],
  119. ['frontend/Magento/a, frontend/Magento/b are parents of virtual theme.'
  120. . ' Parent themes cannot be uninstalled.',
  121. 'frontend/Magento/a, frontend/Magento/b are parents of physical theme.'
  122. . ' Parent themes cannot be uninstalled.']
  123. ],
  124. ];
  125. }
  126. }