mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-25 09:23:28 +01:00
Some more test work
- Refactor some simple tests into base for reuse - Add (simple) tests for links://
This commit is contained in:
parent
94647314d6
commit
1432502e62
@ -164,7 +164,7 @@ class Base
|
|||||||
}
|
}
|
||||||
unset(self::$fstab[$path]);
|
unset(self::$fstab[$path]);
|
||||||
|
|
||||||
Api\Config::save_value('vfs_fstab',self::$fstab,'phpgwapi');
|
\EGroupware\Api\Config::save_value('vfs_fstab',self::$fstab,'phpgwapi');
|
||||||
$GLOBALS['egw_info']['server']['vfs_fstab'] = self::$fstab;
|
$GLOBALS['egw_info']['server']['vfs_fstab'] = self::$fstab;
|
||||||
// invalidate session cache
|
// invalidate session cache
|
||||||
if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited
|
if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited
|
||||||
|
81
api/tests/Vfs/Links/StreamWrapperTest.php
Normal file
81
api/tests/Vfs/Links/StreamWrapperTest.php
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
<?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();
|
||||||
|
|
||||||
|
$this->mountLinks('/apps');
|
||||||
|
|
||||||
|
$info_id = $this->make_infolog();
|
||||||
|
$this->files[] = $this->test_file = $this->getFilename(null, $info_id);
|
||||||
|
|
||||||
|
// Check that the file is not there
|
||||||
|
$pre_start = Vfs::stat($this->test_file);
|
||||||
|
$this->assertEquals(null,$pre_start,
|
||||||
|
"File '$this->test_file' was there before we started, check clean up"
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -32,6 +32,11 @@ class StreamWrapperBase extends LoggedInTest
|
|||||||
*/
|
*/
|
||||||
const LOG_LEVEL = 0;
|
const LOG_LEVEL = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string If we're just doing a simple test with one file, use this file
|
||||||
|
*/
|
||||||
|
protected $test_file = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep track of files to remove after
|
* Keep track of files to remove after
|
||||||
* @var Array
|
* @var Array
|
||||||
@ -115,7 +120,83 @@ class StreamWrapperBase extends LoggedInTest
|
|||||||
if(is_null($path)) $path = Vfs::get_home_dir().'/';
|
if(is_null($path)) $path = Vfs::get_home_dir().'/';
|
||||||
if(substr($path,-1,1) !== '/') $path = $path . '/';
|
if(substr($path,-1,1) !== '/') $path = $path . '/';
|
||||||
|
|
||||||
return $path . get_class(this) . '_' . $this->getName() . '.txt';
|
$reflect = new \ReflectionClass($this);
|
||||||
|
return $path . $reflect->getShortName() . '_' . $this->getName() . '.txt';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple test that we can write something and it's there
|
||||||
|
* By putting it in the base class, this test gets run for every backend
|
||||||
|
*/
|
||||||
|
public function testSimpleReadWrite() : void
|
||||||
|
{
|
||||||
|
if(!$this->test_file)
|
||||||
|
{
|
||||||
|
$this->markTestSkipped("No test file set - set it in setUp() or overriding test");
|
||||||
|
}
|
||||||
|
$contents = $this->getName() . "\nJust a test ;)\n";
|
||||||
|
$this->assertNotFalse(
|
||||||
|
file_put_contents(Vfs::PREFIX . $this->test_file, $contents),
|
||||||
|
"Could not write file $this->test_file"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check contents are unchanged
|
||||||
|
$this->assertEquals(
|
||||||
|
$contents, file_get_contents(Vfs::PREFIX . $this->test_file),
|
||||||
|
"Read file contents do not match what was written"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Simple delete of a file
|
||||||
|
* By putting it in the base class, this test gets run for every backend
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testDelete() : void
|
||||||
|
{
|
||||||
|
if(!$this->test_file)
|
||||||
|
{
|
||||||
|
$this->markTestSkipped("No test file set - set it in setUp() or overriding test");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write
|
||||||
|
$contents = $this->getName() . "\nJust a test ;)\n";
|
||||||
|
$this->assertNotFalse(
|
||||||
|
file_put_contents(Vfs::PREFIX . $this->test_file, $contents),
|
||||||
|
"Could not write file $this->test_file"
|
||||||
|
);
|
||||||
|
|
||||||
|
$start = Vfs::stat($this->test_file);
|
||||||
|
$this->assertNotNull(
|
||||||
|
$start,
|
||||||
|
"File '$this->test_file' was not what we expected to find after writing"
|
||||||
|
);
|
||||||
|
|
||||||
|
Vfs::unlink($this->test_file);
|
||||||
|
|
||||||
|
$post = Vfs::stat($this->test_file);
|
||||||
|
$this->assertEquals(null,$post,
|
||||||
|
"File '$this->test_file' was there after deleting"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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),
|
||||||
|
"Unabe to mount $url => $path"
|
||||||
|
);
|
||||||
|
Vfs::$is_root = false;
|
||||||
|
|
||||||
|
$this->mounts[] = $path;
|
||||||
|
Vfs::clearstatcache();
|
||||||
|
Vfs::init_static();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -187,7 +268,7 @@ class StreamWrapperBase extends LoggedInTest
|
|||||||
Vfs::$is_root = true;
|
Vfs::$is_root = true;
|
||||||
|
|
||||||
// I guess merge needs the dir in SQLFS first
|
// I guess merge needs the dir in SQLFS first
|
||||||
if(!Vfs::is_dir($dir)) Vfs::mkdir($path);
|
if(!Vfs::is_dir($path)) Vfs::mkdir($path);
|
||||||
Vfs::chmod($path, 0750);
|
Vfs::chmod($path, 0750);
|
||||||
Vfs::chown($path, $GLOBALS['egw_info']['user']['account_id']);
|
Vfs::chown($path, $GLOBALS['egw_info']['user']['account_id']);
|
||||||
|
|
||||||
@ -265,20 +346,4 @@ class StreamWrapperBase extends LoggedInTest
|
|||||||
*/
|
*/
|
||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
return $element_id;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -25,6 +25,13 @@ class StreamWrapperTest extends StreamWrapperBase
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->files[] = $this->test_file = $this->getFilename();
|
||||||
|
|
||||||
|
// Check that the file is not there
|
||||||
|
$pre_start = Vfs::stat($this->test_file);
|
||||||
|
$this->assertEquals(null,$pre_start,
|
||||||
|
"File '$this->test_file' was there before we started, check clean up"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown() : void
|
protected function tearDown() : void
|
||||||
@ -34,56 +41,4 @@ class StreamWrapperTest extends StreamWrapperBase
|
|||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple test that we can write something and it's there
|
|
||||||
*/
|
|
||||||
public function testSimpleReadWrite() : void
|
|
||||||
{
|
|
||||||
$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 file $test_file"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Check contents are unchanged
|
|
||||||
$this->assertEquals(
|
|
||||||
$contents, file_get_contents(Vfs::PREFIX . $test_file),
|
|
||||||
"Read file contents do not match what was written"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple delete of a file
|
|
||||||
*/
|
|
||||||
public function testDelete() : void
|
|
||||||
{
|
|
||||||
$this->files[] = $test_file = $this->getFilename();
|
|
||||||
|
|
||||||
// Check that the file is not there
|
|
||||||
$pre_start = Vfs::stat($test_file);
|
|
||||||
$this->assertEquals(null,$pre_start,
|
|
||||||
"File '$test_file' was there before we started, check clean up"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Write
|
|
||||||
$contents = $this->getName() . "\nJust a test ;)\n";
|
|
||||||
$this->assertNotFalse(
|
|
||||||
file_put_contents(Vfs::PREFIX . $test_file, $contents),
|
|
||||||
"Could not write file $test_file"
|
|
||||||
);
|
|
||||||
|
|
||||||
$start = Vfs::stat($test_file);
|
|
||||||
$this->assertNotNull(
|
|
||||||
$start,
|
|
||||||
"File '$test_file' was not what we expected to find after writing"
|
|
||||||
);
|
|
||||||
|
|
||||||
Vfs::unlink($test_file);
|
|
||||||
|
|
||||||
$post = Vfs::stat($test_file);
|
|
||||||
$this->assertEquals(null,$post,
|
|
||||||
"File '$test_file' was there after deleting"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user