/**
  * @covers \Magento\Backup\Model\Backup::output
  * @param bool $isFile
  * @param string $result
  * @dataProvider outputDataProvider
  */
 public function testOutput($isFile, $result)
 {
     $path = '/path/to';
     $time = 1;
     $name = 'test';
     $type = 'db';
     $extension = 'sql';
     $relativePath = '/path/to/1_db_test.sql';
     $contents = 'test_result';
     $this->directoryMock->expects($this->atLeastOnce())->method('isFile')->with($relativePath)->willReturn($isFile);
     $this->directoryMock->expects($this->any())->method('getRelativePath')->with($relativePath)->willReturn($relativePath);
     $this->directoryMock->expects($this->any())->method('readFile')->with($relativePath)->willReturn($contents);
     $this->dataHelperMock->expects($this->any())->method('getExtensionByType')->with($type)->willReturn($extension);
     $this->backupModel->setPath($path);
     $this->backupModel->setName($name);
     $this->backupModel->setTime($time);
     $this->assertEquals($result, $this->backupModel->output());
 }
Beispiel #2
0
 /**
  * @covers \Magento\Backup\Controller\Adminhtml\Index\Download::execute
  */
 public function testExecuteBackupFound()
 {
     $time = 1;
     $type = 'db';
     $filename = 'filename';
     $size = 10;
     $output = 'test';
     $this->backupModelMock->expects($this->atLeastOnce())->method('getTime')->willReturn($time);
     $this->backupModelMock->expects($this->atLeastOnce())->method('exists')->willReturn(true);
     $this->backupModelMock->expects($this->atLeastOnce())->method('getSize')->willReturn($size);
     $this->backupModelMock->expects($this->atLeastOnce())->method('output')->willReturn($output);
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['time', null, $time], ['type', null, $type]]);
     $this->backupModelFactoryMock->expects($this->once())->method('create')->with($time, $type)->willReturn($this->backupModelMock);
     $this->dataHelperMock->expects($this->once())->method('generateBackupDownloadName')->with($this->backupModelMock)->willReturn($filename);
     $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Backup\\Helper\\Data')->willReturn($this->dataHelperMock);
     $this->fileFactoryMock->expects($this->once())->method('create')->with($filename, null, DirectoryList::VAR_DIR, 'application/octet-stream', $size)->willReturn($this->responseMock);
     $this->resultRawMock->expects($this->once())->method('setContents')->with($output);
     $this->resultRawFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRawMock);
     $this->assertSame($this->resultRawMock, $this->downloadController->execute());
 }