Skip to content

Commit

Permalink
Use greenmail IMAP server for testing message rendering
Browse files Browse the repository at this point in the history
It's already integrated in the test-suite and the upstream image runs on
arm64, too.
  • Loading branch information
pabzm committed Dec 18, 2024
1 parent 0b5f408 commit 2eef5c3
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 4 deletions.
15 changes: 15 additions & 0 deletions .ci/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
services:
mailhost:
image: docker.io/greenmail/standalone
environment:
GREENMAIL_OPTS: '-Dgreenmail.setup.test.all -Dgreenmail.hostname=0.0.0.0 -Dgreenmail.auth.disabled -Dgreenmail.preload.dir=/home/greenmail/preload'
volumes:
- "../tests/MessageRendering/data/greenmail:/home/greenmail/preload"
browserhost:
image: docker.io/selenium/standalone-chromium
ports:
Expand Down Expand Up @@ -40,6 +44,17 @@ services:
command:
- .ci/run_tests.sh

test_message_rendering:
depends_on:
- mailhost
image: ghcr.io/roundcube/roundcubemail-testrunner:php8.3
environment:
RC_CONFIG_IMAP_HOST: 'tls://mailhost:3143'
volumes:
- '..:/app'
command:
- .ci/run_test_message_rendering.sh

codespell:
image: ghcr.io/roundcube/roundcubemail-testrunner:php8.3
volumes:
Expand Down
11 changes: 11 additions & 0 deletions .ci/run_test_message_rendering.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash -ex

if ! test -f config/config-test.inc.php; then
cp -v .ci/config-test.inc.php config/config-test.inc.php
fi

# Install dependencies, prefer highest.
composer update --prefer-dist --no-interaction --no-progress

# Execute tests.
vendor/bin/phpunit -c ./tests/MessageRendering/phpunit.xml --fail-on-warning --fail-on-risky
9 changes: 6 additions & 3 deletions tests/MessageRendering/MessageRenderingTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace Tests\MessageRendering;

use Masterminds\HTML5;
use Roundcube\Tests\ActionTestCase;
use Roundcube\Tests\ExitException;

/**
* Class to base actual test classes on, which test specific message rendering.
*/
class MessageRenderingTestCase extends \ActionTestCase
class MessageRenderingTestCase extends ActionTestCase
{
/**
* Get the body from the document, trimmed from surrounding whitespace.
Expand Down Expand Up @@ -40,13 +42,14 @@ protected function getScrubbedSubject(\DOMXPath $domxpath): string
*/
protected function runAndGetHtmlOutputDomxpath(string $msgId): \DOMXPath
{
$imap_host = getenv('RC_CONFIG_IMAP_HOST') ?: 'tls://localhost:143';
$rcmail = \rcmail::get_instance();
// We need to overwrite the storage object, else storage_init() just
// returns the cached one (which might be a StorageMock instance).
$mockStorage = $rcmail->storage = null;
$rcmail->storage_init();
// Login our test user so we can fetch messages from the imap server.
$rcmail->login('test', 'pass', 'tls://localhost');
$rcmail->login('test-message-rendering@localhost', 'pass', $imap_host);
$storage = $rcmail->get_storage();
$storage->set_options(['all_headers' => true]);
// We need to set the folder, else no message can be fetched.
Expand Down Expand Up @@ -77,7 +80,7 @@ protected function runAndGetHtmlOutputDomxpath(string $msgId): \DOMXPath
$html = '';
try {
$action->run();
} catch (\ExitException $e) {
} catch (ExitException $e) {
$html = $output->getOutput();
}

Expand Down
1 change: 0 additions & 1 deletion tests/MessageRendering/dovecot-maildir.conf

This file was deleted.

0 comments on commit 2eef5c3

Please sign in to comment.