Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

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