PageRenderTime 61ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/tests/cases/console/libs/tasks/db_config.test.php

https://github.com/msadouni/cakephp2x
PHP | 156 lines | 84 code | 17 blank | 55 comment | 2 complexity | 3ed712e93d9a4373e97918460035b2f2 MD5 | raw file
  1. <?php
  2. /**
  3. * DBConfigTask Test Case
  4. *
  5. * PHP Version 5.x
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package cake
  16. * @subpackage cake.tests.cases.console.libs.tasks
  17. * @since CakePHP(tm) v 1.3
  18. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  19. */
  20. App::import('Shell', 'Shell', false);
  21. if (!defined('DISABLE_AUTO_DISPATCH')) {
  22. define('DISABLE_AUTO_DISPATCH', true);
  23. }
  24. if (!class_exists('ShellDispatcher')) {
  25. ob_start();
  26. $argv = false;
  27. require CAKE . 'console' . DS . 'cake.php';
  28. ob_end_clean();
  29. }
  30. require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'db_config.php';
  31. //require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
  32. Mock::generatePartial(
  33. 'ShellDispatcher', 'TestDbConfigTaskMockShellDispatcher',
  34. array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
  35. );
  36. Mock::generatePartial(
  37. 'DbConfigTask', 'MockDbConfigTask',
  38. array('in', 'hr', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
  39. );
  40. class TEST_DATABASE_CONFIG {
  41. var $default = array(
  42. 'driver' => 'mysql',
  43. 'persistent' => false,
  44. 'host' => 'localhost',
  45. 'login' => 'user',
  46. 'password' => 'password',
  47. 'database' => 'database_name',
  48. 'prefix' => '',
  49. );
  50. var $otherOne = array(
  51. 'driver' => 'mysql',
  52. 'persistent' => false,
  53. 'host' => 'localhost',
  54. 'login' => 'user',
  55. 'password' => 'password',
  56. 'database' => 'other_one',
  57. 'prefix' => '',
  58. );
  59. }
  60. /**
  61. * DbConfigTest class
  62. *
  63. * @package cake
  64. * @subpackage cake.tests.cases.console.libs.tasks
  65. */
  66. class DbConfigTaskTest extends CakeTestCase {
  67. /**
  68. * startTest method
  69. *
  70. * @return void
  71. * @access public
  72. */
  73. function startTest() {
  74. $this->Dispatcher =& new TestDbConfigTaskMockShellDispatcher();
  75. $this->Task =& new MockDbConfigTask($this->Dispatcher);
  76. $this->Task->Dispatch =& $this->Dispatcher;
  77. $this->Task->Dispatch->shellPaths = App::path('shells');
  78. $this->Task->params['working'] = rtrim(APP, DS);
  79. $this->Task->databaseClassName = 'TEST_DATABASE_CONFIG';
  80. }
  81. /**
  82. * endTest method
  83. *
  84. * @return void
  85. * @access public
  86. */
  87. function endTest() {
  88. unset($this->Task, $this->Dispatcher);
  89. ClassRegistry::flush();
  90. }
  91. /**
  92. * Test the getConfig method.
  93. *
  94. * @return void
  95. * @access public
  96. */
  97. function testGetConfig() {
  98. $this->Task->setReturnValueAt(0, 'in', 'otherOne');
  99. $result = $this->Task->getConfig();
  100. $this->assertEqual($result, 'otherOne');
  101. }
  102. /**
  103. * test that initialize sets the path up.
  104. *
  105. * @return void
  106. * @access public
  107. */
  108. function testInitialize() {
  109. $this->assertTrue(empty($this->Task->path));
  110. $this->Task->initialize();
  111. $this->assertFalse(empty($this->Task->path));
  112. $this->assertEqual($this->Task->path, APP . 'config' . DS);
  113. }
  114. /**
  115. * test execute and by extension __interactive
  116. *
  117. * @return void
  118. * @access public
  119. */
  120. function testExecuteIntoInteractive() {
  121. $this->Task->initialize();
  122. $this->Task->expectOnce('_stop');
  123. $this->Task->setReturnValue('in', 'y');
  124. $this->Task->setReturnValueAt(0, 'in', 'default');
  125. $this->Task->setReturnValueAt(1, 'in', 'n');
  126. $this->Task->setReturnValueAt(2, 'in', 'localhost');
  127. $this->Task->setReturnValueAt(3, 'in', 'n');
  128. $this->Task->setReturnValueAt(4, 'in', 'root');
  129. $this->Task->setReturnValueAt(5, 'in', 'password');
  130. $this->Task->setReturnValueAt(6, 'in', 'cake_test');
  131. $this->Task->setReturnValueAt(7, 'in', 'n');
  132. $this->Task->setReturnValueAt(8, 'in', 'y');
  133. $this->Task->setReturnValueAt(9, 'in', 'y');
  134. $this->Task->setReturnValueAt(10, 'in', 'y');
  135. $this->Task->setReturnValueAt(11, 'in', 'n');
  136. $result = $this->Task->execute();
  137. }
  138. }
  139. ?>