mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-07 08:34:42 +01:00
Some more test work
- Fix some existing tests so they don't fail due to changes - Add tests for Vfs\Sharing\StreamWrapper
This commit is contained in:
parent
e02fad1731
commit
97283bad76
@ -74,13 +74,13 @@ abstract class LoggedInTest extends TestCase
|
||||
*/
|
||||
public static function tearDownAfterClass() : void
|
||||
{
|
||||
// Clean up VFS
|
||||
Vfs::clearstatcache();
|
||||
// Reset stream context, or current user will always be there
|
||||
stream_context_set_option(stream_context_get_default(),['vfs'=>['user' => null]]);
|
||||
// Clean up VFS
|
||||
Vfs::clearstatcache();
|
||||
// Reset stream context, or current user will always be there
|
||||
stream_context_set_option(stream_context_get_default(),['vfs'=>['user' => null]]);
|
||||
|
||||
// Clear some link caching
|
||||
Link::init_static(true);
|
||||
// Clear some link caching
|
||||
Link::init_static(true);
|
||||
|
||||
if($GLOBALS['egw'])
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ class StreamWrapperTest extends Vfs\StreamWrapperBase
|
||||
$this->mountFilesystem(static::$mountpoint);
|
||||
}
|
||||
|
||||
protected function allowAccess(string $test_name, string $test_file, int $test_user, string $needed) : void
|
||||
protected function allowAccess(string $test_name, string &$test_file, int $test_user, string $needed) : void
|
||||
{
|
||||
// We'll allow access by putting test user in Default group
|
||||
$command = new \admin_cmd_edit_user($test_user, ['account_groups' => array_merge($this->account['account_groups'],['Default'])]);
|
||||
|
@ -64,7 +64,7 @@ class StreamWrapperTest extends Vfs\StreamWrapperBase
|
||||
parent::testWithAccess();
|
||||
}
|
||||
|
||||
protected function allowAccess(string $test_name, string $test_file, int $test_user, string $needed) : void
|
||||
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();
|
||||
|
117
api/tests/Vfs/Sharing/StreamWrapperTest.php
Normal file
117
api/tests/Vfs/Sharing/StreamWrapperTest.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test the basics of Sharing::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\Sharing;
|
||||
|
||||
require_once __DIR__ . '/../StreamWrapperBase.php';
|
||||
|
||||
use EGroupware\Api;
|
||||
use EGroupware\Api\Vfs;
|
||||
use EGroupware\Api\Vfs\Sharing;
|
||||
|
||||
|
||||
class StreamWrapperTest extends Vfs\StreamWrapperBase
|
||||
{
|
||||
protected $share = [];
|
||||
|
||||
static $test_dir = 'TestShareFolder';
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->createShare();
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function tearDown() : void
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testSimpleReadWrite(): string
|
||||
{
|
||||
$this->files[] = $this->test_file = $this->getFilename('',false);
|
||||
|
||||
return parent::testSimpleReadWrite();
|
||||
}
|
||||
|
||||
public function testNoReadAccess(): void
|
||||
{
|
||||
$this->files[] = $this->test_file = $this->getFilename('',false);
|
||||
|
||||
parent::testNoReadAccess();
|
||||
}
|
||||
|
||||
public function testWithAccess(): void
|
||||
{
|
||||
$this->files[] = $this->test_file = $this->getFilename('',false);
|
||||
|
||||
parent::testWithAccess();
|
||||
}
|
||||
|
||||
protected function allowAccess(string $test_name, string &$test_file, int $test_user, string $needed) : void
|
||||
{
|
||||
// Anyone who mounts will have access, but the available path changes
|
||||
$test_file = '/home/'. $GLOBALS['egw']->accounts->id2name($test_user) . '/' .
|
||||
Vfs\Sharing::SHARES_DIRECTORY .'/'.static::$test_dir .'/'. Vfs::basename($test_file);
|
||||
}
|
||||
|
||||
public function mount() : void
|
||||
{
|
||||
Api\Vfs\Sharing::setup_share(true,$this->share);
|
||||
}
|
||||
|
||||
public function createShare(&$dir='', $extra = array(), $create = 'createShare')
|
||||
{
|
||||
// First, create the directory to be shared
|
||||
$this->files[] = $dir = Vfs::get_home_dir() . '/'. static::$test_dir;
|
||||
Vfs::mkdir($dir);
|
||||
|
||||
// Create and use link
|
||||
$this->getShareExtra($dir, Sharing::WRITABLE, $extra);
|
||||
|
||||
$this->share = Vfs\Sharing::create('',$dir,Sharing::WRITABLE,$dir,'',$extra);
|
||||
$link = Vfs\Sharing::share2link($this->share);
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the extra information required to create a share link for the given
|
||||
* directory, with the given mode
|
||||
*
|
||||
* @param string $dir Share target
|
||||
* @param int $mode Share mode
|
||||
* @param Array $extra
|
||||
*/
|
||||
protected function getShareExtra($dir, $mode, &$extra)
|
||||
{
|
||||
switch($mode)
|
||||
{
|
||||
case Sharing::WRITABLE:
|
||||
$extra['share_writable'] = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a filename that reflects the current test
|
||||
* @param $path
|
||||
* @param bool $mounted Get the path if the share is mounted, or the original
|
||||
* @return string
|
||||
*/
|
||||
protected function getFilename($path = null, $mounted = true) : string
|
||||
{
|
||||
return parent::getFilename(Vfs::get_home_dir() . '/'.
|
||||
($mounted ? Vfs\Sharing::SHARES_DIRECTORY .'/' : '').static::$test_dir .'/'. $path);
|
||||
}
|
||||
|
||||
}
|
@ -55,6 +55,7 @@ class SharingACLTest extends SharingBase
|
||||
|
||||
protected function tearDown() : void
|
||||
{
|
||||
LoggedInTest::setUpBeforeClass();
|
||||
parent::tearDown();
|
||||
if($this->account_id)
|
||||
{
|
||||
@ -198,9 +199,6 @@ class SharingACLTest extends SharingBase
|
||||
$this->assertNotNull($form, "Could not read the share link");
|
||||
$rows = $data['data']['content']['nm']['rows'];
|
||||
|
||||
Vfs::clearstatcache();
|
||||
Vfs::init_static();
|
||||
Vfs\StreamWrapper::init_static();
|
||||
|
||||
// Check we can't find the non-shared file
|
||||
$result = array_filter($rows, function($v) {
|
||||
@ -236,10 +234,6 @@ class SharingACLTest extends SharingBase
|
||||
$this->assertNotNull($form, "Could not read the share link");
|
||||
$rows = array_values($data['data']['content']['nm']['rows']);
|
||||
|
||||
Vfs::clearstatcache();
|
||||
Vfs::init_static();
|
||||
Vfs\StreamWrapper::init_static();
|
||||
|
||||
// Check we can't find the non-shared file
|
||||
$result = array_filter($rows, function($v) {
|
||||
return $v['name'] == $this->no_access;
|
||||
|
@ -31,7 +31,7 @@ class SharingBackendTest extends SharingBase
|
||||
*/
|
||||
public function testHomeReadonly()
|
||||
{
|
||||
$dir = Vfs::get_home_dir().'/';
|
||||
$dir = Vfs::get_home_dir().'/'.$this->getName(false).'/';
|
||||
|
||||
$this->checkDirectory($dir, Sharing::READONLY);
|
||||
}
|
||||
@ -42,7 +42,7 @@ class SharingBackendTest extends SharingBase
|
||||
*/
|
||||
public function testHomeWritable()
|
||||
{
|
||||
$dir = Vfs::get_home_dir().'/';
|
||||
$dir = Vfs::get_home_dir().'/'.$this->getName(false).'/';
|
||||
|
||||
$this->checkDirectory($dir, Sharing::WRITABLE);
|
||||
}
|
||||
@ -124,6 +124,9 @@ class SharingBackendTest extends SharingBase
|
||||
*/
|
||||
public function testLinksReadonly()
|
||||
{
|
||||
// Need to mount apps
|
||||
$this->mountLinks("/apps");
|
||||
|
||||
// Create an infolog entry for testing purposes
|
||||
$info_id = $this->make_infolog();
|
||||
$bo = new \infolog_bo();
|
||||
@ -142,6 +145,9 @@ class SharingBackendTest extends SharingBase
|
||||
*/
|
||||
public function testLinksWritable()
|
||||
{
|
||||
// Need to mount apps
|
||||
$this->mountLinks("/apps");
|
||||
|
||||
// Create an infolog entry for testing purposes
|
||||
$bo = new \infolog_bo();
|
||||
$info_id = $this->make_infolog();
|
||||
|
@ -153,6 +153,10 @@ class SharingBase extends LoggedInTest
|
||||
{
|
||||
$dir .= '/';
|
||||
}
|
||||
if(!Vfs::is_readable($dir))
|
||||
{
|
||||
Vfs::mkdir($dir);
|
||||
}
|
||||
$this->files += $this->addFiles($dir);
|
||||
|
||||
$logged_in_files = array_map(
|
||||
@ -230,7 +234,7 @@ class SharingBase extends LoggedInTest
|
||||
switch($mode)
|
||||
{
|
||||
case Sharing::READONLY:
|
||||
$this->assertFalse(Vfs::is_writable($file));
|
||||
$this->assertFalse(Vfs::is_writable($file), "Readonly share file '$file' is writable");
|
||||
if(!Vfs::is_dir($file))
|
||||
{
|
||||
// We expect this to fail
|
||||
@ -251,6 +255,26 @@ class SharingBase extends LoggedInTest
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Mount the app entries into the filesystem
|
||||
*
|
||||
* @param string $path
|
||||
*/
|
||||
protected function mountLinks($path)
|
||||
{
|
||||
Vfs::$is_root = true;
|
||||
$url = Links\StreamWrapper::PREFIX . '/apps';
|
||||
$this->assertTrue(
|
||||
Vfs::mount($url, $path, false, false),
|
||||
"Unable to mount $url => $path"
|
||||
);
|
||||
Vfs::$is_root = false;
|
||||
|
||||
$this->mounts[] = $path;
|
||||
Vfs::clearstatcache();
|
||||
Vfs::init_static();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start versioning for the given path
|
||||
*
|
||||
@ -565,7 +589,7 @@ class SharingBase extends LoggedInTest
|
||||
|
||||
// Make sure we start at root, not somewhere else like the token mounted
|
||||
// as a sub-directory
|
||||
$this->assertEquals('/', $data->data->content->nm->path);
|
||||
$this->assertEquals('/', $data->data->content->nm->path, "Share was not mounted at /");
|
||||
|
||||
unset($data->data->content->nm->actions);
|
||||
//var_dump($data->data->content->nm);
|
||||
|
@ -409,7 +409,7 @@ abstract class StreamWrapperBase extends LoggedInTest
|
||||
* @param string $needed r, w, rw
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function allowAccess(string $test_name, string $test_file, int $test_user, string $needed) : void;
|
||||
abstract protected function allowAccess(string $test_name, string &$test_file, int $test_user, string $needed) : void;
|
||||
|
||||
/**
|
||||
* Mount the app entries into the filesystem
|
||||
|
@ -47,7 +47,7 @@ class StreamWrapperTest extends StreamWrapperBase
|
||||
// Nothing here
|
||||
}
|
||||
|
||||
protected function allowAccess(string $test_name, string $test_file, int $test_user, string $needed) : void
|
||||
protected function allowAccess(string $test_name, string &$test_file, int $test_user, string $needed) : void
|
||||
{
|
||||
// We'll allow access by putting test user in Default group
|
||||
$command = new \admin_cmd_edit_user($test_user, ['account_groups' => array_merge($this->account['account_groups'],['Default'])]);
|
||||
|
Loading…
Reference in New Issue
Block a user