mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 05:18:52 +00:00
[ticket/15287] Update test
PHPBB3-15287
This commit is contained in:
parent
5897876f2f
commit
95ebd5d894
1 changed files with 34 additions and 30 deletions
|
@ -13,47 +13,51 @@
|
||||||
|
|
||||||
class phpbb_storage_adapter_local_test extends phpbb_test_case
|
class phpbb_storage_adapter_local_test extends phpbb_test_case
|
||||||
{
|
{
|
||||||
protected $adapter;
|
protected $adapter;
|
||||||
|
|
||||||
|
protected $path;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$config = new \phpbb\config\config(array(
|
|
||||||
'test_path' => '.',
|
|
||||||
));
|
|
||||||
$filesystem = new \phpbb\filesystem\filesystem();
|
$filesystem = new \phpbb\filesystem\filesystem();
|
||||||
$phpbb_root_path = getcwd() . DIRECTORY_SEPARATOR;
|
$phpbb_root_path = getcwd() . DIRECTORY_SEPARATOR;
|
||||||
$path_key = 'test_path';
|
|
||||||
$this->adapter = new \phpbb\storage\adapter\local($config, $filesystem, $phpbb_root_path, $path_key);
|
$this->adapter = new \phpbb\storage\adapter\local($filesystem, $phpbb_root_path);
|
||||||
|
$this->adapter->configure(['path' => 'test_path']);
|
||||||
|
|
||||||
|
$this->path = $phpbb_root_path . 'test_path/';
|
||||||
|
mkdir($this->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function data_test_exists()
|
public function data_test_exists()
|
||||||
{
|
{
|
||||||
yield ['README.md', true];
|
yield [$this->path . '../README.md', true];
|
||||||
yield ['nonexistent_file.php', false];
|
yield [$this->path . 'nonexistent_file.php', false];
|
||||||
yield ['phpBB/phpbb', true];
|
yield [$this->path . '../phpBB/phpbb', true];
|
||||||
yield ['nonexistent/folder', false];
|
yield [$this->path . 'nonexistent/folder', false];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
$this->adapter = null;
|
$this->adapter = null;
|
||||||
|
rmdir($this->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_put_contents()
|
public function test_put_contents()
|
||||||
{
|
{
|
||||||
$this->adapter->put_contents('file.txt', 'abc');
|
$this->adapter->put_contents('file.txt', 'abc');
|
||||||
$this->assertTrue(file_exists('file.txt'));
|
$this->assertTrue(file_exists($this->path . 'file.txt'));
|
||||||
$this->assertEquals(file_get_contents('file.txt'), 'abc');
|
$this->assertEquals(file_get_contents($this->path . 'file.txt'), 'abc');
|
||||||
unlink('file.txt');
|
unlink($this->path . 'file.txt');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_get_contents()
|
public function test_get_contents()
|
||||||
{
|
{
|
||||||
file_put_contents('file.txt', 'abc');
|
file_put_contents($this->path . 'file.txt', 'abc');
|
||||||
$this->assertEquals($this->adapter->get_contents('file.txt'), 'abc');
|
$this->assertEquals($this->adapter->get_contents('file.txt'), 'abc');
|
||||||
unlink('file.txt');
|
unlink($this->path . 'file.txt');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,37 +70,37 @@
|
||||||
|
|
||||||
public function test_delete_file()
|
public function test_delete_file()
|
||||||
{
|
{
|
||||||
file_put_contents('file.txt', '');
|
file_put_contents($this->path . 'file.txt', '');
|
||||||
$this->assertTrue(file_exists('file.txt'));
|
$this->assertTrue(file_exists($this->path . 'file.txt'));
|
||||||
$this->adapter->delete('file.txt');
|
$this->adapter->delete('file.txt');
|
||||||
$this->assertFalse(file_exists('file.txt'));
|
$this->assertFalse(file_exists($this->path . 'file.txt'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_delete_folder()
|
public function test_delete_folder()
|
||||||
{
|
{
|
||||||
mkdir('path/to/dir', 0777, true);
|
mkdir($this->path . 'path/to/dir', 0777, true);
|
||||||
$this->assertTrue(file_exists('path/to/dir'));
|
$this->assertTrue(file_exists($this->path . 'path/to/dir'));
|
||||||
$this->adapter->delete('path');
|
$this->adapter->delete('path');
|
||||||
$this->assertFalse(file_exists('path/to/dir'));
|
$this->assertFalse(file_exists($this->path . 'path/to/dir'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_rename()
|
public function test_rename()
|
||||||
{
|
{
|
||||||
file_put_contents('file.txt', '');
|
file_put_contents($this->path . 'file.txt', '');
|
||||||
$this->adapter->rename('file.txt', 'file2.txt');
|
$this->adapter->rename('file.txt', 'file2.txt');
|
||||||
$this->assertFalse(file_exists('file.txt'));
|
$this->assertFalse(file_exists($this->path . 'file.txt'));
|
||||||
$this->assertTrue(file_exists('file2.txt'));
|
$this->assertTrue(file_exists($this->path . 'file2.txt'));
|
||||||
unlink('file2.txt');
|
unlink($this->path . 'file2.txt');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_copy()
|
public function test_copy()
|
||||||
{
|
{
|
||||||
file_put_contents('file.txt', 'abc');
|
file_put_contents($this->path . 'file.txt', 'abc');
|
||||||
$this->adapter->copy('file.txt', 'file2.txt');
|
$this->adapter->copy('file.txt', 'file2.txt');
|
||||||
$this->assertEquals(file_get_contents('file.txt'), 'abc');
|
$this->assertEquals(file_get_contents($this->path . 'file.txt'), 'abc');
|
||||||
$this->assertEquals(file_get_contents('file.txt'), 'abc');
|
$this->assertEquals(file_get_contents($this->path . 'file.txt'), 'abc');
|
||||||
unlink('file.txt');
|
unlink($this->path . 'file.txt');
|
||||||
unlink('file2.txt');
|
unlink($this->path . 'file2.txt');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue