PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/simpletest/testhtmlwriter.php

https://github.com/kpike/moodle
PHP | 94 lines | 49 code | 18 blank | 27 comment | 1 complexity | 1737168786adcfed260acccb2cd04c82 MD5 | raw file
  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. * Unit tests for the html_writer class.
  18. *
  19. * @package moodlecore
  20. * @copyright 2010 Tim Hunt
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. if (!defined('MOODLE_INTERNAL')) {
  24. die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
  25. }
  26. require_once($CFG->libdir . '/outputcomponents.php');
  27. /**
  28. * Unit tests for the html_writer class.
  29. *
  30. * @copyright 2010 Tim Hunt
  31. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32. */
  33. class html_writer_test extends UnitTestCase {
  34. public static $includecoverage = array('lib/outputcomponents.php');
  35. public function test_start_tag() {
  36. $this->assertEqual('<div>', html_writer::start_tag('div'));
  37. }
  38. public function test_start_tag_with_attr() {
  39. $this->assertEqual('<div class="frog">',
  40. html_writer::start_tag('div', array('class' => 'frog')));
  41. }
  42. public function test_start_tag_with_attrs() {
  43. $this->assertEqual('<div class="frog" id="mydiv">',
  44. html_writer::start_tag('div', array('class' => 'frog', 'id' => 'mydiv')));
  45. }
  46. public function test_end_tag() {
  47. $this->assertEqual('</div>', html_writer::end_tag('div'));
  48. }
  49. public function test_empty_tag() {
  50. $this->assertEqual('<br />', html_writer::empty_tag('br'));
  51. }
  52. public function test_empty_tag_with_attrs() {
  53. $this->assertEqual('<input type="submit" value="frog" />',
  54. html_writer::empty_tag('input', array('type' => 'submit', 'value' => 'frog')));
  55. }
  56. public function test_nonempty_tag_with_content() {
  57. $this->assertEqual('<div>Hello world!</div>',
  58. html_writer::nonempty_tag('div', 'Hello world!'));
  59. }
  60. public function test_nonempty_tag_empty() {
  61. $this->assertEqual('',
  62. html_writer::nonempty_tag('div', ''));
  63. }
  64. public function test_nonempty_tag_null() {
  65. $this->assertEqual('',
  66. html_writer::nonempty_tag('div', null));
  67. }
  68. public function test_nonempty_tag_zero() {
  69. $this->assertEqual('<div class="score">0</div>',
  70. html_writer::nonempty_tag('div', 0, array('class' => 'score')));
  71. }
  72. public function test_nonempty_tag_zero_string() {
  73. $this->assertEqual('<div class="score">0</div>',
  74. html_writer::nonempty_tag('div', '0', array('class' => 'score')));
  75. }
  76. }