SystemSqlDefaultsTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 testHomeCreatePostBlockIsContentOnly(): 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(0, (int)$aMatch[1], 'It shows only its form: the content-only design box (BX_DB_CONTENT_ONLY).');
  21. }
  22. public function testPoweredByBadgeFollowsTheFooterColour(): void
  23. {
  24. $bFound = preg_match("/\\('sys_footer', 'system', 'powered_by', [^\\n]*?'_blank', '(<svg.*?<\\/svg>)'/", self::systemSql(), $aMatch);
  25. $this->assertSame(1, $bFound, 'system.sql adds the powered-by badge to the footer menu.');
  26. $this->assertStringContainsString('fill="currentColor"', $aMatch[1], 'The badge draws in the footer link colour, so it reads in light and dark.');
  27. $this->assertDoesNotMatchRegularExpression('/(fill|stroke)="#/', $aMatch[1], 'No fixed colour that would vanish on one of the two schemes.');
  28. }
  29. public function testHomeRecommendedFriendsShowsAnEmptyState(): void
  30. {
  31. $bFound = preg_match("/\\('sys_home', 4, 'system', '_sys_page_block_title_sys_recom_friends', [^\\n]*?'service', '([^\\n]*?)', /", self::systemSql(), $aMatch);
  32. $this->assertSame(1, $bFound, 'system.sql adds Recommended friends to the right column of the home page.');
  33. $aContent = unserialize(stripslashes($aMatch[1]));
  34. $this->assertSame('browse_recommendations_friends', $aContent['method']);
  35. $this->assertTrue($aContent['params'][1]['empty_state'] ?? false, 'With nothing to suggest, the block explains why instead of leaving the column blank.');
  36. }
  37. }