PL
games/runtime-demo / tests / RuntimeBannerTest.php · commit 459a354
<?phpnamespace Tests;use App\Scene\DemoScene;use JumPHP\Net\RuntimeLink;use JumPHP\Runtime\ManualRuntime;use JumPHP\Runtime\RuntimeBanner;use JumPHP\Runtime\RuntimeGuide;use JumPHP\Testing\GameTestCase;/** The one-line notice of an application: when it shows, what the button does, and that "Not now" is remembered. */final class RuntimeBannerTest extends GameTestCase{    private function banner(string $state): RuntimeBanner    {        $this->game->engine->options->set('runtime_banner_dismissed', false);        $this->game->engine->setRuntime(new ManualRuntime($state));        $this->game->start(DemoScene::class);        $this->game->run(3);        $banner = $this->game->scene()->widget('notice');        self::assertInstanceOf(RuntimeBanner::class, $banner);        return $banner;    }    public function testItIsHiddenWhenTheRuntimeIsReady(): void    {        self::assertFalse($this->banner(RuntimeLink::READY)->visible);    }    public function testItInvitesToInstallWhenTheRuntimeIsMissing(): void    {        $banner = $this->banner(RuntimeLink::MISSING);        self::assertTrue($banner->visible);        $go = $this->game->scene()->widget('noticeGo');        self::assertSame('How to install', $go->text);        self::assertStringContainsString('JumPHP runtime', $this->game->scene()->widget('noticeText')->text);        $this->game->scene()->click($go);        $this->game->run(2);        self::assertInstanceOf(RuntimeGuide::class, $this->game->scene());    }    public function testItAsksThePermissionWhenTheRuntimeRuns(): void    {        $banner = $this->banner(RuntimeLink::RUNNING);        self::assertTrue($banner->visible);        self::assertSame('Allow this app', $this->game->scene()->widget('noticeGo')->text);    }    public function testNotNowIsRemembered(): void    {        $banner = $this->banner(RuntimeLink::MISSING);        $this->game->scene()->click($this->game->scene()->widget('noticeLater'));        $this->game->run(2);        self::assertFalse($banner->visible);        self::assertTrue((bool)$this->game->engine->options->get('runtime_banner_dismissed', false));    }}