ArtificerMenuRowsTest.php 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Menu rows in Artificer's popups, account panel and side menus share the header More list's look: 44px rows,
  4. * 8px corners, 16px labels, no gaps. Read from the template and CSS files, so a row style that drifts back fails here.
  5. */
  6. class ArtificerMenuRowsTest extends \PHPUnit\Framework\TestCase
  7. {
  8. private static function read(string $sPath): string
  9. {
  10. $s = file_get_contents(__DIR__ . '/../../../../' . $sPath);
  11. if ($s === false)
  12. self::fail($sPath . ' is not readable.');
  13. return str_replace("\r\n", "\n", $s);
  14. }
  15. public function testAccountPanelRowsAre44pxWith16pxLabels(): void
  16. {
  17. $s = self::read('modules/boonex/artificer/data/template/system/menu_floating_blocks_wide.html');
  18. $this->assertMatchesRegularExpression('/\.bx-artificer ul\.bx-menu-floating-blocks-wide \{\s*padding-left: 0\.5rem;/', self::read('template/css/tailwind.css'), 'The list is inset 8px (a class would lose to Artificer\'s menu.css).');
  19. $this->assertMatchesRegularExpression('/<li class="[^"]*\bmin-h-11\b[^"]*\brounded-lg\b[^"]*\btext-base\b/', $s, 'Rows are 44px with 8px corners and 16px labels.');
  20. $this->assertStringNotContainsString('text-sm', $s, 'No small labels left.');
  21. $this->assertStringNotContainsString('py-2', $s, 'The row sets the height, not the link\'s padding.');
  22. }
  23. public function testSideMenuRowsHaveNoGaps(): void
  24. {
  25. $s = self::read('modules/boonex/artificer/data/template/system/menu_vertical_more_less.html');
  26. $this->assertStringNotContainsString('space-y-2', $s, 'Rows sit right under each other, as in the More list.');
  27. $this->assertStringContainsString('rounded-lg', $s);
  28. }
  29. public function testMainMenuSidebarAndStatsCardFollow(): void
  30. {
  31. $this->assertStringNotContainsString('space-y-1', self::read('modules/boonex/artificer/data/template/system/sidebar_site.html'), 'Main menu sidebar rows have no gaps.');
  32. $this->assertStringNotContainsString('space-y-1', self::read('modules/boonex/artificer/data/template/system/menu_sidebar_site.html'), 'Nor do its submenus.');
  33. $this->assertStringNotContainsString('rounded-md', self::read('modules/boonex/artificer/data/template/system/profile_stats.html'), 'The profile row has 8px corners like the menu rows.');
  34. $sCss = self::read('template/css/tailwind.css');
  35. $this->assertMatchesRegularExpression('/\.bx-artificer \.bx-sidebar-item > a,[^{]*\{[^}]*min-height: 2\.75rem;[^}]*border-radius: 0\.5rem;/', $sCss, 'Main menu sidebar rows are 44px with 8px corners.');
  36. $this->assertMatchesRegularExpression('/\.bx-profile-stats \.bx-profile-avatar-cnt,[^{]*\{\s*margin: -0\.5rem;/', self::read('modules/boonex/artificer/data/template/system/css/menu.css'), 'The stats card\'s rows, the profile one included, sit 8px from its edges (16px block padding less 8px).');
  37. }
  38. public function testBlockTabsAreCapsulesInLineWithContent(): void
  39. {
  40. $s = self::read('modules/boonex/artificer/data/template/system/css/common.css');
  41. $this->assertMatchesRegularExpression('/\.bx-db-menu ul\.bx-menu-custom\.bx-menu-custom-hor > li:not\(\.bx-stl-mil-sm\) \{[^}]*padding: 0;/', $s, 'Tabs have no side padding, so the first and last line up with the block content.');
  42. $this->assertMatchesRegularExpression('/gap: 0\.5rem;/', $s, 'The tab list spaces its tabs with a gap.');
  43. $this->assertMatchesRegularExpression('/\.bx-db-menu ul\.bx-menu-hor > li > a\.bx-stl-mil-sm,[^{]*\{\s*border-radius: 9999px;/', $s, 'Block tabs are capsules like the header tabs.');
  44. }
  45. public function testPopupMenuRowsAreRoundedNotSquare(): void
  46. {
  47. $sCss = self::read('template/css/tailwind.css');
  48. // Only the popup section, so the side menus' rule (with the same height) can't satisfy these checks.
  49. $iStart = strpos($sCss, 'Menus in popups (More');
  50. $iEnd = strpos($sCss, '/* Side menus (profile stats');
  51. $this->assertNotFalse($iStart, 'tailwind.css has the popup menu rows section.');
  52. $this->assertNotFalse($iEnd, 'tailwind.css has the side menu rows section after it.');
  53. $sPopup = substr($sCss, $iStart, $iEnd - $iStart);
  54. $this->assertStringContainsString('.bx-artificer .bx-popup ul:is(.bx-menu-ver, .bx-menu-custom-ver, [class*="bx-menu-object-"])', $sPopup, 'One rule styles every vertical menu in a popup.');
  55. $this->assertStringContainsString(':not(.bx-menu-floating-blocks-wide)', $sPopup, 'The account panel pads its own rows, so links there get no second padding.');
  56. $this->assertMatchesRegularExpression('/min-height: 2\.75rem;/', $sPopup, 'Popup rows are 44px.');
  57. $this->assertMatchesRegularExpression('/border-radius: 0\.5rem;/', $sPopup, 'Popup rows have 8px corners.');
  58. $this->assertMatchesRegularExpression('/padding-inline-start: 0\.75rem;/', $sPopup, '12px on the icon side.');
  59. $sMenuCss = self::read('modules/boonex/artificer/data/template/system/css/menu.css');
  60. $this->assertDoesNotMatchRegularExpression('/more-auto \.bx-popup \.bx-menu-custom \.bx-menu-item[^{]*\{\s*border-radius: 0;/', $sMenuCss, 'No legacy rule squares the More rows again.');
  61. }
  62. }