SystemSqlDefaultsTest.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Defaults a fresh install gets from install/sql/system.sql. Read from the SQL itself, so a site whose admin
  4. * changed a setting in Studio does not fail the suite.
  5. */
  6. class SystemSqlDefaultsTest extends \PHPUnit\Framework\TestCase
  7. {
  8. private static function systemSql(): string
  9. {
  10. $sSql = file_get_contents(__DIR__ . '/../../../install/sql/system.sql');
  11. if ($sSql === false)
  12. self::fail('install/sql/system.sql is not readable.');
  13. return $sSql;
  14. }
  15. public function testHomeCreatePostBlockIsACardWithTitle(): void
  16. {
  17. // The home page's create-post block: designbox_id follows object, cell, module, title_system and title.
  18. $bFound = preg_match("/\\('sys_home', \\d+, 'system', '_sys_page_block_title_sys_create_post', '_sys_page_block_title_create_post', (\\d+),/", self::systemSql(), $aMatch);
  19. $this->assertSame(1, $bFound, 'system.sql adds the create-post block to the home page.');
  20. $this->assertSame(11, (int)$aMatch[1], 'On the site it is the "Add new..." card: content, title, background and padding (BX_DB_PADDING_DEF).');
  21. }
  22. public function testHomeCreatePostBlockInAppHasNoTitleAndASolidPhoneBackground(): void
  23. {
  24. // NEO draws the composer row straight in the block. Its App config keeps the background and padding,
  25. // drops the design box's title, and makes the background opaque on phones, where the feed's cards are.
  26. $sSql = file_get_contents(__DIR__ . '/../../../modules/system/install/sql/enable-app-pages.sql');
  27. $bFound = preg_match("/UPDATE `sys_pages_blocks` SET `config_api`='([^']*)' WHERE `object`='sys_home' AND `module`='system' AND `title_system`='_sys_page_block_title_sys_create_post';/", (string)$sSql, $aMatch);
  28. $this->assertSame(1, $bFound, 'enable-app-pages.sql sets the App config of the home create-post block.');
  29. $aConfig = json_decode($aMatch[1], true);
  30. $this->assertSame(['bg' => true, 'padding' => true, 'title' => false, 'solid' => ['mobile']], $aConfig['designbox'] ?? null);
  31. }
  32. public function testPoweredByBadgeFollowsTheFooterColour(): void
  33. {
  34. $bFound = preg_match("/\\('sys_footer', 'system', 'powered_by', [^\\n]*?'_blank', '(<svg.*?<\\/svg>)'/", self::systemSql(), $aMatch);
  35. $this->assertSame(1, $bFound, 'system.sql adds the powered-by badge to the footer menu.');
  36. $this->assertStringContainsString('fill="currentColor"', $aMatch[1], 'The badge draws in the footer link colour, so it reads in light and dark.');
  37. $this->assertDoesNotMatchRegularExpression('/(fill|stroke)="#/', $aMatch[1], 'No fixed colour that would vanish on one of the two schemes.');
  38. }
  39. public function testHomeRecommendedFriendsShowsAnEmptyState(): void
  40. {
  41. $bFound = preg_match("/\\('sys_home', 4, 'system', '_sys_page_block_title_sys_recom_friends', [^\\n]*?'service', '([^\\n]*?)', /", self::systemSql(), $aMatch);
  42. $this->assertSame(1, $bFound, 'system.sql adds Recommended friends to the right column of the home page.');
  43. $aContent = unserialize(stripslashes($aMatch[1]));
  44. $this->assertSame('browse_recommendations_friends', $aContent['method']);
  45. $this->assertTrue($aContent['params'][1]['empty_state'] ?? false, 'With nothing to suggest, the block explains why instead of leaving the column blank.');
  46. }
  47. public function testSearchIsAnActiveMemberToolbarItem(): void
  48. {
  49. $sSql = self::systemSql();
  50. // Member toolbar columns: ... icon, addon, submenu_object, submenu_popup, visible_for_levels, hidden_on_pt, active, copyable, order.
  51. $bFound = preg_match("/\\('sys_toolbar_member', 'system', 'search', '_sys_menu_item_title_system_search', [^\\n]*?, '([^']*)', '', '', 0, (\\d+), (\\d+), (\\d+), \\d+, (\\d+)\\)/", $sSql, $aMatch);
  52. $this->assertSame(1, $bFound, 'system.sql adds the search button to the member toolbar, where it can be edited in Studio like its neighbours.');
  53. $this->assertSame('search', $aMatch[1], 'It is drawn with the Lucide search icon.');
  54. $this->assertSame(2147483647, (int)$aMatch[2], 'Guests and members both see it.');
  55. $this->assertSame(0, (int)$aMatch[3], 'It is not hidden on any page type.');
  56. $this->assertSame(1, (int)$aMatch[4], 'It is active on a fresh install.');
  57. $this->assertSame(0, (int)$aMatch[5], 'It comes first in the toolbar.');
  58. $this->assertStringNotContainsString("('sys_toolbar_site', 'system', 'search'", $sSql, 'One search item only: the site toolbar no longer has its own.');
  59. }
  60. public function testSearchIsActiveInTheApi(): void
  61. {
  62. $sSql = file_get_contents(__DIR__ . '/../../../modules/system/install/sql/enable-app-menus.sql');
  63. $this->assertStringContainsString("SET `active_api`=1 WHERE `set_name`='sys_toolbar_member' AND `module`='system' AND `name`='search';", $sSql, 'The app receives the same search item.');
  64. $this->assertStringNotContainsString("`set_name`='sys_toolbar_site' AND `module`='system' AND `name`='search'", $sSql);
  65. }
  66. public function testToolbarHasNoHardcodedSearchButton(): void
  67. {
  68. $sRoot = __DIR__ . '/../../../';
  69. foreach (['template/_page_toolbar.html', 'template/_page_toolbar_search.html', 'modules/boonex/artificer/template/header.html', 'modules/boonex/artificer/data/template/system/pt_application.html'] as $sFile) {
  70. $sHtml = file_get_contents($sRoot . $sFile);
  71. $this->assertStringNotContainsString('bx-ti-search-button', $sHtml, $sFile . ': the search button comes from the member toolbar menu, not from the template.');
  72. $this->assertStringNotContainsString('bx_site_search_show', $sHtml, $sFile);
  73. }
  74. }
  75. }