From c2486e81d64daa31e2b92cb3b56f7dac1df41c43 Mon Sep 17 00:00:00 2001 From: Sean Madsen Date: Thu, 15 Mar 2018 10:40:16 -0400 Subject: [PATCH] CRM-21264 - Add test for isHtmlTokenInTableCell Test currently fails on "simplest TRUE" case added, which demonstrates the bug described in CRM-21264. Also added other test cases which current fail as well. --- .../Form/Task/PDFLetterCommonTest.php | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php index aed99437d5..93ef591a39 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php @@ -376,4 +376,78 @@ value=$contact_aggregate+$contribution.total_amount} } } + /** + * @param string $token + * @param string $entity + * @param string $textToSearch + * @param bool $expected + * + * @dataProvider isHtmlTokenInTableCellProvider + */ + public function testIsHtmlTokenInTableCell($token, $entity, $textToSearch, $expected) { + $this->assertEquals($expected, + CRM_Contribute_Form_Task_PDFLetterCommon::isHtmlTokenInTableCell($token, $entity, $textToSearch) + ); + } + + public function isHtmlTokenInTableCellProvider() { + return [ + + 'simplest TRUE' => [ + 'token', + 'entity', + '{entity.token}', + TRUE, + ], + + 'simplest FALSE' => [ + 'token', + 'entity', + '{entity.token}', + FALSE, + ], + + 'token between two tables' => [ + 'token', + 'entity', + '
Top
+ {entity.token} +
Bottom
', + FALSE, + ], + + 'token in two tables' => [ + 'token', + 'entity', + '
{entity.token}
foo
+
{entity.token}
foo
', + TRUE, + ], + + 'token outside of table and inside of table' => [ + 'token', + 'entity', + ' {entity.token} +
{entity.token}
foo
', + FALSE, + ], + + 'token inside more complicated table' => [ + 'token', + 'entity', + '
{entity.token}
', + TRUE, + ], + + 'token inside something that looks like table cell' => [ + 'token', + 'entity', + ' {entity.token} +
Bottom
', + FALSE, + ], + + ]; + } + } -- 2.25.1