Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/sitepres.../lib/twig/src/Test
File: IntegrationTestCase.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of Twig.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Fabien Potencier
[5] Fix | Delete
*
[6] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[7] Fix | Delete
* file that was distributed with this source code.
[8] Fix | Delete
*/
[9] Fix | Delete
namespace WPML\Core\Twig\Test;
[10] Fix | Delete
[11] Fix | Delete
use WPML\Core\PHPUnit\Framework\TestCase;
[12] Fix | Delete
use WPML\Core\Twig\Environment;
[13] Fix | Delete
use WPML\Core\Twig\Error\Error;
[14] Fix | Delete
use WPML\Core\Twig\Extension\ExtensionInterface;
[15] Fix | Delete
use WPML\Core\Twig\Loader\ArrayLoader;
[16] Fix | Delete
use WPML\Core\Twig\Loader\SourceContextLoaderInterface;
[17] Fix | Delete
use WPML\Core\Twig\RuntimeLoader\RuntimeLoaderInterface;
[18] Fix | Delete
use WPML\Core\Twig\Source;
[19] Fix | Delete
use WPML\Core\Twig\TwigFilter;
[20] Fix | Delete
use WPML\Core\Twig\TwigFunction;
[21] Fix | Delete
use WPML\Core\Twig\TwigTest;
[22] Fix | Delete
/**
[23] Fix | Delete
* Integration test helper.
[24] Fix | Delete
*
[25] Fix | Delete
* @author Fabien Potencier <fabien@symfony.com>
[26] Fix | Delete
* @author Karma Dordrak <drak@zikula.org>
[27] Fix | Delete
*/
[28] Fix | Delete
abstract class IntegrationTestCase extends \WPML\Core\PHPUnit\Framework\TestCase
[29] Fix | Delete
{
[30] Fix | Delete
/**
[31] Fix | Delete
* @return string
[32] Fix | Delete
*/
[33] Fix | Delete
protected abstract function getFixturesDir();
[34] Fix | Delete
/**
[35] Fix | Delete
* @return RuntimeLoaderInterface[]
[36] Fix | Delete
*/
[37] Fix | Delete
protected function getRuntimeLoaders()
[38] Fix | Delete
{
[39] Fix | Delete
return [];
[40] Fix | Delete
}
[41] Fix | Delete
/**
[42] Fix | Delete
* @return ExtensionInterface[]
[43] Fix | Delete
*/
[44] Fix | Delete
protected function getExtensions()
[45] Fix | Delete
{
[46] Fix | Delete
return [];
[47] Fix | Delete
}
[48] Fix | Delete
/**
[49] Fix | Delete
* @return TwigFilter[]
[50] Fix | Delete
*/
[51] Fix | Delete
protected function getTwigFilters()
[52] Fix | Delete
{
[53] Fix | Delete
return [];
[54] Fix | Delete
}
[55] Fix | Delete
/**
[56] Fix | Delete
* @return TwigFunction[]
[57] Fix | Delete
*/
[58] Fix | Delete
protected function getTwigFunctions()
[59] Fix | Delete
{
[60] Fix | Delete
return [];
[61] Fix | Delete
}
[62] Fix | Delete
/**
[63] Fix | Delete
* @return TwigTest[]
[64] Fix | Delete
*/
[65] Fix | Delete
protected function getTwigTests()
[66] Fix | Delete
{
[67] Fix | Delete
return [];
[68] Fix | Delete
}
[69] Fix | Delete
/**
[70] Fix | Delete
* @dataProvider getTests
[71] Fix | Delete
*/
[72] Fix | Delete
public function testIntegration($file, $message, $condition, $templates, $exception, $outputs)
[73] Fix | Delete
{
[74] Fix | Delete
$this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs);
[75] Fix | Delete
}
[76] Fix | Delete
/**
[77] Fix | Delete
* @dataProvider getLegacyTests
[78] Fix | Delete
* @group legacy
[79] Fix | Delete
*/
[80] Fix | Delete
public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs)
[81] Fix | Delete
{
[82] Fix | Delete
$this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs);
[83] Fix | Delete
}
[84] Fix | Delete
public function getTests($name, $legacyTests = \false)
[85] Fix | Delete
{
[86] Fix | Delete
$fixturesDir = \realpath($this->getFixturesDir());
[87] Fix | Delete
$tests = [];
[88] Fix | Delete
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($fixturesDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
[89] Fix | Delete
if (!\preg_match('/\\.test$/', $file)) {
[90] Fix | Delete
continue;
[91] Fix | Delete
}
[92] Fix | Delete
if ($legacyTests xor \false !== \strpos($file->getRealpath(), '.legacy.test')) {
[93] Fix | Delete
continue;
[94] Fix | Delete
}
[95] Fix | Delete
$test = \file_get_contents($file->getRealpath());
[96] Fix | Delete
if (\preg_match('/--TEST--\\s*(.*?)\\s*(?:--CONDITION--\\s*(.*))?\\s*((?:--TEMPLATE(?:\\(.*?\\))?--(?:.*?))+)\\s*(?:--DATA--\\s*(.*))?\\s*--EXCEPTION--\\s*(.*)/sx', $test, $match)) {
[97] Fix | Delete
$message = $match[1];
[98] Fix | Delete
$condition = $match[2];
[99] Fix | Delete
$templates = self::parseTemplates($match[3]);
[100] Fix | Delete
$exception = $match[5];
[101] Fix | Delete
$outputs = [[null, $match[4], null, '']];
[102] Fix | Delete
} elseif (\preg_match('/--TEST--\\s*(.*?)\\s*(?:--CONDITION--\\s*(.*))?\\s*((?:--TEMPLATE(?:\\(.*?\\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) {
[103] Fix | Delete
$message = $match[1];
[104] Fix | Delete
$condition = $match[2];
[105] Fix | Delete
$templates = self::parseTemplates($match[3]);
[106] Fix | Delete
$exception = \false;
[107] Fix | Delete
\preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\\-\\-DATA\\-\\-|$)/s', $test, $outputs, \PREG_SET_ORDER);
[108] Fix | Delete
} else {
[109] Fix | Delete
throw new \InvalidArgumentException(\sprintf('Test "%s" is not valid.', \str_replace($fixturesDir . '/', '', $file)));
[110] Fix | Delete
}
[111] Fix | Delete
$tests[] = [\str_replace($fixturesDir . '/', '', $file), $message, $condition, $templates, $exception, $outputs];
[112] Fix | Delete
}
[113] Fix | Delete
if ($legacyTests && empty($tests)) {
[114] Fix | Delete
// add a dummy test to avoid a PHPUnit message
[115] Fix | Delete
return [['not', '-', '', [], '', []]];
[116] Fix | Delete
}
[117] Fix | Delete
return $tests;
[118] Fix | Delete
}
[119] Fix | Delete
public function getLegacyTests()
[120] Fix | Delete
{
[121] Fix | Delete
return $this->getTests('testLegacyIntegration', \true);
[122] Fix | Delete
}
[123] Fix | Delete
protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs)
[124] Fix | Delete
{
[125] Fix | Delete
if (!$outputs) {
[126] Fix | Delete
$this->markTestSkipped('no tests to run');
[127] Fix | Delete
}
[128] Fix | Delete
if ($condition) {
[129] Fix | Delete
eval('$ret = ' . $condition . ';');
[130] Fix | Delete
if (!$ret) {
[131] Fix | Delete
$this->markTestSkipped($condition);
[132] Fix | Delete
}
[133] Fix | Delete
}
[134] Fix | Delete
$loader = new \WPML\Core\Twig\Loader\ArrayLoader($templates);
[135] Fix | Delete
foreach ($outputs as $i => $match) {
[136] Fix | Delete
$config = \array_merge(['cache' => \false, 'strict_variables' => \true], $match[2] ? eval($match[2] . ';') : []);
[137] Fix | Delete
$twig = new \WPML\Core\Twig\Environment($loader, $config);
[138] Fix | Delete
$twig->addGlobal('global', 'global');
[139] Fix | Delete
foreach ($this->getRuntimeLoaders() as $runtimeLoader) {
[140] Fix | Delete
$twig->addRuntimeLoader($runtimeLoader);
[141] Fix | Delete
}
[142] Fix | Delete
foreach ($this->getExtensions() as $extension) {
[143] Fix | Delete
$twig->addExtension($extension);
[144] Fix | Delete
}
[145] Fix | Delete
foreach ($this->getTwigFilters() as $filter) {
[146] Fix | Delete
$twig->addFilter($filter);
[147] Fix | Delete
}
[148] Fix | Delete
foreach ($this->getTwigTests() as $test) {
[149] Fix | Delete
$twig->addTest($test);
[150] Fix | Delete
}
[151] Fix | Delete
foreach ($this->getTwigFunctions() as $function) {
[152] Fix | Delete
$twig->addFunction($function);
[153] Fix | Delete
}
[154] Fix | Delete
$p = new \ReflectionProperty($twig, 'templateClassPrefix');
[155] Fix | Delete
$p->setAccessible(\true);
[156] Fix | Delete
$p->setValue($twig, '\\WPML\\Core\\__TwigTemplate_' . \hash('sha256', \uniqid(\mt_rand(), \true), \false) . '_');
[157] Fix | Delete
try {
[158] Fix | Delete
$template = $twig->load('index.twig');
[159] Fix | Delete
} catch (\Exception $e) {
[160] Fix | Delete
if (\false !== $exception) {
[161] Fix | Delete
$message = $e->getMessage();
[162] Fix | Delete
$this->assertSame(\trim($exception), \trim(\sprintf('%s: %s', \get_class($e), $message)));
[163] Fix | Delete
$last = \substr($message, \strlen($message) - 1);
[164] Fix | Delete
$this->assertTrue('.' === $last || '?' === $last, 'Exception message must end with a dot or a question mark.');
[165] Fix | Delete
return;
[166] Fix | Delete
}
[167] Fix | Delete
throw new \WPML\Core\Twig\Error\Error(\sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e);
[168] Fix | Delete
}
[169] Fix | Delete
try {
[170] Fix | Delete
$output = \trim($template->render(eval($match[1] . ';')), "\n ");
[171] Fix | Delete
} catch (\Exception $e) {
[172] Fix | Delete
if (\false !== $exception) {
[173] Fix | Delete
$this->assertSame(\trim($exception), \trim(\sprintf('%s: %s', \get_class($e), $e->getMessage())));
[174] Fix | Delete
return;
[175] Fix | Delete
}
[176] Fix | Delete
$e = new \WPML\Core\Twig\Error\Error(\sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e);
[177] Fix | Delete
$output = \trim(\sprintf('%s: %s', \get_class($e), $e->getMessage()));
[178] Fix | Delete
}
[179] Fix | Delete
if (\false !== $exception) {
[180] Fix | Delete
list($class) = \explode(':', $exception);
[181] Fix | Delete
$constraintClass = \class_exists('WPML\\Core\\PHPUnit\\Framework\\Constraint\\Exception') ? 'PHPUnit\\Framework\\Constraint\\Exception' : 'PHPUnit_Framework_Constraint_Exception';
[182] Fix | Delete
$this->assertThat(null, new $constraintClass($class));
[183] Fix | Delete
}
[184] Fix | Delete
$expected = \trim($match[3], "\n ");
[185] Fix | Delete
if ($expected !== $output) {
[186] Fix | Delete
\printf("Compiled templates that failed on case %d:\n", $i + 1);
[187] Fix | Delete
foreach (\array_keys($templates) as $name) {
[188] Fix | Delete
echo "Template: {$name}\n";
[189] Fix | Delete
$loader = $twig->getLoader();
[190] Fix | Delete
if (!$loader instanceof \WPML\Core\Twig\Loader\SourceContextLoaderInterface) {
[191] Fix | Delete
$source = new \WPML\Core\Twig\Source($loader->getSource($name), $name);
[192] Fix | Delete
} else {
[193] Fix | Delete
$source = $loader->getSourceContext($name);
[194] Fix | Delete
}
[195] Fix | Delete
echo $twig->compile($twig->parse($twig->tokenize($source)));
[196] Fix | Delete
}
[197] Fix | Delete
}
[198] Fix | Delete
$this->assertEquals($expected, $output, $message . ' (in ' . $file . ')');
[199] Fix | Delete
}
[200] Fix | Delete
}
[201] Fix | Delete
protected static function parseTemplates($test)
[202] Fix | Delete
{
[203] Fix | Delete
$templates = [];
[204] Fix | Delete
\preg_match_all('/--TEMPLATE(?:\\((.*?)\\))?--(.*?)(?=\\-\\-TEMPLATE|$)/s', $test, $matches, \PREG_SET_ORDER);
[205] Fix | Delete
foreach ($matches as $match) {
[206] Fix | Delete
$templates[$match[1] ? $match[1] : 'index.twig'] = $match[2];
[207] Fix | Delete
}
[208] Fix | Delete
return $templates;
[209] Fix | Delete
}
[210] Fix | Delete
}
[211] Fix | Delete
\class_alias('WPML\\Core\\Twig\\Test\\IntegrationTestCase', 'WPML\\Core\\Twig_Test_IntegrationTestCase');
[212] Fix | Delete
[213] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function