public function Twig_Tests_IntegrationTest::getTests

File

drupal/core/vendor/twig/twig/test/Twig/Tests/integrationTest.php, line 21

Class

Twig_Tests_IntegrationTest

Code

public function getTests() {
  $fixturesDir = realpath(dirname(__FILE__) . '/Fixtures/');
  $tests = array();
  foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fixturesDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
    if (!preg_match('/\\.test$/', $file)) {
      continue;
    }
    $test = file_get_contents($file
      ->getRealpath());
    if (preg_match('/
                    --TEST--\\s*(.*?)\\s*(?:--CONDITION--\\s*(.*))?\\s*((?:--TEMPLATE(?:\\(.*?\\))?--(?:.*))+)\\s*--EXCEPTION--\\s*(.*)/sx', $test, $match)) {
      $message = $match[1];
      $condition = $match[2];
      $templates = $this
        ->parseTemplates($match[3]);
      $exception = $match[4];
      $outputs = array(
        null,
        array(),
        null,
        '',
      );
    }
    elseif (preg_match('/--TEST--\\s*(.*?)\\s*(?:--CONDITION--\\s*(.*))?\\s*((?:--TEMPLATE(?:\\(.*?\\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) {
      $message = $match[1];
      $condition = $match[2];
      $templates = $this
        ->parseTemplates($match[3]);
      $exception = false;
      preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\\-\\-DATA\\-\\-|$)/s', $test, $outputs, PREG_SET_ORDER);
    }
    else {
      throw new InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir . '/', '', $file)));
    }
    $tests[] = array(
      str_replace($fixturesDir . '/', '', $file),
      $message,
      $condition,
      $templates,
      $exception,
      $outputs,
    );
  }
  return $tests;
}