. /** * Unit tests for ../deprecatedlib.php. * * @package moodlecore * @copyright 2009 Tim Hunt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later (5) */ if (!defined('MOODLE_INTERNAL')) { die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page } require_once($CFG->libdir . '/deprecatedlib.php'); class outputlib_methods_test extends UnitTestCase { public function test_print_single_button() { global $PAGE, $CFG; // Basic params, absolute URL $link = 'http://www.test.com/index.php'; $options = array('param1' => 'value1'); $label = 'OK'; $method = 'get'; $return = true; $tooltip = ''; $disabled = false; $jsconfirmmessage = ''; $formid = ''; $html = print_single_button($link, $options, $label, $method, '', $return, $tooltip, $disabled, $jsconfirmmessage, $formid); $this->assert(new ContainsTagWithAttributes('form', array('method' => $method, 'action' => $link)), $html); $this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'param1', 'value' => 'value1')), $html); $this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => 'OK')), $html); // URL with & params $newlink = $link . '?param1=value1&param2=value2'; $html = print_single_button($newlink, $options, $label, $method, '', $return, $tooltip, $disabled, $jsconfirmmessage, $formid); $this->assert(new ContainsTagWithAttributes('form', array('method' => $method, 'action' => $link)), $html); $this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'param1', 'value' => 'value1')), $html); $this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => 'OK')), $html); // URL with & params $newlink = $link . '?param1=value1¶m2=value2'; $html = print_single_button($newlink, $options, $label, $method, '', $return, $tooltip, $disabled, $jsconfirmmessage, $formid); $this->assert(new ContainsTagWithAttributes('form', array('method' => $method, 'action' => $link)), $html); $this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'param1', 'value' => 'value1')), $html); $this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => 'OK')), $html); // relative URL with & params $newlink = 'index.php?param1=value1¶m2=value2'; $oldurl = $PAGE->url; $PAGE->set_url('index.php'); $html = print_single_button($newlink, $options, $label, $method, '', $return, $tooltip, $disabled, $jsconfirmmessage, $formid); $this->assert(new ContainsTagWithAttributes('form', array('method' => $method, 'action' => $CFG->wwwroot . '/index.php')), $html); $this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'param1', 'value' => 'value1')), $html); $this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => 'OK')), $html); $PAGE->set_url($oldurl); } }