KO
apps/winzik / tests / DialogsTest.php · commit 6576d6f
<?phpnamespace Tests;use App\Core\LyricsDownload;use App\Form\FilesForm;use App\Form\FlsForm;use App\Form\LockForm;use App\Form\MainForm;use App\Form\OptionsForm;use App\Form\SkinForm;use App\Form\TagForm;use App\Model\Id3Tag;use App\Scene\AboutScene;use App\Scene\LockScene;use App\Scene\SplashScene;use JumPHP\Gui\Form;use JumPHP\Gui\Pointer;/** The other windows of 2001: tags, files, .FLS, skins, options, Lock, A propos, the splash. */final class DialogsTest extends PlayerTestCase{    private function top(): Form    {        $scene = $this->game->scene();        self::assertInstanceOf(Form::class, $scene);        return $scene;    }    public function testTheInfoButtonOpensTheTagOfTheSongAndOkWritesIt(): void    {        $this->startPlayer();        $copy = $this->wz->storagePath('music/essai.mp3');        @mkdir(dirname($copy), 0777, true);        self::assertTrue(copy($this->wz->path('assets/music/winzik.mp3'), $copy), 'never the demo song itself');        $this->wz->addFiles([$copy]);        $this->wz->playIndex($this->wz->playlist->count() - 1);        self::assertSame($copy, $this->wz->path((string)$this->wz->playlist->current()));        $this->clickControl($this->desk->main, 'info');        $tags = $this->top();        self::assertInstanceOf(TagForm::class, $tags);        self::assertSame('WinZik Band', $tags->widget('artist')->props['text']);        $tags->click($tags->widget('songTitle'));        $tags->key(Pointer::END);        $tags->type(' (remix)');        $tags->click($tags->widget('ok'));        $this->game->run(2);        self::assertInstanceOf(MainForm::class, $this->game->scene(), 'Ok closes it');        self::assertSame('WinZik (remix)', Id3Tag::read($copy)->title);        self::assertStringContainsString('WinZik (remix)', $this->wz->titleText(), 'the scrolling title follows');    }    public function testThePlusButtonAddsTheFilesOfAFolderAndItsSubFolders(): void    {        $this->startPlayer();        $root = $this->wz->storagePath('music/collection');        @mkdir($root . '/cd2', 0777, true);        foreach (['a.mp3', 'b.wav', 'cd2/c.mid', 'cd2/d.ogg', 'cd2/notes.txt'] as $f) {            file_put_contents($root . '/' . $f, 'x');        }        $this->clickControl($this->desk->playlist, 'add');        $files = $this->top();        self::assertInstanceOf(FilesForm::class, $files);        $files->click($files->widget('path'));        $files->key(Pointer::END);        for ($i = 0; $i < 200; $i++) {            $files->key(Pointer::BACKSPACE);        }        $files->type($root . "\n");        $this->game->run(1);        self::assertSame(['a.mp3', 'b.wav'], $files->widget('files')->props['items']);        $files->click($files->widget('addDir'));        $this->game->run(5);        self::assertStringContainsString('4 fichier(s) ajouté(s)', (string)$files->widget('status')->props['text']);        self::assertSame(8, $this->wz->playlist->count());        $this->game->shot('files');        $files->click($files->widget('cancel'));        $this->game->run(1);        self::assertInstanceOf(MainForm::class, $this->game->scene());    }    public function testAListSavedAsFlsComesBackWhenLoaded(): void    {        $this->startPlayer();        $this->clickControl($this->desk->playlist, 'save');        $fls = $this->top();        self::assertInstanceOf(FlsForm::class, $fls);        $fls->click($fls->widget('ok'));        $this->game->run(1);        self::assertFileExists($this->wz->storagePath('playlists/winzik.fls'));        $this->wz->removeLines([0, 1]);        self::assertSame(2, $this->wz->playlist->count());        $this->clickControl($this->desk->playlist, 'load');        $fls = $this->top();        self::assertSame(['winzik.fls'], $fls->widget('lists')->props['items']);        $fls->widget('lists')->select(0);        $fls->click($fls->widget('ok'));        $this->game->run(1);        self::assertSame(4, $this->wz->playlist->count());    }    public function testTheSkinViewerChangesTheSkinAtOnce(): void    {        $this->startPlayer();        $this->form->openSkins();        $this->game->run(1);        $skins = $this->top();        self::assertSame(['Ambre', 'Ampli 2000 (façon Winamp)', 'Aurore', 'Bois & Laiton', 'Carbone', 'Classique (façon Winamp 2)', 'Corail', 'Givre', 'Menthe', 'Néon 84', 'Phosphore', 'Sakura', 'Skin Chaine-Hifi', 'Skin de base', 'the SKIN', 'WINZIK'], $skins->widget('skins')->props['items']);        $skins->widget('skins')->select(14);        $this->game->run(1);        self::assertSame('the SKIN', $this->wz->skin->name);        $skins->click($skins->widget('choose'));        $this->game->run(30);        self::assertSame('the SKIN', $this->wz->skin->name);        $this->game->shot('the-skin');    }    public function testQuitInTheSkinViewerGoesBackToTheSkinBefore(): void    {        $this->startPlayer();        $this->form->openSkins();        $this->game->run(1);        $skins = $this->top();        $skins->widget('skins')->select(4);        $skins->click($skins->widget('quit'));        $this->game->run(1);        self::assertSame('Givre', $this->wz->skin->name, 'the skin of the first start');    }    public function testTheOptionsSetTheSecondFolderOfTheLyrics(): void    {        $this->startPlayer();        $dir = $this->wz->storagePath('mes-paroles');        @mkdir($dir, 0777, true);        file_put_contents($dir . '/archettes-city.lyr', "[LYR]\r\n[ 1 ]\r\nLa la la\r\n");        $this->wz->playIndex(1);        self::assertNull($this->wz->lyrics);        $this->form->openOptions();        $this->game->run(1);        $options = $this->top();        $options->click($options->widget('lyricsDir'));        $options->type($dir);        $options->click($options->widget('ok'));        $this->game->wait(1.5);        self::assertSame('La la la', $this->wz->lyricLine(), 'rep2 + song.LYR');    }    public function testTheLockModeAsksItsPasswordToGiveTheScreenBack(): void    {        $this->startPlayer();        $this->wz->play();        $this->form->openLock();        $this->game->run(1);        $lock = $this->top();        $lock->type("eggs\n");        $this->game->run(2);        self::assertInstanceOf(LockScene::class, $this->game->scene());        $this->game->wait(1);        $this->game->shot('lock');        $keyboard = $this->form->engineOrNull()?->input->getKeyboard();        self::assertNotNull($keyboard);        foreach (['b', 'a', 'd', "\r"] as $char) {            $keyboard->down(ord($char));            $this->game->run(1);            $keyboard->up(ord($char));            $this->game->run(1);        }        self::assertInstanceOf(LockScene::class, $this->game->scene(), 'a wrong password: still locked');        foreach (['e', 'g', 'g', 's', "\r"] as $char) {            $keyboard->down(ord($char));            $this->game->run(1);            $keyboard->up(ord($char));            $this->game->run(1);        }        self::assertInstanceOf(MainForm::class, $this->game->scene());        self::assertSame('playing', $this->wz->player->state, 'the music went on');    }    public function testAProposFindsTheLettersOfWinZikThenTheCreditsGoUp(): void    {        $this->startPlayer();        mt_srand(2001);        $this->form->openAbout();        $this->game->wait(12);        $about = $this->game->scene();        self::assertInstanceOf(AboutScene::class, $about);        self::assertSame(['W', 'i', 'n', 'Z', 'i', 'K'], $about->letters());        self::assertTrue($about->scrolling());        $this->game->shot('a-propos');    }    public function testTheSplashShowsThenThePlayerComes(): void    {        $this->game->start(SplashScene::class);        $this->game->wait(1);        $this->game->shot('splash');        self::assertInstanceOf(SplashScene::class, $this->game->scene());        $this->game->wait(2.5);        self::assertInstanceOf(MainForm::class, $this->game->scene());    }    public function testTheLyricsAreLookedForWhereTheOldSiteKeptThem(): void    {        self::assertSame([            'https://web.archive.org/web/2004id_/http://winster.free.fr/LYR/LENE%20MARLIN/LENE%20MARLIN%20-%20FLOWN%20AWAY.LYR',            'https://web.archive.org/web/2004id_/http://winster.free.fr/LYR/LENE%20MARLIN/FLOWN%20AWAY.LYR',        ], LyricsDownload::candidates('Lene Marlin', 'Flown away'));    }    public function testTheMarketplaceSaysWhenThereIsNoNetwork(): void    {        $this->startPlayer();        $this->form->openMarket('lyrics');        $this->game->run(2);        $market = $this->top();        self::assertInstanceOf(\App\Form\MarketForm::class, $market);        self::assertSame('Marketplace des paroles', $market->widget('heading')->props['text']);        self::assertStringContainsString('Pas de marketplace', (string)$market->widget('status')->props['text'], 'the tests run without network');        $market->click($market->widget('quit'));        $this->game->run(1);        self::assertInstanceOf(MainForm::class, $this->game->scene());    }}