3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Tests for parsing translatable strings in HTML content.
16 class CRM_Utils_HTMLTest
extends CiviUnitTestCase
{
21 public function translateExamples() {
29 '<div>Hello world</div>',
34 '<div>{{ts("Hello world")}}</div>',
37 // text, no arg, alternate text
39 '<div>{{ts("Good morning, Dave")}}</div>',
40 ['Good morning, Dave'],
44 '<div>{{ts("Hello world", {1: "whiz"})}}</div>',
47 // text, not really ts(), no arg
49 '<div>{{clients("Hello world")}}</div>',
52 // text, not really ts(), with arg
54 '<div>{{clients("Hello world", {1: "whiz"})}}</div>',
57 // two strings, duplicate
59 '<div>{{ts("Hello world")}}</div> <p>{{ts("Hello world")}}</p>',
62 // two strings, addition
64 '<div>{{ts("Hello world") + "-" + ts("How do you do?")}}</p>',
65 ['Hello world', 'How do you do?'],
67 // two strings, separate calls
69 '<div>{{ts("Hello world")}}</div> <p>{{ts("How do you do?")}}</p>',
70 ['Hello world', 'How do you do?'],
74 '<div>{{ts(\'Hello world\')}}</div>',
79 '<div>{{ts(message)}}</div>',
82 // ts() within a string
84 '<div>{{ts("Does the ts(\'example\') notation work?")}}</div>',
85 ['Does the ts(\'example\') notation work?'],
89 '<div crm-title="ts("Hello world")"></div>',
92 // attribute, with arg
94 '<div crm-title="ts("Hello world", {1: "whiz"})"></div>',
97 // attribute, two strings, with arg
99 '<div crm-title="ts("Hello world", {1: "whiz"}) + ts("How do you do, %1?", {2: "funky"})"></div>',
100 ['Hello world', 'How do you do, %1?'],
102 // trick question! Not used on Smarty templates.
104 '<div>{ts}Hello world{/ts}</div>',
112 * @param string $html
113 * Example HTML input.
114 * @param array $expectedStrings
115 * List of expected strings.
116 * @dataProvider translateExamples
118 public function testParseStrings($html, $expectedStrings) {
119 // Magic! The JS parser works with HTML!
120 $actualStrings = CRM_Utils_JS
::parseStrings($html);
121 sort($expectedStrings);
122 sort($actualStrings);
123 $this->assertEquals($expectedStrings, $actualStrings);