14 use Symfony\Component\Console\Tester\CommandTester;
25 private $maintenanceMode;
30 private $dependencyChecker;
45 private $cleanupFiles;
55 private $backupRollbackFactory;
62 private $themeValidator;
67 private $themeUninstaller;
72 private $themeDependencyChecker;
77 private $themePackageInfo;
86 $this->maintenanceMode = $this->createMock(\
Magento\Framework\
App\MaintenanceMode::class);
87 $composerInformation = $this->createMock(\
Magento\Framework\Composer\ComposerInformation::class);
88 $composerInformation->expects($this->any())
89 ->method(
'getRootRequiredPackages')
90 ->willReturn([
'magento/theme-a',
'magento/theme-b',
'magento/theme-c']);
91 $this->dependencyChecker = $this->createMock(\
Magento\Framework\Composer\DependencyChecker::class);
92 $this->collection = $this->createMock(\
Magento\Theme\Model\Theme\Data\Collection::class);
93 $this->cache = $this->createMock(\
Magento\Framework\
App\Cache::class);
94 $this->cleanupFiles = $this->createMock(\
Magento\Framework\
App\State\CleanupFiles::class);
95 $this->backupRollbackFactory = $this->createMock(\
Magento\Framework\Setup\BackupRollbackFactory::class);
96 $this->themeValidator = $this->createMock(\
Magento\Theme\Model\ThemeValidator::class);
97 $this->themeUninstaller = $this->createMock(\
Magento\Theme\Model\Theme\ThemeUninstaller::class);
98 $this->themeDependencyChecker = $this->createMock(\
Magento\Theme\Model\Theme\ThemeDependencyChecker::class);
99 $this->themePackageInfo = $this->createMock(\
Magento\Theme\Model\Theme\ThemePackageInfo::class);
103 $composerInformation,
104 $this->maintenanceMode,
105 $this->dependencyChecker,
107 $this->backupRollbackFactory,
108 $this->themeValidator,
109 $this->themePackageInfo,
110 $this->themeUninstaller,
111 $this->themeDependencyChecker,
114 $this->tester =
new CommandTester($this->command);
119 $this->themePackageInfo->expects($this->at(0))->method(
'getPackageName')->willReturn(
'dummy');
120 $this->themePackageInfo->expects($this->at(1))->method(
'getPackageName')->willReturn(
'magento/theme-a');
121 $this->collection->expects($this->any())
122 ->method(
'getThemeByFullPath')
124 $this->getMockForAbstractClass(
125 \
Magento\Framework\View\Design\ThemeInterface::class,
131 $this->collection->expects($this->any())->method(
'hasTheme')->willReturn(
true);
132 $this->tester->execute([
'theme' => [
'area/vendor/test1',
'area/vendor/test2']]);
133 $this->assertContains(
134 'test1 is not an installed Composer package',
135 $this->tester->getDisplay()
137 $this->assertNotContains(
138 'test2 is not an installed Composer package',
139 $this->tester->getDisplay()
145 $this->themePackageInfo->expects($this->exactly(2))->method(
'getPackageName')->willReturn(
'');
146 $this->collection->expects($this->any())
147 ->method(
'getThemeByFullPath')
149 $this->getMockForAbstractClass(
150 \
Magento\Framework\View\Design\ThemeInterface::class,
156 $this->collection->expects($this->any())->method(
'hasTheme')->willReturn(
false);
157 $this->tester->execute([
'theme' => [
'area/vendor/test1',
'area/vendor/test2']]);
158 $this->assertContains(
159 'Unknown theme(s): area/vendor/test1, area/vendor/test2' . PHP_EOL,
160 $this->tester->getDisplay()
166 $this->themePackageInfo->expects($this->exactly(4))
167 ->method(
'getPackageName')
168 ->will($this->returnValueMap([
169 [
'area/vendor/test1',
'dummy1'],
170 [
'area/vendor/test2',
'magento/theme-b'],
171 [
'area/vendor/test3',
''],
172 [
'area/vendor/test4',
'dummy2'],
174 $this->collection->expects($this->any())
175 ->method(
'getThemeByFullPath')
177 $this->getMockForAbstractClass(
178 \
Magento\Framework\View\Design\ThemeInterface::class,
184 $this->collection->expects($this->at(1))->method(
'hasTheme')->willReturn(
true);
185 $this->collection->expects($this->at(3))->method(
'hasTheme')->willReturn(
true);
186 $this->collection->expects($this->at(5))->method(
'hasTheme')->willReturn(
false);
187 $this->collection->expects($this->at(7))->method(
'hasTheme')->willReturn(
true);
188 $this->tester->execute([
196 $this->assertContains(
197 'area/vendor/test1, area/vendor/test4 are not installed Composer packages',
198 $this->tester->getDisplay()
200 $this->assertNotContains(
201 'area/vendor/test2 is not an installed Composer package',
202 $this->tester->getDisplay()
204 $this->assertContains(
205 'Unknown theme(s): area/vendor/test3' . PHP_EOL,
206 $this->tester->getDisplay()
212 $this->themePackageInfo->expects($this->any())->method(
'getPackageName')->willReturn(
'magento/theme-a');
213 $this->collection->expects($this->any())
214 ->method(
'getThemeByFullPath')
216 $this->getMockForAbstractClass(
217 \
Magento\Framework\View\Design\ThemeInterface::class,
223 $this->themeDependencyChecker->expects($this->any())->method(
'checkChildTheme')->willReturn([]);
224 $this->collection->expects($this->any())->method(
'hasTheme')->willReturn(
true);
229 $theme = $this->createMock(\
Magento\Theme\Model\Theme::class);
230 $theme->expects($this->any())->method(
'hasChildThemes')->willReturn(
false);
231 $this->collection->expects($this->any())->method(
'getIterator')->willReturn(
new \ArrayIterator([]));
236 $this->themeValidator->expects($this->once())->method(
'validateIsThemeInUse')->willReturn([]);
241 $this->dependencyChecker->expects($this->once())->method(
'checkDependencies')->willReturn([]);
249 $this->themeValidator
250 ->expects($this->once())
251 ->method(
'validateIsThemeInUse')
252 ->willReturn([
'frontend/Magento/a is in use in default config']);
253 $this->tester->execute([
'theme' => [
'frontend/Magento/a']]);
255 'Unable to uninstall. Please resolve the following issues:' . PHP_EOL
256 .
'frontend/Magento/a is in use in default config' . PHP_EOL,
257 $this->tester->getDisplay()
266 $this->dependencyChecker->expects($this->once())
267 ->method(
'checkDependencies')
268 ->willReturn([
'magento/theme-a' => [
'magento/theme-b',
'magento/theme-c']]);
269 $this->tester->execute([
'theme' => [
'frontend/Magento/a']]);
270 $this->assertContains(
271 'Unable to uninstall. Please resolve the following issues:' . PHP_EOL .
272 'frontend/Magento/a has the following dependent package(s):' 273 . PHP_EOL .
"\tmagento/theme-b" . PHP_EOL .
"\tmagento/theme-c",
274 $this->tester->getDisplay()
284 $this->cache->expects($this->once())->method(
'clean');
286 $this->themeUninstaller->expects($this->once())
287 ->method(
'uninstallRegistry')
288 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $this->anything());
289 $this->themeUninstaller->expects($this->once())
290 ->method(
'uninstallCode')
291 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $this->anything());
297 $backupRollback = $this->createMock(\
Magento\Framework\Setup\BackupRollback::class);
298 $this->backupRollbackFactory->expects($this->once())
300 ->willReturn($backupRollback);
301 $this->tester->execute([
'theme' => [
'area/vendor/test'],
'--backup-code' =>
true]);
302 $this->tester->getDisplay();
308 $this->cleanupFiles->expects($this->never())->method(
'clearMaterializedViewFiles');
309 $this->tester->execute([
'theme' => [
'area/vendor/test']]);
310 $this->assertContains(
'Enabling maintenance mode', $this->tester->getDisplay());
311 $this->assertContains(
'Disabling maintenance mode', $this->tester->getDisplay());
312 $this->assertContains(
'Alert: Generated static view files were not cleared.', $this->tester->getDisplay());
313 $this->assertNotContains(
'Generated static view files cleared successfully', $this->tester->getDisplay());
319 $this->cleanupFiles->expects($this->once())->method(
'clearMaterializedViewFiles');
320 $this->tester->execute([
'theme' => [
'area/vendor/test'],
'-c' =>
true]);
321 $this->assertContains(
'Enabling maintenance mode', $this->tester->getDisplay());
322 $this->assertContains(
'Disabling maintenance mode', $this->tester->getDisplay());
323 $this->assertNotContains(
'Alert: Generated static view files were not cleared.', $this->tester->getDisplay());
324 $this->assertContains(
'Generated static view files cleared successfully', $this->tester->getDisplay());
333 $this->tester->execute([
'theme' => [$themePath]]);
334 $this->assertContains(
335 'Theme path should be specified as full path which is area/vendor/name.',
336 $this->tester->getDisplay()
354 [
'area/vendor/test1/'],
355 [
'/area/vendor/test1'],
testExecuteFailedValidationNotTheme()
testExecuteFailedDependencyCheck()
testExecuteFailedValidationNotPackage()
testExecuteWithBackupCode()
testExecuteWrongThemeFormat($themePath)
testExecuteCleanStaticFiles()
setupPassDependencyCheck()
setupPassChildThemeCheck()
dataProviderThemeFormat()
setupPassThemeInUseCheck()
testExecuteFailedValidationMixed()
testExecuteFailedThemeInUseCheck()