<?phpnamespace Tests;use App\Gui\PopupMenu;use App\Native\NativeShell;/** The windows on the desktop: dragging, sticking, the compact mode, the tray, the menu. */final class WindowsTest extends PlayerTestCase{ public function testThePlayerDraggedToTheEdgeSticksToIt(): void { $this->startPlayer(); $main = $this->desk->main; [$x, $y] = $this->at($main, 150, 104 - 10); // the empty bottom of the player $this->dragView($x, $y, $x + 60 * $this->desk->scale, $y + 40 * $this->desk->scale); self::assertEqualsWithDelta(72, $main->x, 1); self::assertEqualsWithDelta(52, $main->y, 1); self::assertSame($main->y + $main->height(), $this->desk->playlist->y, 'the list under it follows'); [$x, $y] = $this->at($main, 150, 94); $this->dragView($x, $y, $x - 66 * $this->desk->scale, $y); self::assertSame(0.0, $main->x, 'near the left edge: stuck to it (nbcot)'); } public function testThePlayListLeavesThePlayerThenSticksBackUnderIt(): void { $this->startPlayer(); $list = $this->desk->playlist; $this->wz->ui['playlist']['attached'] = false; // undocked (menu): docked, it carries the player [$x, $y] = $this->at($list, 200, 40); $this->dragView($x, $y, $x + 300 * $this->desk->scale, $y + 20 * $this->desk->scale); self::assertFalse($this->wz->ui['playlist']['attached']); self::assertEqualsWithDelta(312, $list->x, 1); $main = $this->desk->main; [$x, $y] = $this->at($list, 200, 40); $target = $this->at($main, 200 + 4, $main->height() + 40 + 5); $this->dragView($x, $y, $target[0], $target[1]); self::assertTrue($this->wz->ui['playlist']['attached']); self::assertSame($main->y + $main->height(), $list->y); self::assertSame($main->x, $list->x); } public function testThePlaylistButtonHidesAndShowsTheList(): void { $this->startPlayer(); $this->clickControl($this->desk->main, 'playlist'); self::assertFalse($this->desk->playlist->visible()); $this->clickControl($this->desk->main, 'playlist'); self::assertTrue($this->desk->playlist->visible()); } public function testTheCompactModeReplacesThePlayerAndComesBack(): void { $this->startPlayer(); $this->clickControl($this->desk->main, 'compact'); self::assertFalse($this->desk->main->visible()); self::assertTrue($this->desk->compact->visible()); self::assertSame($this->desk->main->x, $this->desk->compact->x, 'the small bar shows where the player was'); self::assertSame($this->desk->main->y, $this->desk->compact->y); $this->clickControl($this->desk->compact, 'play'); self::assertSame('playing', $this->wz->player->state); $this->clickControl($this->desk->compact, 'open'); $this->game->wait(0.6); self::assertSame(33.0, $this->desk->compact->height(), 'the title shows under the buttons'); $this->game->shot('compact'); $this->clickControl($this->desk->compact, 'back'); self::assertTrue($this->desk->main->visible()); } public function testTheMiniBarUnfoldsWithoutMovingItsTopOrAgainstTheBottomItsBottom(): void { $this->startPlayer(); $this->clickControl($this->desk->main, 'compact'); $bar = $this->desk->compact; [$x, $y] = [$bar->x, $bar->y]; $this->clickControl($bar, 'open'); $this->game->wait(0.6); self::assertSame(33.0, $bar->height()); self::assertSame([$x, $y], [$bar->x, $bar->y], 'unfolded where it was: the title shows under its buttons'); $this->clickControl($bar, 'open'); $this->game->wait(0.6); self::assertSame([$x, $y, 13.0], [$bar->x, $bar->y, $bar->height()], 'folded back: still there'); // against the bottom of the screen: it unfolds upward, its bottom edge stays $bottom = $this->desk->deskHeight() - $this->desk->bottomMargin(); [$bar->x, $bar->y] = [40.0, $bottom - 13]; $bar->remember(); $this->wz->ui['compact']['expanded'] = true; // its "?" (the lyrics bar runs over the bottom here) $this->game->wait(0.6); self::assertSame([40.0, $bottom, 33.0], [$bar->x, $bar->y + $bar->height(), $bar->height()], 'unfolded upward, its bottom on the bottom of the screen'); self::assertSame((int)round($bottom - 33), $this->wz->ui['compact']['y'], 'that place kept'); $this->game->shot('compact-bottom'); $this->wz->ui['compact']['expanded'] = false; $this->game->wait(0.6); self::assertSame([40.0, $bottom - 13], [$bar->x, $bar->y], 'folded back down onto the bottom'); } public function testTheMiniBarOnATitleBarIsPlacedByItsButtonsNotByItsTitle(): void { // a window at 300, 200 (800 wide) with a title bar of 30 pixels, the zoom 2: the buttons (26) in its middle [$right, $top] = NativeShell::onTitleBar([300, 200, 800, 600, 30], 2.0, 0, 0); self::assertSame([726.0, 172.0], [$right, $top]); // that place is the bar's, folded or unfolded (centred on its height unfolded, it went up 20 pixels and down) self::assertSame([$right + 5, $top - 3], NativeShell::onTitleBar([300, 200, 800, 600, 30], 2.0, 5, -3)); } public function testTheTrayHidesEverythingAndADoubleClickOnTheIconBringsItBack(): void { $this->startPlayer(); $this->clickControl($this->desk->main, 'tray'); self::assertFalse($this->desk->main->visible()); $this->game->shot('tray'); $iconX = $this->desk->x + ($this->desk->deskWidth() - 60) * $this->desk->scale; $iconY = $this->desk->y + ($this->desk->deskHeight() - 14) * $this->desk->scale; $this->form->clickAt($iconX, $iconY); $this->game->run(1); self::assertTrue($this->desk->main->visible(), 'one click on the icon is enough'); // the WinZik button at the bottom left too (the corners of a web page may be hidden) $this->clickControl($this->desk->main, 'tray'); $this->form->clickAt($this->desk->x + 40 * $this->desk->scale, $iconY); $this->game->run(1); self::assertTrue($this->desk->main->visible()); } public function testTheLyricsButtonLeavesOnlyTheLyricsAndQBringsThePlayerBack(): void { $this->startPlayer(); $this->clickControl($this->desk->main, 'lyrics'); self::assertFalse($this->desk->main->visible()); self::assertTrue($this->desk->lyrics->visible()); $this->clickControl($this->desk->lyrics, 'quit'); self::assertTrue($this->desk->main->visible()); } public function testTheMainWindowOpensDownwardsWithItsHiddenButton(): void { $this->startPlayer(); $this->wz->ui['main']['expanded'] = false; // opened at the first start (the visualizer): closed first $this->game->run(40); self::assertSame(99.0, $this->desk->main->height()); $this->clickControl($this->desk->main, 'expand'); $this->game->wait(0.5); self::assertSame(128.0, $this->desk->main->height()); self::assertSame($this->desk->main->y + 128, $this->desk->playlist->y); } public function testARightClickOpensTheMenuOfWinZik(): void { $this->startPlayer(); [$x, $y] = $this->at($this->desk->main, 150, 95); $this->rightClick($x, $y); self::assertTrue($this->desk->hasMenu()); self::assertContains('Options', $this->desk->menuLabels()); self::assertContains('A propos', $this->desk->menuLabels()); // "Menu" opens its submenu, its "Hasard" switches it $row = $y + (PopupMenu::ROW / 2 + 3) * $this->desk->scale; $this->form->clickAt($x + 40 * $this->desk->scale, $row); $this->game->run(1); self::assertContains('Hasard', $this->desk->menuLabels()); $this->game->shot('menu'); $sub = $x + (PopupMenu::WIDTH + 30) * $this->desk->scale; $this->form->clickAt($sub, $y + (3 + 3 * PopupMenu::ROW + 5) * $this->desk->scale); $this->game->run(1); self::assertTrue($this->wz->playlist->shuffle); self::assertFalse($this->desk->hasMenu()); } public function testTheKeyboardDrivesThePlayer(): void { $this->startPlayer(); $this->form->type(' '); self::assertSame('playing', $this->wz->player->state); $this->form->type('b'); self::assertSame(1, $this->wz->playlist->active); $this->form->type('h'); self::assertTrue($this->wz->playlist->shuffle); $this->form->type('v'); self::assertSame('stopped', $this->wz->player->state); } public function testTheEditModeChoosesLinesAndTheBinRemovesThem(): void { $this->startPlayer(); $list = $this->desk->playlist; $this->clickControl($list, 'edit'); self::assertTrue($list->editing()); $this->clickIn($list, 120, $list::LIST_TOP + 5); $this->clickIn($list, 120, $list::LIST_TOP + $list::ROW_HEIGHT + 5); $this->game->shot('edit-mode'); $this->clickControl($list, 'delete'); self::assertSame(['assets/music/chaine-hifi.wav', 'assets/music/partage.mp3'], $this->wz->playlist->items); } public function testTheOptionsOf085PutWinZikInTheTaskBar(): void { $this->startPlayer(); $this->form->openOptions(); $this->game->run(1); $options = $this->game->scene(); self::assertInstanceOf(\App\Form\OptionsForm::class, $options); $options->click($options->widget('taskbar')); $options->click($options->widget('ok')); $this->game->run(2); self::assertTrue($this->wz->options['taskbar']); self::assertSame(28.0, (float)$this->desk->bottomMargin(), 'the lyrics bar is above the task bar'); // the WinZik button of the task bar hides the windows, then brings them back $bx = $this->desk->x + 40 * $this->desk->scale; $by = $this->desk->y + ($this->desk->deskHeight() - 14) * $this->desk->scale; $this->form->clickAt($bx, $by); $this->game->run(1); self::assertFalse($this->desk->main->visible()); $this->game->shot('taskbar'); $this->form->clickAt($bx, $by); $this->game->run(1); self::assertTrue($this->desk->main->visible()); } public function testThePlayerMovesFromAnyButtonButNotFromItsSliders(): void { $this->startPlayer(); $main = $this->desk->main; [$x, $y] = $this->at($main, 124, 85); // the play button $this->dragView($x, $y, $x + 50 * $this->desk->scale, $y + 30 * $this->desk->scale); self::assertEqualsWithDelta(62, $main->x, 1, 'dragged by its play button'); self::assertSame('stopped', $this->wz->player->state, 'and it did not play'); [$x, $y] = $this->at($main, 30, 52); // the volume slider $this->dragView($x, $y, $x + 40 * $this->desk->scale, $y); self::assertEqualsWithDelta(62, $main->x, 1, 'a slider drags itself, not the window'); self::assertGreaterThan(50, $this->wz->player->volume); } public function testTheEqualizerSlidersAndPresets(): void { $this->startPlayer(); $this->form->type('e'); $this->game->run(1); $eq = $this->desk->eq; self::assertTrue($eq->visible()); [$cx, $cy, $cw, $ch] = $eq->controls()['s0']; [$x, $y] = $this->at($eq, $cx + $cw / 2, $cy + 6); $this->dragView($x, $y, $x, $y - 2); self::assertGreaterThan(10, $this->wz->eq->preamp, 'the preamp up'); self::assertGreaterThan(1.5, $this->wz->player->gain, 'a real gain on the volume'); $this->clickControl($eq, 'presets'); self::assertTrue($this->desk->hasMenu()); self::assertContains('Rock', $this->desk->menuLabels()); $this->wz->eq->preset('Rock'); $this->wz->eqChanged(); self::assertSame(5.0, $this->wz->eq->bands[0]); $this->clickControl($eq, 'on'); self::assertFalse($this->wz->eq->on); self::assertSame(1.0, $this->wz->player->gain, 'off: no gain'); $this->game->shot('equalizer'); } public function testTheWindowsUnrollAtTheStartAndRollUpAtTheEnd(): void { $this->startPlayer(); $main = $this->desk->main; self::assertLessThan($main->width(), $this->desk->revealed($main), 'the start: only their left part (SetWindowRgn)'); $this->game->wait(1); self::assertSame($main->width(), $this->desk->revealed($main), 'then all of it'); $this->desk->quitWithEffect(); for ($i = 0; $i < 50 && $this->desk->revealed($main) >= $main->width(); $i++) { $this->game->run(1); // the edge comes from the right of the desktop to the player } $rolling = $this->desk->revealed($main); self::assertLessThan($main->width(), $rolling, 'Quitter: they roll up'); $this->game->run(6); self::assertLessThan($rolling, $this->desk->revealed($main)); } public function testTheMenuOfTheIconShowsTheLyricsEvenWhenWinZikIsInTheTray(): void { $this->startPlayer(); $this->clickControl($this->desk->main, 'tray'); self::assertFalse($this->desk->main->visible()); $this->desk->openTrayMenu(400, $this->desk->deskHeight() - 5); $menu = $this->desk->menu(); self::assertNotNull($menu); self::assertLessThanOrEqual($this->desk->deskHeight(), $menu->y + $menu->height(), 'from the bottom: upwards, whole'); $labels = array_column($menu->items, 'label'); self::assertContains('Afficher les paroles (barre en bas)', $labels); $full = $menu->items[array_search('Paroles en plein écran', $labels, true)]; ($full['run'])(); $this->game->wait(1); self::assertTrue($this->desk->lyrics->visible(), 'the lyrics shown'); self::assertTrue($this->desk->lyrics->full(), 'on the whole screen'); self::assertFalse($this->desk->main->visible(), 'the lyrics alone'); } public function testOnTheWebANoteSaysWhatTheDesktopVersionDoesMore(): void { $this->startPlayer(); $note = $this->desk->note; self::assertNotNull($note); self::assertFalse($note->visible(), 'not in the desktop version'); $note->forced = true; // as in the browser $this->game->wait(3); self::assertTrue($note->visible()); self::assertGreaterThan($this->desk->main->x + $this->desk->main->width(), $note->x, 'at the right of the player'); $this->game->shot('web-note'); $this->clickControl($note, 'close'); self::assertFalse($note->visible(), 'closed for good'); self::assertTrue($this->wz->options['webNoteClosed']); }}