MDL-49294 logging: Improve cleanup tests
[moodle.git] / lib / tests / string_manager_standard_test.php
blob6ae3bbe9d37a5bbac214c9d0f658ae3df667da9d
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Unit tests for localization support in lib/moodlelib.php
20 * @package core
21 * @category phpunit
22 * @copyright 2013 David Mudrak <david@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 global $CFG;
29 require_once($CFG->libdir.'/moodlelib.php');
31 /**
32 * Tests for the API of the string_manager.
34 * @copyright 2013 David Mudrak <david@moodle.com>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class core_string_manager_standard_testcase extends advanced_testcase {
39 public function test_string_manager_instance() {
40 $this->resetAfterTest();
42 $otherroot = dirname(__FILE__).'/fixtures/langtest';
43 $stringman = testable_core_string_manager::instance($otherroot);
44 $this->assertInstanceOf('core_string_manager', $stringman);
47 public function test_get_language_dependencies() {
48 $this->resetAfterTest();
50 $otherroot = dirname(__FILE__).'/fixtures/langtest';
51 $stringman = testable_core_string_manager::instance($otherroot);
53 // There is no parent language for 'en'.
54 $this->assertSame(array(), $stringman->get_language_dependencies('en'));
55 // Language with no parent language declared.
56 $this->assertSame(array('aa'), $stringman->get_language_dependencies('aa'));
57 // Language with parent language explicitly set to English (en < de).
58 $this->assertSame(array('de'), $stringman->get_language_dependencies('de'));
59 // Language dependency hierarchy (de < de_du < de_kids).
60 $this->assertSame(array('de', 'de_du', 'de_kids'), $stringman->get_language_dependencies('de_kids'));
61 // Language with the parent language misconfigured to itself (sd < sd).
62 $this->assertSame(array('sd'), $stringman->get_language_dependencies('sd'));
63 // Language with circular dependency (cda < cdb < cdc < cda).
64 $this->assertSame(array('cda', 'cdb', 'cdc'), $stringman->get_language_dependencies('cdc'));
65 // Orphaned language (N/A < bb).
66 $this->assertSame(array('bb'), $stringman->get_language_dependencies('bb'));
67 // Descendant of an orphaned language (N/A < bb < bc).
68 $this->assertSame(array('bb', 'bc'), $stringman->get_language_dependencies('bc'));
73 /**
74 * Helper class providing testable string_manager
76 * @copyright 2013 David Mudrak <david@moodle.com>
77 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
79 class testable_core_string_manager extends core_string_manager_standard {
81 /**
82 * Factory method
84 * @param string $otherroot full path to the location of installed upstream language packs
85 * @param string $localroot full path to the location of locally customized language packs, defaults to $otherroot
86 * @param bool $usecache use application permanent cache
87 * @param array $translist explicit list of visible translations
88 * @param string $menucache the location of a file that caches the list of available translations
89 * @return testable_core_string_manager
91 public static function instance($otherroot, $localroot = null, $usecache = false, array $translist = array(), $menucache = null) {
92 global $CFG;
94 if (is_null($localroot)) {
95 $localroot = $otherroot;
98 if (is_null($menucache)) {
99 $menucache = $CFG->cachedir.'/languages';
102 return new testable_core_string_manager($otherroot, $localroot, $usecache, $translist, $menucache);