Merge pull request #15948 from eileenmcnaughton/export_test
[civicrm-core.git] / tests / phpunit / CRM / Core / Resources / StringsTest.php
1 <?php
2 /*
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Tests for parsing translatable strings in HTML content.
14 * @group headless
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(
27 ['Hello from Javascript'],
28 $strings->get('example', "$basedir/hello.js", "text/javascript")
29 );
30 $this->assertEquals(
31 ['Hello from HTML'],
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 }
46
47 }