PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/klevo/wildflower
PHP | 109 lines | 53 code | 6 blank | 50 comment | 3 complexity | 7ded0b36002f086de26de4f188d5a72a MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * ModelTaskTest file
  5. *
  6. * Test Case for test generation shell task
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * CakePHP : Rapid Development Framework (http://cakephp.org)
  11. * Copyright 2006-2010, Cake Software Foundation, Inc.
  12. *
  13. * Licensed under The MIT License
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
  17. * @link http://cakefoundation.org/projects/info/cakephp CakePHP Project
  18. * @package cake
  19. * @subpackage cake.tests.cases.console.libs.tasks
  20. * @since CakePHP v 1.2.6
  21. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  22. */
  23. App::import('Core', 'Shell');
  24. if (!defined('DISABLE_AUTO_DISPATCH')) {
  25. define('DISABLE_AUTO_DISPATCH', true);
  26. }
  27. if (!class_exists('ShellDispatcher')) {
  28. ob_start();
  29. $argv = false;
  30. require CAKE . 'console' . DS . 'cake.php';
  31. ob_end_clean();
  32. }
  33. if (!class_exists('TestTask')) {
  34. require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
  35. }
  36. Mock::generatePartial(
  37. 'ShellDispatcher', 'TestModelTaskMockShellDispatcher',
  38. array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
  39. );
  40. Mock::generatePartial(
  41. 'ModelTask', 'MockModelTask',
  42. array('in', 'out', 'createFile', '_checkUnitTest')
  43. );
  44. /**
  45. * ModelTaskTest class
  46. *
  47. * @package cake
  48. * @subpackage cake.tests.cases.console.libs.tasks
  49. */
  50. class ModelTaskTest extends CakeTestCase {
  51. var $fixtures = array('core.datatype', 'core.binary_test', 'core.article');
  52. /**
  53. * setUp method
  54. *
  55. * @return void
  56. * @access public
  57. */
  58. function setUp() {
  59. $this->Dispatcher =& new TestModelTaskMockShellDispatcher();
  60. $this->Task =& new MockModelTask($this->Dispatcher);
  61. $this->Task->Dispatch =& $this->Dispatcher;
  62. }
  63. /**
  64. * tearDown method
  65. *
  66. * @return void
  67. * @access public
  68. */
  69. function tearDown() {
  70. ClassRegistry::flush();
  71. }
  72. /**
  73. * test fixture generation with floats
  74. *
  75. * @return void
  76. **/
  77. function testFixtureGeneration() {
  78. $this->Task->useDbConfig = 'test_suite';
  79. $this->Task->setReturnValue('createFile', true);
  80. $result = $this->Task->fixture('Datatype');
  81. $this->assertPattern('/float_field\' => 1/', $result);
  82. $result = $this->Task->fixture('BinaryTest');
  83. $this->assertPattern("/'data' => 'Lorem ipsum dolor sit amet'/", $result);
  84. }
  85. /**
  86. * test that execute passes runs bake depending with named model.
  87. *
  88. * @return void
  89. * @access public
  90. */
  91. function testBakeModel() {
  92. $this->Task->connection = 'test_suite';
  93. $this->Task->path = '/my/path/';
  94. $filename = '/my/path/article.php';
  95. $this->Task->setReturnValue('_checkUnitTest', 1);
  96. $this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
  97. $model =& new Model(array('name' => 'Article', 'table' => 'articles', 'ds' => 'test_suite'));
  98. $this->Task->bake($model);
  99. $this->assertEqual(count(ClassRegistry::keys()), 0);
  100. $this->assertEqual(count(ClassRegistry::mapKeys()), 0);
  101. }
  102. }
  103. ?>