mirror of
https://github.com/moodle/moodle.git
synced 2025-01-30 03:58:34 +01:00
MDL-20204 fianl cleanup - removing obsolete renderer stuff
This commit is contained in:
parent
d9df2a8993
commit
4ed857901a
@ -1022,7 +1022,7 @@ class js_writer {
|
||||
// TODO: Following components will be refactored soon
|
||||
|
||||
/**
|
||||
* Base class for classes representing HTML elements, like html_select.
|
||||
* Base class for classes representing HTML elements.
|
||||
*
|
||||
* Handles the id and class attributes.
|
||||
*
|
||||
@ -1300,360 +1300,6 @@ class html_label extends html_component {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This class hold all the information required to describe a <select> menu that
|
||||
* will be printed by {@link core_renderer::select()}. (Or by an overridden
|
||||
* version of that method in a subclass.)
|
||||
*
|
||||
* This component can also hold enough metadata to be used as a popup form. It just
|
||||
* needs a bit more setting up than for a simple menu. See the shortcut methods for
|
||||
* developer-friendly usage.
|
||||
*
|
||||
* All the fields that are not set by the constructor have sensible defaults, so
|
||||
* you only need to set the properties where you want non-default behaviour.
|
||||
*
|
||||
* @copyright 2009 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class html_select extends labelled_html_component {
|
||||
/**
|
||||
* The html_select object parses an array of options into component objects
|
||||
* @see nested attribute
|
||||
* @var mixed $options the choices to show in the menu. An array $value => $display, of html_select_option or of html_select_optgroup objects.
|
||||
*/
|
||||
public $options;
|
||||
/**
|
||||
* @var string $name the name of this form control. That is, the name of the GET/POST
|
||||
* variable that will be set if this select is submitted as part of a form.
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* @var string $selectedvalue the option to select initially. Should match one
|
||||
* of the $options array keys. Default none.
|
||||
*/
|
||||
public $selectedvalue;
|
||||
/**
|
||||
* Defaults to get_string('choosedots').
|
||||
* Set this to '' if you do not want a 'nothing is selected' option.
|
||||
* This is ignored if the rendertype is 'radio' or 'checkbox'
|
||||
* @var string The label for the 'nothing is selected' option.
|
||||
*/
|
||||
public $nothinglabel = null;
|
||||
/**
|
||||
* @var string The value returned by the 'nothing is selected' option. Defaults to 0.
|
||||
*/
|
||||
public $nothingvalue = 0;
|
||||
/**
|
||||
* @var boolean set this to true if you want the control to appear disabled.
|
||||
*/
|
||||
public $disabled = false;
|
||||
/**
|
||||
* @var integer if non-zero, sets the tabindex attribute on the <select> element. Default 0.
|
||||
*/
|
||||
public $tabindex = 0;
|
||||
/**
|
||||
* @var mixed Defaults to false, which means display the select as a dropdown menu.
|
||||
* If true, display this select as a list box whose size is chosen automatically.
|
||||
* If an integer, display as list box of that size.
|
||||
*/
|
||||
public $listbox = false;
|
||||
/**
|
||||
* @var integer if you are using $listbox === true to get an automatically
|
||||
* sized list box, the size of the list box will be the number of options,
|
||||
* or this number, whichever is smaller.
|
||||
*/
|
||||
public $maxautosize = 10;
|
||||
/**
|
||||
* @var boolean if true, allow multiple selection. Only used if $listbox is true, or if
|
||||
* the select is to be output as checkboxes.
|
||||
*/
|
||||
public $multiple = false;
|
||||
/**
|
||||
* Another way to use nested menu is to prefix optgroup labels with -- and end the optgroup with --
|
||||
* Leave this setting to false if you are using the latter method.
|
||||
* @var boolean $nested if true, uses $options' keys as option headings (optgroup)
|
||||
*/
|
||||
public $nested = false;
|
||||
/**
|
||||
* @var html_form $form An optional html_form component
|
||||
*/
|
||||
public $form;
|
||||
/**
|
||||
* @var help_icon $array help icon params
|
||||
*/
|
||||
public $helpicon;
|
||||
/**
|
||||
* @var boolean $rendertype How the select element should be rendered: menu or radio (checkbox is just radio + multiple)
|
||||
*/
|
||||
public $rendertype = 'menu';
|
||||
|
||||
/**
|
||||
* @see html_component::prepare()
|
||||
* @return void
|
||||
*/
|
||||
public function prepare(renderer_base $output, moodle_page $page, $target) {
|
||||
global $CFG;
|
||||
|
||||
// name may contain [], which would make an invalid id. e.g. numeric question type editing form, assignment quickgrading
|
||||
if (empty($this->id)) {
|
||||
$this->id = 'menu' . str_replace(array('[', ']'), '', $this->name);
|
||||
}
|
||||
|
||||
if (empty($this->classes)) {
|
||||
$this->set_classes(array('menu' . str_replace(array('[', ']'), '', $this->name)));
|
||||
}
|
||||
|
||||
if (is_null($this->nothinglabel)) {
|
||||
$this->nothinglabel = get_string('choosedots');
|
||||
}
|
||||
|
||||
if (!empty($this->label) && !($this->label instanceof html_label)) {
|
||||
$label = new html_label();
|
||||
$label->text = $this->label;
|
||||
$label->for = $this->name;
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
$this->add_class('select');
|
||||
|
||||
$this->initialise_options();
|
||||
parent::prepare($output, $page, $target);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a shortcut for making a simple select menu. It lets you specify
|
||||
* the options, name and selected option in one line of code.
|
||||
* @param array $options used to initialise {@link $options}.
|
||||
* @param string $name used to initialise {@link $name}.
|
||||
* @param string $selected used to initialise {@link $selected}.
|
||||
* @param string $nothinglabel The label for the 'nothing is selected' option. Defaults to "Choose..."
|
||||
* @return html_select A html_select object with the three common fields initialised.
|
||||
*/
|
||||
public static function make($options, $name, $selected = '', $nothinglabel='choosedots') {
|
||||
$menu = new html_select();
|
||||
$menu->options = $options;
|
||||
$menu->name = $name;
|
||||
$menu->selectedvalue = $selected;
|
||||
return $menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a help icon next to the select menu.
|
||||
*
|
||||
* <pre>
|
||||
* $select->set_help_icon($page, $text, $component);
|
||||
* </pre>
|
||||
*
|
||||
* @param string $helppage Either the keyword that defines a help page or a help_icon object
|
||||
* @param text $text The text of the help icon
|
||||
* @param component $component
|
||||
* @param boolean $linktext Whether or not to show text next to the icon
|
||||
* @return void
|
||||
*/
|
||||
public function set_help_icon($helppage='', $text='', $component='moodle') {
|
||||
if ($helppage) {
|
||||
$this->helpicon = array('helppage'=>$helppage, 'text'=>$text, 'component'=>$component);
|
||||
} else {
|
||||
$this->helpicon = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the $options array and instantiates html_select_option objects in
|
||||
* the place of the original value => label pairs. This is useful for when you
|
||||
* need to setup extra html attributes and actions on individual options before
|
||||
* the component is sent to the renderer
|
||||
* @return void;
|
||||
*/
|
||||
public function initialise_options() {
|
||||
// If options are already instantiated objects, stop here
|
||||
$firstoption = reset($this->options);
|
||||
if ($firstoption instanceof html_select_option || $firstoption instanceof html_select_optgroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->rendertype == 'radio' && $this->multiple) {
|
||||
$this->rendertype = 'checkbox';
|
||||
}
|
||||
|
||||
// If nested is on, or if radio/checkbox rendertype is set, remove the default Choose option
|
||||
if ($this->nested || $this->rendertype == 'radio' || $this->rendertype == 'checkbox') {
|
||||
$this->nothinglabel = '';
|
||||
}
|
||||
|
||||
$options = $this->options;
|
||||
|
||||
$this->options = array();
|
||||
|
||||
if ($this->nested && $this->rendertype != 'menu') {
|
||||
throw new coding_exception('html_select cannot render nested options as radio buttons or checkboxes.');
|
||||
} else if ($this->nested) {
|
||||
foreach ($options as $section => $values) {
|
||||
$optgroup = new html_select_optgroup();
|
||||
$optgroup->text = $section;
|
||||
|
||||
foreach ($values as $value => $display) {
|
||||
$option = new html_select_option();
|
||||
$option->value = s($value);
|
||||
$option->text = $display;
|
||||
if ($display === '') {
|
||||
$option->text = $value;
|
||||
}
|
||||
|
||||
if ((string) $value == (string) $this->selectedvalue ||
|
||||
(is_array($this->selectedvalue) && in_array($value, $this->selectedvalue))) {
|
||||
$option->selected = 'selected';
|
||||
}
|
||||
|
||||
$optgroup->options[] = $option;
|
||||
}
|
||||
|
||||
$this->options[] = $optgroup;
|
||||
}
|
||||
} else {
|
||||
$inoptgroup = false;
|
||||
$optgroup = false;
|
||||
|
||||
foreach ($options as $value => $display) {
|
||||
if ($display == '--') { /// we are ending previous optgroup
|
||||
// $this->options[] = $optgroup;
|
||||
$inoptgroup = false;
|
||||
continue;
|
||||
} else if (substr($display,0,2) == '--') { /// we are starting a new optgroup
|
||||
if (!empty($optgroup->options)) {
|
||||
$this->options[] = $optgroup;
|
||||
}
|
||||
|
||||
$optgroup = new html_select_optgroup();
|
||||
$optgroup->text = substr($display,2); // stripping the --
|
||||
|
||||
$inoptgroup = true; /// everything following will be in an optgroup
|
||||
continue;
|
||||
|
||||
} else {
|
||||
// Add $nothing option if there are not optgroups
|
||||
if ($this->nothinglabel && empty($this->options[0]) && !$inoptgroup) {
|
||||
$nothingoption = new html_select_option();
|
||||
$nothingoption->value = 0;
|
||||
if (!empty($this->nothingvalue)) {
|
||||
$nothingoption->value = $this->nothingvalue;
|
||||
}
|
||||
$nothingoption->text = $this->nothinglabel;
|
||||
$this->options = array($nothingoption) + $this->options;
|
||||
}
|
||||
|
||||
$option = new html_select_option();
|
||||
$option->text = $display;
|
||||
|
||||
if ($display === '') {
|
||||
$option->text = $value;
|
||||
}
|
||||
|
||||
if ((string) $value == (string) $this->selectedvalue ||
|
||||
(is_array($this->selectedvalue) && in_array($value, $this->selectedvalue))) {
|
||||
$option->selected = 'selected';
|
||||
}
|
||||
|
||||
$option->value = s($value);
|
||||
|
||||
if ($inoptgroup) {
|
||||
$optgroup->options[] = $option;
|
||||
} else {
|
||||
$this->options[] = $option;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($optgroup) {
|
||||
$this->options[] = $optgroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This class represents a select option element
|
||||
*
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class html_select_option extends labelled_html_component {
|
||||
/**
|
||||
* @var string $value The value of this option (will be sent with form)
|
||||
*/
|
||||
public $value;
|
||||
/**
|
||||
* @var string $text The display value of the option
|
||||
*/
|
||||
public $text;
|
||||
/**
|
||||
* @var boolean $selected Whether or not this option is selected
|
||||
*/
|
||||
public $selected = false;
|
||||
/**
|
||||
* @var boolean $disabled Whether or not this option is disabled
|
||||
*/
|
||||
public $disabled = false;
|
||||
|
||||
public function __construct() {
|
||||
$this->label = new html_label();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see html_component::prepare()
|
||||
* @return void
|
||||
*/
|
||||
public function prepare(renderer_base $output, moodle_page $page, $target) {
|
||||
if (empty($this->text) && (string)$this->text!=='0') {
|
||||
throw new coding_exception('html_select_option requires a $text value.');
|
||||
}
|
||||
|
||||
if (empty($this->label->text)) {
|
||||
$this->set_label($this->text);
|
||||
} else if (!($this->label instanceof html_label)) {
|
||||
$this->set_label($this->label);
|
||||
}
|
||||
if (empty($this->id)) {
|
||||
$this->generate_id();
|
||||
}
|
||||
|
||||
parent::prepare($output, $page, $target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This class represents a select optgroup element
|
||||
*
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class html_select_optgroup extends html_component {
|
||||
/**
|
||||
* @var string $text The display value of the optgroup
|
||||
*/
|
||||
public $text;
|
||||
/**
|
||||
* @var array $options An array of html_select_option objects
|
||||
*/
|
||||
public $options = array();
|
||||
|
||||
public function prepare(renderer_base $output, moodle_page $page, $target) {
|
||||
if (empty($this->text)) {
|
||||
throw new coding_exception('html_select_optgroup requires a $text value.');
|
||||
}
|
||||
if (empty($this->options)) {
|
||||
throw new coding_exception('html_select_optgroup requires at least one html_select_option object');
|
||||
}
|
||||
parent::prepare($output, $page, $target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Holds all the information required to render a <table> by
|
||||
* {@see core_renderer::table()} or by an overridden version of that
|
||||
@ -2211,74 +1857,6 @@ class html_textarea extends html_component {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Component representing a simple form wrapper. Its purpose is mainly to enclose
|
||||
* a submit input with the appropriate action and hidden inputs.
|
||||
*
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class html_form extends html_component {
|
||||
/**
|
||||
* @var string $method post or get
|
||||
*/
|
||||
public $method = 'post';
|
||||
/**
|
||||
* If a string is given, it will be converted to a moodle_url during prepare()
|
||||
* @var mixed $url A moodle_url including params or a string
|
||||
*/
|
||||
public $url;
|
||||
/**
|
||||
* @var boolean $showbutton If true, the submit button will always be shown even if JavaScript is available
|
||||
*/
|
||||
public $showbutton = false;
|
||||
/**
|
||||
* @var string $targetwindow The name of the target page to open the linked page in.
|
||||
*/
|
||||
public $targetwindow = 'self';
|
||||
/**
|
||||
* @var html_button $button A submit button
|
||||
*/
|
||||
public $button;
|
||||
/**
|
||||
* @var boolean $jssubmitaction If true, the submit button will be hidden when JS is enabled
|
||||
*/
|
||||
public $jssubmitaction = false;
|
||||
/**
|
||||
* Constructor: sets up the other components in case they are needed
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = null) {
|
||||
parent::__construct($options);
|
||||
$this->button = new html_button();
|
||||
$this->button->text = get_string('go');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see lib/html_component#prepare()
|
||||
* @return void
|
||||
*/
|
||||
public function prepare(renderer_base $output, moodle_page $page, $target) {
|
||||
|
||||
if (empty($this->url)) {
|
||||
throw new coding_exception('A html_form must have a $url value (string or moodle_url).');
|
||||
}
|
||||
|
||||
if (is_string($this->url)) {
|
||||
$this->url = new moodle_url($this->url);
|
||||
}
|
||||
|
||||
if ($this->method == 'post') {
|
||||
// automatic CSRF protection
|
||||
$this->url->param('sesskey', sesskey());
|
||||
}
|
||||
|
||||
parent::prepare($output, $page, $target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Component representing a list.
|
||||
*
|
||||
|
@ -974,7 +974,7 @@ class core_renderer extends renderer_base {
|
||||
/**
|
||||
* Print a message along with button choices for Continue/Cancel
|
||||
*
|
||||
* If a string or moodle_url is given instead of a html_button, method defaults to post.
|
||||
* If a string or moodle_url is given instead of a single_button, method defaults to post.
|
||||
*
|
||||
* @param string $message The question to ask the user
|
||||
* @param single_button|moodle_url|string $continue The single_button component representing the Continue answer. Can also be a moodle_url or string URL
|
||||
@ -989,7 +989,7 @@ class core_renderer extends renderer_base {
|
||||
} else if ($continue instanceof moodle_url) {
|
||||
$continue = new single_button($continue, get_string('continue'), 'post');
|
||||
} else {
|
||||
throw new coding_exception('The continue param to $OUTPUT->confirm() must be either a URL (string/moodle_url) or a html_form instance.');
|
||||
throw new coding_exception('The continue param to $OUTPUT->confirm() must be either a URL (string/moodle_url) or a single_button instance.');
|
||||
}
|
||||
|
||||
if ($cancel instanceof single_button) {
|
||||
@ -999,7 +999,7 @@ class core_renderer extends renderer_base {
|
||||
} else if ($cancel instanceof moodle_url) {
|
||||
$cancel = new single_button($cancel, get_string('cancel'), 'get');
|
||||
} else {
|
||||
throw new coding_exception('The cancel param to $OUTPUT->confirm() must be either a URL (string/moodle_url) or a html_form instance.');
|
||||
throw new coding_exception('The cancel param to $OUTPUT->confirm() must be either a URL (string/moodle_url) or a single_button instance.');
|
||||
}
|
||||
|
||||
$output = $this->box_start('generalbox', 'notice');
|
||||
@ -1229,65 +1229,6 @@ class core_renderer extends renderer_base {
|
||||
return html_writer::tag('div', array('class' => $select->class), $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a html_form component and an optional rendered submit button,
|
||||
* outputs a HTML form with correct divs and inputs and a single submit button.
|
||||
* This doesn't render any other visible inputs. Use moodleforms for these.
|
||||
* @param html_form $form A html_form instance
|
||||
* @param string $contents HTML fragment to put inside the form. If given, must contain at least the submit button.
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
public function form(html_form $form, $contents=null) {
|
||||
$form = clone($form);
|
||||
$form->prepare($this, $this->page, $this->target);
|
||||
$this->prepare_event_handlers($form);
|
||||
$buttonoutput = null;
|
||||
|
||||
if (empty($contents) && !empty($form->button)) {
|
||||
debugging("You probably want to use \$OUTPUT->single_button(\$form), please read that function's documentation", DEBUG_DEVELOPER);
|
||||
} else if (empty($contents)) {
|
||||
$contents = html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('ok')));
|
||||
} else if (!empty($form->button)) {
|
||||
$form->button->prepare($this, $this->page, $this->target);
|
||||
$this->prepare_event_handlers($form->button);
|
||||
|
||||
$buttonattributes = array('class' => $form->button->get_classes_string(),
|
||||
'type' => 'submit',
|
||||
'value' => $form->button->text,
|
||||
'disabled' => $form->button->disabled ? 'disabled' : null,
|
||||
'id' => $form->button->id);
|
||||
|
||||
if ($form->jssubmitaction) {
|
||||
$buttonattributes['class'] .= ' hiddenifjs';
|
||||
}
|
||||
|
||||
$buttonoutput = html_writer::empty_tag('input', $buttonattributes);
|
||||
|
||||
// Hide the submit button if the button has a JS submit action
|
||||
if ($form->jssubmitaction) {
|
||||
$buttonoutput = html_writer::start_tag('div', array('id' => "noscript$form->id", 'class'=>'hiddenifjs')) . $buttonoutput . html_writer::end_tag('div');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$hiddenoutput = '';
|
||||
|
||||
foreach ($form->url->params() as $var => $val) {
|
||||
$hiddenoutput .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $var, 'value' => $val));
|
||||
}
|
||||
|
||||
$formattributes = array(
|
||||
'method' => $form->method,
|
||||
'action' => $form->url->out_omit_querystring(),
|
||||
'id' => $form->id,
|
||||
'class' => $form->get_classes_string());
|
||||
|
||||
$divoutput = html_writer::tag('div', array(), $hiddenoutput . $contents . $buttonoutput);
|
||||
$output = html_writer::tag('form', $formattributes, $divoutput);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string containing a link to the user documentation.
|
||||
* Also contains an icon by default. Shown to teachers and admin only.
|
||||
@ -1772,46 +1713,6 @@ class core_renderer extends renderer_base {
|
||||
return $this->container($this->render($button), 'closewindow');
|
||||
}
|
||||
|
||||
/**
|
||||
* Output an <option> or <optgroup> element. If an optgroup element is detected,
|
||||
* this will recursively output its options as well.
|
||||
*
|
||||
* @param mixed $option a html_select_option or html_select_optgroup
|
||||
* @return string the HTML for the <option> or <optgroup>
|
||||
*/
|
||||
public function select_option($option) {
|
||||
$option = clone($option);
|
||||
$option->prepare($this, $this->page, $this->target);
|
||||
$this->prepare_event_handlers($option);
|
||||
|
||||
if ($option instanceof html_select_option) {
|
||||
return html_writer::tag('option', array(
|
||||
'value' => $option->value,
|
||||
'disabled' => $option->disabled ? 'disabled' : null,
|
||||
'class' => $option->get_classes_string(),
|
||||
'selected' => $option->selected ? 'selected' : null), $option->text);
|
||||
} else if ($option instanceof html_select_optgroup) {
|
||||
$output = html_writer::start_tag('optgroup', array('label' => $option->text, 'class' => $option->get_classes_string()));
|
||||
foreach ($option->options as $selectoption) {
|
||||
$output .= $this->select_option($selectoption);
|
||||
}
|
||||
$output .= html_writer::end_tag('optgroup');
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a <label> element.
|
||||
* @param html_label $label A html_label object
|
||||
* @return HTML fragment
|
||||
*/
|
||||
public function label($label) {
|
||||
$label = clone($label);
|
||||
$label->prepare($this, $this->page, $this->target);
|
||||
$this->prepare_event_handlers($label);
|
||||
return html_writer::tag('label', array('for' => $label->for, 'class' => $label->get_classes_string()), $label->text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output an error message. By default wraps the error message in <span class="error">.
|
||||
* If the error message is blank, nothing is output.
|
||||
|
@ -606,35 +606,6 @@ class core_renderer_test extends UnitTestCase {
|
||||
|
||||
}
|
||||
|
||||
public function test_button() {
|
||||
global $CFG;
|
||||
$originalform = new html_form();
|
||||
$originalform->button->text = 'Click Here';
|
||||
$originalform->url = '/index.php';
|
||||
|
||||
$form = clone($originalform);
|
||||
|
||||
$html = $this->renderer->button($form);
|
||||
$this->assert(new ContainsTagWithAttribute('div', 'class', 'singlebutton'), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('form', array('method' => 'post', 'action' => $CFG->wwwroot . '/index.php')), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('value' => 'Click Here', 'type' => 'submit')), $html);
|
||||
|
||||
$form = clone($originalform);
|
||||
$form->button->confirmmessage = 'Are you sure?';
|
||||
|
||||
$html = $this->renderer->button($form);
|
||||
$this->assert(new ContainsTagWithAttribute('div', 'class', 'singlebutton'), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('form', array('method' => 'post', 'action' => $CFG->wwwroot . '/index.php')), $html);
|
||||
$this->assert(new ContainsTagWithAttribute('input', 'type', 'submit'), $html);
|
||||
|
||||
$form = clone($originalform);
|
||||
$form->url = new moodle_url($form->url, array('var1' => 'value1', 'var2' => 'value2'));
|
||||
$html = $this->renderer->button($form);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('name' => 'var1', 'type' => 'hidden', 'value' => 'value1')), $html);
|
||||
|
||||
}
|
||||
|
||||
public function test_link() {
|
||||
$link = new html_link();
|
||||
$link->url = 'http://test.com';
|
||||
@ -673,112 +644,6 @@ class core_renderer_test extends UnitTestCase {
|
||||
$html = $this->renderer->link($link->url->out());
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: consider the degree of detail in which we test HTML output, because
|
||||
* the unit tests may be run under a different theme, with different HTML
|
||||
* renderers. Maybe we should limit unit tests to standardwhite.
|
||||
*/
|
||||
public function test_confirm() {
|
||||
// Basic test with string URLs
|
||||
$continueurl = 'http://www.test.com/index.php?continue=1';
|
||||
$cancelurl = 'http://www.test.com/index.php?cancel=1';
|
||||
$message = 'Are you sure?';
|
||||
|
||||
$html = $this->renderer->confirm($message, $continueurl, $cancelurl);
|
||||
$this->assert(new ContainsTagWithAttributes('div', array('id' => 'notice', 'class' => 'box generalbox')), $html);
|
||||
$this->assert(new ContainsTagWithContents('p', $message), $html);
|
||||
$this->assert(new ContainsTagWithAttribute('div', 'class', 'buttons'), $html);
|
||||
$this->assert(new ContainsTagWithAttribute('div', 'class', 'singlebutton'), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('form', array('method' => 'post', 'action' => 'http://www.test.com/index.php')), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'continue', 'value' => 1)), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => get_string('continue'), 'class' => 'singlebutton')), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'cancel', 'value' => 1)), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => get_string('cancel'), 'class' => 'singlebutton')), $html);
|
||||
|
||||
// Use html_forms with default values, should produce exactly the same output as above
|
||||
$formcontinue = new html_form();
|
||||
$formcancel = new html_form();
|
||||
$formcontinue->url = new moodle_url($continueurl);
|
||||
$formcancel->url = new moodle_url($cancelurl);
|
||||
$formcontinue->button->text = get_string('continue');
|
||||
$formcancel->button->text = get_string('cancel');
|
||||
$html = $this->renderer->confirm($message, $formcontinue, $formcancel);
|
||||
$this->assert(new ContainsTagWithAttributes('div', array('id' => 'notice', 'class' => 'box generalbox')), $html);
|
||||
$this->assert(new ContainsTagWithContents('p', $message), $html);
|
||||
$this->assert(new ContainsTagWithAttribute('div', 'class', 'buttons'), $html);
|
||||
$this->assert(new ContainsTagWithAttribute('div', 'class', 'singlebutton'), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('form', array('method' => 'post', 'action' => 'http://www.test.com/index.php')), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'continue', 'value' => 1)), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => get_string('continue'), 'class' => 'singlebutton')), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'cancel', 'value' => 1)), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => get_string('cancel'), 'class' => 'singlebutton')), $html);
|
||||
|
||||
// Give the buttons some different labels
|
||||
$formcontinue = new html_form();
|
||||
$formcancel = new html_form();
|
||||
$formcontinue->url = new moodle_url($continueurl);
|
||||
$formcancel->url = new moodle_url($cancelurl);
|
||||
$formcontinue->button->text = 'Continue anyway';
|
||||
$formcancel->button->text = 'Wow OK, I get it, backing out!';
|
||||
$html = $this->renderer->confirm($message, $formcontinue, $formcancel);
|
||||
$this->assert(new ContainsTagWithAttributes('form', array('method' => 'post', 'action' => 'http://www.test.com/index.php')), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'continue', 'value' => 1)), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => $formcontinue->button->text, 'class' => 'singlebutton')), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'cancel', 'value' => 1)), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => $formcancel->button->text, 'class' => 'singlebutton')), $html);
|
||||
|
||||
// Change the method and add extra variables
|
||||
$formcontinue = new html_form();
|
||||
$formcancel = new html_form();
|
||||
$formcontinue->button->text = get_string('continue');
|
||||
$formcancel->button->text = get_string('cancel');
|
||||
$formcontinue->url = new moodle_url($continueurl, array('var1' => 'val1', 'var2' => 'val2'));
|
||||
$formcancel->url = new moodle_url($cancelurl, array('var3' => 'val3', 'var4' => 'val4'));
|
||||
$html = $this->renderer->confirm($message, $formcontinue, $formcancel);
|
||||
$this->assert(new ContainsTagWithAttributes('form', array('method' => 'post', 'action' => 'http://www.test.com/index.php')), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'continue', 'value' => 1)), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'var1', 'value' => 'val1')), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'var2', 'value' => 'val2')), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => get_string('continue'), 'class' => 'singlebutton')), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'cancel', 'value' => 1)), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => get_string('cancel'), 'class' => 'singlebutton')), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'var3', 'value' => 'val3')), $html);
|
||||
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'var4', 'value' => 'val4')), $html);
|
||||
|
||||
}
|
||||
|
||||
public function test_spacer() {
|
||||
global $CFG;
|
||||
|
||||
$spacer = new html_image();
|
||||
|
||||
$html = $this->renderer->spacer($spacer);
|
||||
$this->assert(new ContainsTagWithAttributes('img', array('class' => 'image spacer',
|
||||
'src' => $CFG->wwwroot . '/pix/spacer.gif',
|
||||
'alt' => ''
|
||||
)), $html);
|
||||
$spacer = new html_image();
|
||||
$spacer->src = $this->renderer->pix_url('myspacer');
|
||||
$spacer->alt = 'sometext';
|
||||
$spacer->add_class('my');
|
||||
|
||||
$html = $this->renderer->spacer($spacer);
|
||||
|
||||
$this->assert(new ContainsTagWithAttributes('img', array(
|
||||
'class' => 'my image spacer',
|
||||
'src' => $this->renderer->pix_url('myspacer'),
|
||||
'alt' => 'sometext')), $html);
|
||||
|
||||
}
|
||||
|
||||
public function test_paging_bar() {
|
||||
global $CFG;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user