From ba33460c5ae39e18ad39f6d9a09124c4ad4b1b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zoli=20Szab=C3=B3?= Date: Thu, 3 Jan 2019 11:35:23 +0200 Subject: [PATCH] [TASK] Failing (and not-failing) tests for #646 --- tests/Unit/EmogrifierTest.php | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/Unit/EmogrifierTest.php b/tests/Unit/EmogrifierTest.php index b40c1a36..f70b865a 100644 --- a/tests/Unit/EmogrifierTest.php +++ b/tests/Unit/EmogrifierTest.php @@ -268,6 +268,70 @@ public function emogrifyBodyContentKeepsSpecialCharactersInTextNodes($codeNotToB static::assertContains($codeNotToBeChanged, $result); } + /** + * Provides a list of common template variable formats. + * To be extended... + * + * @return string[] + */ + private function templateVariablesProvider() + { + return ['{var}', '{$var}']; + } + + /** + * Provides a list of elements & attributes which should not be URI-encoded. + * + * @return string[] + */ + private function elementsWithUriSpecificAttributesProvider() + { + return [ + 'a[href] + %s' => '', + 'link[href] + %s' => '', + 'base[href] + %s' => '', + 'script[src] + %s' => '', + 'form[action] + %s' => '
', + 'iframe[src] + %s' => '', + 'iframe[srcdoc] + %s' => '', + 'q[cite] + %s' => '', + 'blockquote[cite] + %s' => '
', + 'ins[cite] + %s' => '', + 'del[cite] + %s' => '', + ]; + } + + /** + * @return string[][] + */ + public function attributesWithSpecialCharactersDataProvider() + { + $data = []; + foreach ($this->elementsWithUriSpecificAttributesProvider() as $nameTemplate => $attributeTemplate) { + foreach ($this->templateVariablesProvider() as $variable) { + $data[\sprintf($nameTemplate, $variable)] = [\sprintf($attributeTemplate, $variable)]; + } + } + return $data; + } + + /** + * @test + * + * @param string $codeNotToBeChanged + * + * @dataProvider attributesWithSpecialCharactersDataProvider + */ + public function emogrifyKeepsSpecialCharactersInUriSpecificAttributes($codeNotToBeChanged) + { + $html = '

' . $codeNotToBeChanged . '

'; + $this->subject->setHtml($html); + + $result = $this->subject->emogrify(); + + static::assertContains($codeNotToBeChanged, $result); + } + /** * @test */