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

/core/elis/program/tests/deepsight_datatable_class_test.php

https://github.com/remotelearner/elis.cm
PHP | 198 lines | 107 code | 14 blank | 77 comment | 2 complexity | 2dfe22481b309c9268f70f1b65ef7eff MD5 | raw file
  1. <?php
  2. /**
  3. * ELIS(TM): Enterprise Learning Intelligence Suite
  4. * Copyright (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @package elis_program
  20. * @author Remote-Learner.net Inc
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. * @copyright (C) 2013 Remote Learner.net Inc http://www.remote-learner.net
  23. * @author James McQuillan <james.mcquillan@remote-learner.net>
  24. *
  25. */
  26. require_once(dirname(__FILE__).'/../../core/test_config.php');
  27. global $CFG;
  28. require_once($CFG->dirroot.'/elis/program/lib/setup.php');
  29. require_once(dirname(__FILE__).'/other/deepsight_testlib.php');
  30. require_once(elispm::lib('data/course.class.php'));
  31. require_once(elispm::lib('data/pmclass.class.php'));
  32. /**
  33. * Mock class datatable class exposing protected methods and properties
  34. */
  35. class deepsight_datatable_class_mock extends deepsight_datatable_class {
  36. /**
  37. * Magic function to expose protected properties
  38. * @param string $name The name of the property
  39. * @return string|int|bool The value of the property
  40. */
  41. public function __get($name) {
  42. return (isset($this->$name)) ? $this->$name : false;
  43. }
  44. /**
  45. * Magic function to expose protected properties
  46. * @param string $name The name of the property
  47. * @return string|int|bool The value of the property
  48. */
  49. public function __isset($name) {
  50. return (isset($this->$name)) ? true : false;
  51. }
  52. /**
  53. * Expose protected methods.
  54. * @param string $name The name of the called method.
  55. * @param array $args Array of arguments.
  56. */
  57. public function __call($name, $args) {
  58. if (method_exists($this, $name)) {
  59. return call_user_func_array(array($this, $name), $args);
  60. }
  61. }
  62. /**
  63. * Expose protected properties.
  64. * @param string $name The name of the property.
  65. * @param mixed $val The name to set.
  66. */
  67. public function __set($name, $val) {
  68. $this->$name = $val;
  69. }
  70. }
  71. /**
  72. * Tests the base class datatable class.
  73. * @group elis_program
  74. * @group deepsight
  75. */
  76. class deepsight_datatable_class_testcase extends deepsight_datatable_standard_implementation_test {
  77. /**
  78. * Construct the datatable we're testing.
  79. *
  80. * @return deepsight_datatable The deepsight_datatable object we're testing.
  81. */
  82. protected function get_test_table() {
  83. global $DB;
  84. return new deepsight_datatable_class_mock($DB, 'test', 'http://localhost', 'testuniqid');
  85. }
  86. /**
  87. * Do any setup before tests that rely on data in the database - i.e. create users/courses/classes/etc or import csvs.
  88. */
  89. protected function set_up_tables() {
  90. $dataset = $this->createCsvDataSet(array(
  91. pmclass::TABLE => elispm::file('tests/fixtures/deepsight_class.csv'),
  92. course::TABLE => elispm::file('tests/fixtures/deepsight_course.csv'),
  93. ));
  94. $this->loadDataSet($dataset);
  95. }
  96. /**
  97. * Dataprovider for test_bulklist_get_display.
  98. *
  99. * @return array The array of argument arrays.
  100. */
  101. public function dataprovider_bulklist_get_display() {
  102. return array(
  103. array(array(5, 6), array(6 => 'CLS6', 5 => 'CLS5'), 2)
  104. );
  105. }
  106. /**
  107. * Dataprovider for test_get_search_results()
  108. *
  109. * @return array The array of argument arrays.
  110. */
  111. public function dataprovider_get_search_results() {
  112. // Parse the csv to get information and create element arrays, indexed by element id.
  113. $csvdata = file_get_contents(dirname(__FILE__).'/fixtures/deepsight_class.csv');
  114. $csvdata = explode("\n", $csvdata);
  115. $keys = explode(',', $csvdata[0]);
  116. $lines = count($csvdata);
  117. $csvelements = array();
  118. for ($i=1; $i<$lines; $i++) {
  119. $curele = explode(',', $csvdata[$i]);
  120. $csvelements[$curele[0]] = array_combine($keys, $curele);
  121. }
  122. unset($csvdata, $keys);
  123. // Create search result arrays, indexed by element id.
  124. $results = array();
  125. foreach ($csvelements as $id => $element) {
  126. $results[$id] = array(
  127. 'element_id' => $id,
  128. 'element_idnumber' => $element['idnumber'],
  129. 'crs_name' => 'Test Course'.$element['courseid'],
  130. 'id' => $id,
  131. 'meta' => array(
  132. 'label' => $element['idnumber']
  133. )
  134. );
  135. }
  136. return array(
  137. // Test Default.
  138. array(
  139. array(),
  140. array('element.idnumber' => 'ASC'),
  141. 0,
  142. 20,
  143. array($results[5], $results[6], $results[7], $results[8]),
  144. 4
  145. ),
  146. // Test Sorting.
  147. array(
  148. array(),
  149. array('element.idnumber' => 'DESC'),
  150. 0,
  151. 20,
  152. array($results[8], $results[7], $results[6], $results[5]),
  153. 4
  154. ),
  155. // Test Basic Searching.
  156. array(
  157. array('idnumber' => array('CL 5')),
  158. array('element.idnumber' => 'DESC'),
  159. 0,
  160. 20,
  161. array($results[5]),
  162. 1
  163. ),
  164. // Test program searching.
  165. array(
  166. array('course_name' => array('Test Course100')),
  167. array('element.idnumber' => 'ASC'),
  168. 0,
  169. 20,
  170. array($results[5], $results[6]),
  171. 2
  172. ),
  173. // Test limited page results.
  174. array(
  175. array(),
  176. array('element.idnumber' => 'ASC'),
  177. 0,
  178. 2,
  179. array($results[5], $results[6]),
  180. 4
  181. ),
  182. );
  183. }
  184. }