<?phpnamespace Tests;use App\Core\AutoUpdate;use App\Form\MainForm;use App\Scene\SplashScene;/** The installed WinZik looks for its update during the splash, waits for it, and starts again on it. */final class UpdateTest extends PlayerTestCase{ private function splashWithUpdater(): AutoUpdate { $this->startPlayer(); // WinZik booted (its settings, its services) $engine = $this->form->engineOrNull(); self::assertNotNull($engine); $key = openssl_pkey_new(['private_key_type' => OPENSSL_KEYTYPE_EC, 'curve_name' => 'prime256v1']); self::assertNotFalse($key); // an address that answers nothing (the check fails at once): the states are then set by the test $updater = new AutoUpdate($engine->http(), 'http://127.0.0.1:9/update.json', '0.9.91', 'winzik', (string)openssl_pkey_get_details($key)['key'], __FILE__); $this->wz->updater = $updater; $this->wz->options['autoUpdate'] = true; $this->game->start(SplashScene::class); return $updater; } public function testTheSplashWaitsForTheUpdateItDownloads(): void { $updater = $this->splashWithUpdater(); $updater->state = 'installing'; $updater->version = '0.9.92'; $updater->progress = 0.42; $this->game->wait(4); $splash = $this->game->scene(); self::assertInstanceOf(SplashScene::class, $splash, 'it waits for the download'); self::assertSame('Mise à jour vers WinZik 0.9.92 : 42 %', $splash->updateLine()); $this->game->shot('splash-update'); $updater->state = 'latest'; $this->game->wait(1); self::assertInstanceOf(MainForm::class, $this->game->scene(), 'nothing more to wait for: the player'); } public function testWithoutNetworkThePlayerOpensAfterTheSplash(): void { $this->splashWithUpdater(); $this->game->wait(6); self::assertInstanceOf(MainForm::class, $this->game->scene()); } public function testTheButtonsOfTheOptionsMoveTheCompactBarAtOnce(): void { $this->startPlayer(); $this->form->openOptions(); $this->game->run(2); $o = $this->game->scene(); self::assertInstanceOf(\App\Form\OptionsForm::class, $o); $jogX = $o->widget('jogX'); $jogY = $o->widget('jogY'); self::assertInstanceOf(\App\Gui\JogDial::class, $jogX); self::assertInstanceOf(\App\Gui\JogDial::class, $jogY); // a short click on its right side: one step $o->clickAt($jogX->x + $jogX->w - 4, $jogX->y + $jogX->h / 2); self::assertSame(1, $this->wz->options['compactDx'], 'at once, without OK'); // held near its left end: it runs as long as it is held, the bar moving at each value $p = new \JumPHP\Gui\Pointer(); [$p->x, $p->y] = [$jogY->x + 3, $jogY->y + $jogY->h / 2]; $jogY->pointerDown($p); $this->game->wait(1.5); $jogY->pointerUp($p, true); self::assertLessThan(-30, $this->wz->options['compactDy'], 'held: it ran'); $after = $this->wz->options['compactDy']; $this->game->wait(0.5); self::assertSame($after, $this->wz->options['compactDy'], 'let go: it stops'); $o->click($o->widget('cancel')); $this->game->run(2); self::assertSame(0, $this->wz->options['compactDx'], 'Annuler: back'); } public function testResetTheOptionsAsksOnceMoreThenErasesEverySetting(): void { $this->startPlayer(); $this->wz->options['zoomPct'] = 120; $this->wz->save(); $settings = $this->wz->storagePath(\App\Core\WinZik::SETTINGS); self::assertFileExists($settings); $this->form->openOptions(); $this->game->run(2); $o = $this->game->scene(); self::assertInstanceOf(\App\Form\OptionsForm::class, $o); $o->click($o->widget('reset')); $this->game->run(1); self::assertFileExists($settings, 'one click only asks'); self::assertStringContainsString('Confirmer', (string)$o->widget('reset')->props['text']); $this->game->wait(6); self::assertSame('Réinitialiser les options et redémarrer', $o->widget('reset')->props['text'], 'not confirmed: as before'); $o->click($o->widget('reset')); $o->click($o->widget('reset')); $this->game->run(1); self::assertFileDoesNotExist($settings, 'confirmed: erased'); $this->wz->touch(); $this->wz->save(); self::assertFileDoesNotExist($settings, 'nothing written again before the restart'); } /** the song of the last time, to be played again (what load() sets when WinZik was playing when it quit) */ private function songToResume(): void { $this->wz->stop(); (new \ReflectionProperty($this->wz, 'resumePlay'))->setValue($this->wz, true); } public function testTheSongOfTheLastTimeWaitsUntilItIsKnownThatNoUpdateComes(): void { $updater = $this->splashWithUpdater(); $this->songToResume(); $updater->state = 'checking'; $this->game->wait(2); self::assertNotSame('playing', $this->wz->player->state, 'no sound while the update is looked for'); $updater->state = 'latest'; $this->game->run(2); self::assertSame('playing', $this->wz->player->state, 'no update: it plays'); } public function testAnUpdateThatInstallsNeverStartsTheSong(): void { $updater = $this->splashWithUpdater(); $this->songToResume(); $updater->state = 'installing'; $this->game->wait(2); self::assertNotSame('playing', $this->wz->player->state); // installed (on the player: the splash would restart WinZik) $this->game->start(MainForm::class); $updater->state = 'installed'; $this->game->run(5); self::assertNotSame('playing', $this->wz->player->state, 'the new WinZik will play it, not this one'); } public function testAClickOfTheUserCancelsTheSongOfTheLastTime(): void { $updater = $this->splashWithUpdater(); $this->songToResume(); $updater->state = 'checking'; $this->wz->stop(); // the user stopped it meanwhile $updater->state = 'latest'; $this->game->run(3); self::assertNotSame('playing', $this->wz->player->state, 'the user decided'); }}