mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
Additional test cases
This commit is contained in:
parent
f57f29d277
commit
69e9082def
3 changed files with 120 additions and 5 deletions
|
|
@ -29,6 +29,9 @@ class InvalidHostException extends \Exception {
|
|||
class AccessDeniedException extends \Exception {
|
||||
}
|
||||
|
||||
class InvalidTypeException extends \Exception {
|
||||
}
|
||||
|
||||
class ErrorCodes {
|
||||
/**
|
||||
* connection errors
|
||||
|
|
@ -44,4 +47,6 @@ class ErrorCodes {
|
|||
const NameCollision = 'NT_STATUS_OBJECT_NAME_COLLISION';
|
||||
const AccessDenied = 'NT_STATUS_ACCESS_DENIED';
|
||||
const DirectoryNotEmpty = 'NT_STATUS_DIRECTORY_NOT_EMPTY';
|
||||
const FileIsADirectory = 'NT_STATUS_FILE_IS_A_DIRECTORY';
|
||||
const NotADirectory = 'NT_STATUS_NOT_A_DIRECTORY';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,10 +184,11 @@ class Share {
|
|||
/**
|
||||
* @param $lines
|
||||
*
|
||||
* @throws \SMB\NotFoundException
|
||||
* @throws \SMB\AlreadyExistsException
|
||||
* @throws \SMB\AccessDeniedException
|
||||
* @throws \SMB\NotEmptyException
|
||||
* @throws NotFoundException
|
||||
* @throws AlreadyExistsException
|
||||
* @throws AccessDeniedException
|
||||
* @throws NotEmptyException
|
||||
* @throws InvalidTypeException
|
||||
* @throws \Exception
|
||||
* @return bool
|
||||
*/
|
||||
|
|
@ -210,6 +211,9 @@ class Share {
|
|||
throw new AccessDeniedException();
|
||||
case ErrorCodes::DirectoryNotEmpty:
|
||||
throw new NotEmptyException();
|
||||
case ErrorCodes::FileIsADirectory:
|
||||
case ErrorCodes::NotADirectory:
|
||||
throw new InvalidTypeException();
|
||||
default:
|
||||
throw new \Exception();
|
||||
}
|
||||
|
|
|
|||
108
tests/share.php
108
tests/share.php
|
|
@ -30,11 +30,30 @@ class Share extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
public function tearDown() {
|
||||
if ($this->share) {
|
||||
$this->share->rmdir($this->root);
|
||||
$this->cleanDir($this->root);
|
||||
}
|
||||
unset($this->share);
|
||||
}
|
||||
|
||||
public function cleanDir($dir) {
|
||||
$content = $this->share->dir($dir);
|
||||
foreach ($content as $name => $metadata) {
|
||||
if ($metadata['type'] === 'dir') {
|
||||
$this->cleanDir($dir . '/' . $name);
|
||||
} else {
|
||||
$this->share->del($dir . '/' . $name);
|
||||
}
|
||||
}
|
||||
$this->share->rmdir($dir);
|
||||
}
|
||||
|
||||
private function getTextFile() {
|
||||
$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_put_contents($file, $text);
|
||||
return $file;
|
||||
}
|
||||
|
||||
public function testListShares() {
|
||||
$shares = $this->server->listShares();
|
||||
foreach ($shares as $share) {
|
||||
|
|
@ -149,4 +168,91 @@ class Share extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
unlink($tmpFile1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \SMB\NotFoundException
|
||||
*/
|
||||
public function testCreateFolderInNonExistingFolder() {
|
||||
$this->share->mkdir($this->root . '/foo/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \SMB\NotFoundException
|
||||
*/
|
||||
public function testRemoveFolderInNonExistingFolder() {
|
||||
$this->share->rmdir($this->root . '/foo/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \SMB\NotFoundException
|
||||
*/
|
||||
public function testRemoveNonExistingFolder() {
|
||||
$this->share->rmdir($this->root . '/foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \SMB\AlreadyExistsException
|
||||
*/
|
||||
public function testCreateExistingFolder() {
|
||||
$this->share->mkdir($this->root . '/bar');
|
||||
$this->share->mkdir($this->root . '/bar');
|
||||
$this->share->rmdir($this->root . '/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \SMB\InvalidTypeException
|
||||
*/
|
||||
public function testCreateFileExistingFolder() {
|
||||
$this->share->mkdir($this->root . '/bar');
|
||||
$this->share->put($this->getTextFile(), $this->root . '/bar');
|
||||
$this->share->rmdir($this->root . '/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \SMB\NotFoundException
|
||||
*/
|
||||
public function testCreateFileInNonExistingFolder() {
|
||||
$this->share->put($this->getTextFile(), $this->root . '/foo/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \SMB\NotFoundException
|
||||
*/
|
||||
public function testTestRemoveNonExistingFile() {
|
||||
$this->share->del($this->root . '/foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \SMB\NotFoundException
|
||||
*/
|
||||
public function testDownloadNonExistingFile() {
|
||||
$this->share->get($this->root . '/foo', '/dev/null');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \SMB\InvalidTypeException
|
||||
*/
|
||||
public function testDownloadFolder() {
|
||||
$this->share->mkdir($this->root . '/foobar');
|
||||
$this->share->get($this->root . '/foobar', '/dev/null');
|
||||
$this->share->rmdir($this->root . '/foobar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \SMB\NotFoundException
|
||||
*/
|
||||
public function testDelFolder() {
|
||||
$this->share->mkdir($this->root . '/foobar');
|
||||
$this->share->del($this->root . '/foobar');
|
||||
$this->share->rmdir($this->root . '/foobar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \SMB\InvalidTypeException
|
||||
*/
|
||||
public function testRmdirFile() {
|
||||
$this->share->put($this->getTextFile(), $this->root . '/foobar');
|
||||
$this->share->rmdir($this->root . '/foobar');
|
||||
$this->share->del($this->root . '/foobar');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue