mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
Improve testing for escaping and handling unicode
This commit is contained in:
parent
8f8f8cbf5e
commit
e9cda42fa9
1 changed files with 100 additions and 64 deletions
|
|
@ -46,6 +46,35 @@ class Share extends \PHPUnit_Framework_TestCase {
|
||||||
unset($this->share);
|
unset($this->share);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function nameProvider() {
|
||||||
|
// / ? < > \ : * | " are illegal characters in path on windows, no use trying to get them working
|
||||||
|
return array(
|
||||||
|
array('simple'),
|
||||||
|
array('with spaces_and-underscores'),
|
||||||
|
array("single'quote'"),
|
||||||
|
array('$as#d€££Ö€ßœĚęĘĞĜΣΥΦΩΫΫ')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fileDataProvider() {
|
||||||
|
return array(
|
||||||
|
array('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua'),
|
||||||
|
array('Mixed language, 日本語 が わからか and Various _/* characters \\|” €')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function nameAndDataProvider() {
|
||||||
|
$names = $this->nameProvider();
|
||||||
|
$data = $this->fileDataProvider();
|
||||||
|
$result = array();
|
||||||
|
foreach ($names as $name) {
|
||||||
|
foreach ($data as $text) {
|
||||||
|
$result[] = array($name[0], $text[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
public function cleanDir($dir) {
|
public function cleanDir($dir) {
|
||||||
$content = $this->share->dir($dir);
|
$content = $this->share->dir($dir);
|
||||||
foreach ($content as $name => $metadata) {
|
foreach ($content as $name => $metadata) {
|
||||||
|
|
@ -58,8 +87,10 @@ class Share extends \PHPUnit_Framework_TestCase {
|
||||||
$this->share->rmdir($dir);
|
$this->share->rmdir($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTextFile() {
|
private function getTextFile($text = '') {
|
||||||
|
if (!$text) {
|
||||||
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
|
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
|
||||||
|
}
|
||||||
$file = tempnam('/tmp', 'smb_test_');
|
$file = tempnam('/tmp', 'smb_test_');
|
||||||
file_put_contents($file, $text);
|
file_put_contents($file, $text);
|
||||||
return $file;
|
return $file;
|
||||||
|
|
@ -93,8 +124,10 @@ class Share extends \PHPUnit_Framework_TestCase {
|
||||||
$this->assertEquals(array(), $this->share->dir($this->root));
|
$this->assertEquals(array(), $this->share->dir($this->root));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFile() {
|
/**
|
||||||
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
|
* @dataProvider fileDataProvider
|
||||||
|
*/
|
||||||
|
public function testFile($text) {
|
||||||
$size = strlen($text);
|
$size = strlen($text);
|
||||||
$tmpFile1 = tempnam('/tmp', 'smb_test_');
|
$tmpFile1 = tempnam('/tmp', 'smb_test_');
|
||||||
file_put_contents($tmpFile1, $text);
|
file_put_contents($tmpFile1, $text);
|
||||||
|
|
@ -123,15 +156,14 @@ class Share extends \PHPUnit_Framework_TestCase {
|
||||||
$this->assertEquals(array(), $this->share->dir($this->root));
|
$this->assertEquals(array(), $this->share->dir($this->root));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEscaping() {
|
/**
|
||||||
// / ? < > \ : * | ” are illegal characters in path on windows, no use trying to get them working
|
* @dataProvider nameProvider
|
||||||
$names = array('simple', 'with spaces', "single'quote'", '$as#d', '€', '££Ö€ßœĚęĘĞĜΣΥΦΩΫΫ', '_under - score');
|
*/
|
||||||
|
public function testEscaping($name) {
|
||||||
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
|
$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_');
|
$tmpFile1 = tempnam('/tmp', 'smb_test_');
|
||||||
file_put_contents($tmpFile1, $text);
|
file_put_contents($tmpFile1, $text);
|
||||||
|
|
||||||
foreach ($names as $name) {
|
|
||||||
$this->share->mkdir($this->root . '/' . $name);
|
$this->share->mkdir($this->root . '/' . $name);
|
||||||
$dir = $this->share->dir($this->root);
|
$dir = $this->share->dir($this->root);
|
||||||
$this->assertArrayHasKey($name, $dir);
|
$this->assertArrayHasKey($name, $dir);
|
||||||
|
|
@ -174,7 +206,6 @@ class Share extends \PHPUnit_Framework_TestCase {
|
||||||
unlink($tmpFile2);
|
unlink($tmpFile2);
|
||||||
|
|
||||||
$this->assertEquals(array(), $this->share->dir($this->root));
|
$this->assertEquals(array(), $this->share->dir($this->root));
|
||||||
}
|
|
||||||
|
|
||||||
unlink($tmpFile1);
|
unlink($tmpFile1);
|
||||||
}
|
}
|
||||||
|
|
@ -294,27 +325,32 @@ class Share extends \PHPUnit_Framework_TestCase {
|
||||||
$this->assertGreaterThan(0, count($files));
|
$this->assertGreaterThan(0, count($files));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReadStream() {
|
/**
|
||||||
$sourceFile = $this->getTextFile();
|
* @dataProvider nameAndDataProvider
|
||||||
$this->share->put($sourceFile, $this->root . '/foobar');
|
*/
|
||||||
$fh = $this->share->read($this->root . '/foobar');
|
public function testReadStream($name, $text) {
|
||||||
|
$sourceFile = $this->getTextFile($text);
|
||||||
|
$this->share->put($sourceFile, $this->root . '/' . $name);
|
||||||
|
$fh = $this->share->read($this->root . '/' . $name);
|
||||||
$content = stream_get_contents($fh);
|
$content = stream_get_contents($fh);
|
||||||
fclose($fh);
|
fclose($fh);
|
||||||
$this->share->del($this->root . '/foobar');
|
$this->share->del($this->root . '/' . $name);
|
||||||
|
|
||||||
$this->assertEquals(file_get_contents($sourceFile), $content);
|
$this->assertEquals(file_get_contents($sourceFile), $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWriteStream() {
|
/**
|
||||||
$fh = $this->share->write($this->root . '/foobar', 'qwerty');
|
* @dataProvider nameAndDataProvider
|
||||||
fwrite($fh, 'qwerty');
|
*/
|
||||||
|
public function testWriteStream($name, $text) {
|
||||||
|
$fh = $this->share->write($this->root . '/' . $name);
|
||||||
|
fwrite($fh, $text);
|
||||||
fclose($fh);
|
fclose($fh);
|
||||||
// sleep(5);
|
|
||||||
|
|
||||||
|
|
||||||
$tmpFile1 = tempnam('/tmp', 'smb_test_');
|
$tmpFile1 = tempnam('/tmp', 'smb_test_');
|
||||||
$this->share->get($this->root . '/foobar', $tmpFile1);
|
$this->share->get($this->root . '/' . $name, $tmpFile1);
|
||||||
$this->assertEquals('qwerty', file_get_contents($tmpFile1));
|
$this->assertEquals($text, file_get_contents($tmpFile1));
|
||||||
|
$this->share->del($this->root . '/' . $name);
|
||||||
unlink($tmpFile1);
|
unlink($tmpFile1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue