mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
Split out and improve tests
This commit is contained in:
parent
5c57d2d094
commit
65b76d6428
3 changed files with 74 additions and 95 deletions
|
|
@ -38,23 +38,14 @@ class Connection extends RawConnection {
|
|||
|
||||
$output = array();
|
||||
$line = $this->readLine();
|
||||
$length = strlen(self::DELIMITER);
|
||||
while (substr($line, 0, $length) !== self::DELIMITER) { //next prompt functions as delimiter
|
||||
$length = mb_strlen(self::DELIMITER);
|
||||
while (mb_substr($line, 0, $length) !== self::DELIMITER) { //next prompt functions as delimiter
|
||||
$output[] .= $line;
|
||||
$line = parent::read();
|
||||
$line = $this->readLine();
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* read a single line of unprocessed output
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function readLine() {
|
||||
return parent::read();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the first line holds a connection failure
|
||||
*
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ class RawConnection {
|
|||
setlocale(LC_ALL, Server::LOCALE);
|
||||
$env = array_merge($env, array(
|
||||
'CLI_FORCE_INTERACTIVE' => 'y', // Needed or the prompt isn't displayed!!
|
||||
'LC_ALL' => Server::LOCALE
|
||||
'LC_ALL' => Server::LOCALE,
|
||||
'LANG' => Server::LOCALE
|
||||
));
|
||||
$this->process = proc_open($command, $descriptorSpec, $this->pipes, '/', $env);
|
||||
if (!$this->isValid()) {
|
||||
|
|
@ -72,8 +73,8 @@ class RawConnection {
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function read() {
|
||||
return trim(fgets($this->getOutputStream()));
|
||||
public function readLine() {
|
||||
return stream_get_line($this->getOutputStream(), 4086, "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -83,7 +84,7 @@ class RawConnection {
|
|||
*/
|
||||
public function readAll() {
|
||||
$output = array();
|
||||
while ($line = $this->read()) {
|
||||
while ($line = $this->readLine()) {
|
||||
$output[] = $line;
|
||||
}
|
||||
return $output;
|
||||
|
|
|
|||
|
|
@ -37,12 +37,13 @@ abstract class AbstractShare extends \PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
public function nameProvider() {
|
||||
// / ? < > \ : * | " are illegal characters in path on windows, no use trying to get them working
|
||||
// / ? < > \ : * | " are illegal characters in path on windows
|
||||
return array(
|
||||
array('simple'),
|
||||
array('with spaces_and-underscores'),
|
||||
array("single'quote'"),
|
||||
array('$as#d€££Ö€ßœĚęĘĞĜΣΥΦΩΫΫ')
|
||||
array('日本語'),
|
||||
array('$as#d€££Ö€ßœĚęĘĞĜΣΥΦΩΫ')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -96,110 +97,101 @@ abstract class AbstractShare extends \PHPUnit_Framework_TestCase {
|
|||
$this->fail('Share "' . $this->config->share . '" not found');
|
||||
}
|
||||
|
||||
public function testDirectory() {
|
||||
public function testRootStartsEmpty() {
|
||||
$this->assertEquals(array(), $this->share->dir($this->root));
|
||||
|
||||
$this->share->mkdir($this->root . '/foo');
|
||||
$dirs = $this->share->dir($this->root);
|
||||
$this->assertCount(1, $dirs);
|
||||
$this->assertEquals('foo', $dirs[0]->getName());
|
||||
|
||||
$this->share->rename($this->root . '/foo', $this->root . '/bar');
|
||||
|
||||
$dirs = $this->share->dir($this->root);
|
||||
$this->assertEquals(1, count($dirs));
|
||||
$this->assertEquals('bar', $dirs[0]->getName());
|
||||
|
||||
$this->share->rmdir($this->root . '/bar');
|
||||
$this->assertCount(0, $this->share->dir($this->root));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider fileDataProvider
|
||||
*/
|
||||
public function testFile($text) {
|
||||
$size = strlen($text);
|
||||
$tmpFile1 = tempnam('/tmp', 'smb_test_');
|
||||
file_put_contents($tmpFile1, $text);
|
||||
|
||||
$this->share->put($tmpFile1, $this->root . '/lorem.txt');
|
||||
unlink($tmpFile1);
|
||||
|
||||
$files = $this->share->dir($this->root);
|
||||
$this->assertCount(1, $files);
|
||||
$this->assertEquals('lorem.txt', $files[0]->getName());
|
||||
$this->assertEquals($size, $files[0]->getSize());
|
||||
|
||||
$this->share->rename($this->root . '/lorem.txt', $this->root . '/foo.txt');
|
||||
|
||||
$files = $this->share->dir($this->root);
|
||||
$this->assertEquals(1, count($files));
|
||||
$this->assertEquals('foo.txt', $files[0]->getName());
|
||||
|
||||
$tmpFile2 = tempnam('/tmp', 'smb_test_');
|
||||
$this->share->get($this->root . '/foo.txt', $tmpFile2);
|
||||
|
||||
$this->assertEquals($text, file_get_contents($tmpFile2));
|
||||
unlink($tmpFile2);
|
||||
|
||||
$this->share->del($this->root . '/foo.txt');
|
||||
$this->assertCount(0, $this->share->dir($this->root));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider nameProvider
|
||||
*/
|
||||
public function testEscaping($name) {
|
||||
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
|
||||
$tmpFile1 = tempnam('/tmp', 'smb_test_');
|
||||
file_put_contents($tmpFile1, $text);
|
||||
|
||||
public function testMkdir($name) {
|
||||
$this->share->mkdir($this->root . '/' . $name);
|
||||
$dir = $this->share->dir($this->root);
|
||||
$this->assertEquals($name, $dir[0]->getName());
|
||||
$this->assertTrue($dir[0]->isDirectory());
|
||||
$this->assertCount(0, $this->share->dir($this->root . '/' . $name));
|
||||
$dirs = $this->share->dir($this->root);
|
||||
$this->assertCount(1, $dirs);
|
||||
$this->assertEquals($name, $dirs[0]->getName());
|
||||
$this->assertTrue($dirs[0]->isDirectory());
|
||||
}
|
||||
|
||||
$this->share->put($tmpFile1, $this->root . '/' . $name . '/foo.txt');
|
||||
$dir = $this->share->dir($this->root . '/' . $name);
|
||||
$this->assertEquals('foo.txt', $dir[0]->getName());
|
||||
/**
|
||||
* @dataProvider nameProvider
|
||||
*/
|
||||
public function testRenameDirectory($name) {
|
||||
$this->share->mkdir($this->root . '/' . $name);
|
||||
$this->share->rename($this->root . '/' . $name, $this->root . '/' . $name . '_rename');
|
||||
$dirs = $this->share->dir($this->root);
|
||||
$this->assertEquals(1, count($dirs));
|
||||
$this->assertEquals($name . '_rename', $dirs[0]->getName());
|
||||
}
|
||||
|
||||
$tmpFile2 = tempnam('/tmp', 'smb_test_');
|
||||
$this->share->get($this->root . '/' . $name . '/foo.txt', $tmpFile2);
|
||||
$this->assertEquals($text, file_get_contents($tmpFile2));
|
||||
unlink($tmpFile2);
|
||||
|
||||
$this->share->rename($this->root . '/' . $name . '/foo.txt', $this->root . '/' . $name . '/bar.txt');
|
||||
$dir = $this->share->dir($this->root . '/' . $name);
|
||||
$this->assertEquals('bar.txt', $dir[0]->getName());
|
||||
$this->assertFalse($dir[0]->isDirectory());
|
||||
|
||||
$this->share->del($this->root . '/' . $name . '/bar.txt');
|
||||
$this->assertCount(0, $this->share->dir($this->root . '/' . $name));
|
||||
/**
|
||||
* @dataProvider nameProvider
|
||||
*/
|
||||
public function testRmdir($name) {
|
||||
$this->share->mkdir($this->root . '/' . $name);
|
||||
$this->share->rmdir($this->root . '/' . $name);
|
||||
$this->assertCount(0, $this->share->dir($this->root));
|
||||
}
|
||||
|
||||
$this->share->put($tmpFile1, $this->root . '/' . $name);
|
||||
$dir = $this->share->dir($this->root);
|
||||
$this->assertEquals($name, $dir[0]->getName());
|
||||
/**
|
||||
* @dataProvider nameAndDataProvider
|
||||
*/
|
||||
public function testPut($name, $text) {
|
||||
$tmpFile = $this->getTextFile($text);
|
||||
$size = filesize($tmpFile);
|
||||
|
||||
$tmpFile2 = tempnam('/tmp', 'smb_test_');
|
||||
$this->share->get($this->root . '/' . $name, $tmpFile2);
|
||||
$this->assertEquals($text, file_get_contents($tmpFile2));
|
||||
unlink($tmpFile2);
|
||||
$this->share->put($tmpFile, $this->root . '/' . $name);
|
||||
unlink($tmpFile);
|
||||
|
||||
$files = $this->share->dir($this->root);
|
||||
$this->assertCount(1, $files);
|
||||
$this->assertEquals($name, $files[0]->getName());
|
||||
$this->assertEquals($size, $files[0]->getSize());
|
||||
$this->assertFalse($files[0]->isDirectory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider nameProvider
|
||||
*/
|
||||
public function testRenameFile($name) {
|
||||
$tmpFile = $this->getTextFile();
|
||||
|
||||
$this->share->put($tmpFile, $this->root . '/' . $name);
|
||||
unlink($tmpFile);
|
||||
|
||||
$this->share->rename($this->root . '/' . $name, $this->root . '/' . $name . '_renamed');
|
||||
|
||||
$files = $this->share->dir($this->root);
|
||||
$this->assertEquals(1, count($files));
|
||||
$this->assertEquals($name . '_renamed', $files[0]->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider nameAndDataProvider
|
||||
*/
|
||||
public function testGet($name, $text) {
|
||||
$tmpFile = $this->getTextFile($text);
|
||||
|
||||
$this->share->put($tmpFile, $this->root . '/' . $name);
|
||||
unlink($tmpFile);
|
||||
|
||||
$targetFile = tempnam('/tmp', 'smb_test_');
|
||||
$this->share->get($this->root . '/' . $name, $targetFile);
|
||||
|
||||
$this->assertEquals($text, file_get_contents($targetFile));
|
||||
unlink($targetFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider nameProvider
|
||||
*/
|
||||
public function testDel($name) {
|
||||
$tmpFile = $this->getTextFile();
|
||||
|
||||
$this->share->put($tmpFile, $this->root . '/' . $name);
|
||||
unlink($tmpFile);
|
||||
|
||||
$this->share->del($this->root . '/' . $name);
|
||||
|
||||
$tmpFile2 = tempnam('/tmp', 'smb_test_' . $name);
|
||||
$this->share->put($tmpFile2, $this->root . '/' . $name);
|
||||
$dir = $this->share->dir($this->root);
|
||||
$this->assertEquals($name, $dir[0]->getName());
|
||||
$this->share->del($this->root . '/' . $name);
|
||||
unlink($tmpFile2);
|
||||
|
||||
$this->assertEquals(array(), $this->share->dir($this->root));
|
||||
|
||||
unlink($tmpFile1);
|
||||
$this->assertCount(0, $this->share->dir($this->root));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -329,11 +321,6 @@ abstract class AbstractShare extends \PHPUnit_Framework_TestCase {
|
|||
$this->share->del($this->root . '/foo.txt');
|
||||
}
|
||||
|
||||
public function testListRoot() {
|
||||
$files = $this->share->dir('');
|
||||
$this->assertGreaterThan(0, count($files));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider nameAndDataProvider
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue