<?phpnamespace Tests;use App\Audio\Player;use App\Gui\PlaylistWindow;use JumPHP\Gui\Pointer;/** The phone app (Android): the windows one under the other, as wide as the screen, used with a finger. */final class PhoneTest extends PlayerTestCase{ /** the bottom of the screen the list must reach (desktop pixels) */ private function screenBottom(): float { $lyrics = $this->desk->lyrics !== null && $this->desk->lyrics->visible() ? $this->desk->lyrics->barHeight() : 0; return $this->desk->deskHeight() - $this->desk->bottomMargin() - $lyrics; } public function testThePlayerTheEqualizerAndTheListFillTheScreenOfThePhone(): void { $this->startPlayer(['phone' => true, 'eq' => 'Rock']); $this->game->run(2); $desk = $this->desk; self::assertTrue($desk->phone); self::assertLessThan($desk->h, $desk->w, 'upright'); // the player across the screen (at a sharp zoom: a little room may be left at its sides), at its top self::assertLessThanOrEqual($desk->w + 0.5, $desk->main->width() * $desk->scale); self::assertGreaterThan($desk->w * 0.93, $desk->main->width() * $desk->scale); self::assertSame(0.0, $desk->main->y); // the equalizer under it, the list under them down to the bottom self::assertTrue($desk->eq->visible()); self::assertSame($desk->main->height(), $desk->eq->y); self::assertSame($desk->eq->y + $desk->eq->height(), $desk->playlist->y); $bottom = $desk->playlist->y + $desk->playlist->height(); self::assertLessThanOrEqual($this->screenBottom(), $bottom); self::assertGreaterThan($this->screenBottom() - PlaylistWindow::ROW_HEIGHT, $bottom); $this->game->wait(1); // the windows unroll at the start $this->game->shot('phone'); // the equalizer closed: the list goes up and gets longer $rows = $desk->playlist->rows(); $this->wz->toggleEq(); $this->game->run(2); self::assertSame($desk->main->height(), $desk->playlist->y); self::assertGreaterThan($rows, $desk->playlist->rows()); } public function testTheLayoutFollowsTheScreenWhenThePhoneTurns(): void { $this->startPlayer(['phone' => true]); $upright = $this->desk->scale; $this->desk->phoneAspect = 19.5 / 9; // on its side $this->form->invalidate(); $this->game->run(2); $desk = $this->desk; self::assertGreaterThan($desk->h, $desk->w); self::assertNotEquals($upright, $desk->scale); self::assertTrue($desk->phoneColumns()); // the player at the left, the list at the right, as tall as the screen self::assertSame(0.0, $desk->playlist->y); self::assertSame($desk->main->width(), $desk->playlist->x); self::assertLessThanOrEqual($desk->deskWidth() + 0.01, $desk->playlist->x + $desk->playlist->width()); self::assertLessThanOrEqual($this->screenBottom(), $desk->playlist->y + $desk->playlist->height()); $this->game->wait(1); $this->game->shot('phone-landscape'); } public function testATouchBesideAButtonPressesIt(): void { $this->startPlayer(['phone' => true]); $main = $this->desk->main; [$cx, $cy, $cw, $ch] = $main->controls()['play']; $x = $cx + $cw / 2; $y = $cy + $ch + 2; // just under the button, on the background of the player self::assertSame('', $main->controlAt($x, $y)); $this->clickIn($main, $x, $y); self::assertSame(Player::PLAYING, $this->wz->player->state); } public function testTheWindowsDoNotMoveAndALongPressOpensTheMenu(): void { $this->startPlayer(['phone' => true]); $main = $this->desk->main; // dragged by its background: it stays where it is [$fx, $fy] = $this->at($main, 30, 40); $before = [$main->x, $main->y]; $this->dragView($fx, $fy, $fx + 200, $fy + 300); self::assertSame($before, [$main->x, $main->y]); self::assertFalse($this->desk->hasMenu()); // held still: the menu of the right click $p = new Pointer(); [$p->x, $p->y, $p->down, $p->held] = [$fx, $fy, true, true]; $this->form->handle($p); $this->game->run(50); self::assertTrue($this->desk->hasMenu()); self::assertContains('Egaliseur', $this->desk->menuLabels()); self::assertNotContains('Zoom', $this->desk->menuLabels(), 'the phone zooms by itself'); // let go: the menu stays open (the finger was not on one of its lines) $up = new Pointer(); [$up->x, $up->y, $up->up] = [$fx, $fy, true]; $this->form->handle($up); $this->game->run(1); self::assertTrue($this->desk->hasMenu()); $this->game->wait(1); $this->game->shot('phone-menu'); }}