|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace PhpList\RestBundle\Tests\Unit\Messaging\Request; |
| 6 | + |
| 7 | +use PhpList\RestBundle\Messaging\Request\Message\MessageContentRequest; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | +use Symfony\Component\Validator\Context\ExecutionContextInterface; |
| 10 | +use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface; |
| 11 | + |
| 12 | +class MessageContentRequestTest extends TestCase |
| 13 | +{ |
| 14 | + public function testValidateNoClickTrackLinksWithCleanTextDoesNotAddViolation(): void |
| 15 | + { |
| 16 | + $request = new MessageContentRequest(); |
| 17 | + $request->text = 'Hello, this is a normal message body.'; |
| 18 | + |
| 19 | + $context = $this->createMock(ExecutionContextInterface::class); |
| 20 | + $context->expects($this->never())->method('buildViolation'); |
| 21 | + |
| 22 | + $request->validateNoClickTrackLinks($context); |
| 23 | + } |
| 24 | + |
| 25 | + public function testValidateNoClickTrackLinksWithLtPhpPatternAddsViolation(): void |
| 26 | + { |
| 27 | + $request = new MessageContentRequest(); |
| 28 | + $request->text = 'See this link: https://example.com/lt.php?id=abcdefghijklmnop'; |
| 29 | + |
| 30 | + $builder = $this->createMock(ConstraintViolationBuilderInterface::class); |
| 31 | + $builder->expects($this->once())->method('atPath')->with('text')->willReturnSelf(); |
| 32 | + $builder->expects($this->once())->method('addViolation'); |
| 33 | + |
| 34 | + $context = $this->createMock(ExecutionContextInterface::class); |
| 35 | + $context->expects($this->once()) |
| 36 | + ->method('buildViolation') |
| 37 | + ->willReturn($builder); |
| 38 | + |
| 39 | + $request->validateNoClickTrackLinks($context); |
| 40 | + } |
| 41 | + |
| 42 | + public function testValidateNoClickTrackLinksWithLinkMapPatternAddsViolation(): void |
| 43 | + { |
| 44 | + $request = new MessageContentRequest(); |
| 45 | + $request->text = 'Mapped link: https://example.com/lt/abcdefghijklmnopqrstuv'; |
| 46 | + |
| 47 | + $builder = $this->createMock(ConstraintViolationBuilderInterface::class); |
| 48 | + $builder->expects($this->once())->method('atPath')->with('text')->willReturnSelf(); |
| 49 | + $builder->expects($this->once())->method('addViolation'); |
| 50 | + |
| 51 | + $context = $this->createMock(ExecutionContextInterface::class); |
| 52 | + $context->expects($this->once()) |
| 53 | + ->method('buildViolation') |
| 54 | + ->willReturn($builder); |
| 55 | + |
| 56 | + $request->validateNoClickTrackLinks($context); |
| 57 | + } |
| 58 | +} |
0 commit comments