mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-11 09:11:05 +01:00
4886583cc1
without the need to destroy the session, if the sharee is a different user This is accomplished by keeping the sharee in the stream context / attribute of the vfs class(es) instead of static Vfs::$user. Later is still used for the current user - identical to egw_info[user][account_id]. This commit / merge of the vfs-context feature branch also added the abilty to mount WebDAV sources, eg. a sharing link from an other EGroupware instance or any WebDAV server
129 lines
3.3 KiB
PHP
129 lines
3.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Test file properties (proppatch)
|
|
*
|
|
* @link http://www.egroupware.org
|
|
* @author Nathan Gray
|
|
* @copyright (c) 2020 Nathan Gray
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
*/
|
|
|
|
namespace EGroupware\Api\Vfs;
|
|
|
|
require_once __DIR__ . '/StreamWrapperBase.php';
|
|
|
|
use EGroupware\Api;
|
|
use EGroupware\Api\LoggedInTest as LoggedInTest;
|
|
use EGroupware\Api\Vfs;
|
|
use EGroupware\Stylite\Vfs\Versioning;
|
|
|
|
|
|
class ProppatchTest extends LoggedInTest
|
|
{
|
|
protected function setUp() : void
|
|
{
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
protected function tearDown() : void
|
|
{
|
|
// Do local stuff first, parent will remove stuff
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
/**
|
|
* Check read / write / delete proppatch
|
|
*/
|
|
public function testProppatch()
|
|
{
|
|
$this->files[] = $test_file = $this->getFilename();
|
|
$contents = $this->getName() . "\nJust a test ;)\n";
|
|
$this->assertNotFalse(
|
|
file_put_contents(Vfs::PREFIX . $test_file, $contents),
|
|
"Could not write test file $test_file"
|
|
);
|
|
|
|
$proppatch = [['ns' => Vfs::DEFAULT_PROP_NAMESPACE, 'name' => 'test', 'val' => 'something']];
|
|
$this->assertTrue(
|
|
Vfs::proppatch($test_file, $proppatch),
|
|
"Could not set properties"
|
|
);
|
|
$read = Vfs::propfind($test_file);
|
|
|
|
$this->assertEquals($proppatch, $read,
|
|
"Read proppatch does not match what was written"
|
|
);
|
|
|
|
// Try to delete, while we're here
|
|
$proppatch[0]['val'] = null;
|
|
$this->assertTrue(
|
|
Vfs::proppatch($test_file, $proppatch),
|
|
"Could not delete properties by setting val = null"
|
|
);
|
|
$read_deleted = Vfs::propfind($test_file);
|
|
$this->assertNotFalse($read_deleted, "Problem reading properties after deleting");
|
|
$this->assertEquals([], $read_deleted, "Found properties after deleting");
|
|
}
|
|
|
|
/**
|
|
* Test that an invalid proppatch is not accepted
|
|
*/
|
|
public function testInvalidProppatch()
|
|
{
|
|
$this->files[] = $test_file = $this->getFilename();
|
|
$contents = $this->getName() . "\nJust a test ;)\n";
|
|
$this->assertNotFalse(
|
|
file_put_contents(Vfs::PREFIX . $test_file, $contents),
|
|
"Could not write test file $test_file"
|
|
);
|
|
|
|
$proppatch = [['No worky']];
|
|
$this->assertFalse(
|
|
Vfs::proppatch($test_file, $proppatch),
|
|
"Managed to set invalid properties"
|
|
);
|
|
}
|
|
|
|
public function testWriteWithNoPermissionsFails()
|
|
{
|
|
$this->files[] = $test_file = $this->getFilename();
|
|
Vfs::remove($test_file);
|
|
$contents = $this->getName() . "\nJust a test ;)\n";
|
|
$this->assertNotFalse(
|
|
file_put_contents(Vfs::PREFIX . $test_file, $contents),
|
|
"Could not write test file $test_file"
|
|
);
|
|
|
|
// Change owner so we lose permission
|
|
Vfs::$is_root = true;
|
|
$this->assertTrue(
|
|
Vfs::chown($test_file, 'anonymous'),
|
|
"Could not chown test file '$test_file'"
|
|
);
|
|
Vfs::$is_root = false;
|
|
|
|
// Try to set property
|
|
$proppatch = [['ns' => Vfs::DEFAULT_PROP_NAMESPACE, 'name' => 'test', 'val' => 'something']];
|
|
$this->assertFalse(
|
|
Vfs::proppatch($test_file, $proppatch),
|
|
"Managed to set properties with no permission"
|
|
);
|
|
|
|
}
|
|
|
|
/**
|
|
* Make a filename that reflects the current test
|
|
*/
|
|
protected function getFilename($path = null)
|
|
{
|
|
if(is_null($path)) $path = Vfs::get_home_dir().'/';
|
|
if(substr($path,-1,1) !== '/') $path = $path . '/';
|
|
|
|
$reflect = new \ReflectionClass($this);
|
|
return $path . $reflect->getShortName() . '_' . $this->getName(false) . '.txt';
|
|
}
|
|
|
|
} |