You are here

public static function VarnishPurgeFeatureContext::prepare in Varnish purger 8.2

Setup for the test suite, enable some required modules and add content title.

@BeforeSuite

File

tests/src/Behat/features/bootstrap/VarnishPurgeFeatureContext.php, line 21

Class

VarnishPurgeFeatureContext
Behat steps for testing the varnish_purger module.

Code

public static function prepare(BeforeSuiteScope $scope) {
  $data = Settings::getAll();

  // We need a concrete plugin class and one is included in the purge module.
  $data['extension_discovery_scan_tests'] = TRUE;
  $data['reverse_proxy_addresses'] = [
    '127.0.0.1',
  ];
  $data['varnish_purge_zeroconfig_port'] = 8080;
  new Settings($data);

  /** @var \Drupal\Core\Extension\ModuleHandler $moduleHandler */
  $moduleHandler = \Drupal::service('module_handler');
  if (!$moduleHandler
    ->moduleExists('varnish_purger')) {
    \Drupal::service('module_installer')
      ->install([
      'varnish_purger',
      'varnish_purge_tags',
      'purge_processor_test',
    ]);
  }

  // Also uninstall the inline form errors module for easier testing.
  if ($moduleHandler
    ->moduleExists('inline_form_errors')) {
    \Drupal::service('module_installer')
      ->uninstall([
      'inline_form_errors',
    ]);
  }

  // Set a 1 year expiry as recommended by the purge module.
  \Drupal::service('config.factory')
    ->getEditable('system.performance')
    ->set('cache', [
    'page' => [
      'max_age' => 365 * 24 * 60 * 60,
    ],
  ])
    ->save();

  // Add the zeroconfig purger as the only purger.
  \Drupal::service('config.factory')
    ->getEditable('purge.plugins')
    ->set('purgers', [
    [
      'order_index' => 1,
      'instance_id' => '340fedee82',
      'plugin_id' => 'varnish_zeroconfig_purger',
    ],
  ])
    ->save();
}