<?phpnamespace Tests;use App\Gui\PopupMenu;use App\Native\NativeTextures;final class NativeFixesTest extends PlayerTestCase{ public function testAMenuTallerThanTheScreenScrollsAndEveryLineCanBeReached(): void { $items = []; for ($i = 0; $i < 40; $i++) { $items[] = ['label' => "Ligne $i", 'run' => fn () => null]; } // a screen of 300 desktop pixels (zoom 200 % on a small screen): 40 rows of 17 do not fit $menu = new PopupMenu($items, 50, 250, 800, 300, [0.0, 0.0, 800.0, 300.0]); self::assertTrue($menu->scrolls()); self::assertGreaterThanOrEqual(0.0, $menu->y); self::assertLessThanOrEqual(300.0, $menu->y + $menu->height(), 'the whole menu on the screen'); $x = $menu->x + PopupMenu::WIDTH / 2; $bottomArrow = $menu->y + $menu->height() - 3 - PopupMenu::ROW / 2; $reached = []; for ($frame = 0; $frame < 400; $frame++) { for ($y = $menu->y; $y < $menu->y + $menu->height(); $y += 2) { $row = $menu->rowAt($x, $y); if ($row >= 0) { $reached[$row] = true; } } $menu->hoverAt($x, $bottomArrow, 800, 300); // the pointer stays on the bottom arrow } self::assertCount(40, $reached, 'every line reached by scrolling down'); // a menu that fits does not scroll $small = new PopupMenu(array_slice($items, 0, 5), 50, 250, 800, 300, [0.0, 0.0, 800.0, 300.0]); self::assertFalse($small->scrolls()); self::assertSame($small->fullHeight(), $small->height()); } public function testATextThatIsNotUtf8IsMadeRenderable(): void { self::assertSame('Café', NativeTextures::clean('Café')); $latin1 = "Caf\xe9"; self::assertTrue(mb_check_encoding(NativeTextures::clean($latin1), 'UTF-8')); self::assertStringStartsWith('Caf', NativeTextures::clean($latin1)); } public function testANewFilmOpensInItsWindowAndShownWhateverTheLastOneDid(): void { $this->startPlayer(); $video = $this->desk->video; self::assertNotNull($video); // the film before: on the whole screen, then hidden by its x; saved so (a restart keeps them) $this->wz->ui['video']['full'] = true; $this->wz->ui['video']['visible'] = false; $this->wz->player->file = $this->wz->relative('/tmp/winzik-test-film.mp4'); self::assertTrue($this->wz->playingVideo()); $this->game->run(1); self::assertFalse($video->full(), 'not on the whole screen'); self::assertTrue((bool)$this->wz->ui['video']['visible'], 'shown'); // the same film: what the user does is kept $this->wz->ui['video']['visible'] = false; $this->game->run(1); self::assertFalse((bool)$this->wz->ui['video']['visible']); }}