1 |
efrain |
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.
|
|
|
13 |
//
|
|
|
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/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Test factory for lib/outputfactories.php.
|
|
|
19 |
*
|
|
|
20 |
* @package core
|
|
|
21 |
* @category phpunit
|
|
|
22 |
* @copyright 2014 Damyon Wiese
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
defined('MOODLE_INTERNAL') || die();
|
|
|
27 |
|
|
|
28 |
global $CFG;
|
|
|
29 |
require_once($CFG->libdir . '/outputfactories.php');
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* This is renderer factory testing of the classname autoloading.
|
|
|
33 |
*
|
|
|
34 |
* @copyright 2014 Damyon Wiese
|
|
|
35 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
36 |
* @package core
|
|
|
37 |
* @category phpunit
|
|
|
38 |
*/
|
|
|
39 |
class test_output_factory extends renderer_factory_base {
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Constructor.
|
|
|
43 |
*
|
|
|
44 |
*/
|
|
|
45 |
public function __construct() {
|
|
|
46 |
// Leave the construct empty to override the parent.
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Not used - we want to test the autoloaded class locations - even if there are no classes yet.
|
|
|
51 |
*/
|
|
|
52 |
public function get_renderer(moodle_page $page, $component, $subtype = null, $target = null) {
|
|
|
53 |
throw new coding_exception('Do not call this function, this class is for testing only.');
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/*
|
|
|
57 |
* Return the list of classnames searched for by the standard_renderer_factory.
|
|
|
58 |
*
|
|
|
59 |
* @param string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
|
|
|
60 |
* @param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
|
|
|
61 |
* @param string $target one of rendering target constants
|
|
|
62 |
* @return string[] of classnames
|
|
|
63 |
*/
|
|
|
64 |
public function get_standard_renderer_factory_search_paths($component, $subtype = null, $target = null) {
|
|
|
65 |
$classnames = $this->standard_renderer_classnames($component, $subtype);
|
|
|
66 |
$searchtargets = array();
|
|
|
67 |
|
|
|
68 |
list($target, $suffix) = $this->get_target_suffix($target);
|
|
|
69 |
// Add all suffix versions first - to match the real search order.
|
|
|
70 |
foreach ($classnames as $classnamedetails) {
|
|
|
71 |
if ($classnamedetails['validwithoutprefix']) {
|
|
|
72 |
$newclassname = $classnamedetails['classname'] . $suffix;
|
|
|
73 |
$searchtargets[] = $newclassname;
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
// Add all non-suffixed versions now.
|
|
|
77 |
foreach ($classnames as $classnamedetails) {
|
|
|
78 |
if ($classnamedetails['validwithoutprefix']) {
|
|
|
79 |
$newclassname = $classnamedetails['classname'];
|
|
|
80 |
$searchtargets[] = $newclassname;
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
return $searchtargets;
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* Return the list of classnames searched for by the get_renderer method of theme_overridden_renderer.
|
|
|
89 |
*
|
|
|
90 |
* @param string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
|
|
|
91 |
* @param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
|
|
|
92 |
* @param string $target one of rendering target constants
|
|
|
93 |
* @return string[] of classnames
|
|
|
94 |
*/
|
|
|
95 |
public function get_theme_overridden_renderer_factory_search_paths($component, $subtype = null, $target = null) {
|
|
|
96 |
$themeprefixes = ['theme_child', 'theme_parent'];
|
|
|
97 |
$searchtargets = array();
|
|
|
98 |
$classnames = $this->standard_renderer_classnames($component, $subtype);
|
|
|
99 |
|
|
|
100 |
list($target, $suffix) = $this->get_target_suffix($target);
|
|
|
101 |
|
|
|
102 |
// Theme lib.php and renderers.php files are loaded automatically
|
|
|
103 |
// when loading the theme configs.
|
|
|
104 |
|
|
|
105 |
// First try the renderers with correct suffix.
|
|
|
106 |
foreach ($themeprefixes as $prefix) {
|
|
|
107 |
foreach ($classnames as $classnamedetails) {
|
|
|
108 |
if ($classnamedetails['validwithprefix']) {
|
|
|
109 |
if ($classnamedetails['autoloaded']) {
|
|
|
110 |
$newclassname = $prefix . $classnamedetails['classname'] . $suffix;
|
|
|
111 |
} else {
|
|
|
112 |
$newclassname = $prefix . '_' . $classnamedetails['classname'] . $suffix;
|
|
|
113 |
}
|
|
|
114 |
$searchtargets[] = $newclassname;
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
foreach ($classnames as $classnamedetails) {
|
|
|
119 |
if ($classnamedetails['validwithoutprefix']) {
|
|
|
120 |
$newclassname = $classnamedetails['classname'] . $suffix;
|
|
|
121 |
$searchtargets[] = $newclassname;
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
// Then try general renderer.
|
|
|
126 |
foreach ($themeprefixes as $prefix) {
|
|
|
127 |
foreach ($classnames as $classnamedetails) {
|
|
|
128 |
if ($classnamedetails['validwithprefix']) {
|
|
|
129 |
if ($classnamedetails['autoloaded']) {
|
|
|
130 |
$newclassname = $prefix . $classnamedetails['classname'];
|
|
|
131 |
} else {
|
|
|
132 |
$newclassname = $prefix . '_' . $classnamedetails['classname'];
|
|
|
133 |
}
|
|
|
134 |
$searchtargets[] = $newclassname;
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
// Final attempt - no prefix or suffix.
|
|
|
140 |
foreach ($classnames as $classnamedetails) {
|
|
|
141 |
if ($classnamedetails['validwithoutprefix']) {
|
|
|
142 |
$newclassname = $classnamedetails['classname'];
|
|
|
143 |
$searchtargets[] = $newclassname;
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
return $searchtargets;
|
|
|
147 |
}
|
|
|
148 |
}
|