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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Tests for parsing translatable strings in HTML content.
33 class CRM_Utils_HTMLTest
extends CiviUnitTestCase
{
37 public function translateExamples() {
43 $cases[] = array(// missing ts
44 '<div>Hello world</div>',
47 $cases[] = array(// text, no arg
48 '<div>{{ts("Hello world")}}</div>',
51 $cases[] = array(// text, no arg, alternate text
52 '<div>{{ts("Good morning, Dave")}}</div>',
53 array('Good morning, Dave'),
55 $cases[] = array(// text, with arg
56 '<div>{{ts("Hello world", {1: "whiz"})}}</div>',
59 $cases[] = array(// text, not really ts(), no arg
60 '<div>{{clients("Hello world")}}</div>',
63 $cases[] = array(// text, not really ts(), with arg
64 '<div>{{clients("Hello world", {1: "whiz"})}}</div>',
67 $cases[] = array(// two strings, duplicate
68 '<div>{{ts("Hello world")}}</div> <p>{{ts("Hello world")}}</p>',
71 $cases[] = array(// two strings, addition
72 '<div>{{ts("Hello world") + "-" + ts("How do you do?")}}</p>',
73 array('Hello world', 'How do you do?'),
75 $cases[] = array(// two strings, separate calls
76 '<div>{{ts("Hello world")}}</div> <p>{{ts("How do you do?")}}</p>',
77 array('Hello world', 'How do you do?'),
79 $cases[] = array(// single quoted
80 '<div>{{ts(\'Hello world\')}}</div>',
83 $cases[] = array(// unclear string
84 '<div>{{ts(message)}}</div>',
87 $cases[] = array(// ts() within a string
88 '<div>{{ts("Does the ts(\'example\') notation work?")}}</div>',
89 array('Does the ts(\'example\') notation work?'),
91 $cases[] = array(// attribute, no arg
92 '<div crm-title="ts("Hello world")"></div>',
95 $cases[] = array(// attribute, with arg
96 '<div crm-title="ts("Hello world", {1: "whiz"})"></div>',
99 $cases[] = array(// attribute, two strings, with arg
100 '<div crm-title="ts("Hello world", {1: "whiz"}) + ts("How do you do, %1?", {2: "funky"})"></div>',
101 array('Hello world', 'How do you do, %1?'),
103 $cases[] = array(// 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);