Download tasks/194441f45927ce1f/source/patch.diff from FuCY/php: direct link, hf CLI and curl.
- Browser
- Download file 10.5 kB
-
https://huggingface.co/datasets/FuCY/php/resolve/main/tasks/194441f45927ce1f/source/patch.diff
- Command line
-
hf download hf://datasets/FuCY/php/tasks/194441f45927ce1f/source/patch.diff
-
curl -L -o patch.diff https://huggingface.co/datasets/FuCY/php/resolve/main/tasks/194441f45927ce1f/source/patch.diff
10.5 kB
| diff --git a/src/Oro/Bundle/EmailBundle/Provider/EmailRenderer.php b/src/Oro/Bundle/EmailBundle/Provider/EmailRenderer.php | |
| index 7ed98a24484..f2c601262d5 100644 | |
| --- a/src/Oro/Bundle/EmailBundle/Provider/EmailRenderer.php | |
| +++ b/src/Oro/Bundle/EmailBundle/Provider/EmailRenderer.php | |
| use Oro\Bundle\EntityBundle\Twig\Sandbox\TemplateRenderer; | |
| use Oro\Bundle\EntityBundle\Twig\Sandbox\TemplateRendererConfigProviderInterface; | |
| use Oro\Bundle\EntityBundle\Twig\Sandbox\VariableProcessorRegistry; | |
| +use Oro\Bundle\UIBundle\Tools\HtmlTagHelper; | |
| use Symfony\Contracts\Translation\TranslatorInterface; | |
| use Twig\Environment; | |
| class EmailRenderer extends TemplateRenderer | |
| /** @var TranslatorInterface */ | |
| private $translator; | |
| + /** @var HtmlTagHelper|null */ | |
| + private $htmlTagHelper; | |
| + | |
| public function __construct( | |
| Environment $environment, | |
| TemplateRendererConfigProviderInterface $configProvider, | |
| public function __construct( | |
| $this->translator = $translator; | |
| } | |
| + public function setHtmlTagHelper(HtmlTagHelper $htmlTagHelper): void | |
| + { | |
| + $this->htmlTagHelper = $htmlTagHelper; | |
| + } | |
| + | |
| /** | |
| * Compiles the given email template. | |
| * | |
| public function compilePreview(EmailTemplateInterface $template): string | |
| { | |
| $this->ensureSandboxConfigured(); | |
| + if ($this->htmlTagHelper) { | |
| + $content = $this->htmlTagHelper->sanitize($template->getContent(), 'default', false); | |
| + } else { | |
| + $content = $template->getContent(); | |
| + } | |
| + | |
| return $this->environment | |
| - ->createTemplate('{% verbatim %}' . $template->getContent() . '{% endverbatim %}') | |
| + ->createTemplate('{% verbatim %}' . $content . '{% endverbatim %}') | |
| ->render(); | |
| } | |
| diff --git a/src/Oro/Bundle/EmailBundle/Resources/config/services.yml b/src/Oro/Bundle/EmailBundle/Resources/config/services.yml | |
| index dd9e337ecdd..253161e2ad4 100644 | |
| --- a/src/Oro/Bundle/EmailBundle/Resources/config/services.yml | |
| +++ b/src/Oro/Bundle/EmailBundle/Resources/config/services.yml | |
| services: | |
| - '@Doctrine\Inflector\Inflector' | |
| calls: | |
| - [addSystemVariableDefaultFilter, ['userSignature', 'oro_html_sanitize']] | |
| + - [setHtmlTagHelper, ['@oro_ui.html_tag_helper']] | |
| lazy: true | |
| oro_email.email_renderer_configuration: | |
| diff --git a/src/Oro/Bundle/EmailBundle/Tests/Unit/Provider/EmailRendererTest.php b/src/Oro/Bundle/EmailBundle/Tests/Unit/Provider/EmailRendererTest.php | |
| index cf108b8969f..196a6aa5d1f 100644 | |
| --- a/src/Oro/Bundle/EmailBundle/Tests/Unit/Provider/EmailRendererTest.php | |
| +++ b/src/Oro/Bundle/EmailBundle/Tests/Unit/Provider/EmailRendererTest.php | |
| class EmailRendererTest extends \PHPUnit\Framework\TestCase | |
| { | |
| - private const ENTITY_VARIABLE_TEMPLATE = | |
| - '{% if %val% is defined %}' | |
| - . '{{ _entity_var("%name%", %val%, %parent%) }}' | |
| - . '{% else %}' | |
| - . '{{ "oro.email.variable.not.found" }}' | |
| - . '{% endif %}'; | |
| - | |
| /** @var TemplateRendererConfigProviderInterface|\PHPUnit\Framework\MockObject\MockObject */ | |
| private $configProvider; | |
| - /** @var VariableProcessorRegistry|\PHPUnit\Framework\MockObject\MockObject */ | |
| - private $variablesProcessorRegistry; | |
| - | |
| - /** @var TranslatorInterface|\PHPUnit\Framework\MockObject\MockObject */ | |
| - private $translation; | |
| - | |
| /** @var ContainerInterface|\PHPUnit\Framework\MockObject\MockObject */ | |
| private $container; | |
| class EmailRendererTest extends \PHPUnit\Framework\TestCase | |
| protected function setUp(): void | |
| { | |
| - $environment = new Environment(new ArrayLoader(), ['strict_variables' => true]); | |
| $this->configProvider = $this->createMock(TemplateRendererConfigProviderInterface::class); | |
| - $this->variablesProcessorRegistry = $this->createMock(VariableProcessorRegistry::class); | |
| - $this->translation = $this->createMock(TranslatorInterface::class); | |
| $this->container = $this->createMock(ContainerInterface::class); | |
| - $this->translation->expects($this->any()) | |
| + $variablesProcessorRegistry = $this->createMock(VariableProcessorRegistry::class); | |
| + | |
| + $htmlTagHelper = $this->createMock(HtmlTagHelper::class); | |
| + $htmlTagHelper->expects(self::any()) | |
| + ->method('sanitize') | |
| + ->with(self::isType(\PHPUnit\Framework\Constraint\IsType::TYPE_STRING), 'default', false) | |
| + ->willReturnCallback(static function (string $content) { | |
| + return $content . '(sanitized)'; | |
| + }); | |
| + | |
| + $translation = $this->createMock(TranslatorInterface::class); | |
| + $translation->expects(self::any()) | |
| ->method('trans') | |
| ->willReturnArgument(0); | |
| + $environment = new Environment(new ArrayLoader(), ['strict_variables' => true]); | |
| $environment->addExtension(new SandboxExtension(new SecurityPolicy())); | |
| $environment->addExtension(new HttpKernelExtension()); | |
| $environment->addExtension(new HtmlTagExtension($this->container)); | |
| protected function setUp(): void | |
| $this->renderer = new EmailRenderer( | |
| $environment, | |
| $this->configProvider, | |
| - $this->variablesProcessorRegistry, | |
| - $this->translation, | |
| + $variablesProcessorRegistry, | |
| + $translation, | |
| (new InflectorFactory())->build() | |
| ); | |
| + | |
| + $this->renderer->setHtmlTagHelper($htmlTagHelper); | |
| } | |
| private function getEmailTemplate(string $content, string $subject = ''): EmailTemplateInterface | |
| private function getEmailTemplate(string $content, string $subject = ''): EmailT | |
| return $emailTemplate; | |
| } | |
| - private function getEntityVariableTemplate(string $propertyName, string $path, string $parentPath): string | |
| - { | |
| - return strtr( | |
| - self::ENTITY_VARIABLE_TEMPLATE, | |
| - [ | |
| - '%name%' => $propertyName, | |
| - '%val%' => $path, | |
| - '%parent%' => $parentPath, | |
| - ] | |
| - ); | |
| - } | |
| - | |
| private function expectVariables(array $entityVariableProcessors = [], array $systemVariableValues = []): void | |
| { | |
| $entityVariableProcessorsMap = []; | |
| foreach ($entityVariableProcessors as $entityClass => $processors) { | |
| $entityVariableProcessorsMap[] = [$entityClass, $processors]; | |
| } | |
| - $this->configProvider->expects($this->any()) | |
| + $this->configProvider->expects(self::any()) | |
| ->method('getEntityVariableProcessors') | |
| ->willReturnMap($entityVariableProcessorsMap); | |
| - $this->configProvider->expects($this->any()) | |
| + $this->configProvider->expects(self::any()) | |
| ->method('getSystemVariableValues') | |
| ->willReturn($systemVariableValues); | |
| } | |
| - public function testCompilePreview() | |
| + public function testCompilePreview(): void | |
| { | |
| $entity = new TestEntityForVariableProvider(); | |
| - $this->configProvider->expects($this->any()) | |
| + $this->configProvider->expects(self::any()) | |
| ->method('getConfiguration') | |
| ->willReturn([ | |
| 'properties' => [], | |
| public function testCompilePreview() | |
| $emailTemplate->setContent($template); | |
| $emailTemplate->setSubject(''); | |
| - $this->assertSame($template, $this->renderer->compilePreview($emailTemplate)); | |
| + self::assertSame($template.'(sanitized)', $this->renderer->compilePreview($emailTemplate)); | |
| } | |
| - public function testCompileMessage() | |
| + public function testCompileMessage(): void | |
| { | |
| $entity = new TestEntityForVariableProvider(); | |
| $entity->setField1('Test'); | |
| public function testCompileMessage() | |
| . ' {{ system.testVar }}' | |
| . ' N/A'; | |
| - $this->configProvider->expects($this->any()) | |
| + $this->configProvider->expects(self::any()) | |
| ->method('getConfiguration') | |
| ->willReturn([ | |
| 'properties' => [], | |
| public function testCompileMessage() | |
| $this->expectVariables($entityVariableProcessors, $systemVars); | |
| $htmlTagHelper = $this->createMock(HtmlTagHelper::class); | |
| - $this->container->expects($this->once()) | |
| + $this->container->expects(self::once()) | |
| ->method('get') | |
| ->with('oro_ui.html_tag_helper') | |
| ->willReturn($htmlTagHelper); | |
| public function testCompileMessage() | |
| $result = $this->renderer->compileMessage($emailTemplate, $templateParams); | |
| $expectedContent = 'test <a href="http://example.com">test</a> 2 test_system N/A'; | |
| - $this->assertIsArray($result); | |
| - $this->assertCount(2, $result); | |
| - $this->assertSame($subject, $result[0]); | |
| - $this->assertSame($expectedContent, $result[1]); | |
| + self::assertIsArray($result); | |
| + self::assertCount(2, $result); | |
| + self::assertSame($subject, $result[0]); | |
| + self::assertSame($expectedContent, $result[1]); | |
| } | |
| - public function testRenderTemplate() | |
| + public function testRenderTemplate(): void | |
| { | |
| $template = 'test ' | |
| . "\n" | |
| public function testRenderTemplate() | |
| . '{{ system.currentDate }}'; | |
| $entity = new TestEntityForVariableProvider(); | |
| - $this->configProvider->expects($this->any()) | |
| + $this->configProvider->expects(self::any()) | |
| ->method('getConfiguration') | |
| ->willReturn([ | |
| 'properties' => [], | |
| public function testRenderTemplate() | |
| ], ['currentDate' => '10-12-2019']); | |
| $htmlTagHelper = $this->createMock(HtmlTagHelper::class); | |
| - $this->container->expects($this->once()) | |
| + $this->container->expects(self::once()) | |
| ->method('get') | |
| ->with('oro_ui.html_tag_helper') | |
| ->willReturn($htmlTagHelper); | |
| public function testRenderTemplate() | |
| 'test ' | |
| . "\n" | |
| . '10-12-2019'; | |
| - $this->assertSame($expectedRenderedResult, $result); | |
| + self::assertSame($expectedRenderedResult, $result); | |
| } | |
| } | |