Eine Installation löscht das gespeicherte Update-Ergebnis; eine Prüfung, die läuft, solange das Plugin nicht geladen ist, speichert eines ohne das Plugin, und der Schalter für automatische Updates fehlt bis zu eine Stunde. RecheckOnInstall vergisst das Ergebnis beim ersten admin_init mit der neuen Version (Priorität 5, vor _maybe_update_plugins des Core), der es dann mit registriertem GiteaUpdater neu aufbaut. Die Option lit_mcp_installed_version räumt der Uninstaller auf. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Updater;
|
|
|
|
use Brain\Monkey\Actions;
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
use LIT\MCP\Updater\RecheckOnInstall;
|
|
|
|
final class RecheckOnInstallTest extends TestCase
|
|
{
|
|
public function testRunsAtAdminInitBeforeCoreRebuildsTheUpdateResult(): void
|
|
{
|
|
$recheck = new RecheckOnInstall('1.0.5');
|
|
// Core's _maybe_update_plugins sits on admin_init at the default priority 10.
|
|
Actions\expectAdded('admin_init')->once()->with([$recheck, 'recheckIfNew'], 5);
|
|
|
|
$recheck->register();
|
|
}
|
|
|
|
/** @dataProvider installedBefore */
|
|
public function testForgetsTheUpdateResultWhenTheVersionIsNewToThisSite(string|false $stored): void
|
|
{
|
|
Functions\when('get_option')->justReturn($stored);
|
|
Functions\expect('delete_site_transient')->once()->with('update_plugins');
|
|
Functions\expect('update_option')->once()->with(RecheckOnInstall::OPTION, '1.0.5', false);
|
|
|
|
(new RecheckOnInstall('1.0.5'))->recheckIfNew();
|
|
}
|
|
|
|
/** @return array<string, array{string|false}> */
|
|
public static function installedBefore(): array
|
|
{
|
|
return [
|
|
'fresh install, nothing stored' => [false],
|
|
'replaced by a newer version' => ['1.0.4'],
|
|
'replaced by an older version' => ['1.0.9'],
|
|
];
|
|
}
|
|
|
|
public function testDoesNothingForTheVersionAlreadySeen(): void
|
|
{
|
|
Functions\when('get_option')->justReturn('1.0.5');
|
|
Functions\expect('delete_site_transient')->never();
|
|
Functions\expect('update_option')->never();
|
|
|
|
(new RecheckOnInstall('1.0.5'))->recheckIfNew();
|
|
}
|
|
}
|