Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ThemeDependencyCheckerTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class ThemeDependencyCheckerTest extends \PHPUnit\Framework\TestCase
12 {
16  private $themeDependencyChecker;
17 
21  private $themeCollection;
22 
26  private $themeProvider;
27 
31  private $themePackageInfo;
32 
33  public function setup()
34  {
35  $this->themePackageInfo = $this->createMock(\Magento\Theme\Model\Theme\ThemePackageInfo::class);
36  $this->themeCollection = $this->createMock(\Magento\Theme\Model\Theme\Data\Collection::class);
37  $this->themeProvider = $this->createMock(\Magento\Theme\Model\Theme\ThemeProvider::class);
38 
39  $this->themeDependencyChecker = new ThemeDependencyChecker(
40  $this->themeCollection,
41  $this->themeProvider,
42  $this->themePackageInfo
43  );
44  }
45 
47  {
48  $packages = [
49  'vendor/package1',
50  'vendor/package2'
51  ];
52  $this->themePackageInfo->expects($this->exactly(2))->method('getFullThemePath')->willReturn(null);
53  $this->themeDependencyChecker->checkChildThemeByPackagesName($packages);
54  }
55 
64  public function testExecuteFailedChildThemeCheck($hasVirtual, $hasPhysical, array $input, $expected)
65  {
66  $theme = $this->createMock(\Magento\Theme\Model\Theme::class);
67  $theme->expects($this->any())->method('hasChildThemes')->willReturn($hasVirtual);
68  $parentThemeA = $this->createMock(\Magento\Theme\Model\Theme::class);
69  $parentThemeA->expects($this->any())->method('getFullPath')->willReturn('frontend/Magento/a');
70  $parentThemeB = $this->createMock(\Magento\Theme\Model\Theme::class);
71  $parentThemeB->expects($this->any())->method('getFullPath')->willReturn('frontend/Magento/b');
72  $childThemeC = $this->createMock(\Magento\Theme\Model\Theme::class);
73  $childThemeC->expects($this->any())->method('getFullPath')->willReturn('frontend/Magento/c');
74  $childThemeD = $this->createMock(\Magento\Theme\Model\Theme::class);
75  $childThemeD->expects($this->any())->method('getFullPath')->willReturn('frontend/Magento/d');
76 
77  if ($hasPhysical) {
78  $childThemeC->expects($this->any())->method('getParentTheme')->willReturn($parentThemeA);
79  $childThemeD->expects($this->any())->method('getParentTheme')->willReturn($parentThemeB);
80  }
81 
82  $this->themeProvider->expects($this->any())->method('getThemeByFullPath')->willReturn($theme);
83  $this->themeCollection->expects($this->any())
84  ->method('getIterator')
85  ->willReturn(new \ArrayIterator([$childThemeC, $childThemeD]));
86 
87  $this->assertEquals($expected, $this->themeDependencyChecker->checkChildTheme($input));
88  }
89 
94  {
95  return [
96  [
97  true,
98  false,
99  ['frontend/Magento/a'],
100  ['frontend/Magento/a is a parent of virtual theme. Parent themes cannot be uninstalled.']
101  ],
102  [
103  true,
104  false,
105  ['frontend/Magento/a', 'frontend/Magento/b'],
106  ['frontend/Magento/a, frontend/Magento/b are parents of virtual theme.'
107  . ' Parent themes cannot be uninstalled.']
108  ],
109  [
110  false,
111  true,
112  ['frontend/Magento/a'],
113  ['frontend/Magento/a is a parent of physical theme. Parent themes cannot be uninstalled.']
114  ],
115  [
116  false,
117  true,
118  ['frontend/Magento/a', 'frontend/Magento/b'],
119  ['frontend/Magento/a, frontend/Magento/b are parents of physical theme.'
120  . ' Parent themes cannot be uninstalled.']
121  ],
122  [
123  true,
124  true,
125  ['frontend/Magento/a'],
126  ['frontend/Magento/a is a parent of virtual theme. Parent themes cannot be uninstalled.',
127  'frontend/Magento/a is a parent of physical theme. Parent themes cannot be uninstalled.']
128  ],
129  [
130  true,
131  true,
132  ['frontend/Magento/a', 'frontend/Magento/b'],
133  ['frontend/Magento/a, frontend/Magento/b are parents of virtual theme.'
134  . ' Parent themes cannot be uninstalled.',
135  'frontend/Magento/a, frontend/Magento/b are parents of physical theme.'
136  . ' Parent themes cannot be uninstalled.']
137  ],
138  ];
139  }
140 }
$theme
testExecuteFailedChildThemeCheck($hasVirtual, $hasPhysical, array $input, $expected)