setHtml($htmlContent); $actualPlainText = $plainTextHelper->getText(); $this->assertEquals($expectedPlainText, $actualPlainText); } /** * @return array> */ public function emailContentProvider(): array { return [ // Test case 1: Simple paragraph [ '

This is a simple paragraph.

', 'This is a simple paragraph.', ], // Test case 2: Line breaks [ '

This is line one.
This is line two.

', "This is line one.\nThis is line two.", ], // Test case 3: Links [ '

Check this link.

', 'Check this link [http://example.com].', ], // Test case 4: Bold text [ '

This is bold text.

', 'This is bold text.', ], // Test case 5: Full html body [ ' Test Email

Welcome to Our Newsletter

This is an example paragraph in our email content.

', "WELCOME TO OUR NEWSLETTER\n\nThis is an example paragraph in our email content.", ], ]; } /** * @dataProvider getPreviewProvider */ public function testGetPreview(?int $previewLength, string $htmlContent, string $expectedPlainText): void { $options = []; if ($previewLength) { $options['preview_length'] = $previewLength; } $plainTextHelper = new PlainTextHelper($options); $plainTextHelper->setHtml($htmlContent); $actualPlainText = $plainTextHelper->getPreview(); $this->assertEquals($expectedPlainText, $actualPlainText); } /** * @return array> */ public function getPreviewProvider(): array { return [ // Test case 1: Simple paragraph, with default options [ null, '

This is a simple paragraph.

', 'This is a simple paragraph.', ], // Test case 2: Simple paragraph, with length set to 10 (whitespace truncated) [ 10, '

This is a simple paragraph.

', 'This is a...', ], // Test case 3: Full html body [ 25, '

Welcome to Our Newsletter

This is an example paragraph in our email content.

', 'WELCOME TO OUR NEWSLETTER...', ], ]; } }