3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 linking to resource files
33 class CRM_Utils_JSTest
extends CiviUnitTestCase
{
37 public function translateExamples() {
43 $cases[] = array(// missing ts
44 'alert("Hello world")',
47 $cases[] = array(// basic function call
48 'alert(ts("Hello world"));',
51 $cases[] = array(// with arg
52 'alert(ts("Hello world", {1: "whiz"}));',
55 $cases[] = array(// not really ts()
56 'alert(clients("Hello world"));',
59 $cases[] = array(// not really ts()
60 'alert(clients("Hello world", {1: "whiz"}));',
63 $cases[] = array(// with arg
65 "public function whits() {\n" .
67 " mitts(\"wallaby\", function(zoo) {\n" .
68 " alert(zoo + ts(\"Hello\"))\n" .
74 $cases[] = array(// duplicate
75 'alert(ts("Hello world") + "-" + ts("Hello world"));',
78 $cases[] = array(// two strings, addition
79 'alert(ts("Hello world") + "-" + ts("How do you do?"));',
80 array('Hello world', 'How do you do?'),
82 $cases[] = array(// two strings, separate calls
83 'alert(ts("Hello world");\nalert(ts("How do you do?"));',
84 array('Hello world', 'How do you do?'),
87 'alert(ts(\'Single quoted\'));',
88 array('Single quoted'),
90 $cases[] = array(// unclear string
91 'alert(ts(message));',
94 $cases[] = array(// ts() within a string
95 'alert(ts("Does the ts(\'example\') notation work?"));',
96 array('Does the ts(\'example\') notation work?'),
102 * @param string $jsCode
103 * @param array $expectedStrings
104 * @dataProvider translateExamples
106 public function testParseStrings($jsCode, $expectedStrings) {
107 $actualStrings = CRM_Utils_JS
::parseStrings($jsCode);
108 sort($expectedStrings);
109 sort($actualStrings);
110 $this->assertEquals($expectedStrings, $actualStrings);