90 lines
3.8 KiB
PHP
90 lines
3.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
test('plugin metadata and packaging docs match project rules', function (): void {
|
|
$conf = file_get_contents(PLUGIN_ROOT . '/plugin.conf') ?: '';
|
|
$packing = file_get_contents(PROJECT_ROOT . '/PACKING.md') ?: '';
|
|
|
|
assert_contains('name=MX-Autologin', $conf);
|
|
assert_contains('id=mxautologin', $conf);
|
|
assert_contains('type=user', $conf);
|
|
assert_contains('version=1.1.2', $conf);
|
|
assert_contains('user_run_as=root', $conf);
|
|
assert_contains('/Users/marek/GPT/ChatGPT/da_plugins/mail-login/src', $packing);
|
|
assert_contains('/Users/marek/GPT/ChatGPT/da_plugins/mail-login/archives/X.Y.Z/mxautologin.tar.gz', $packing);
|
|
});
|
|
|
|
test('package source excludes local-only files and dangerous placeholders', function (): void {
|
|
$package = file_get_contents(PLUGIN_ROOT . '/scripts/package.sh') ?: '';
|
|
assert_contains("--exclude='./.git'", $package);
|
|
assert_contains("--exclude='./tests'", $package);
|
|
assert_contains('mxautologin.tar.gz', $package);
|
|
assert_true(is_file(PLUGIN_ROOT . '/scripts/keygen.sh'));
|
|
|
|
$bad = [];
|
|
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PLUGIN_ROOT, FilesystemIterator::SKIP_DOTS));
|
|
foreach ($it as $file) {
|
|
if (!$file->isFile()) {
|
|
continue;
|
|
}
|
|
$relative = substr($file->getPathname(), strlen(PLUGIN_ROOT) + 1);
|
|
if (str_starts_with($relative, '.git/') || str_starts_with($relative, 'tests/')) {
|
|
continue;
|
|
}
|
|
$content = file_get_contents($file->getPathname()) ?: '';
|
|
if (preg_match('/TODO|TBD|FIXME|placeholder|not implemented/i', $content)) {
|
|
$bad[] = $relative;
|
|
}
|
|
}
|
|
assert_same([], $bad);
|
|
});
|
|
|
|
test('package source contains no mx helper implementation or mode switch', function (): void {
|
|
assert_false(is_dir(PLUGIN_ROOT . '/mx-helper'), 'mx-helper directory must not be shipped');
|
|
|
|
$forbidden = [];
|
|
$needles = ['MX_LOGIN_MODE', 'mail-login-helper', 'mail-login-create-url', '/mx-helper/'];
|
|
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PLUGIN_ROOT, FilesystemIterator::SKIP_DOTS));
|
|
foreach ($it as $file) {
|
|
if (!$file->isFile()) {
|
|
continue;
|
|
}
|
|
$relative = substr($file->getPathname(), strlen(PLUGIN_ROOT) + 1);
|
|
if (str_starts_with($relative, '.git/') || str_starts_with($relative, 'tests/')) {
|
|
continue;
|
|
}
|
|
$content = file_get_contents($file->getPathname()) ?: '';
|
|
foreach ($needles as $needle) {
|
|
if (str_contains($relative, $needle) || str_contains($content, $needle)) {
|
|
$forbidden[] = $relative . ':' . $needle;
|
|
}
|
|
}
|
|
}
|
|
|
|
assert_same([], $forbidden);
|
|
});
|
|
|
|
test('directadmin entry points use mx autologin directory and display label', function (): void {
|
|
$txt = file_get_contents(PLUGIN_ROOT . '/hooks/user_txt.html') ?: '';
|
|
$img = file_get_contents(PLUGIN_ROOT . '/hooks/user_img.html') ?: '';
|
|
$login = file_get_contents(PLUGIN_ROOT . '/user/login.raw') ?: '';
|
|
$index = file_get_contents(PLUGIN_ROOT . '/user/index.html') ?: '';
|
|
|
|
assert_contains('/CMD_PLUGINS/mxautologin/login.raw', $txt);
|
|
assert_contains('Zaloguj do serwera poczty', $txt);
|
|
assert_contains('/CMD_PLUGINS/mxautologin/images/user_icon.svg', $img);
|
|
assert_contains('alt="Zaloguj do serwera poczty"', $img);
|
|
assert_contains('/usr/local/directadmin/plugins/mxautologin/php.ini', $login);
|
|
assert_contains('/CMD_PLUGINS/mxautologin/login.raw', $index);
|
|
});
|
|
|
|
test('plugin icon follows directadmin login screen palette', function (): void {
|
|
$icon = file_get_contents(PLUGIN_ROOT . '/images/user_icon.svg') ?: '';
|
|
|
|
assert_contains('#2c8ec4', $icon);
|
|
assert_contains('#00689c', $icon);
|
|
assert_contains('#ff8a2a', $icon);
|
|
assert_contains('#ffffff', $icon);
|
|
assert_not_contains('#14532d', $icon);
|
|
});
|