LoginTestHarness.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @package login
  4. * @subpackage test
  5. */
  6. require_once strtr(realpath(dirname(__FILE__)) . '/LoginTestCase.php','\\','/');
  7. /**
  8. * Main Login test harness.
  9. *
  10. * @package login
  11. * @subpackage test
  12. */
  13. class LoginTestHarness {
  14. /**
  15. * @var modX Static reference to modX instance.
  16. */
  17. public static $modx = null;
  18. /**
  19. * @var array Static reference to configuration array.
  20. */
  21. public static $properties = array();
  22. /**
  23. * Load all Test Suites for xPDO Test Harness.
  24. *
  25. * @return LoginTestHarness
  26. */
  27. public static function suite() {
  28. $suite = new LoginTestHarness('LoginHarness');
  29. return $suite;
  30. }
  31. /**
  32. * Grab a persistent instance of the xPDO class to share connection data
  33. * across multiple tests and test suites.
  34. *
  35. * @param array $options An array of configuration parameters.
  36. * @return xPDO An xPDO object instance.
  37. */
  38. public static function _getConnection($options = array()) {
  39. $modx = LoginTestHarness::$modx;
  40. if (is_object($modx)) {
  41. if (!$modx->request) { $modx->getRequest(); }
  42. if (!$modx->error) { $modx->request->loadErrorHandler(); }
  43. $modx->error->reset();
  44. LoginTestHarness::$modx = $modx;
  45. return LoginTestHarness::$modx;
  46. }
  47. /* include config.core.php */
  48. $properties = array();
  49. include_once strtr(realpath(dirname(__FILE__)) . '/config.inc.php','\\','/');
  50. require_once $config['modx_base_path'].'config.core.php';
  51. require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
  52. require_once MODX_CORE_PATH.'model/modx/modx.class.php';
  53. include_once strtr(realpath(dirname(__FILE__)) . '/properties.inc.php','\\','/');
  54. if (!defined('MODX_REQP')) {
  55. define('MODX_REQP',false);
  56. }
  57. $modx = new modX(null,$properties);
  58. $ctx = !empty($options['ctx']) ? $options['ctx'] : 'web';
  59. $modx->initialize($ctx);
  60. $debug = !empty($options['debug']);
  61. $modx->setDebug($debug);
  62. if (!empty($properties['logTarget'])) $modx->setLogTarget($properties['logTarget']);
  63. if (!empty($properties['logLevel'])) $modx->setLogLevel($properties['logLevel']);
  64. $modx->user = $modx->newObject('modUser');
  65. $modx->user->set('id',$modx->getOption('modx.test.user.id',null,1));
  66. $modx->user->set('username',$modx->getOption('modx.test.user.username',null,'test'));
  67. $modx->getRequest();
  68. $modx->getParser();
  69. $modx->request->loadErrorHandler();
  70. LoginTestHarness::$modx = $modx;
  71. LoginTestHarness::$properties = $properties;
  72. return $modx;
  73. }
  74. }