<?phpnamespace Tests;use App\Core\WinZik;use App\Form\MainForm;use App\Gui\Desktop;use App\Gui\SkinWindow;use JumPHP\Gui\Pointer;use JumPHP\Testing\GameTestCase;/** Starts WinZik from its first start and clicks its skinned windows where their buttons are. */abstract class PlayerTestCase extends GameTestCase{ protected MainForm $form; protected Desktop $desk; protected WinZik $wz; protected bool $shuffleAtStart = false; protected function startPlayer(array $params = []): void { $this->game->start(MainForm::class, ['fresh' => true] + $params); $form = $this->game->scene(); self::assertInstanceOf(MainForm::class, $form); $this->form = $form; $desk = $form->widget('desktop'); self::assertInstanceOf(Desktop::class, $desk); $this->desk = $desk; $this->wz = $form->winzik(); // Hasard is on at the first start: the tests of the order of the songs start without it $this->shuffleAtStart = $this->wz->playlist->shuffle; $this->wz->playlist->shuffle = (bool)($params['shuffle'] ?? false); // the pointer of a test before (left over a window: its keys would go to it) away from the windows $this->form->engineOrNull()?->input->getMouse()->move(-1000, -1000); $this->game->run(2); } /** The view point of a point of a window (skin pixels). @return array{0: float, 1: float} */ protected function at(SkinWindow $window, float $x, float $y): array { return [$this->desk->x + ($window->x + $x) * $this->desk->scale, $this->desk->y + ($window->y + $y) * $this->desk->scale]; } /** A click in the middle of a control of a window ('play', 'next'...). */ protected function clickControl(SkinWindow $window, string $control, bool $double = false): void { [$cx, $cy, $cw, $ch] = $window->controls()[$control]; [$x, $y] = $this->at($window, $cx + $cw / 2, $cy + $ch / 2); $this->form->clickAt($x, $y, $double); $this->game->run(1); } /** A click at a point of a window. */ protected function clickIn(SkinWindow $window, float $x, float $y): void { [$vx, $vy] = $this->at($window, $x, $y); $this->form->clickAt($vx, $vy); $this->game->run(1); } protected function rightClick(float $x, float $y): void { $p = new Pointer(); [$p->x, $p->y, $p->right] = [$x, $y, true]; $this->form->handle($p); $this->game->run(1); } /** Pressed at one point, moved to another, let go (view pixels). */ protected function dragView(float $fromX, float $fromY, float $toX, float $toY, int $steps = 6): void { $p = new Pointer(); [$p->x, $p->y, $p->down, $p->held] = [$fromX, $fromY, true, true]; $this->form->handle($p); for ($i = 1; $i <= $steps; $i++) { $m = new Pointer(); [$m->x, $m->y, $m->held] = [$fromX + ($toX - $fromX) * $i / $steps, $fromY + ($toY - $fromY) * $i / $steps, true]; $this->form->handle($m); } $up = new Pointer(); [$up->x, $up->y, $up->up] = [$toX, $toY, true]; $this->form->handle($up); $this->game->run(1); }}