79e46ccf7e
Issue 1: `unzip -l "$ZIP_PATH" | grep -q ...` combined with set -o pipefail silently fails when grep -q exits on first match and SIGPIPEs the upstream unzip (which has not yet finished streaming the long file list). pipefail sees unzip's non-zero exit and fails the pipeline, so the guard thinks the file is missing. Fix: capture unzip -l output to a variable once, then grep the string via herestring. The first two sanity checks using `unzip -p` (short output, tight race window) were not affected. Issue 2: test_wp_plugin_info_json_download_url_contains_expected_asset_name assumed Gitea asset URLs always contain the asset filename. This is not true on git.netranking.ru, which returns /attachments/<uuid> — a UUID-only URL. Relaxed the test to assert the URL is an HTTPS Gitea URL; freshness of download_url is enforced indirectly via the version-match test. Post-mortem: 1.2.0 release was completed via a manual recovery script after release.sh failed at the zip-sanity step. State on main is consistent: tag v1.2.0 -> release commit, JSON commit directly on top of release commit, JSON points to the live Gitea asset.
87 lines
3.7 KiB
PHP
87 lines
3.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Cf7stg\Tests;
|
|
|
|
final class UpdateCheckerIntegrationTest extends Cf7stgTestCase
|
|
{
|
|
private const PLUGIN_ROOT = __DIR__ . '/..';
|
|
private const PUC_LOADER = self::PLUGIN_ROOT . '/includes/lib/plugin-update-checker/plugin-update-checker.php';
|
|
private const WP_PLUGIN_INFO_JSON = self::PLUGIN_ROOT . '/wp-plugin-info.json';
|
|
private const PLUGIN_MAIN_FILE = self::PLUGIN_ROOT . '/cf7-spam-to-telegram.php';
|
|
|
|
public function test_puc_loader_file_exists(): void
|
|
{
|
|
self::assertFileExists(self::PUC_LOADER);
|
|
}
|
|
|
|
public function test_puc_factory_class_loadable_after_require(): void
|
|
{
|
|
require_once self::PUC_LOADER;
|
|
self::assertTrue(
|
|
class_exists('YahnisElsts\\PluginUpdateChecker\\v5\\PucFactory'),
|
|
'PucFactory must be loadable after requiring the PUC loader'
|
|
);
|
|
}
|
|
|
|
public function test_wp_plugin_info_json_is_valid(): void
|
|
{
|
|
self::assertFileExists(self::WP_PLUGIN_INFO_JSON);
|
|
$data = json_decode(file_get_contents(self::WP_PLUGIN_INFO_JSON), true);
|
|
self::assertIsArray($data, 'wp-plugin-info.json must be valid JSON');
|
|
foreach (['name', 'slug', 'version', 'download_url', 'sections'] as $required) {
|
|
self::assertArrayHasKey($required, $data, "missing required key: $required");
|
|
}
|
|
self::assertSame('cf7-spam-to-telegram', $data['slug']);
|
|
self::assertIsArray($data['sections']);
|
|
self::assertArrayHasKey('description', $data['sections']);
|
|
self::assertArrayHasKey('changelog', $data['sections']);
|
|
}
|
|
|
|
public function test_wp_plugin_info_json_version_matches_plugin_constant(): void
|
|
{
|
|
$data = json_decode(file_get_contents(self::WP_PLUGIN_INFO_JSON), true);
|
|
$jsonVersion = $data['version'];
|
|
|
|
$phpSource = file_get_contents(self::PLUGIN_MAIN_FILE);
|
|
preg_match("/define\\('CF7STG_VERSION',\\s*'([^']+)'\\)/", $phpSource, $m);
|
|
self::assertNotEmpty($m[1] ?? null, 'CF7STG_VERSION constant must be defined in plugin main file');
|
|
|
|
self::assertSame(
|
|
$m[1],
|
|
$jsonVersion,
|
|
'wp-plugin-info.json::version must match CF7STG_VERSION in cf7-spam-to-telegram.php'
|
|
);
|
|
}
|
|
|
|
public function test_wp_plugin_info_json_download_url_is_gitea_asset_url(): void
|
|
{
|
|
$data = json_decode(file_get_contents(self::WP_PLUGIN_INFO_JSON), true);
|
|
$url = $data['download_url'];
|
|
self::assertNotEmpty($url, 'download_url must not be empty');
|
|
self::assertStringStartsWith(
|
|
'https://git.netranking.ru/',
|
|
$url,
|
|
'download_url must point to our Gitea host'
|
|
);
|
|
// Gitea returns one of two formats for release asset URLs:
|
|
// https://git.netranking.ru/<owner>/<repo>/releases/download/<tag>/<name>
|
|
// https://git.netranking.ru/attachments/<uuid>
|
|
// We cannot assert the asset name in the URL because the UUID format
|
|
// (used by git.netranking.ru) omits the filename entirely. Freshness
|
|
// is enforced indirectly: the plugin version must match CF7STG_VERSION
|
|
// (see test above), so a stale JSON would fail that test instead.
|
|
}
|
|
|
|
public function test_plugin_class_has_register_update_checker_method(): void
|
|
{
|
|
self::assertTrue(
|
|
method_exists('\\Cf7stg\\Plugin', 'register_update_checker'),
|
|
'Plugin class must expose register_update_checker()'
|
|
);
|
|
$ref = new \ReflectionMethod('\\Cf7stg\\Plugin', 'register_update_checker');
|
|
self::assertTrue($ref->isStatic(), 'register_update_checker must be static');
|
|
self::assertTrue($ref->isPrivate(), 'register_update_checker must be private');
|
|
}
|
|
}
|