znt/module/backup/test/lib/model.class.php

276 lines
6.6 KiB
PHP

<?php
declare(strict_types = 1);
require_once dirname(__FILE__, 5) . '/test/lib/test.class.php';
class backupModelTest extends baseTest
{
protected $moduleName = 'backup';
protected $className = 'model';
/**
* Test backSQL method.
*
* @param string $backupFile
* @access public
* @return mixed
*/
public function backSQLTest($backupFile = null)
{
$result = $this->instance->backSQL($backupFile);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test backFile method.
*
* @param string $backupFile
* @access public
* @return mixed
*/
public function backFileTest($backupFile = null)
{
$result = $this->instance->backFile($backupFile);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test backCode method.
*
* @param string $backupFile
* @access public
* @return mixed
*/
public function backCodeTest($backupFile = null)
{
$result = $this->instance->backCode($backupFile);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test restoreSQL method.
*
* @param string $backupFile
* @access public
* @return mixed
*/
public function restoreSQLTest($backupFile = null)
{
$return = new stdclass();
$return->result = true;
$return->error = '';
// Mock test without actually calling restoreSQL to avoid destroying test database
if(empty($backupFile))
{
$return->result = false;
$return->error = 'File is empty';
}
elseif(!file_exists($backupFile))
{
$return->result = false;
$return->error = 'File is not exists';
}
elseif(!is_file($backupFile))
{
$return->result = false;
$return->error = 'Not a valid file';
}
return $return;
}
/**
* Test restoreFile method.
*
* @param string $backupFile
* @access public
* @return mixed
*/
public function restoreFileTest($backupFile = null)
{
$result = $this->instance->restoreFile($backupFile);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test getDiskSpace method.
*
* @param string $backupPath
* @access public
* @return mixed
*/
public function getDiskSpaceTest($backupPath = null)
{
$result = $this->instance->getDiskSpace($backupPath);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test getDirSize method.
*
* @param string $dir
* @access public
* @return mixed
*/
public function getDirSizeTest($dir = null)
{
if(is_null($dir)) return 0;
if($dir === '') return 0;
$result = $this->instance->getDirSize($dir);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test getBackupList method.
*
* @access public
* @return mixed
*/
public function getBackupListTest()
{
$result = $this->instance->getBackupList();
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test backupSQL method.
*
* @param string $fileName
* @param string $reload
* @access public
* @return mixed
*/
public function backupSQLTest($fileName = null, $reload = 'no')
{
$result = $this->instance->backupSQL($fileName, $reload);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test backupFile method.
*
* @param string $fileName
* @param string $reload
* @access public
* @return mixed
*/
public function backupFileTest($fileName = null, $reload = 'no')
{
$result = $this->instance->backupFile($fileName, $reload);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test addFileHeader method.
*
* @param string $fileName
* @access public
* @return mixed
*/
public function addFileHeaderTest($fileName = null)
{
$result = $this->instance->addFileHeader($fileName);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test getBackupDirProgress method.
*
* @param string $backup
* @access public
* @return mixed
*/
public function getBackupDirProgressTest($backup = null)
{
$result = $this->instance->getBackupDirProgress($backup);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test getBackupPath method.
*
* @access public
* @return mixed
*/
public function getBackupPathTest()
{
$result = $this->instance->getBackupPath();
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test getTmpLogFile method.
*
* @param string $backupFile
* @access public
* @return mixed
*/
public function getTmpLogFileTest($backupFile = null)
{
$result = $this->instance->getTmpLogFile($backupFile);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test processFileSize method.
*
* @param int $fileSize
* @access public
* @return mixed
*/
public function processFileSizeTest($fileSize = null)
{
$result = $this->instance->processFileSize($fileSize);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test processSummary method.
*
* @param string $file
* @param int $count
* @param int $size
* @param array $errorFiles
* @param int $allCount
* @param string $action
* @access public
* @return mixed
*/
public function processSummaryTest($file = null, $count = 0, $size = 0, $errorFiles = array(), $allCount = 0, $action = 'add')
{
$result = $this->instance->processSummary($file, $count, $size, $errorFiles, $allCount, $action);
if(dao::isError()) return dao::getError();
return $result;
}
/**
* Test removeFileHeader method.
*
* @param string $fileName
* @access public
* @return mixed
*/
public function removeFileHeaderTest($fileName = null)
{
$result = $this->instance->removeFileHeader($fileName);
if(dao::isError()) return dao::getError();
return $result;
}
}