You are here

public function MonitoringCoreWebTest::doTestTwigDebugSensor in Monitoring 8

Tests the twig debug sensor.

See also

\Drupal\monitoring\Plugin\monitoring\SensorPlugin\TwigDebugSensorPlugin

1 call to MonitoringCoreWebTest::doTestTwigDebugSensor()
MonitoringCoreWebTest::testSensors in tests/src/Functional/MonitoringCoreWebTest.php
Tests individual sensors.

File

tests/src/Functional/MonitoringCoreWebTest.php, line 190

Class

MonitoringCoreWebTest
Integration tests for the core pieces of monitoring.

Namespace

Drupal\Tests\monitoring\Functional

Code

public function doTestTwigDebugSensor() {

  // Ensure that the sensor does not report an error with the default
  // configuration.
  $result = $this
    ->runSensor('twig_debug_mode');
  $this
    ->assertTrue($result
    ->isOk());
  $this
    ->assertEqual($result
    ->getMessage(), 'Optimal configuration');
  $twig_config = $this->container
    ->getParameter('twig.config');

  // Set parameters to the optimal configuration to make sure implicit changes
  // does not trigger any notices and check sensor message.
  $twig_config['debug'] = FALSE;
  $twig_config['cache'] = TRUE;
  $twig_config['auto_reload'] = NULL;
  $this
    ->setContainerParameter('twig.config', $twig_config);
  $this
    ->rebuildContainer();
  $result = $this
    ->runSensor('twig_debug_mode');
  $this
    ->assertTrue($result
    ->isOk());
  $this
    ->assertEqual($result
    ->getMessage(), 'Optimal configuration');
  $twig_config = $this->container
    ->getParameter('twig.config');

  // Change parameters and check sensor message.
  $twig_config['debug'] = TRUE;
  $twig_config['cache'] = FALSE;
  $twig_config['auto_reload'] = TRUE;
  $this
    ->setContainerParameter('twig.config', $twig_config);
  $this
    ->rebuildContainer();
  $result = $this
    ->runSensor('twig_debug_mode');
  $this
    ->assertTrue($result
    ->isWarning());
  $this
    ->assertEqual($result
    ->getMessage(), 'Twig debug mode is enabled, Twig cache disabled, Automatic recompilation of Twig templates enabled');
}