2018-01-15 19:52:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the save to VFS functions
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @package mail
|
|
|
|
* @copyright (c) 2018 by Nathan Gray
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
namespace EGroupware\Mail;
|
|
|
|
|
|
|
|
require_once realpath(__DIR__.'/../../api/tests/AppTest.php'); // Application test base
|
|
|
|
|
|
|
|
use Egroupware\Api;
|
|
|
|
|
|
|
|
class SaveToVfsTest extends \EGroupware\Api\AppTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create a custom status we can use to test
|
|
|
|
*/
|
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
|
|
|
parent::setUpBeforeClass();
|
|
|
|
|
|
|
|
}
|
|
|
|
public static function tearDownAfterClass()
|
|
|
|
{
|
|
|
|
|
|
|
|
// Have to remove custom status first, before the DB is gone
|
|
|
|
parent::tearDownAfterClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that we make nice filenames for the VFS
|
|
|
|
*
|
|
|
|
* Under Windows the characters < > ? " : | \ / * are not allowed.
|
|
|
|
* % causes problems with VFS UI
|
|
|
|
*
|
|
|
|
* @param String $filename
|
|
|
|
* @dataProvider filenameProvider
|
|
|
|
*/
|
|
|
|
public function testVfsFilename($filename, $replacements)
|
|
|
|
{
|
2018-01-22 17:12:44 +01:00
|
|
|
$cleaned = VfsTestMail::clean_subject_for_filename($filename);
|
2018-01-15 19:52:15 +01:00
|
|
|
|
|
|
|
$this->assertNotContains('<', $cleaned);
|
|
|
|
$this->assertNotContains('>', $cleaned);
|
|
|
|
$this->assertNotContains('"', $cleaned);
|
|
|
|
$this->assertNotContains('#', $cleaned);
|
|
|
|
$this->assertNotContains(':', $cleaned);
|
|
|
|
$this->assertNotContains('|', $cleaned);
|
|
|
|
$this->assertNotContains('\\', $cleaned);
|
|
|
|
$this->assertNotContains('*', $cleaned);
|
|
|
|
$this->assertNotContains('/', $cleaned);
|
|
|
|
$this->assertNotContains('?', $cleaned);
|
2018-03-02 12:13:13 +01:00
|
|
|
$this->assertNotContains('\x0b', $cleaned);
|
2018-01-15 19:52:15 +01:00
|
|
|
|
|
|
|
// Length should stay the same
|
2018-01-22 17:12:44 +01:00
|
|
|
$this->assertEquals(strlen($filename), strlen($cleaned), 'Length changed');
|
2018-01-15 19:52:15 +01:00
|
|
|
|
|
|
|
if(!$replacements)
|
|
|
|
{
|
|
|
|
$this->assertEquals($filename, $cleaned);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->assertNotEquals($filename, $cleaned);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function filenameProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('Normal! All allowed (!@$^&) {\'} []', false),
|
|
|
|
array('Contains a >', true),
|
|
|
|
array('Contains a <', true),
|
|
|
|
array('Contains a "', true),
|
|
|
|
array('Contains a #', true),
|
|
|
|
array('Contains a :', true),
|
|
|
|
array('Contains a |', true),
|
2018-01-22 17:12:44 +01:00
|
|
|
array('Contains a \\', true),
|
2018-01-15 19:52:15 +01:00
|
|
|
array('Contains a *', true),
|
|
|
|
array('Contains a /', true),
|
|
|
|
array('Contains a ?', true),
|
|
|
|
array('Contains a %', true),
|
2018-03-05 14:43:44 +01:00
|
|
|
array('Contains a \x0b', true),
|
2018-01-15 19:52:15 +01:00
|
|
|
array('This one contains them all < > " : | \ * / ? % are not allowed', true)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-22 17:12:44 +01:00
|
|
|
class VfsTestMail extends \mail_bo
|
2018-01-15 19:52:15 +01:00
|
|
|
{
|
|
|
|
// Expose for testing
|
2018-01-22 17:12:44 +01:00
|
|
|
public static function clean_subject_for_filename($filename)
|
2018-01-15 19:52:15 +01:00
|
|
|
{
|
|
|
|
return parent::clean_subject_for_filename($filename);
|
|
|
|
}
|
|
|
|
}
|