generate_pa11y-ci-config.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env php
  2. <?php
  3. declare(strict_types = 1);
  4. $urls = [];
  5. foreach ([[360, 640, true], [1280, 720, true], [1280, 720, false], [2560, 1080, false]] as $viewport) {
  6. [$x, $y, $is_mobile] = $viewport;
  7. $gen = function (string $url, string $actions = "") use ($x, $y, $is_mobile) {
  8. $path = "/screenshots/new/{$x}x{$y}" . ($is_mobile ? '-mobile' : '') . '-' . ($url === '' ? 'root' : str_replace('/', '-', $url)) . ".png";
  9. $is_mobile = $is_mobile ? 'true' : 'false';
  10. return <<<EOU
  11. {
  12. "url": "https://nginx/{$url}",
  13. "screenCapture": "{$path}",
  14. "viewport": {
  15. "width": {$x},
  16. "height": {$y},
  17. "isMobile": {$is_mobile}
  18. }{$actions}
  19. }
  20. EOU;
  21. };
  22. foreach ([
  23. '', 'feed/public',
  24. 'doc/faq', 'doc/tos', 'doc/privacy', 'doc/source', 'doc/version',
  25. 'main/login', 'main/register',
  26. ] as $url) {
  27. $urls[] = $gen($url);
  28. }
  29. $urls[] = $gen('main/login', <<<EOA
  30. ,
  31. "actions": [
  32. "navigate to https://nginx/main/login",
  33. "set field #inputNicknameOrEmail to taken_user",
  34. "set field #inputPassword to foobar",
  35. "click element #signIn",
  36. "wait for path to not be /login"
  37. ]
  38. EOA);
  39. foreach (['feed/public', 'feed/home', '@taken_user/circles',
  40. 'feed/network', 'feed/clique', 'feed/federated', 'feed/notifications',
  41. '@taken_user/collections', '@taken_user/favourites', '@taken_user/reverse_favourites',
  42. 'directory/people', 'directory/groups', 'settings', 'main/logout'
  43. ] as $url) {
  44. $urls[] = $gen($url);
  45. }
  46. }
  47. $urls = implode(",\n", $urls);
  48. $config = <<<EOF
  49. {
  50. "defaults": {
  51. "chromeLaunchConfig": {
  52. "ignoreHTTPSErrors": true
  53. },
  54. "standard": "WCAG2AAA",
  55. "timeout": 10000
  56. },
  57. "concurrency": 4,
  58. "urls": [
  59. {$urls}
  60. ]
  61. }
  62. EOF;
  63. file_put_contents('/pa11y/config.json', $config);