ThemeUninstallerTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\ThemeUninstaller;
  8. class ThemeUninstallerTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Theme\Model\Theme\ThemePackageInfo|\PHPUnit_Framework_MockObject_MockObject
  12. */
  13. private $themePackageInfo;
  14. /**
  15. * @var \Magento\Framework\Composer\Remove|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. private $remove;
  18. /**
  19. * @var \Magento\Theme\Model\Theme\ThemeProvider|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. private $themeProvider;
  22. /**
  23. * @var ThemeUninstaller
  24. */
  25. private $themeUninstaller;
  26. /**
  27. * @var \Symfony\Component\Console\Output\OutputInterface|\PHPUnit_Framework_MockObject_MockObject
  28. */
  29. private $output;
  30. protected function setUp()
  31. {
  32. $this->themePackageInfo = $this->createMock(\Magento\Theme\Model\Theme\ThemePackageInfo::class);
  33. $this->remove = $this->createMock(\Magento\Framework\Composer\Remove::class);
  34. $this->themeProvider = $this->createMock(\Magento\Theme\Model\Theme\ThemeProvider::class);
  35. $this->themeUninstaller = new ThemeUninstaller($this->themePackageInfo, $this->remove, $this->themeProvider);
  36. $this->output = $this->getMockForAbstractClass(
  37. \Symfony\Component\Console\Output\OutputInterface::class,
  38. [],
  39. '',
  40. false
  41. );
  42. }
  43. public function testUninstallRegistry()
  44. {
  45. $this->output->expects($this->atLeastOnce())->method('writeln');
  46. $this->themePackageInfo->expects($this->never())->method($this->anything());
  47. $this->remove->expects($this->never())->method($this->anything());
  48. $theme = $this->createMock(\Magento\Theme\Model\Theme::class);
  49. $theme->expects($this->exactly(3))->method('delete');
  50. $this->themeProvider->expects($this->exactly(3))->method('getThemeByFullPath')->willReturn($theme);
  51. $this->themeUninstaller->uninstallRegistry(
  52. $this->output,
  53. ['frontend/Magento/ThemeA', 'frontend/Magento/ThemeB', 'frontend/Magento/ThemeC']
  54. );
  55. }
  56. public function testUninstallCode()
  57. {
  58. $this->output->expects($this->atLeastOnce())->method('writeln');
  59. $this->themePackageInfo->expects($this->at(0))->method('getPackageName')->willReturn('packageA');
  60. $this->themePackageInfo->expects($this->at(1))->method('getPackageName')->willReturn('packageB');
  61. $this->themePackageInfo->expects($this->at(2))->method('getPackageName')->willReturn('packageC');
  62. $this->remove->expects($this->once())
  63. ->method('remove')
  64. ->with(['packageA', 'packageB', 'packageC'])
  65. ->willReturn('');
  66. $this->themeProvider->expects($this->never())->method($this->anything());
  67. $this->themeUninstaller->uninstallCode(
  68. $this->output,
  69. ['frontend/Magento/ThemeA', 'frontend/Magento/ThemeB', 'frontend/Magento/ThemeC']
  70. );
  71. }
  72. }