3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Tests for parsing translatable strings in HTML content.
32 class CRM_Utils_HTMLTest
extends CiviUnitTestCase
{
37 public function translateExamples() {
45 '<div>Hello world</div>',
50 '<div>{{ts("Hello world")}}</div>',
53 // text, no arg, alternate text
55 '<div>{{ts("Good morning, Dave")}}</div>',
56 ['Good morning, Dave'],
60 '<div>{{ts("Hello world", {1: "whiz"})}}</div>',
63 // text, not really ts(), no arg
65 '<div>{{clients("Hello world")}}</div>',
68 // text, not really ts(), with arg
70 '<div>{{clients("Hello world", {1: "whiz"})}}</div>',
73 // two strings, duplicate
75 '<div>{{ts("Hello world")}}</div> <p>{{ts("Hello world")}}</p>',
78 // two strings, addition
80 '<div>{{ts("Hello world") + "-" + ts("How do you do?")}}</p>',
81 ['Hello world', 'How do you do?'],
83 // two strings, separate calls
85 '<div>{{ts("Hello world")}}</div> <p>{{ts("How do you do?")}}</p>',
86 ['Hello world', 'How do you do?'],
90 '<div>{{ts(\'Hello world\')}}</div>',
95 '<div>{{ts(message)}}</div>',
98 // ts() within a string
100 '<div>{{ts("Does the ts(\'example\') notation work?")}}</div>',
101 ['Does the ts(\'example\') notation work?'],
105 '<div crm-title="ts("Hello world")"></div>',
108 // attribute, with arg
110 '<div crm-title="ts("Hello world", {1: "whiz"})"></div>',
113 // attribute, two strings, with arg
115 '<div crm-title="ts("Hello world", {1: "whiz"}) + ts("How do you do, %1?", {2: "funky"})"></div>',
116 ['Hello world', 'How do you do, %1?'],
118 // trick question! Not used on Smarty templates.
120 '<div>{ts}Hello world{/ts}</div>',
128 * @param string $html
129 * Example HTML input.
130 * @param array $expectedStrings
131 * List of expected strings.
132 * @dataProvider translateExamples
134 public function testParseStrings($html, $expectedStrings) {
135 // Magic! The JS parser works with HTML!
136 $actualStrings = CRM_Utils_JS
::parseStrings($html);
137 sort($expectedStrings);
138 sort($actualStrings);
139 $this->assertEquals($expectedStrings, $actualStrings);