DE
apps/winzik / tests / ErgonomicsTest.php · commit 6576d6f
<?phpnamespace Tests;use App\Audio\Player;use App\Gui\SkinWindow;/** Using WinZik with the mouse only: the counter, the wheel, the double clicks, the hints and the lit buttons. */final class ErgonomicsTest extends PlayerTestCase{    /** The pointer stays a while over a point of a window (the desktop's frames, as with a real mouse). */    private function pointTo(SkinWindow $window, float $x, float $y, float $seconds = 1.0): void    {        [$vx, $vy] = $this->at($window, $x, $y);        $engine = $this->form->engineOrNull();        self::assertNotNull($engine);        $engine->input->getMouse()->move($vx, $vy);        $this->game->wait($seconds);    }    private function middleOf(SkinWindow $window, string $control): array    {        [$x, $y, $w, $h] = $window->controls()[$control];        return [$x + $w / 2, $y + $h / 2];    }    public function testAClickOnTheCounterShowsTheTimeLeftThenTheTimeGoneBy(): void    {        $this->startPlayer();        $main = $this->desk->main;        $this->clickControl($main, 'play');        $this->game->wait(2);        [$x, $y] = [$main->x, $main->y];        $this->clickControl($main, 'time');        self::assertTrue($this->wz->options['timeLeft'], 'the time left');        self::assertSame([$x, $y], [$main->x, $main->y], 'a click: the window stays');        $this->game->run(1);        $this->game->shot('time-left');        $this->clickControl($main, 'time');        self::assertFalse($this->wz->options['timeLeft'], 'back to the time gone by');        self::assertSame(Player::PLAYING, $this->wz->player->state, 'the song goes on');    }    public function testADoubleClickOnTheBalanceBringsItBackToTheMiddle(): void    {        $this->startPlayer();        $main = $this->desk->main;        $this->wz->setBalance(60);        [$vx, $vy] = $this->at($main, 220, 52);        $this->form->clickAt($vx, $vy);        $this->game->run(1);        self::assertGreaterThan(40, $this->wz->player->balance, 'a click: where it is clicked');        $this->form->clickAt($vx, $vy, true);        $this->game->run(1);        self::assertSame(0, $this->wz->player->balance, 'a double click: in the middle');    }    public function testThePointerOverThePositionBarShowsWhereAClickGoes(): void    {        $this->startPlayer();        $main = $this->desk->main;        $this->clickControl($main, 'play');        $duration = $this->wz->player->duration();        self::assertGreaterThan(0, $duration);        $this->pointTo($main, 6 + 235 / 2, 68, 0.2);        $half = (int)floor($duration / 2);        self::assertStringStartsWith(sprintf('Aller à %02d:%02d', intdiv($half, 60), $half % 60), $main->titleShown());        $this->game->run(1);        $this->game->shot('position-hint');        $this->pointTo($main, 150, 40, 0.2);        self::assertStringNotContainsString('Aller à', $main->titleShown(), 'away from it: the song again');    }    public function testThePointerAMomentOnTheCounterSaysWhatAClickDoes(): void    {        $this->startPlayer();        $main = $this->desk->main;        [$x, $y] = $this->middleOf($main, 'time');        $this->pointTo($main, $x, $y, 0.3);        self::assertNotSame('Clic : temps restant', $main->titleShown(), 'not at once');        $this->pointTo($main, $x, $y, 0.6);        self::assertSame('Clic : temps restant', $main->titleShown());        [$x, $y] = $this->middleOf($main, 'play');        $this->pointTo($main, $x, $y, 0.2);        self::assertSame('play', $main->hoveredControl(), 'the button under the pointer is lit');        $this->game->run(1);        $this->game->shot('hover-play');    }    public function testTheWheelOnAnEqualizerSliderMovesItByOneDecibel(): void    {        $this->startPlayer();        $this->wz->toggleEq();        $this->game->wait(1.5);        // the windows unrolled        $eq = $this->desk->eq;        self::assertTrue($eq->visible());        [$x, $y] = $this->middleOf($eq, 's3');        $this->pointTo($eq, $x, $y, 0.2);        $before = $this->wz->eq->bands[2];        self::assertTrue($eq->wheel(1));        self::assertEqualsWithDelta($before + 1, $this->wz->eq->bands[2], 0.001, 'up: one dB more');        $eq->wheel(-3);        self::assertEqualsWithDelta($before - 2, $this->wz->eq->bands[2], 0.001, 'three notches down');        self::assertSame('310 Hz : ' . str_replace('.', ',', sprintf('%+.1f dB', $before - 2)), $eq->caption(), 'its band and value at the top');        $this->game->run(1);        $this->game->shot('eq-wheel');        [$x, $y] = $this->middleOf($eq, 's0');        $this->pointTo($eq, $x, $y, 0.2);        $eq->wheel(2);        self::assertEqualsWithDelta(2.0, $this->wz->eq->preamp, 0.001, 'the preamp too');        $this->pointTo($eq, 130, 108, 0.2);        self::assertFalse($eq->wheel(1), 'off the sliders: nothing');    }    public function testADoubleClickOnAnEqualizerSliderPutsItBackToZero(): void    {        $this->startPlayer();        $this->wz->toggleEq();        $this->game->run(2);        $eq = $this->desk->eq;        [$cx, , $cw] = $eq->controls()['s5'];        [$vx, $vy] = $this->at($eq, $cx + $cw / 2, 42);        $this->form->clickAt($vx, $vy);        $this->game->run(1);        self::assertGreaterThan(9, $this->wz->eq->bands[4], 'a click near the top: loud');        $this->form->clickAt($vx, $vy, true);        $this->game->run(1);        self::assertSame(0.0, $this->wz->eq->bands[4], 'a double click: 0 dB');    }    public function testADoubleClickOnTheCurveFlattensTheEqualizer(): void    {        $this->startPlayer();        $this->wz->toggleEq();        $this->game->run(2);        $eq = $this->desk->eq;        $this->wz->eq->bands = [6.0, 4.0, 2.0, 0.0, -2.0, -4.0, 1.0, 3.0, 5.0, 7.0];        $this->wz->eq->preamp = 3.0;        $this->clickControl($eq, 'curve');        self::assertSame(6.0, $this->wz->eq->bands[0], 'one click: nothing');        [$x, $y] = $this->middleOf($eq, 'curve');        $this->pointTo($eq, $x, $y, 1.0);        self::assertSame('Double-clic : tout remettre à 0 dB', $eq->caption(), 'it says so');        $this->clickControl($eq, 'curve', true);        self::assertSame(array_fill(0, 10, 0.0), $this->wz->eq->bands);        self::assertSame(0.0, $this->wz->eq->preamp);    }    public function testTheWheelOnTheLyricsTimingButtonsMovesThemByATenth(): void    {        $this->startPlayer();        $this->clickControl($this->desk->main, 'play');        $this->clickControl($this->desk->main, 'lyrics');        $bar = $this->desk->lyrics;        self::assertTrue($bar->visible());        self::assertNotNull($this->wz->lyrics);        $first = $this->wz->lyrics->lines[0][0];        [$x, $y] = $this->middleOf($bar, 'later');        $this->pointTo($bar, $x, $y, 1.0);        self::assertSame('Paroles plus tard (molette : 0,1 s)', $bar->hint(0.4), 'what it does, by the button');        $this->game->run(1);        $this->game->shot('lyrics-hint');        self::assertTrue($bar->wheel(1));        self::assertNotNull($this->wz->lyrics);        self::assertEqualsWithDelta($first + 0.1, $this->wz->lyrics->lines[0][0], 0.001, 'a tenth later');        $bar->wheel(-2);        self::assertNotNull($this->wz->lyrics);        self::assertEqualsWithDelta($first - 0.1, $this->wz->lyrics->lines[0][0], 0.001, 'two tenths earlier');        // the copy shifted in var/lyr goes: the other tests read the song's own lyrics        self::assertStringStartsWith(rtrim($this->wz->storagePath('lyr'), '/') . '/', $this->wz->lyricsFile);        unlink($this->wz->lyricsFile);    }    public function testADoubleClickOnAJogDialPutsItBackToZero(): void    {        $this->startPlayer();        $this->form->openOptions();        $this->game->run(2);        $o = $this->game->scene();        self::assertInstanceOf(\App\Form\OptionsForm::class, $o);        $jog = $o->widget('jogX');        self::assertInstanceOf(\App\Gui\JogDial::class, $jog);        $right = [$jog->x + $jog->w - 4, $jog->y + $jog->h / 2];        for ($i = 0; $i < 3; $i++) {            $o->clickAt(...$right);            $this->game->wait(0.8);        // apart: three clicks, not a double click        }        self::assertSame(3, $this->wz->options['compactDx']);        $o->clickAt($right[0], $right[1], true);        self::assertSame(0, $this->wz->options['compactDx'], 'a double click: back to 0');        self::assertSame(0, $jog->props['value']);        $this->game->wait(1.0);     // the next click of another test is not the third of a double click    }}