Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NomediaTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 require_once __DIR__ . '/_files/io.php';
11 
12 class NomediaTest extends \PHPUnit\Framework\TestCase
13 {
17  private $objectManager;
18 
22  protected $_filesystemMock;
23 
28 
32  protected $_backupDbMock;
33 
37  private $fsMock;
38 
39  public static function setUpBeforeClass()
40  {
41  require __DIR__ . '/_files/app_dirs.php';
42  }
43 
44  public static function tearDownAfterClass()
45  {
46  require __DIR__ . '/_files/app_dirs_rollback.php';
47  }
48 
49  protected function setUp()
50  {
51  $this->objectManager = new ObjectManager($this);
52  $this->_backupDbMock = $this->createMock(\Magento\Framework\Backup\Db::class);
53  $this->_backupDbMock->expects($this->any())->method('setBackupExtension')->will($this->returnSelf());
54 
55  $this->_backupDbMock->expects($this->any())->method('setTime')->will($this->returnSelf());
56 
57  $this->_backupDbMock->expects($this->any())->method('setBackupsDir')->will($this->returnSelf());
58 
59  $this->_backupDbMock->expects($this->any())->method('setResourceModel')->will($this->returnSelf());
60 
61  $this->_backupDbMock->expects(
62  $this->any()
63  )->method(
64  'getBackupPath'
65  )->will(
66  $this->returnValue('\unexistingpath')
67  );
68 
69  $this->_backupDbMock->expects($this->any())->method('create')->will($this->returnValue(true));
70 
71  $this->_filesystemMock = $this->createMock(\Magento\Framework\Filesystem::class);
72  $dirMock = $this->getMockForAbstractClass(\Magento\Framework\Filesystem\Directory\WriteInterface::class);
73  $this->_filesystemMock->expects($this->any())
74  ->method('getDirectoryWrite')
75  ->will($this->returnValue($dirMock));
76 
77  $this->_backupFactoryMock = $this->createMock(\Magento\Framework\Backup\Factory::class);
78  $this->_backupFactoryMock->expects(
79  $this->once()
80  )->method(
81  'create'
82  )->will(
83  $this->returnValue($this->_backupDbMock)
84  );
85 
86  $this->fsMock = $this->createMock(\Magento\Framework\Backup\Filesystem\Rollback\Fs::class);
87  }
88 
93  public function testAction($action)
94  {
95  $this->_backupFactoryMock->expects($this->once())->method('create');
96 
97  $rootDir = TESTS_TEMP_DIR . '/Magento/Backup/data';
98 
99  $model = $this->objectManager->getObject(
100  \Magento\Framework\Backup\Nomedia::class,
101  [
102  'filesystem' => $this->_filesystemMock,
103  'backupFactory' => $this->_backupFactoryMock,
104  'rollBackFs' => $this->fsMock,
105  ]
106  );
107  $model->setRootDir($rootDir);
108  $model->setBackupsDir($rootDir);
109  $model->{$action}();
110  $this->assertTrue($model->getIsSuccess());
111 
112  $this->assertEquals([$rootDir, $rootDir . '/media', $rootDir . '/pub/media'], $model->getIgnorePaths());
113  }
114 
118  public static function actionProvider()
119  {
120  return [['create'], ['rollback']];
121  }
122 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$rootDir
Definition: website.php:12