/** * @expectedException PHPUnit_Framework_Error_Warning */ public function testClosedirDouble() { $state = smbclient_state_new(); smbclient_state_init($state, null, SMB_USER, SMB_PASS); $dir = smbclient_opendir($state, 'smb://' . SMB_HOST . '/' . SMB_SHARE); $this->assertTrue(smbclient_closedir($state, $dir)); $this->assertFalse(smbclient_closedir($state, $dir)); }
/** * @expectedException PHPUnit_Framework_Error_Warning */ public function testGetxattrFileNotFound() { $state = smbclient_state_new(); smbclient_state_init($state, null, SMB_USER, SMB_PASS); $attr = smbclient_getxattr($state, 'smb://' . SMB_HOST . '/' . SMB_SHARE . '/testdir/does-not-exist', 'system.dos_attr.mode'); $this->assertFalse($attr); $this->assertEquals(smbclient_state_errno($state), 2); // ENOENT }
/** * @expectedException PHPUnit_Framework_Error_Warning */ public function testOpendirNotDir() { $state = smbclient_state_new(); smbclient_state_init($state, null, SMB_USER, SMB_PASS); $dir = smbclient_opendir($state, 'smb://' . SMB_HOST . '/' . SMB_SHARE . '/testfile.txt'); $this->assertFalse($dir); $errno = smbclient_state_errno($state); $this->assertEquals(20, $errno); // ENOTDIR }
public function testFstatVFS() { $state = smbclient_state_new(); smbclient_state_init($state, null, SMB_USER, SMB_PASS); $file = smbclient_open($state, $this->testuri, 'r'); $vfs = smbclient_fstatvfs($state, $file); smbclient_close($state, $file); smbclient_state_free($state); $this->assertTrue(is_array($vfs)); $this->hasParts($vfs); }
/** * @param string $workGroup * @param string $user * @param string $password * @return bool */ public function init($workGroup, $user, $password) { if ($this->connected) { return true; } $this->state = smbclient_state_new(); $result = @smbclient_state_init($this->state, $workGroup, $user, $password); $this->testResult($result, ''); $this->connected = true; return $result; }
public function testCreateUrlencodedSuccess() { $testuri = 'smb://' . SMB_HOST . '/' . SMB_SHARE . '/ex%25%25%25ample.txt'; $realfile = SMB_LOCAL . '/ex%%%ample.txt'; $state = smbclient_state_new(); smbclient_state_init($state, null, SMB_USER, SMB_PASS); $file = smbclient_creat($state, $testuri); $this->assertTrue(is_resource($file)); $this->assertFileExists($realfile); #unlink($realfile); }
public function testLseekCurPositive() { $state = smbclient_state_new(); smbclient_state_init($state, null, SMB_USER, SMB_PASS); $file = smbclient_creat($state, $this->testuri); smbclient_write($state, $file, 'abcdefgh'); $ret = smbclient_lseek($state, $file, 3, SEEK_CUR); $this->assertEquals(11, $ret); smbclient_write($state, $file, 'foo', 3); smbclient_close($state, $file); $this->assertStringEqualsFile($this->realfile, sprintf('%s%c%c%c%s', 'abcdefgh', 0, 0, 0, 'foo')); }
public function testRenameDirSuccess() { $state = smbclient_state_new(); smbclient_state_init($state, null, SMB_USER, SMB_PASS); // Create mock dir "foo" via regular filesystem: mkdir(SMB_LOCAL . '/foo'); $this->assertTrue(smbclient_rename($state, 'smb://' . SMB_HOST . '/' . SMB_SHARE . '/foo', $state, 'smb://' . SMB_HOST . '/' . SMB_SHARE . '/bar')); $moved = is_dir(SMB_LOCAL . '/bar'); $this->assertTrue($moved); $gone = is_dir(SMB_LOCAL . '/foo'); $this->assertFalse($gone); @rmdir(SMB_LOCAL . '/foo'); @rmdir(SMB_LOCAL . '/bar'); }
public function testWriteOversized() { $state = smbclient_state_new(); smbclient_state_init($state, null, SMB_USER, SMB_PASS); $file = smbclient_creat($state, $this->testuri); $this->assertTrue(is_resource($file)); // Write way more bytes than data: $ret = smbclient_write($state, $file, $this->testdata, 1000); $this->assertTrue(is_integer($ret)); $this->assertEquals(strlen($this->testdata), $ret); // Use the regular filesystem to check the file that was created: $this->assertFileExists($this->realfile); $this->assertEquals(filesize($this->realfile), $ret); $this->assertStringEqualsFile($this->realfile, $this->testdata); }
public function testReaddirSuccess() { $state = smbclient_state_new(); smbclient_state_init($state, null, SMB_USER, SMB_PASS); $dir = smbclient_opendir($state, 'smb://' . SMB_HOST . '/' . SMB_SHARE); $smb = array(); while (($out = smbclient_readdir($state, $dir)) !== false) { $smb[] = $out['name']; } // Compare this with a copy we get through the filesystem: $local = scandir(SMB_LOCAL); // Sort both arrays to ensure equality: sort($smb); sort($local); $this->assertEquals($smb, $local); }
public function testStateInitValid() { $state = smbclient_state_new(); $this->assertTrue(smbclient_state_init($state, null, SMB_USER, SMB_PASS)); }
/** * @expectedException PHPUnit_Framework_Error_Warning */ public function testStateFreeDouble() { $state = smbclient_state_new(); $this->assertTrue(smbclient_state_free($state)); $this->assertFalse(smbclient_state_free($state)); }
public function testStateNew() { $state = smbclient_state_new(); $this->assertTrue(is_resource($state)); }
public function testOptionNTHash() { $state = smbclient_state_new(); if (smbclient_option_get($state, SMBCLIENT_OPT_USE_NT_HASH) === null) { smbclient_state_free($state); return; } smbclient_option_set($state, SMBCLIENT_OPT_USE_NT_HASH, true); // NTLM hash of 'password' generated at http://www.tobtu.com/lmntlm.php smbclient_state_init($state, null, SMB_USER, SMB_HASH); $dir = smbclient_opendir($state, 'smb://' . SMB_HOST . '/' . SMB_SHARE); while (($out = smbclient_readdir($state, $dir)) !== false) { } $this->assertTrue(is_resource($dir)); smbclient_closedir($state, $dir); smbclient_state_free($state); }