glossary.lib.test.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. require_once(api_get_path(LIBRARY_PATH).'glossary.lib.php');
  3. class TestGlossary extends UnitTestCase {
  4. public function __construct() {
  5. $this->UnitTestCase('Glossary library - main/inc/lib/glossary.lib.test.php');
  6. //build a course for these tests
  7. TestManager::create_test_course('COURSEGLOSSARY');
  8. }
  9. public function __destruct() {
  10. TestManager::delete_test_course('COURSEGLOSSARY');
  11. }
  12. function testGetGlossaryTerms() {
  13. $res = GlossaryManager::get_glossary_terms();
  14. $this->assertTrue(is_array($res));
  15. }
  16. function testSaveGlossaryIncomplete() {
  17. $values = 'stuffing';
  18. ob_start();
  19. $res = GlossaryManager::save_glossary($values);
  20. ob_end_clean();
  21. $this->assertFalse($res);
  22. }
  23. function testSaveGlossaryComplete() {
  24. $values = array('glossary_title'=>'stuffing','glossary_description'=>'something to fill');
  25. ob_start();
  26. $res = GlossaryManager::save_glossary($values);
  27. ob_end_clean();
  28. $this->assertTrue(is_numeric($res));
  29. $this->assertTrue($res > 0);
  30. //clean
  31. ob_start();
  32. GlossaryManager::delete_glossary($res);
  33. ob_end_clean();
  34. }
  35. function testGetGlossaryTermByGlossaryIdIsString() {
  36. $glossary_id = 1;
  37. $res = GlossaryManager::get_glossary_term_by_glossary_id($glossary_id);
  38. $this->assertTrue(is_string($res));
  39. }
  40. function testGetGlossaryTermByGlossaryIdIsEmpty() {
  41. $glossary_id = 1000000;
  42. $res = GlossaryManager::get_glossary_term_by_glossary_id($glossary_id);
  43. $this->assertEqual($res,'');
  44. }
  45. function testGetGlossaryTermByGlossaryName() {
  46. $glossary_name = '';
  47. $res = GlossaryManager::get_glossary_term_by_glossary_name($glossary_name);
  48. $this->assertTrue(is_string($res));
  49. }
  50. function testUpdateGlossary() {
  51. ob_start();
  52. $values = '';
  53. $res = GlossaryManager::update_glossary($values);
  54. ob_end_clean();
  55. $this->assertFalse($res);
  56. }
  57. function testGetMaxGlossaryItem() {
  58. $res = GlossaryManager::get_max_glossary_item();
  59. $this->assertTrue(is_numeric($res));
  60. }
  61. function testGlossaryExists() {
  62. $term = '';
  63. $not_id = 1;
  64. $res = GlossaryManager::glossary_exists($term,$not_id);
  65. $this->assertTrue(is_bool($res));
  66. }
  67. function testGetGlossaryInformation() {
  68. $glossary_id = 1;
  69. $res = GlossaryManager::get_glossary_information($glossary_id);
  70. $this->assertTrue(is_bool($res));
  71. }
  72. function testDisplayGlossary() {
  73. ob_start();
  74. $res = GlossaryManager::display_glossary();
  75. ob_end_clean();
  76. $this->assertTrue(is_null($res));
  77. }
  78. function testDisplayGlossaryList() {
  79. ob_start();
  80. $res = GlossaryManager::display_glossary_list();
  81. ob_end_clean();
  82. $this->assertTrue($res);
  83. }
  84. function testGetNumberGlossaryTerms() {
  85. $res = GlossaryManager::get_number_glossary_terms();
  86. $this->assertTrue(is_numeric($res));
  87. }
  88. function testGetGlossaryData() {
  89. $from = 1;
  90. $number_of_items = 2;
  91. $column = 1;
  92. $direction = 'ASC';
  93. $res = GlossaryManager::get_glossary_data($from, $number_of_items, $column, $direction);
  94. $this->assertTrue(is_array($res));
  95. }
  96. function testActionsFilter() {
  97. $glossary_id = 1;
  98. $url_params = '';
  99. $row = '';
  100. $res = GlossaryManager::actions_filter($glossary_id,$url_params,$row);
  101. $this->assertTrue(is_string($res));
  102. }
  103. function testJavascriptGlossary() {
  104. $res = GlossaryManager::javascript_glossary();
  105. $this->assertTrue(is_string($res));
  106. }
  107. function testReorderGlossary() {
  108. $res = GlossaryManager::reorder_glossary();
  109. $this->assertTrue(is_null($res));
  110. }
  111. function testMoveGlossary() {
  112. ob_start();
  113. $direction = '';
  114. $glossary_id = '';
  115. $res = GlossaryManager::move_glossary($direction, $glossary_id);
  116. ob_end_clean();
  117. $this->assertTrue(is_null($res));
  118. }
  119. function testDeleteGlossaryIsFalse() {
  120. ob_start();
  121. $glossary_id = 1;
  122. $res = GlossaryManager::delete_glossary($glossary_id);
  123. ob_end_clean();
  124. $this->assertFalse($res);
  125. }
  126. function testDeleteGlossaryIsTrue() {
  127. $values = array('glossary_title'=>'stuffing','glossary_description'=>'something to fill');
  128. ob_start();
  129. $id = GlossaryManager::save_glossary($values);
  130. $res = GlossaryManager::delete_glossary($id);
  131. ob_end_clean();
  132. $this->assertTrue($res);
  133. }
  134. }