mirror of
https://github.com/fadlee/bigdump.git
synced 2025-10-24 05:06:09 +02:00
I've converted the original `bigdump.php` script into an object-oriented application with a clear separation of concerns. Key changes include: - A new directory structure (`src`, `public`, `templates`, `config`). - Object-oriented code with classes for `Configuration`, `Database`, `FileHandler`, and `Dumper`. - Separation of HTML, CSS, and JavaScript from the PHP logic. - Improved security by mitigating XSS and file path traversal risks. - A new `README.md` with updated instructions. - Unit tests for the core classes (written but not run due to environment constraints).
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
use BigDump\Configuration;
|
|
use BigDump\FileHandler;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class FileHandlerTest extends TestCase
|
|
{
|
|
private $config;
|
|
private $fileHandler;
|
|
private $testFile;
|
|
private $uploadDir;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->config = new Configuration();
|
|
$this->fileHandler = new FileHandler($this->config);
|
|
$this->uploadDir = $this->config->upload_dir;
|
|
$this->testFile = $this->uploadDir . '/test.sql';
|
|
|
|
if (!is_dir($this->uploadDir)) {
|
|
mkdir($this->uploadDir, 0777, true);
|
|
}
|
|
file_put_contents($this->testFile, 'test data');
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
if (file_exists($this->testFile)) {
|
|
unlink($this->testFile);
|
|
}
|
|
// Small cleanup: remove data dir if empty
|
|
if (is_dir($this->uploadDir) && count(scandir($this->uploadDir)) == 2) {
|
|
rmdir($this->uploadDir);
|
|
}
|
|
}
|
|
|
|
public function testGetAvailableDumps()
|
|
{
|
|
$dumps = $this->fileHandler->getAvailableDumps();
|
|
$this->assertCount(1, $dumps);
|
|
$this->assertEquals('test.sql', $dumps[0]['name']);
|
|
}
|
|
|
|
public function testDeleteFile()
|
|
{
|
|
$this->fileHandler->deleteFile('test.sql');
|
|
$this->assertFileDoesNotExist($this->testFile);
|
|
}
|
|
}
|