PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Croogo/Lib/TestSuite/CroogoTestCase.php

https://github.com/kareypowell/croogo
PHP | 96 lines | 56 code | 17 blank | 23 comment | 1 complexity | 986c3a857e033a82c6c6903f9c91b16e MD5 | raw file
  1. <?php
  2. App::uses('CroogoTestFixture', 'Croogo.TestSuite');
  3. App::uses('CroogoRouter', 'Croogo.Lib');
  4. /**
  5. * CroogoTestCase class
  6. *
  7. * @category TestSuite
  8. * @package Croogo
  9. * @version 1.4
  10. * @author Fahad Ibnay Heylaal <contact@fahad19.com>
  11. * @author Rachman Chavik <rchavik@gmail.com>
  12. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  13. * @link http://www.croogo.org
  14. */
  15. class CroogoTestCase extends CakeTestCase {
  16. protected $_paths = array();
  17. /**
  18. * Setup settings.json file for the test application. Tests not requiring
  19. * settings fixture can turn it off by setting this to false.
  20. */
  21. public $setupSettings = true;
  22. public static function setUpBeforeClass() {
  23. self::_restoreSettings();
  24. Configure::write('Config.language', 'eng');
  25. }
  26. public static function tearDownAfterClass() {
  27. self::_restoreSettings();
  28. Configure::write('Config.language', Configure::read('Site.locale'));
  29. }
  30. protected static function _restoreSettings() {
  31. $configDir = CakePlugin::path('Croogo') . 'Test' . DS . 'test_app' . DS . 'Config' . DS;
  32. $source = $configDir . 'settings.default';
  33. $target = $configDir . 'settings.json';
  34. copy($source, $target);
  35. }
  36. /**
  37. * setUp
  38. *
  39. * @return void
  40. */
  41. public function setUp() {
  42. parent::setUp();
  43. $appDir = CakePlugin::path('Croogo') . 'Test' . DS . 'test_app' . DS;
  44. App::build(array(
  45. 'Plugin' => array($appDir . 'Plugin' . DS),
  46. 'View' => array($appDir . 'View' . DS),
  47. ), App::PREPEND);
  48. $this->_paths = App::paths();
  49. CakePlugin::unload('Install');
  50. CakePlugin::load('Example');
  51. Configure::write('Acl.database', 'test');
  52. $this->setupSettings($appDir);
  53. }
  54. public function setupSettings($appDir) {
  55. if (!$this->setupSettings) {
  56. return;
  57. }
  58. $Setting = ClassRegistry::init('Settings.Setting');
  59. $Setting->settingsPath = $appDir . 'Config' . DS . 'settings.json';
  60. Configure::drop('settings');
  61. Configure::config('settings', new CroogoJsonReader(dirname($Setting->settingsPath) . DS));
  62. $Setting->writeConfiguration();
  63. }
  64. public function tearDown() {
  65. parent::tearDown();
  66. App::build($this->_paths);
  67. }
  68. /**
  69. * Helper method to create an test API request (with the appropriate detector)
  70. */
  71. protected function _apiRequest($params) {
  72. $request = new CakeRequest();
  73. $request->addParams($params);
  74. $request->addDetector('api', array(
  75. 'callback' => array('CroogoRouter', 'isApiRequest'),
  76. ));
  77. return $request;
  78. }
  79. }