3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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.
31 class CRM_Utils_HTMLTest
extends CiviUnitTestCase
{
35 public function translateExamples() {
41 $cases[] = array(// missing ts
42 '<div>Hello world</div>',
45 $cases[] = array(// text, no arg
46 '<div>{{ts("Hello world")}}</div>',
49 $cases[] = array(// text, no arg, alternate text
50 '<div>{{ts("Good morning, Dave")}}</div>',
51 array('Good morning, Dave'),
53 $cases[] = array(// text, with arg
54 '<div>{{ts("Hello world", {1: "whiz"})}}</div>',
57 $cases[] = array(// text, not really ts(), no arg
58 '<div>{{clients("Hello world")}}</div>',
61 $cases[] = array(// text, not really ts(), with arg
62 '<div>{{clients("Hello world", {1: "whiz"})}}</div>',
65 $cases[] = array(// two strings, duplicate
66 '<div>{{ts("Hello world")}}</div> <p>{{ts("Hello world")}}</p>',
69 $cases[] = array(// two strings, addition
70 '<div>{{ts("Hello world") + "-" + ts("How do you do?")}}</p>',
71 array('Hello world', 'How do you do?'),
73 $cases[] = array(// two strings, separate calls
74 '<div>{{ts("Hello world")}}</div> <p>{{ts("How do you do?")}}</p>',
75 array('Hello world', 'How do you do?'),
77 $cases[] = array(// single quoted
78 '<div>{{ts(\'Hello world\')}}</div>',
81 $cases[] = array(// unclear string
82 '<div>{{ts(message)}}</div>',
85 $cases[] = array(// ts() within a string
86 '<div>{{ts("Does the ts(\'example\') notation work?")}}</div>',
87 array('Does the ts(\'example\') notation work?'),
89 $cases[] = array(// attribute, no arg
90 '<div crm-title="ts("Hello world")"></div>',
93 $cases[] = array(// attribute, with arg
94 '<div crm-title="ts("Hello world", {1: "whiz"})"></div>',
97 $cases[] = array(// attribute, two strings, with arg
98 '<div crm-title="ts("Hello world", {1: "whiz"}) + ts("How do you do, %1?", {2: "funky"})"></div>',
99 array('Hello world', 'How do you do, %1?'),
101 $cases[] = array(// trick question! Not used on Smarty templates.
102 '<div>{ts}Hello world{/ts}</div>',
110 * @param string $html
111 * Example HTML input.
112 * @param array $expectedStrings
113 * List of expected strings.
114 * @dataProvider translateExamples
116 public function testParseStrings($html, $expectedStrings) {
117 // Magic! The JS parser works with HTML!
118 $actualStrings = CRM_Utils_JS
::parseStrings($html);
119 sort($expectedStrings);
120 sort($actualStrings);
121 $this->assertEquals($expectedStrings, $actualStrings);