DataTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backup\Test\Unit\Helper;
  7. use Magento\Framework\App\Filesystem\DirectoryList;
  8. use Magento\Framework\App\MaintenanceMode;
  9. use Magento\Framework\Filesystem;
  10. class DataTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Backup\Helper\Data
  14. */
  15. protected $helper;
  16. /**
  17. * @var \Magento\Framework\Filesystem | \PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $filesystem;
  20. protected function setUp()
  21. {
  22. $this->filesystem = $this->getMockBuilder(\Magento\Framework\Filesystem::class)->disableOriginalConstructor()
  23. ->getMock();
  24. $this->filesystem->expects($this->any())
  25. ->method('getDirectoryRead')
  26. ->will($this->returnCallback(function ($code) {
  27. $dir = $this->getMockForAbstractClass(\Magento\Framework\Filesystem\Directory\ReadInterface::class);
  28. $dir->expects($this->any())
  29. ->method('getAbsolutePath')
  30. ->will($this->returnCallback(function ($path) use ($code) {
  31. $path = empty($path) ? $path : '/' . $path;
  32. return rtrim($code, '/') . $path;
  33. }));
  34. return $dir;
  35. }));
  36. $this->helper = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
  37. ->getObject(
  38. \Magento\Backup\Helper\Data::class,
  39. ['filesystem' => $this->filesystem]
  40. );
  41. }
  42. public function testGetBackupIgnorePaths()
  43. {
  44. $this->assertEquals(
  45. [
  46. '.git',
  47. '.svn',
  48. MaintenanceMode::FLAG_DIR . '/' . MaintenanceMode::FLAG_FILENAME,
  49. DirectoryList::SESSION,
  50. DirectoryList::CACHE,
  51. DirectoryList::LOG,
  52. DirectoryList::VAR_DIR . '/full_page_cache',
  53. DirectoryList::VAR_DIR . '/locks',
  54. DirectoryList::VAR_DIR . '/report',
  55. ],
  56. $this->helper->getBackupIgnorePaths()
  57. );
  58. }
  59. public function testGetRollbackIgnorePaths()
  60. {
  61. $this->assertEquals(
  62. [
  63. '.svn',
  64. '.git',
  65. 'var/' . MaintenanceMode::FLAG_FILENAME,
  66. DirectoryList::SESSION,
  67. DirectoryList::LOG,
  68. DirectoryList::VAR_DIR . '/locks',
  69. DirectoryList::VAR_DIR . '/report',
  70. DirectoryList::ROOT . '/errors',
  71. DirectoryList::ROOT . '/index.php',
  72. ],
  73. $this->helper->getRollbackIgnorePaths()
  74. );
  75. }
  76. }