TR
apps/winzik / tests / OriginalPhoneTest.php · commit 6576d6f
<?phpnamespace Tests;use App\Form\MainForm;use App\Form\MobileForm;use App\Form\OptionsForm;use App\Form\WinZikDialog;use App\Gui\Desktop;use JumPHP\Gui\Pointer;/** * "WinZik original" on a phone (option phoneUi = 'original'): the windows of 2001 upright on a 390 x 844 screen, the * menu of the right click by a long press or the "Menu" button, made for a finger, the karaoke turned for the phone on * its side, the dialogs as whole screens. */final class OriginalPhoneTest extends PlayerTestCase{    private const PHONE = 390 / 844;    private function startPhone(array $params = []): void    {        $this->startPlayer(['phone' => self::PHONE] + $params);        $this->wz->options['phoneUi'] = 'original';        $this->game->wait(1);       // the windows unroll at the start    }    /** A finger: down at a point (view pixels), held some frames, lifted. */    private function finger(float $x, float $y, int $frames = 1): void    {        $p = new Pointer();        [$p->x, $p->y, $p->down, $p->held] = [$x, $y, true, true];        $this->form->handle($p);        $this->game->run($frames);        $up = new Pointer();        [$up->x, $up->y, $up->up] = [$x, $y, true];        $this->form->handle($up);        $this->game->run(1);    }    /** The view point of a point of the desktop (desktop pixels). @return array{0: float, 1: float} */    private function view(float $dx, float $dy): array    {        return [$this->desk->x + $dx * $this->desk->scale, $this->desk->y + $dy * $this->desk->scale];    }    private function tapRow(string $label): void    {        $menu = $this->desk->menu();        self::assertNotNull($menu);        $at = $menu->rowCenter($label);        self::assertNotNull($at, $label . ' is in the menu');        $this->finger(...$this->view(...$at));    }    private function back(): void    {        $p = new Pointer();        [$p->x, $p->y] = [-1, -1];        $p->keys[] = Pointer::ESCAPE;        $this->game->scene()->handle($p);        $this->game->run(1);    }    public function testThePlayerAndTheListFillTheWidthOfThePhoneAtASharpZoom(): void    {        $this->startPhone();        $desk = $this->desk;        self::assertTrue($desk->phone);        self::assertSame(0.0, fmod($desk->scale * 2, 1.0), 'a whole or half pixel of the screen per pixel of the skin');        self::assertGreaterThan($desk->w * 0.93, $desk->main->width() * $desk->scale);        // the list across the whole screen, down to the bar of the phone        self::assertSame(0.0, $desk->playlist->x);        self::assertEqualsWithDelta($desk->deskWidth(), $desk->playlist->width(), 1.0);        self::assertSame($desk->main->height(), $desk->playlist->y);        $bottom = $desk->playlist->y + $desk->playlist->height();        $lyrics = $desk->lyrics->visible() ? $desk->lyrics->barHeight() : 0;        self::assertLessThanOrEqual($desk->deskHeight() - Desktop::PHONE_BAR - $lyrics, $bottom);        self::assertGreaterThan($desk->deskHeight() - Desktop::PHONE_BAR - $lyrics - 20, $bottom);        $this->game->shot('original-phone');    }    public function testALongPressFillsARingThenOpensTheMenuMadeForAFinger(): void    {        $this->startPhone();        [$x, $y] = $this->at($this->desk->playlist, 120, 60);        $p = new Pointer();        [$p->x, $p->y, $p->down, $p->held] = [$x, $y, true, true];        $this->form->handle($p);        $this->game->run(18);        self::assertGreaterThan(0.3, $this->desk->ring, 'the ring fills while the finger stays');        self::assertFalse($this->desk->hasMenu());        $this->game->shot('original-phone-ring');        $this->game->run(20);        self::assertTrue($this->desk->hasMenu());        $menu = $this->desk->menu();        self::assertTrue($menu->touch);        self::assertSame(26.0, $menu->row, 'rows a finger can take');        self::assertGreaterThan($this->desk->deskWidth() * 0.9, $menu->width);        $up = new Pointer();        [$up->x, $up->y, $up->up] = [$x, $y, true];        $this->form->handle($up);        $this->game->run(1);        self::assertTrue($this->desk->hasMenu(), 'lifting the finger runs nothing');        $this->game->shot('original-phone-menu');    }    public function testTheMenuButtonOpensTheMenuItsSubmenusOpenInPlaceAndBackClosesThem(): void    {        $this->startPhone();        [$bx, $by, $bw, $bh] = $this->desk->menuButton();        $this->finger(...$this->view($bx + $bw / 2, $by + $bh / 2));        self::assertTrue($this->desk->hasMenu());        self::assertContains('Interface mobile', $this->desk->menuLabels());        self::assertContains('Karaoké plein écran (téléphone en paysage)', $this->desk->menuLabels());        // Options: in place of the menu, its first row goes back        $this->tapRow('Options');        $menu = $this->desk->menu();        self::assertNotNull($menu);        self::assertNotNull($menu->rowCenter('Configurer WinZiK'));        self::assertNull($menu->rowCenter('Egaliseur'), 'the submenu is in place of the menu');        $this->game->shot('original-phone-submenu');        $this->back();        self::assertTrue($this->desk->hasMenu());        self::assertNotNull($this->desk->menu()?->rowCenter('Egaliseur'), 'back: the menu again');        // a row of the submenu runs: Egaliseur shows the equalizer        $this->tapRow('Egaliseur');        self::assertFalse($this->desk->hasMenu());        self::assertTrue($this->desk->eq->visible());        // the button again, then back closes it; a tap beside it too, and that tap does nothing else        $this->finger(...$this->view($bx + $bw / 2, $by + $bh / 2));        self::assertTrue($this->desk->hasMenu());        $this->back();        self::assertFalse($this->desk->hasMenu());        $this->finger(...$this->view($bx + $bw / 2, $by + $bh / 2));        $this->finger(...$this->at($this->desk->main, 10, 10));        self::assertFalse($this->desk->hasMenu());    }    public function testAFingerSlidesTheMenuWhenItIsTallerThanTheScreen(): void    {        $this->startPlayer(['phone' => 1.0]);      // a square screen: the menu is taller than it        [$bx, $by, $bw, $bh] = $this->desk->menuButton();        $this->finger(...$this->view($bx + $bw / 2, $by + $bh / 2));        $this->tapRow('Menu');        $menu = $this->desk->menu()?->active();        self::assertNotNull($menu);        self::assertTrue($menu->scrolls());        [$x, $y] = $this->view($menu->x + 60, $menu->y + $menu->height() - 40);        $this->dragView($x, $y, $x, $y - 200);        self::assertGreaterThan(0, $menu->scroll);        self::assertTrue($this->desk->hasMenu(), 'a slide runs no row');    }    public function testTheEntryInterfaceMobileGoesToThePhoneScreens(): void    {        $this->startPhone();        $this->desk->openBarMenu();        $this->game->run(1);        $this->tapRow('Interface mobile');        $this->game->run(2);        self::assertInstanceOf(MobileForm::class, $this->game->scene());        self::assertSame('mobile', $this->wz->options['phoneUi']);        self::assertFalse(MainForm::originalOnPhone($this->wz));    }    public function testTheKaraokeOnTheWholeScreenIsTurnedForThePhoneOnItsSide(): void    {        $this->startPhone();        $this->clickControl($this->desk->main, 'play');        self::assertNotNull($this->wz->lyrics);        $this->wz->seek(16.5);        $this->desk->openBarMenu();        $this->game->run(1);        $this->tapRow('Karaoké plein écran (téléphone en paysage)');        $this->game->wait(1);        $lyrics = $this->desk->lyrics;        self::assertSame($lyrics, $this->desk->turned());        // landscape: as wide as the phone is tall        self::assertEqualsWithDelta($this->desk->deskHeight(), $lyrics->width(), 0.5);        self::assertEqualsWithDelta($this->desk->deskWidth(), $lyrics->height(), 0.5);        $this->game->shot('original-phone-karaoke');        // its button "back to the bar" (top right of the turned picture: bottom right of the upright screen)        [$gx, $gy, $gw, $gh] = $lyrics->controls()['grow'];        [$u, $v] = [$gx + $gw / 2, $gy + $gh / 2];        $this->finger(...$this->view($this->desk->deskWidth() - $v, $u));        self::assertFalse($lyrics->full());        self::assertNull($this->desk->turned());        $this->game->wait(1);        $this->game->shot('original-phone-lyrics-bar');        self::assertSame($lyrics->barHeight(), $lyrics->height());    }    public function testADialogIsAWholeScreenAtThePhoneWidthAndBackClosesIt(): void    {        $this->startPhone();        $this->form->openOptions();        $this->game->run(2);        $options = $this->game->scene();        self::assertInstanceOf(OptionsForm::class, $options);        self::assertFalse($options->isOverlay(), 'the whole screen');        $phone = $options->phoneScreen();        self::assertNotNull($phone);        self::assertEqualsWithDelta($this->desk->w, $phone[0], 1.0);        self::assertLessThanOrEqual($phone[0] + 0.5, $options->viewWidth());        $this->game->shot('original-phone-options');        $this->back();        self::assertInstanceOf(MainForm::class, $this->game->scene());    }    /** @return list<string> the widgets of a dialog that go past the phone's right edge */    private function overflowing(\JumPHP\Gui\Form $form, float $width): array    {        $out = [];        foreach ($this->walk($form) as $widget) {            if ($widget->isShown($form->breakpoint()) && $widget->w > 0 && $widget->x + $widget->w > $width + 1) {                $out[] = ($widget->props['id'] ?? $widget::class) . ' ends at ' . round($widget->x + $widget->w);            }        }        return $out;    }    /** @return iterable<\JumPHP\Gui\Widget> */    private function walk(\JumPHP\Gui\Form $form): iterable    {        $root = (fn () => $this->root)->call($form);        return $root?->walk() ?? [];    }    public function testEveryDialogOfTheMenuIsWholeOnThePhoneScreen(): void    {        $this->startPhone();        $width = $this->desk->w;        $open = [            'options' => fn () => $this->form->openOptions(),            'files' => fn () => $this->form->openFiles(),            'tags' => fn () => $this->form->openTags(),            'skins' => fn () => $this->form->openSkins(),            'market' => fn () => $this->form->openMarket('skin'),            'plugins' => fn () => $this->form->openPlugins(),            'controls' => fn () => $this->form->openControls(),            'lyrics' => fn () => $this->form->downloadLyrics(),            'fls' => fn () => $this->form->openFls(true),            'lock' => fn () => $this->form->openLock(),        ];        foreach ($open as $name => $openIt) {            $openIt();            $this->game->run(3);            $dialog = $this->game->scene();            self::assertInstanceOf(WinZikDialog::class, $dialog, $name);            self::assertFalse($dialog->isOverlay(), $name . ': the whole screen');            self::assertSame([], $this->overflowing($dialog, $width), $name . ': nothing cut at the right');            $this->game->shot('original-phone-dialog-' . $name);            $this->back();            if (!$this->game->scene() instanceof MainForm) {                $this->game->scene()->close();                $this->game->run(1);            }            self::assertInstanceOf(MainForm::class, $this->game->scene(), $name . ': back closes it');        }    }    protected function tearDown(): void    {        WinZikDialog::$phoneAspect = 0.0;        parent::tearDown();    }}