Skip to content

Commit 08a0757

Browse files
committed
feat: Use asset_url function instead of custom version parsing
1 parent a69b58e commit 08a0757

3 files changed

Lines changed: 58 additions & 36 deletions

File tree

test/TlsIconTest.php

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function __construct($name = null, array $data = [], $dataName = '')
4040
{
4141
parent::__construct($name, $data, $dataName);
4242
$plugin = new tls_icon();
43+
$plugin->init();
4344
$this->strUnEnCrypted = '<img class="lock_icon" src="' . $plugin->get_svg_path('unlock.svg') . '" title="Message received over an unencrypted connection!" />';
4445
$this->strCryptedTlsv12 = '<img class="lock_icon" src="' . $plugin->get_svg_path('lock.svg') . '" title="TLSv1.2" />';
4546
$this->strCryptedTlsv12WithCipher = '<img class="lock_icon" src="' . $plugin->get_svg_path('lock.svg') . '" title="TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)" />';
@@ -53,12 +54,14 @@ public function __construct($name = null, array $data = [], $dataName = '')
5354
public function testInstance()
5455
{
5556
$o = new tls_icon();
57+
$o->init();
5658
$this->assertInstanceOf('tls_icon', $o);
5759
}
5860

5961
public function testStorage_Init()
6062
{
6163
$o = new tls_icon();
64+
$o->init();
6265
$this->assertSame([
6366
'fetch_headers' => 'RECEIVED'
6467
], $o->storage_init([]));
@@ -76,12 +79,14 @@ public function testStorage_Init()
7679
public function testMessageHeadersNothing()
7780
{
7881
$o = new tls_icon();
82+
$o->init();
7983
$this->assertSame([], $o->message_headers([]));
8084
}
8185

8286
public function testMessageHeadersNoMatching()
8387
{
8488
$o = new tls_icon();
89+
$o->init();
8590
$headersProcessed = $o->message_headers([
8691
'output' => [
8792
'subject' => [
@@ -112,6 +117,7 @@ public function testMessageHeadersNoMatching()
112117
public function testMessageHeadersTlsWithCipher()
113118
{
114119
$o = new tls_icon();
120+
$o->init();
115121
$headersProcessed = $o->message_headers([
116122
'output' => [
117123
'subject' => [
@@ -148,6 +154,7 @@ public function testMessageHeadersTlsWithCipher()
148154
public function testMessageHeadersTls()
149155
{
150156
$o = new tls_icon();
157+
$o->init();
151158
$headersProcessed = $o->message_headers([
152159
'output' => [
153160
'subject' => [
@@ -184,6 +191,7 @@ public function testMessageHeadersTls()
184191
public function testMessageHeadersInternal()
185192
{
186193
$o = new tls_icon();
194+
$o->init();
187195
$headersProcessed = $o->message_headers([
188196
'output' => [
189197
'subject' => [
@@ -217,6 +225,7 @@ public function testMessageHeadersInternal()
217225
public function testMessageHeadersInternalLocalhostIPv4()
218226
{
219227
$o = new tls_icon();
228+
$o->init();
220229
$headersProcessed = $o->message_headers([
221230
'output' => [
222231
'subject' => [
@@ -249,6 +258,7 @@ public function testMessageHeadersInternalLocalhostIPv4()
249258
public function testMessageHeadersInternalLocalhostIPv6()
250259
{
251260
$o = new tls_icon();
261+
$o->init();
252262
$headersProcessed = $o->message_headers([
253263
'output' => [
254264
'subject' => [
@@ -287,6 +297,7 @@ public function testPostfixTLS13NewSyntax()
287297
for <test@example.com>; Tue, 16 Sep 2025 12:26:17 +0200 (CEST)';
288298

289299
$o = new tls_icon();
300+
$o->init();
290301
$headersProcessed = $o->message_headers([
291302
'output' => [
292303
'subject' => [
@@ -432,6 +443,7 @@ public function testSendmailTLS13NoVerify()
432443
public function testSendmailTLS12WithVerify()
433444
{
434445
$o = new tls_icon();
446+
$o->init();
435447
$headersProcessed = $o->message_headers([
436448
'output' => [
437449
'subject' => [
@@ -468,6 +480,7 @@ public function testSendmailTLS12WithVerify()
468480
public function testSendmailTLS13MultipleRecipients()
469481
{
470482
$o = new tls_icon();
483+
$o->init();
471484
$headersProcessed = $o->message_headers([
472485
'output' => [
473486
'subject' => [
@@ -504,6 +517,7 @@ public function testSendmailTLS13MultipleRecipients()
504517
public function testStalwartTls()
505518
{
506519
$o = new tls_icon();
520+
$o->init();
507521
$headersProcessed = $o->message_headers([
508522
'output' => [
509523
'subject' => [
@@ -537,42 +551,27 @@ public function testStalwartTls()
537551
], $headersProcessed);
538552
}
539553

540-
/**
541-
* @runInSeparateProcess
542-
*/
543-
public function testGetSvgPathPre17()
554+
public function testAssetUrlStubCanReturnLegacyPath()
544555
{
545-
if (!defined('RCMAIL_VERSION')) {
546-
define('RCMAIL_VERSION', '1.6.9');
547-
}
556+
$rcmail = rcmail::get_instance();
557+
$rcmail->output->set_asset_url_callback(function ($path) {
558+
return 'plugins/tls_icon/' . basename($path);
559+
});
548560

549561
$plugin = new tls_icon();
562+
$plugin->init();
550563
$this->assertSame('plugins/tls_icon/lock.svg', $plugin->get_svg_path('lock.svg'));
551564
}
552565

553-
/**
554-
* @runInSeparateProcess
555-
*/
556-
public function testGetSvgPath17()
566+
public function testAssetUrlStubCanReturnStaticPhpPath()
557567
{
558-
if (!defined('RCMAIL_VERSION')) {
559-
define('RCMAIL_VERSION', '1.7.0');
560-
}
561-
562-
$plugin = new tls_icon();
563-
$this->assertSame('static.php/plugins/tls_icon/lock.svg', $plugin->get_svg_path('lock.svg'));
564-
}
565-
566-
/**
567-
* @runInSeparateProcess
568-
*/
569-
public function testGetSvgPath17Git()
570-
{
571-
if (!defined('RCMAIL_VERSION')) {
572-
define('RCMAIL_VERSION', '1.7-git');
573-
}
568+
$rcmail = rcmail::get_instance();
569+
$rcmail->output->set_asset_url_callback(function ($path) {
570+
return 'static.php/' . $path;
571+
});
574572

575573
$plugin = new tls_icon();
574+
$plugin->init();
576575
$this->assertSame('static.php/plugins/tls_icon/lock.svg', $plugin->get_svg_path('lock.svg'));
577576
}
578577
}

test/rcmail.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@ public function set($keyname, $value) {
2020
}
2121
}
2222

23+
/**
24+
* @internal Test class to mock Roundcube output handling
25+
*/
26+
class rcmail_output {
27+
/**
28+
* @var callable|null
29+
*/
30+
private $asset_url_callback = null;
31+
32+
public function asset_url($path) {
33+
if ($this->asset_url_callback !== null) {
34+
return call_user_func($this->asset_url_callback, $path);
35+
}
36+
37+
return $path;
38+
}
39+
40+
/**
41+
* @internal added method for testing purposes
42+
*/
43+
public function set_asset_url_callback($callback) {
44+
$this->asset_url_callback = $callback;
45+
}
46+
}
47+
2348
/**
2449
* @internal Test class to mock Roundcube
2550
*/
@@ -30,6 +55,11 @@ class rcmail
3055
*/
3156
public $config;
3257

58+
/**
59+
* @var rcmail_output
60+
*/
61+
public $output;
62+
3363
/**
3464
* @var self|null
3565
*/
@@ -38,6 +68,7 @@ class rcmail
3868
public function __construct()
3969
{
4070
$this->config = new rcmail_config();
71+
$this->output = new rcmail_output();
4172
}
4273

4374
public static function get_instance() {

tls_icon.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,7 @@ public function storage_init($p)
4848

4949
public function get_svg_path($filename)
5050
{
51-
// Roundcube 1.7+ requires using static.php for direct file access
52-
if (defined('RCMAIL_VERSION')) {
53-
// Parse version: remove non-numeric parts after the version numbers
54-
$version = preg_replace('/[^0-9.].*/', '', RCMAIL_VERSION);
55-
if (version_compare($version, '1.7', '>=')) {
56-
return 'static.php/plugins/tls_icon/' . $filename;
57-
}
58-
}
59-
return 'plugins/tls_icon/' . $filename;
51+
return $this->rcmail->output->asset_url('plugins/tls_icon/' . $filename);
6052
}
6153

6254
public function message_headers($p)

0 commit comments

Comments
 (0)