1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
<?php
namespace Roundcube\Plugins\Tests;
use PHPUnit\Framework\TestCase;
class Tests_Archive extends TestCase
{
static function setUpBeforeClass(): void
{
include_once INSTALL_PATH . 'plugins/archive/archive.php';
}
/**
* Plugin object construction test
*/
function test_constructor()
{
$rcube = \rcube::get_instance();
$plugin = new \archive($rcube->plugins);
$this->assertInstanceOf(\archive::class, $plugin);
$this->assertInstanceOf(\rcube_plugin::class, $plugin);
$plugin->init();
}
/**
* Test prefs_table() method
*/
function test_prefs_table()
{
$rcube = \rcube::get_instance();
$plugin = new \archive($rcube->plugins);
$args = ['section' => 'server', 'blocks' => ['main' => ['options' => []]]];
$result = $plugin->prefs_table($args);
$this->assertSame(
'<label for="ff_read_on_archive">Mark the message as read on archive</label>',
$result['blocks']['main']['options']['read_on_archive']['title']
);
$this->assertSame(
'<input name="_read_on_archive" id="ff_read_on_archive" value="1" type="checkbox">',
$result['blocks']['main']['options']['read_on_archive']['content']
);
// TODO: section=folders
}
/**
* Test prefs_save() method
*/
function test_prefs_save()
{
$rcube = \rcube::get_instance();
$plugin = new \archive($rcube->plugins);
$_POST = [];
$args = ['section' => 'folders', 'prefs' => []];
$result = $plugin->prefs_save($args);
$this->assertSame('', $result['prefs']['archive_type']);
$_POST = ['_archive_type' => 'aaa'];
$args = ['section' => 'folders', 'prefs' => []];
$result = $plugin->prefs_save($args);
$this->assertSame('aaa', $result['prefs']['archive_type']);
$_POST = [];
$args = ['section' => 'server', 'prefs' => []];
$result = $plugin->prefs_save($args);
$this->assertFalse($result['prefs']['read_on_archive']);
$_POST = ['_read_on_archive' => 1];
$args = ['section' => 'server', 'prefs' => []];
$result = $plugin->prefs_save($args);
$this->assertTrue($result['prefs']['read_on_archive']);
}
}
|