<?php

/**
 * @file
 * Wrapper to run WCMS tests with Drupal's run-tests.sh.
 */

$site_to_test = $_SERVER['argv'][1] ?? NULL;
if (!$site_to_test || in_array($site_to_test, ['-h', '--help', '-v', '--version'])) {
  $script = basename($_SERVER['argv'][0]);
  echo 'Usage: ' . $script . " URL-TO-TEST [ADDITIONAL-ARGUMENTS ...]\n";
  echo "In Drupal 8, pass the argument --suppress-deprecations.\n";
  echo "(The argument is not needed for Drupal 9.)\n";
  exit 1;
}

// Keep copy of original arguments to add to those set by this script.
$original_argv = $_SERVER['argv'];
// Remove script name and site URL.
array_shift($original_argv);
array_shift($original_argv);

$modules_to_test = [
  'uw_base_profile',
];

// Arguments to set when running run-tests.sh.
$_SERVER['argv'] = [
  'run-tests.sh',
  '--verbose',
  '--color',
  '--sqlite',
  '/tmp/drupal/test.sqlite',
  '--module',
  implode(',', $modules_to_test),
  '--url',
  $site_to_test,
];
$_SERVER['argv'] = array_merge($_SERVER['argv'], $original_argv);

// Run the tests.
require __DIR__ . '/../../core/scripts/' . $_SERVER['argv'][0];