NomediaTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Backup\Test\Unit;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  8. require_once __DIR__ . '/_files/io.php';
  9. class NomediaTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
  13. */
  14. private $objectManager;
  15. /**
  16. * @var \Magento\Framework\Filesystem
  17. */
  18. protected $_filesystemMock;
  19. /**
  20. * @var \Magento\Framework\Backup\Factory
  21. */
  22. protected $_backupFactoryMock;
  23. /**
  24. * @var \Magento\Framework\Backup\Db
  25. */
  26. protected $_backupDbMock;
  27. /**
  28. * @var \Magento\Framework\Backup\Filesystem\Rollback\Fs
  29. */
  30. private $fsMock;
  31. public static function setUpBeforeClass()
  32. {
  33. require __DIR__ . '/_files/app_dirs.php';
  34. }
  35. public static function tearDownAfterClass()
  36. {
  37. require __DIR__ . '/_files/app_dirs_rollback.php';
  38. }
  39. protected function setUp()
  40. {
  41. $this->objectManager = new ObjectManager($this);
  42. $this->_backupDbMock = $this->createMock(\Magento\Framework\Backup\Db::class);
  43. $this->_backupDbMock->expects($this->any())->method('setBackupExtension')->will($this->returnSelf());
  44. $this->_backupDbMock->expects($this->any())->method('setTime')->will($this->returnSelf());
  45. $this->_backupDbMock->expects($this->any())->method('setBackupsDir')->will($this->returnSelf());
  46. $this->_backupDbMock->expects($this->any())->method('setResourceModel')->will($this->returnSelf());
  47. $this->_backupDbMock->expects(
  48. $this->any()
  49. )->method(
  50. 'getBackupPath'
  51. )->will(
  52. $this->returnValue('\unexistingpath')
  53. );
  54. $this->_backupDbMock->expects($this->any())->method('create')->will($this->returnValue(true));
  55. $this->_filesystemMock = $this->createMock(\Magento\Framework\Filesystem::class);
  56. $dirMock = $this->getMockForAbstractClass(\Magento\Framework\Filesystem\Directory\WriteInterface::class);
  57. $this->_filesystemMock->expects($this->any())
  58. ->method('getDirectoryWrite')
  59. ->will($this->returnValue($dirMock));
  60. $this->_backupFactoryMock = $this->createMock(\Magento\Framework\Backup\Factory::class);
  61. $this->_backupFactoryMock->expects(
  62. $this->once()
  63. )->method(
  64. 'create'
  65. )->will(
  66. $this->returnValue($this->_backupDbMock)
  67. );
  68. $this->fsMock = $this->createMock(\Magento\Framework\Backup\Filesystem\Rollback\Fs::class);
  69. }
  70. /**
  71. * @param string $action
  72. * @dataProvider actionProvider
  73. */
  74. public function testAction($action)
  75. {
  76. $this->_backupFactoryMock->expects($this->once())->method('create');
  77. $rootDir = TESTS_TEMP_DIR . '/Magento/Backup/data';
  78. $model = $this->objectManager->getObject(
  79. \Magento\Framework\Backup\Nomedia::class,
  80. [
  81. 'filesystem' => $this->_filesystemMock,
  82. 'backupFactory' => $this->_backupFactoryMock,
  83. 'rollBackFs' => $this->fsMock,
  84. ]
  85. );
  86. $model->setRootDir($rootDir);
  87. $model->setBackupsDir($rootDir);
  88. $model->{$action}();
  89. $this->assertTrue($model->getIsSuccess());
  90. $this->assertEquals([$rootDir, $rootDir . '/media', $rootDir . '/pub/media'], $model->getIgnorePaths());
  91. }
  92. /**
  93. * @return array
  94. */
  95. public static function actionProvider()
  96. {
  97. return [['create'], ['rollback']];
  98. }
  99. }