Skip to content

Commit 1f10cda

Browse files
author
Olga Kopylova
committed
Merge remote-tracking branch 'origin/MAGETWO-38833-fix-error-messages-theme-uninstall' into PR_Branch
2 parents 0ec059d + d9aca35 commit 1f10cda

File tree

4 files changed

+82
-56
lines changed

4 files changed

+82
-56
lines changed

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

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -194,25 +194,24 @@ protected function configure()
194194
*/
195195
protected function execute(InputInterface $input, OutputInterface $output)
196196
{
197+
$messages = [];
197198
$themePaths = $input->getArgument(self::INPUT_KEY_THEMES);
198-
$validationMessages = $this->validate($themePaths);
199-
if (!empty($validationMessages)) {
200-
$output->writeln($validationMessages);
201-
return;
202-
}
203-
$isThemeInUseMessages = $this->themeValidator->validateIsThemeInUse($themePaths);
204-
if (!empty($isThemeInUseMessages)) {
205-
$output->writeln($isThemeInUseMessages);
206-
return;
207-
}
208-
$childThemeCheckMessages = $this->checkChildTheme($themePaths);
209-
if (!empty($childThemeCheckMessages)) {
210-
$output->writeln($childThemeCheckMessages);
199+
$messages = array_merge($messages, $this->validate($themePaths));
200+
if (!empty($messages)) {
201+
$output->writeln($messages);
211202
return;
212203
}
213-
$dependencyMessages = $this->checkDependencies($themePaths);
214-
if (!empty($dependencyMessages)) {
215-
$output->writeln($dependencyMessages);
204+
$messages = array_merge(
205+
$messages,
206+
$this->themeValidator->validateIsThemeInUse($themePaths),
207+
$this->checkChildTheme($themePaths),
208+
$this->checkDependencies($themePaths)
209+
);
210+
if (!empty($messages)) {
211+
$output->writeln(
212+
'<error>Unable to uninstall. Please resolve the following issues:</error>'
213+
. PHP_EOL . implode(PHP_EOL, $messages)
214+
);
216215
return;
217216
}
218217

@@ -290,8 +289,8 @@ private function checkDependencies($themePaths)
290289
foreach ($dependencies as $package => $dependingPackages) {
291290
if (!empty($dependingPackages)) {
292291
$messages[] =
293-
'<error>Cannot uninstall ' . $packageToPath[$package] .
294-
" because the following package(s) depend on it:</error>" .
292+
'<error>' . $packageToPath[$package] .
293+
" has the following dependent package(s):</error>" .
295294
PHP_EOL . "\t<error>" . implode('</error>' . PHP_EOL . "\t<error>", $dependingPackages)
296295
. "</error>";
297296
}
@@ -322,13 +321,13 @@ private function checkChildTheme($themePaths)
322321
}
323322
if (!empty($themeHasVirtualChildren)) {
324323
$text = count($themeHasVirtualChildren) > 1 ? ' are parents of' : ' is a parent of';
325-
$messages[] = '<error>Unable to uninstall. '
326-
. implode(', ', $themeHasVirtualChildren) . $text . ' virtual theme</error>';
324+
$messages[] = '<error>' . implode(', ', $themeHasVirtualChildren) . $text . ' virtual theme.'
325+
. ' Parent themes cannot be uninstalled.</error>';
327326
}
328327
if (!empty($themeHasPhysicalChildren)) {
329328
$text = count($themeHasPhysicalChildren) > 1 ? ' are parents of' : ' is a parent of';
330-
$messages[] = '<error>Unable to uninstall. '
331-
. implode(', ', $themeHasPhysicalChildren) . $text . ' physical theme</error>';
329+
$messages[] = '<error>' . implode(', ', $themeHasPhysicalChildren) . $text . ' physical theme.'
330+
. ' Parent themes cannot be uninstalled.</error>';
332331
}
333332
return $messages;
334333
}

app/code/Magento/Theme/Model/ThemeValidator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ public function validateIsThemeInUse($themePaths)
7575
foreach ($configData as $row) {
7676
switch($row['scope']) {
7777
case 'default':
78-
$messages[] = $themesById[$row['value']] . ' is in use in default config';
78+
$messages[] = '<error>' . $themesById[$row['value']] . ' is in use in default config' . '</error>';
7979
break;
8080
case ScopeInterface::SCOPE_WEBSITES:
81-
$messages[] = $themesById[$row['value']] . ' is in use in website '
82-
. $this->storeManager->getWebsite($row['scope_id'])->getName();
81+
$messages[] = '<error>' . $themesById[$row['value']] . ' is in use in website '
82+
. $this->storeManager->getWebsite($row['scope_id'])->getName() . '</error>';
8383
break;
8484
case ScopeInterface::SCOPE_STORES:
85-
$messages[] = $themesById[$row['value']] . ' is in use in store '
86-
. $this->storeManager->getStore($row['scope_id'])->getName();
85+
$messages[] = '<error>' . $themesById[$row['value']] . ' is in use in store '
86+
. $this->storeManager->getStore($row['scope_id'])->getName() . '</error>';
8787
break;
8888
}
8989
}

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

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,33 @@ public function setupPassChildThemeCheck()
250250
$this->collection->expects($this->any())->method('getIterator')->willReturn(new \ArrayIterator([]));
251251
}
252252

253+
public function setupPassThemeInUseCheck()
254+
{
255+
$this->themeValidator->expects($this->once())->method('validateIsThemeInUse')->willReturn([]);
256+
}
257+
258+
public function setupPassDependencyCheck()
259+
{
260+
$this->dependencyChecker->expects($this->once())->method('checkDependencies')->willReturn([]);
261+
}
262+
263+
public function testExecuteFailedThemeInUseCheck()
264+
{
265+
$this->setUpPassValidation();
266+
$this->setupPassChildThemeCheck();
267+
$this->setupPassDependencyCheck();
268+
$this->themeValidator
269+
->expects($this->once())
270+
->method('validateIsThemeInUse')
271+
->willReturn(['frontend/Magento/a is in use in default config']);
272+
$this->tester->execute(['theme' => ['frontend/Magento/a']]);
273+
$this->assertEquals(
274+
'Unable to uninstall. Please resolve the following issues:' . PHP_EOL
275+
. 'frontend/Magento/a is in use in default config' . PHP_EOL,
276+
$this->tester->getDisplay()
277+
);
278+
}
279+
253280
/**
254281
* @dataProvider executeFailedChildThemeCheckDataProvider
255282
* @param bool $hasVirtual
@@ -261,6 +288,8 @@ public function setupPassChildThemeCheck()
261288
public function testExecuteFailedChildThemeCheck($hasVirtual, $hasPhysical, array $input, $expected)
262289
{
263290
$this->setUpPassValidation();
291+
$this->setupPassThemeInUseCheck();
292+
$this->setupPassDependencyCheck();
264293
$theme = $this->getMock('Magento\Theme\Model\Theme', [], [], '', false);
265294
$theme->expects($this->any())->method('hasChildThemes')->willReturn($hasVirtual);
266295
$parentThemeA = $this->getMock('Magento\Theme\Model\Theme', [], [], '', false);
@@ -282,10 +311,7 @@ public function testExecuteFailedChildThemeCheck($hasVirtual, $hasPhysical, arra
282311
->method('getIterator')
283312
->willReturn(new \ArrayIterator([$childThemeC, $childThemeD]));
284313
$this->tester->execute($input);
285-
$this->assertContains(
286-
$expected,
287-
$this->tester->getDisplay()
288-
);
314+
$this->assertContains($expected, $this->tester->getDisplay());
289315
}
290316

291317
/**
@@ -298,74 +324,75 @@ public function executeFailedChildThemeCheckDataProvider()
298324
true,
299325
false,
300326
['theme' => ['frontend/Magento/a']],
301-
'Unable to uninstall. frontend/Magento/a is a parent of virtual theme'
327+
'Unable to uninstall. Please resolve the following issues:' . PHP_EOL
328+
. 'frontend/Magento/a is a parent of virtual theme. Parent themes cannot be uninstalled.'
302329
],
303330
[
304331
true,
305332
false,
306333
['theme' => ['frontend/Magento/a', 'frontend/Magento/b']],
307-
'Unable to uninstall. frontend/Magento/a, frontend/Magento/b are parents of virtual theme'
334+
'Unable to uninstall. Please resolve the following issues:' . PHP_EOL .
335+
'frontend/Magento/a, frontend/Magento/b are parents of virtual theme.'
336+
. ' Parent themes cannot be uninstalled.'
308337
],
309338
[
310339
false,
311340
true,
312341
['theme' => ['frontend/Magento/a']],
313-
'Unable to uninstall. frontend/Magento/a is a parent of physical theme'
342+
'Unable to uninstall. Please resolve the following issues:' . PHP_EOL .
343+
'frontend/Magento/a is a parent of physical theme. Parent themes cannot be uninstalled.'
314344
],
315345
[
316346
false,
317347
true,
318348
['theme' => ['frontend/Magento/a', 'frontend/Magento/b']],
319-
'Unable to uninstall. frontend/Magento/a, frontend/Magento/b are parents of physical theme'
349+
'Unable to uninstall. Please resolve the following issues:' . PHP_EOL .
350+
'frontend/Magento/a, frontend/Magento/b are parents of physical theme.'
351+
. ' Parent themes cannot be uninstalled.'
320352
],
321353
[
322354
true,
323355
true,
324356
['theme' => ['frontend/Magento/a']],
325-
'Unable to uninstall. frontend/Magento/a is a parent of virtual theme' . PHP_EOL .
326-
'Unable to uninstall. frontend/Magento/a is a parent of physical theme'
357+
'Unable to uninstall. Please resolve the following issues:' . PHP_EOL .
358+
'frontend/Magento/a is a parent of virtual theme. Parent themes cannot be uninstalled.' . PHP_EOL .
359+
'frontend/Magento/a is a parent of physical theme. Parent themes cannot be uninstalled.'
327360
],
328361
[
329362
true,
330363
true,
331364
['theme' => ['frontend/Magento/a', 'frontend/Magento/b']],
332-
'Unable to uninstall. frontend/Magento/a, frontend/Magento/b are parents of virtual theme' . PHP_EOL .
333-
'Unable to uninstall. frontend/Magento/a, frontend/Magento/b are parents of physical theme'
365+
'frontend/Magento/a, frontend/Magento/b are parents of virtual theme.'
366+
. ' Parent themes cannot be uninstalled.' . PHP_EOL .
367+
'frontend/Magento/a, frontend/Magento/b are parents of physical theme.'
368+
. ' Parent themes cannot be uninstalled.'
334369
],
335370
];
336371
}
337372

338-
public function testExecuteFailedThemeInUseCheck()
339-
{
340-
$this->setUpPassValidation();
341-
$this->themeValidator
342-
->expects($this->once())
343-
->method('validateIsThemeInUse')
344-
->willReturn(['frontend/Magento/a is in use in default config']);
345-
$this->tester->execute(['theme' => ['frontend/Magento/a']]);
346-
$this->assertEquals('frontend/Magento/a is in use in default config' . PHP_EOL, $this->tester->getDisplay());
347-
}
348-
349373
public function testExecuteFailedDependencyCheck()
350374
{
351375
$this->setUpPassValidation();
376+
$this->setupPassThemeInUseCheck();
352377
$this->setupPassChildThemeCheck();
353378
$this->dependencyChecker->expects($this->once())
354379
->method('checkDependencies')
355380
->willReturn(['magento/theme-a' => ['magento/theme-b', 'magento/theme-c']]);
356381
$this->tester->execute(['theme' => ['frontend/Magento/a']]);
357382
$this->assertContains(
358-
'Cannot uninstall frontend/Magento/a because the following package(s) ' .
359-
'depend on it:' . PHP_EOL . "\tmagento/theme-b" . PHP_EOL . "\tmagento/theme-c",
383+
'Unable to uninstall. Please resolve the following issues:' . PHP_EOL .
384+
'frontend/Magento/a has the following dependent package(s):'
385+
. PHP_EOL . "\tmagento/theme-b" . PHP_EOL . "\tmagento/theme-c",
360386
$this->tester->getDisplay()
361387
);
362388
}
363389

364390
public function setUpExecute()
365391
{
366392
$this->setUpPassValidation();
393+
$this->setupPassThemeInUseCheck();
367394
$this->setupPassChildThemeCheck();
368-
$this->dependencyChecker->expects($this->once())->method('checkDependencies')->willReturn([]);
395+
$this->setupPassDependencyCheck();
369396
$this->remove->expects($this->once())->method('remove');
370397
$this->cache->expects($this->once())->method('clean');
371398
$theme = $this->getMock('Magento\Theme\Model\Theme', [], [], '', false);

app/code/Magento/Theme/Test/Unit/Model/ThemeValidatorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public function testValidateIsThemeInUse()
8181
$result = $this->themeValidator->validateIsThemeInUse(['frontend/Magento/a']);
8282
$this->assertEquals(
8383
[
84-
'frontend/Magento/a is in use in default config',
85-
'frontend/Magento/a is in use in website websiteA',
86-
'frontend/Magento/a is in use in store storeA'
84+
'<error>frontend/Magento/a is in use in default config</error>',
85+
'<error>frontend/Magento/a is in use in website websiteA</error>',
86+
'<error>frontend/Magento/a is in use in store storeA</error>'
8787
],
8888
$result
8989
);

0 commit comments

Comments
 (0)