egroupware/api/tests/Vfs/Links/StreamWrapperTest.php
Ralf Becker 4886583cc1 change sharing to allow mounting shared into existing user sessions
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
2020-10-08 11:24:34 +02:00

113 lines
2.5 KiB
PHP

<?php
/**
* Test the basic Vfs::StreamWrapper
*
* @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\Links;
require_once __DIR__ . '/../StreamWrapperBase.php';
use EGroupware\Api;
use EGroupware\Api\Vfs;
class StreamWrapperTest extends Vfs\StreamWrapperBase
{
protected $entries = [];
protected function setUp() : void
{
parent::setUp();
}
protected function tearDown() : void
{
// Do local stuff first, parent will remove stuff that is needed
$bo = new \infolog_bo();
foreach($this->entries as $entry)
{
$bo->delete($entry);
}
parent::tearDown();
}
public function testSimpleReadWrite(): string
{
$info_id = $this->make_infolog();
$this->files[] = $this->test_file = $this->getFilename(null, $info_id);
return parent::testSimpleReadWrite();
}
public function testNoReadAccess(): void
{
$info_id = $this->make_infolog();
$this->files[] = $this->test_file = $this->getFilename(null, $info_id);
parent::testNoReadAccess();
}
public function testWithAccess(): void
{
$info_id = $this->make_infolog();
$this->files[] = $this->test_file = $this->getFilename(null, $info_id);
parent::testWithAccess();
}
protected function allowAccess(string $test_name, string &$test_file, int $test_user, string $needed) : void
{
// We'll allow access by putting test user in responsible
$so = new \infolog_so();
$element = $so->read(Array('info_id' => $this->entries[0]));
$element['info_responsible'] = [$test_user];
$so->write($element);
}
protected function mount() : void
{
$this->mountLinks('/apps');
}
/**
* Make an infolog entry
*/
protected function make_infolog()
{
$bo = new \infolog_bo();
$element = array(
'info_subject' => "Test infolog for #{$this->getName()}",
'info_des' => 'Test element for ' . $this->getName() . "\n" . Api\DateTime::to(),
'info_status' => 'open'
);
$element_id = $bo->write($element, true, true, true, true);
$this->entries[] = $element_id;
return $element_id;
}
/**
* Make a filename that reflects the current test
* @param $path
* @param $info_id
* @return string
* @throws \ReflectionException
*/
protected function getFilename($path, $info_id)
{
if(is_null($path)) $path = '/apps/infolog/';
if(substr($path,-1,1) !== '/') $path = $path . '/';
$reflect = new \ReflectionClass($this);
return $path .$info_id .'/'. $reflect->getShortName() . '_' . $this->getName() . '.txt';
}
}