From eebfdc75f1b3712f96647e993fb93102c0020fdb Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 16 Aug 2015 19:57:23 +0200 Subject: [PATCH] added a way to manage legacy tests in fixtures --- CHANGELOG | 2 +- lib/Twig/Test/IntegrationTestCase.php | 23 ++++++++++++++++--- .../tags/autoescape/strategy.legacy.test | 11 +++++++++ .../Fixtures/tags/autoescape/strategy.test | 6 ----- .../raw/{basic.test => basic.legacy.test} | 0 ....test => mixed_usage_with_raw.legacy.test} | 0 ...ol.test => whitespace_control.legacy.test} | 0 7 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 test/Twig/Tests/Fixtures/tags/autoescape/strategy.legacy.test rename test/Twig/Tests/Fixtures/tags/raw/{basic.test => basic.legacy.test} (100%) rename test/Twig/Tests/Fixtures/tags/raw/{mixed_usage_with_raw.test => mixed_usage_with_raw.legacy.test} (100%) rename test/Twig/Tests/Fixtures/tags/raw/{whitespace_control.test => whitespace_control.legacy.test} (100%) diff --git a/CHANGELOG b/CHANGELOG index 6e5d75331..8ea012fcc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,7 @@ * 1.21.0 (2015-XX-XX) * added deprecation notices for deprecated features - * added a deprecation "framework" for filters/functions/tests + * added a deprecation "framework" for filters/functions/tests and test fixtures * 1.20.0 (2015-08-12) diff --git a/lib/Twig/Test/IntegrationTestCase.php b/lib/Twig/Test/IntegrationTestCase.php index 261acd41c..6add91da6 100644 --- a/lib/Twig/Test/IntegrationTestCase.php +++ b/lib/Twig/Test/IntegrationTestCase.php @@ -28,7 +28,15 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs); } - public function getTests() + /** + * @dataProvider getLegacyTests + */ + public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs) + { + $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs); + } + + public function getTests($name, $legacyOnly = false) { $fixturesDir = realpath($this->getFixturesDir()); $tests = array(); @@ -38,10 +46,14 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase continue; } + $isLegacyTest = false !== strpos($file->getRealpath(), '.legacy.test'); + if (($isLegacyTest && !$legacyOnly) || (!$isLegacyTest && $legacyOnly)) { + continue; + } + $test = file_get_contents($file->getRealpath()); - if (preg_match('/ - --TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) { + if (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) { $message = $match[1]; $condition = $match[2]; $templates = $this->parseTemplates($match[3]); @@ -63,6 +75,11 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase return $tests; } + public function getLegacyTests() + { + return $this->getTests('testLegacyIntegration', true); + } + protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs) { if ($condition) { diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/strategy.legacy.test b/test/Twig/Tests/Fixtures/tags/autoescape/strategy.legacy.test new file mode 100644 index 000000000..bbf1356e7 --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/autoescape/strategy.legacy.test @@ -0,0 +1,11 @@ +--TEST-- +"autoescape" tag accepts an escaping strategy +--TEMPLATE-- +{% autoescape true js %}{{ var }}{% endautoescape %} + +{% autoescape true html %}{{ var }}{% endautoescape %} +--DATA-- +return array('var' => '
"') +--EXPECT-- +\x3Cbr\x20\x2F\x3E\x22 +<br />" diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/strategy.test b/test/Twig/Tests/Fixtures/tags/autoescape/strategy.test index cf8cceef3..e496f6081 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/strategy.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/strategy.test @@ -1,10 +1,6 @@ --TEST-- "autoescape" tag accepts an escaping strategy --TEMPLATE-- -{% autoescape true js %}{{ var }}{% endautoescape %} - -{% autoescape true html %}{{ var }}{% endautoescape %} - {% autoescape 'js' %}{{ var }}{% endautoescape %} {% autoescape 'html' %}{{ var }}{% endautoescape %} @@ -13,5 +9,3 @@ return array('var' => '
"') --EXPECT-- \x3Cbr\x20\x2F\x3E\x22 <br />" -\x3Cbr\x20\x2F\x3E\x22 -<br />" diff --git a/test/Twig/Tests/Fixtures/tags/raw/basic.test b/test/Twig/Tests/Fixtures/tags/raw/basic.legacy.test similarity index 100% rename from test/Twig/Tests/Fixtures/tags/raw/basic.test rename to test/Twig/Tests/Fixtures/tags/raw/basic.legacy.test diff --git a/test/Twig/Tests/Fixtures/tags/raw/mixed_usage_with_raw.test b/test/Twig/Tests/Fixtures/tags/raw/mixed_usage_with_raw.legacy.test similarity index 100% rename from test/Twig/Tests/Fixtures/tags/raw/mixed_usage_with_raw.test rename to test/Twig/Tests/Fixtures/tags/raw/mixed_usage_with_raw.legacy.test diff --git a/test/Twig/Tests/Fixtures/tags/raw/whitespace_control.test b/test/Twig/Tests/Fixtures/tags/raw/whitespace_control.legacy.test similarity index 100% rename from test/Twig/Tests/Fixtures/tags/raw/whitespace_control.test rename to test/Twig/Tests/Fixtures/tags/raw/whitespace_control.legacy.test