test(update-checker): wp-plugin-info.json validity + version/download_url invariants
This commit is contained in:
@@ -7,6 +7,8 @@ final class UpdateCheckerIntegrationTest extends Cf7stgTestCase
|
|||||||
{
|
{
|
||||||
private const PLUGIN_ROOT = __DIR__ . '/..';
|
private const PLUGIN_ROOT = __DIR__ . '/..';
|
||||||
private const PUC_LOADER = self::PLUGIN_ROOT . '/includes/lib/plugin-update-checker/plugin-update-checker.php';
|
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
|
public function test_puc_loader_file_exists(): void
|
||||||
{
|
{
|
||||||
@@ -21,4 +23,45 @@ final class UpdateCheckerIntegrationTest extends Cf7stgTestCase
|
|||||||
'PucFactory must be loadable after requiring the PUC loader'
|
'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_contains_expected_asset_name(): void
|
||||||
|
{
|
||||||
|
$data = json_decode(file_get_contents(self::WP_PLUGIN_INFO_JSON), true);
|
||||||
|
$expectedAssetName = 'cf7-spam-to-telegram-' . $data['version'] . '.zip';
|
||||||
|
self::assertStringContainsString(
|
||||||
|
$expectedAssetName,
|
||||||
|
$data['download_url'],
|
||||||
|
"download_url must contain expected asset name $expectedAssetName"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user