display.lib.test.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. require_once(api_get_path(LIBRARY_PATH).'display.lib.php');
  3. class TestDisplay extends UnitTestCase {
  4. public function __construct(){
  5. $this->UnitTestCase('Display library - main/inc/display.lib.test.php');
  6. }
  7. public function testdisplay_introduction_section() {
  8. $tool=api_get_tools_lists($my_tool=null);
  9. ob_start();
  10. $res = Display::display_introduction_section($tool);
  11. ob_end_clean();
  12. $this->assertTrue(is_array($tool));
  13. //var_dump($tool);
  14. }
  15. public function testdisplay_localised_html_file(){
  16. global $language_interface;
  17. $doc_url = str_replace('/..', '', $doc_url);
  18. $full_file_name=api_get_path(SYS_COURSE_PATH).'/index'.$doc_url;
  19. ob_start();
  20. $res = Display::display_localised_html_file($full_file_name);
  21. ob_end_clean();
  22. $this->assertTrue(is_string($full_file_name));
  23. //var_dump($full_file_name);
  24. }
  25. public function testdisplay_sortable_table() {
  26. $header='';
  27. $content='';
  28. global $origin;
  29. ob_start();
  30. $res=Display::display_sortable_table($header, $content);
  31. ob_end_clean();
  32. $this->assertNull($res);
  33. //var_dump($res);
  34. }
  35. /**
  36. * Display a table with a special configuration
  37. * @param array $header Titles for the table header
  38. * each item in this array can contain 3 values
  39. * - 1st element: the column title
  40. * - 2nd element: true or false (column sortable?)
  41. * - 3th element: additional attributes for
  42. * th-tag (eg for column-width)
  43. * - 4the element: additional attributes for the td-tags
  44. * @param array $content 2D-array with the tables content
  45. * @return void String about header
  46. */
  47. public function testdisplay_sortable_config_table() {
  48. $header='';
  49. $content='';
  50. global $origin;
  51. ob_start();
  52. $res=Display::display_sortable_config_table($header, $content);
  53. ob_end_clean();
  54. $this->assertNull($res);
  55. //var_dump($res);
  56. }
  57. /**
  58. * Displays a normal message. It is recommended to use this public function
  59. * to display any normal information messages.
  60. *
  61. * @param string $message - include any additional html
  62. * tags if you need them
  63. * @param bool Filter (true) or not (false)
  64. * @return void String message
  65. */
  66. public function testdisplay_normal_message() {
  67. global $charset;
  68. $message=api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : $charset);
  69. ob_start();
  70. $res=Display::display_normal_message($message);
  71. ob_end_clean();
  72. $this->assertNull($res);
  73. //var_dump($res);
  74. }
  75. /**
  76. * Display the reduced page header (without banner)
  77. */
  78. // [/var/www/chamilo/main/inc/reduced_header.inc.php line 30] - exception
  79. /* public function testdisplay_reduced_header() {
  80. global $_plugins,$lp_theme_css,$mycoursetheme,$user_theme,$platform_theme;
  81. global $httpHeadXtra, $htmlHeadXtra, $htmlIncHeadXtra, $_course, $_user, $text_dir, $plugins, $_user, $_cid, $interbreadcrumb, $charset, $language_file, $noPHP_SELF, $language_interface;
  82. global $menu_navigation;
  83. ob_start();
  84. $res=Display::display_reduced_header();
  85. ob_end_clean();
  86. $this->assertNull($res);
  87. //var_dump($res);
  88. }
  89. */
  90. /**
  91. * Displays an confirmation message. Use this if something has been done successfully
  92. *
  93. * @param string $message
  94. * @param bool Filter (true) or not (false)
  95. * @return void String message
  96. */
  97. public function testdisplay_confirmation_message() {
  98. global $charset;
  99. $message=api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : $charset);
  100. ob_start();
  101. $res=Display::display_confirmation_message($message);
  102. ob_end_clean();
  103. $this->assertTrue(is_string($message));
  104. //var_dump($message);
  105. }
  106. /**
  107. * Displays an error message.
  108. * @author Arthur Portugal
  109. * @param string $message - include any additional html tags if you need them
  110. * @param bool Filter (true) or not (false)
  111. * @param object Not display the object in the test browser
  112. * @return string Code HTML
  113. */
  114. public function testdisplay_error_message() {
  115. global $charset;
  116. $message = "error message";
  117. ob_start();
  118. $res=Display::display_error_message($message);
  119. ob_end_clean();
  120. $this->assertTrue(is_string($message));
  121. //var_dump($message);
  122. }
  123. /**
  124. * Display the page footer
  125. * @author Arthur Portugal
  126. * @return string Code HTML about the footer
  127. */
  128. /* public function testdisplay_footer() {
  129. global $_plugins;
  130. ob_start();
  131. $res=Display::display_footer();
  132. ob_end_clean();
  133. $this->assertNull($res);
  134. //var_dump($res);
  135. }
  136. */
  137. /**
  138. * Display the page header
  139. * @param string The name of the page (will be showed in the page title)
  140. * @param string Optional help file name
  141. * @return string Display the hearders messages
  142. */
  143. // [/var/www/chamilo/main/inc/header.inc.php line 31] - exception
  144. /* public function testdisplay_header() {
  145. global $_plugins,$lp_theme_css,$mycoursetheme,$user_theme,$platform_theme;
  146. global $httpHeadXtra, $htmlHeadXtra, $htmlIncHeadXtra, $_course, $_user, $text_dir, $plugins, $_user, $rootAdminWeb, $_cid, $interbreadcrumb, $charset, $language_file, $noPHP_SELF;
  147. global $menu_navigation;
  148. $tool_name = '';
  149. $help = NULL;
  150. $nameTools = $tool_name;
  151. ob_start();
  152. $res=Display::display_header($tool_name, $help);
  153. ob_end_clean();
  154. $this->assertNull($res);
  155. //var_dump($res);
  156. }
  157. */
  158. /**
  159. * This public function displays an icon
  160. * @param string $image the filename of the file (in the main/img/ folder
  161. * @param string $alt_text the alt text (probably a language variable)
  162. * @param array additional attributes (for instance height, width, onclick, ...)
  163. * @return return icon like string in this test (path)
  164. */
  165. public function testdisplay_icon() {
  166. $image='file';
  167. ob_start();
  168. $res=Display::display_icon($image);
  169. ob_end_clean();
  170. $this->assertNull($res);
  171. //var_dump($res);
  172. }
  173. /**
  174. * Displays an warning message. Use this if you want to draw attention to something
  175. *
  176. * @author Arthur Portugal
  177. * @param string $message
  178. * @param bool Filter (true) or not (false)
  179. * @return string with the message (also void)
  180. */
  181. public function testdisplay_warning_message() {
  182. $message="warning-message";
  183. ob_start();
  184. $res=Display::display_warning_message($message);
  185. ob_end_clean();
  186. $this->assertNull($res);
  187. //var_dump($res);
  188. }
  189. /**
  190. * Return an encrypted mailto hyperlink
  191. * @author Arthur Portugal
  192. * @param - $email (string) - e-mail
  193. * @return - encrypted mailto hyperlink
  194. */
  195. public function testencrypted_mailto_link() {
  196. $email='';
  197. $clickable_text = null;
  198. $style_class = '';
  199. ob_start();
  200. $res=Display::encrypted_mailto_link($email, $clickable_text, $style_class);
  201. ob_end_clean();
  202. $this->assertTrue(is_string($res));
  203. //var_dump($res);
  204. }
  205. /**
  206. * Print an <option>-list with all letters (A-Z).
  207. * @param char $selected_letter The letter that should be selected
  208. */
  209. public function testget_alphabet_options() {
  210. $selected_letter = 5;
  211. ob_start();
  212. $res=Display::get_alphabet_options();
  213. ob_end_clean();
  214. $this->assertTrue(is_string($res));
  215. //var_dump($res);
  216. }
  217. public function testget_numeric_options() {
  218. $min='';
  219. $max='';
  220. ob_start();
  221. $res=Display::get_numeric_options($min,$max);
  222. ob_end_clean();
  223. $this->assertTrue(is_string($res));
  224. //var_dump($res);
  225. }
  226. /**
  227. * Create a hyperlink to the platform homepage.
  228. * @param string $name, the visible name of the hyperlink, default is sitename
  229. * @return string with html code for hyperlink
  230. */
  231. public function testget_platform_home_link_html() {
  232. ob_start();
  233. $res=Display::get_platform_home_link_html();
  234. ob_end_clean();
  235. $this->assertTrue(is_string($res));
  236. //var_dump($res);
  237. }
  238. /**
  239. * This public function returns the htmlcode for an icon
  240. *
  241. * @param string $image the filename of the file (in the main/img/ folder
  242. * @param string $alt_text the alt text (probably a language variable)
  243. * @param array additional attributes (for instance height, width, onclick, ...)
  244. *
  245. */
  246. public function testreturn_icon() {
  247. $image='';
  248. ob_start();
  249. $res=Display::return_icon($image);
  250. ob_end_clean();
  251. //$res=ob_get_contents();
  252. $this->assertTrue(is_string($res));
  253. //var_dump($res);
  254. }
  255. }