Commit | Line | Data |
---|---|---|
fd7dc3f3 TO |
1 | <?php |
2 | /* | |
7d61e75f TO |
3 | +--------------------------------------------------------------------+ |
4 | | Copyright CiviCRM LLC. All rights reserved. | | |
5 | | | | |
6 | | This work is published under the GNU AGPLv3 license with some | | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
9 | +--------------------------------------------------------------------+ | |
cbcb7579 | 10 | */ |
fd7dc3f3 | 11 | |
fd7dc3f3 TO |
12 | /** |
13 | * Tests for parsing translatable strings in HTML content. | |
acb109b7 | 14 | * @group headless |
fd7dc3f3 TO |
15 | */ |
16 | class CRM_Core_Resources_StringsTest extends CiviUnitTestCase { | |
17 | ||
18 | /** | |
19 | * Get strings from files. | |
20 | */ | |
21 | public function testGet() { | |
22 | $basedir = $this->createExamples(); | |
23 | $strings = new CRM_Core_Resources_Strings( | |
24 | new CRM_Utils_Cache_Arraycache(NULL) | |
25 | ); | |
26 | $this->assertEquals( | |
9099cab3 | 27 | ['Hello from Javascript'], |
fd7dc3f3 TO |
28 | $strings->get('example', "$basedir/hello.js", "text/javascript") |
29 | ); | |
30 | $this->assertEquals( | |
9099cab3 | 31 | ['Hello from HTML'], |
fd7dc3f3 TO |
32 | $strings->get('example', "$basedir/hello.html", "text/html") |
33 | ); | |
34 | } | |
35 | ||
36 | /** | |
37 | * @return string | |
38 | * Path to the example dir. | |
39 | */ | |
40 | public function createExamples() { | |
41 | $basedir = rtrim($this->createTempDir('ext-'), '/'); | |
42 | file_put_contents("$basedir/hello.js", "alert(ts('Hello from Javascript'));"); | |
43 | file_put_contents("$basedir/hello.html", "<div>{{ts('Hello from HTML')}}</div>"); | |
44 | return $basedir; | |
45 | } | |
cbcb7579 | 46 | |
fd7dc3f3 | 47 | } |