remove incorrectly added (duplicate) test (only just added)
[civicrm-core.git] / tests / phpunit / CRM / Utils / JSTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 require_once 'CiviTest/CiviUnitTestCase.php';
29
30 /**
31 * Tests for linking to resource files
32 */
33 class CRM_Utils_JSTest extends CiviUnitTestCase {
34 /**
35 * @return array
36 */
37 function translateExamples() {
38 $cases = array();
39 $cases[] = array(
40 '',
41 array(),
42 );
43 $cases[] = array( // missing ts
44 'alert("Hello world")',
45 array(),
46 );
47 $cases[] = array( // basic function call
48 'alert(ts("Hello world"));',
49 array('Hello world'),
50 );
51 $cases[] = array( // with arg
52 'alert(ts("Hello world", {1: "whiz"}));',
53 array('Hello world'),
54 );
55 $cases[] = array( // not really ts()
56 'alert(clients("Hello world"));',
57 array(),
58 );
59 $cases[] = array( // not really ts()
60 'alert(clients("Hello world", {1: "whiz"}));',
61 array(),
62 );
63 $cases[] = array( // with arg
64 '
65 function whits() {
66 for (a in b) {
67 mitts("wallaby", function(zoo){
68 alert(zoo + ts("Hello"))
69 });
70 }
71 }
72 ',
73 array('Hello'),
74 );
75 $cases[] = array( // duplicate
76 'alert(ts("Hello world") + "-" + ts("Hello world"));',
77 array('Hello world'),
78 );
79 $cases[] = array( // two strings, addition
80 'alert(ts("Hello world") + "-" + ts("How do you do?"));',
81 array('Hello world', 'How do you do?'),
82 );
83 $cases[] = array( // two strings, separate calls
84 'alert(ts("Hello world");\nalert(ts("How do you do?"));',
85 array('Hello world', 'How do you do?'),
86 );
87 $cases[] = array(
88 'alert(ts(\'Single quoted\'));',
89 array('Single quoted'),
90 );
91 $cases[] = array( // unclear string
92 'alert(ts(message));',
93 array(),
94 );
95 $cases[] = array( // ts() within a string
96 'alert(ts("Does the ts(\'example\') notation work?"));',
97 array('Does the ts(\'example\') notation work?'),
98 );
99 return $cases;
100 }
101
102 /**
103 * @param string $jsCode
104 * @param array $expectedStrings
105 * @dataProvider translateExamples
106 */
107 function testParseStrings($jsCode, $expectedStrings) {
108 $actualStrings = CRM_Utils_JS::parseStrings($jsCode);
109 sort($expectedStrings);
110 sort($actualStrings);
111 $this->assertEquals($expectedStrings, $actualStrings);
112 }
113 }