Skip to content

Commit c7a0c7f

Browse files
author
Fred Sung
committed
MAGETWO-38180: Check if the theme is not a base for any virtual theme
- Code updated from CR feedback.
1 parent de1e2e0 commit c7a0c7f

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

app/code/Magento/Theme/Console/Command/ThemeUninstallCommand.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Magento\Framework\App\DeploymentConfig;
2525
use Magento\Framework\Setup\BackupRollbackFactory;
2626
use Magento\Framework\App\Filesystem\DirectoryList;
27+
use Magento\Framework\Exception\LocalizedException;
2728

2829
/**
2930
* Command for uninstalling theme and backup-code feature
@@ -41,39 +42,51 @@ class ThemeUninstallCommand extends Command
4142
const INPUT_KEY_CLEAR_STATIC_CONTENT = 'clear-static-content';
4243

4344
/**
45+
* Deployment Configuration
46+
*
4447
* @var DeploymentConfig
4548
*/
4649
private $deploymentConfig;
4750

4851
/**
52+
* Maintenance Mode
53+
*
4954
* @var MaintenanceMode
5055
*/
5156
private $maintenanceMode;
5257

5358
/**
59+
* Composer general dependency checker
60+
*
5461
* @var DependencyChecker
5562
*/
5663
private $dependencyChecker;
5764

5865
/**
66+
* Root composer.json information
67+
*
5968
* @var ComposerInformation
6069
*/
6170
private $composer;
6271

6372
/**
73+
* File operation to read theme directory
74+
*
6475
* @var Filesystem
6576
*/
6677
private $filesystem;
6778

6879
/**
80+
* Code remover
81+
*
6982
* @var Remove
7083
*/
7184
private $remove;
7285

7386
/**
7487
* Theme collection in filesystem
7588
*
76-
* @var \Magento\Theme\Model\Theme\Collection
89+
* @var Collection
7790
*/
7891
private $themeCollection;
7992

@@ -85,21 +98,29 @@ class ThemeUninstallCommand extends Command
8598
private $themeProvider;
8699

87100
/**
101+
* Application States
102+
*
88103
* @var State
89104
*/
90105
private $appState;
91106

92107
/**
108+
* System cache model
109+
*
93110
* @var Cache
94111
*/
95112
private $cache;
96113

97114
/**
115+
* Cleaning up application state service
116+
*
98117
* @var State\CleanupFiles
99118
*/
100119
private $cleanupFiles;
101120

102121
/**
122+
* BackupRollback factory
123+
*
103124
* @var BackupRollbackFactory
104125
*/
105126
private $backupRollbackFactory;
@@ -119,7 +140,7 @@ class ThemeUninstallCommand extends Command
119140
* @param Remove $remove
120141
* @param State $appState
121142
* @param BackupRollbackFactory $backupRollbackFactory
122-
* @throws \Magento\Framework\Exception\LocalizedException
143+
* @throws LocalizedException
123144
*/
124145
public function __construct(
125146
Cache $cache,
@@ -256,7 +277,7 @@ private function validate($themePaths)
256277
$unknownPackages = array_diff($unknownPackages, $unknownThemes);
257278
if (!empty($unknownPackages)) {
258279
$text = count($unknownPackages) > 1 ?
259-
' are not installed composer packages' : ' is not an installed composer package';
280+
' are not installed Composer packages' : ' is not an installed Composer package';
260281
$messages[] = '<error>' . implode(', ', $unknownPackages) . $text . '</error>';
261282
}
262283
if (!empty($unknownThemes)) {
@@ -308,9 +329,8 @@ private function checkChildVirtualTheme($themePaths)
308329
}
309330
}
310331
if (!empty($themeHasChildren)) {
311-
$text = count($themeHasChildren) > 1 ?
312-
' are bases of' : ' is a base of';
313-
$messages[] = '<error>Unable to delete. '
332+
$text = count($themeHasChildren) > 1 ? ' are parents of' : ' is a parent of';
333+
$messages[] = '<error>Unable to uninstall. '
314334
. implode(', ', $themeHasChildren) . $text . ' virtual theme</error>';
315335
}
316336
return $messages;

app/code/Magento/Theme/Test/Unit/Console/Command/ThemeUninstallCommandTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,13 @@ public function testExecuteFailedValidationNotPackage()
154154
->method('getThemeByFullPath')
155155
->willReturn($this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface', [], '', false));
156156
$this->collection->expects($this->any())->method('hasTheme')->willReturn(true);
157-
$theme = $this->getMock('Magento\Theme\Model\Theme', [], [], '', false);
158-
$this->themeProvider->expects($this->any())->method('getThemeByFullPath')->willReturn($theme);
159-
$this->themeProvider->expects($this->any())->method('hasChildThemes')->willReturn(false);
160157
$this->tester->execute(['theme' => ['test1', 'test2']]);
161158
$this->assertContains(
162-
'test1 is not an installed composer package',
159+
'test1 is not an installed Composer package',
163160
$this->tester->getDisplay()
164161
);
165162
$this->assertNotContains(
166-
'test2 is not an installed composer package',
163+
'test2 is not an installed Composer package',
167164
$this->tester->getDisplay()
168165
);
169166
}
@@ -225,11 +222,11 @@ public function testExecuteFailedValidationMixed()
225222
->willReturn($dirRead);
226223
$this->tester->execute(['theme' => ['test1', 'test2', 'test3', 'test4']]);
227224
$this->assertContains(
228-
'test1, test4 are not installed composer packages',
225+
'test1, test4 are not installed Composer packages',
229226
$this->tester->getDisplay()
230227
);
231228
$this->assertNotContains(
232-
'test2 is not an installed composer package',
229+
'test2 is not an installed Composer package',
233230
$this->tester->getDisplay()
234231
);
235232
$this->assertContains(
@@ -274,7 +271,7 @@ public function testExecuteFailedChildVirtualThemeCheck()
274271
$this->themeProvider->expects($this->any())->method('getThemeByFullPath')->willReturn($theme);
275272
$this->tester->execute(['theme' => ['frontend/Magento/a']]);
276273
$this->assertContains(
277-
'Unable to delete. frontend/Magento/a is a base of virtual theme',
274+
'Unable to uninstall. frontend/Magento/a is a parent of virtual theme',
278275
$this->tester->getDisplay()
279276
);
280277
}
@@ -287,7 +284,7 @@ public function testExecuteFailedMultipleChildVirtualThemeCheck()
287284
$this->themeProvider->expects($this->any())->method('getThemeByFullPath')->willReturn($theme);
288285
$this->tester->execute(['theme' => ['frontend/Magento/a', 'frontend/Magento/b']]);
289286
$this->assertContains(
290-
'Unable to delete. frontend/Magento/a, frontend/Magento/b are bases of virtual theme',
287+
'Unable to uninstall. frontend/Magento/a, frontend/Magento/b are parents of virtual theme',
291288
$this->tester->getDisplay()
292289
);
293290
}

0 commit comments

Comments
 (0)