5b8eeffecb
register_update_checker() guards on is_file + class_exists so the plugin degrades cleanly on installs that ship without the vendored lib (no update notices, but plugin core remains functional).
79 lines
3.2 KiB
PHP
79 lines
3.2 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_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"
|
|
);
|
|
}
|
|
|
|
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');
|
|
}
|
|
}
|