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'],
42 // angular one-time binding notation - great when there are no args
44 '<div>{{:: ts("One-time binding is more efficient!") }}</div>',
45 ['One-time binding is more efficient!'],
49 '<div>{{ts("Hello world", {1: "whiz"})}}</div>',
52 // text, not really ts(), no arg
54 '<div>{{clients("Hello world")}}</div>',
57 // text, not really ts(), with arg
59 '<div>{{clients("Hello world", {1: "whiz"})}}</div>',
62 // two strings, duplicate
64 '<div>{{ts("Hello world")}}</div> <p>{{ts("Hello world")}}</p>',
67 // two strings, addition
69 '<div>{{ts("Hello world") + "-" + ts("How do you do?")}}</p>',
70 ['Hello world', 'How do you do?'],
72 // two strings, separate calls
74 '<div>{{ts("Hello world")}}</div> <p>{{ts("How do you do?")}}</p>',
75 ['Hello world', 'How do you do?'],
79 '<div>{{ts(\'Hello world\')}}</div>',
84 '<div>{{ts(message)}}</div>',
87 // ts() within a string
89 '<div>{{ts("Does the ts(\'example\') notation work?")}}</div>',
90 ['Does the ts(\'example\') notation work?'],
94 '<div crm-title="ts("Hello world")"></div>',
97 // attribute, with arg
99 '<div crm-title="ts("Hello world", {1: "whiz"})"></div>',
102 // attribute, two strings, with arg
104 '<div crm-title="ts("Hello world", {1: "whiz"}) + ts("How do you do, %1?", {2: "funky"})"></div>',
105 ['Hello world', 'How do you do, %1?'],
107 // trick question! Not used on Smarty templates.
109 '<div>{ts}Hello world{/ts}</div>',
117 * @param string $html
118 * Example HTML input.
119 * @param array $expectedStrings
120 * List of expected strings.
121 * @dataProvider translateExamples
123 public function testParseStrings($html, $expectedStrings) {
124 // Magic! The JS parser works with HTML!
125 $actualStrings = CRM_Utils_JS
::parseStrings($html);
126 sort($expectedStrings);
127 sort($actualStrings);
128 $this->assertEquals($expectedStrings, $actualStrings);