Add more tests for Storage::copy()

This commit is contained in:
Kijin Sung 2016-07-11 11:19:04 +09:00
parent 55547c56e4
commit 59b33e8f29

View file

@ -9,11 +9,13 @@ class StorageTest extends \Codeception\TestCase\Test
public function _after() public function _after()
{ {
@chmod(\RX_BASEDIR . 'tests/_output', 0755);
Rhymix\Framework\Storage::deleteDirectory(\RX_BASEDIR . 'tests/_output', false); Rhymix\Framework\Storage::deleteDirectory(\RX_BASEDIR . 'tests/_output', false);
} }
public function _failed() public function _failed()
{ {
@chmod(\RX_BASEDIR . 'tests/_output', 0755);
Rhymix\Framework\Storage::deleteDirectory(\RX_BASEDIR . 'tests/_output', false); Rhymix\Framework\Storage::deleteDirectory(\RX_BASEDIR . 'tests/_output', false);
} }
@ -191,13 +193,28 @@ class StorageTest extends \Codeception\TestCase\Test
{ {
$source = \RX_BASEDIR . 'tests/_output/copy.source.txt'; $source = \RX_BASEDIR . 'tests/_output/copy.source.txt';
$target = \RX_BASEDIR . 'tests/_output/copy.target.txt'; $target = \RX_BASEDIR . 'tests/_output/copy.target.txt';
$target_dir = \RX_BASEDIR . 'tests/_output';
file_put_contents($source, 'foobarbaz'); file_put_contents($source, 'foobarbaz');
chmod($source, 0646); chmod($source, 0646);
// Copy with exact destination filename
$this->assertTrue(Rhymix\Framework\Storage::copy($source, $target)); $this->assertTrue(Rhymix\Framework\Storage::copy($source, $target));
$this->assertTrue(file_exists($target)); $this->assertTrue(file_exists($target));
$this->assertTrue(file_get_contents($target) === 'foobarbaz'); $this->assertTrue(file_get_contents($target) === 'foobarbaz');
// Copy into directory with source filename
$this->assertTrue(Rhymix\Framework\Storage::copy($source, $target_dir));
$this->assertTrue(file_exists($target_dir . '/copy.source.txt'));
$this->assertTrue(file_get_contents($target_dir . '/copy.source.txt') === 'foobarbaz');
// Copy into directory with no write permissions
chmod($target_dir, 0555);
file_put_contents($source, 'foobarbaz has changed');
$this->assertTrue(Rhymix\Framework\Storage::copy($source, $target));
$this->assertTrue(file_exists($target));
$this->assertTrue(file_get_contents($target) === 'foobarbaz has changed');
chmod($target_dir, 0755);
if (strncasecmp(\PHP_OS, 'Win', 3) !== 0) if (strncasecmp(\PHP_OS, 'Win', 3) !== 0)
{ {
$this->assertEquals(0646, fileperms($target) & 0777); $this->assertEquals(0646, fileperms($target) & 0777);