PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/zeroasterisk/cakedemo-2011-02-09
PHP | 187 lines | 109 code | 26 blank | 52 comment | 2 complexity | df5b22cca67c536242cdf4d61a6a278a MD5 | raw file
  1. <?php
  2. /**
  3. * ExtractTaskTest file
  4. *
  5. * Test Case for i18n extraction shell task
  6. *
  7. * PHP versions 4 and 5
  8. *
  9. * CakePHP : Rapid Development Framework (http://cakephp.org)
  10. * Copyright 2006-2010, Cake Software Foundation, Inc.
  11. *
  12. * Licensed under The MIT License
  13. * Redistributions of files must retain the above copyright notice.
  14. *
  15. * @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
  16. * @link http://cakephp.org CakePHP Project
  17. * @package cake
  18. * @subpackage cake.tests.cases.console.libs.tasks
  19. * @since CakePHP v 1.2.0.7726
  20. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  21. */
  22. App::import('Core', 'Folder');
  23. App::import('Shell', 'Shell', false);
  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. require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'extract.php';
  34. Mock::generatePartial(
  35. 'ShellDispatcher', 'TestExtractTaskMockShellDispatcher',
  36. array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
  37. );
  38. /**
  39. * ExtractTaskTest class
  40. *
  41. * @package cake
  42. * @subpackage cake.tests.cases.console.libs.tasks
  43. */
  44. class ExtractTaskTest extends CakeTestCase {
  45. /**
  46. * setUp method
  47. *
  48. * @return void
  49. * @access public
  50. */
  51. function setUp() {
  52. $this->Dispatcher =& new TestExtractTaskMockShellDispatcher();
  53. $this->Task =& new ExtractTask($this->Dispatcher);
  54. }
  55. /**
  56. * tearDown method
  57. *
  58. * @return void
  59. * @access public
  60. */
  61. function tearDown() {
  62. ClassRegistry::flush();
  63. }
  64. /**
  65. * testExecute method
  66. *
  67. * @return void
  68. * @access public
  69. */
  70. function testExecute() {
  71. $path = TMP . 'tests' . DS . 'extract_task_test';
  72. new Folder($path . DS . 'locale', true);
  73. $this->Task->interactive = false;
  74. $this->Task->params['paths'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages';
  75. $this->Task->params['output'] = $path . DS;
  76. $this->Task->Dispatch->expectNever('stderr');
  77. $this->Task->Dispatch->expectNever('_stop');
  78. $this->Task->execute();
  79. $this->assertTrue(file_exists($path . DS . 'default.pot'));
  80. $result = file_get_contents($path . DS . 'default.pot');
  81. $pattern = '/"Content-Type\: text\/plain; charset\=utf-8/';
  82. $this->assertPattern($pattern, $result);
  83. $pattern = '/"Content-Transfer-Encoding\: 8bit/';
  84. $this->assertPattern($pattern, $result);
  85. $pattern = '/"Plural-Forms\: nplurals\=INTEGER; plural\=EXPRESSION;/';
  86. $this->assertPattern($pattern, $result);
  87. // home.ctp
  88. $pattern = '/msgid "Your tmp directory is writable."\nmsgstr ""\n/';
  89. $this->assertPattern($pattern, $result);
  90. $pattern = '/msgid "Your tmp directory is NOT writable."\nmsgstr ""\n/';
  91. $this->assertPattern($pattern, $result);
  92. $pattern = '/msgid "The %s is being used for caching. To change the config edit ';
  93. $pattern .= 'APP\/config\/core.php "\nmsgstr ""\n/';
  94. $this->assertPattern($pattern, $result);
  95. $pattern = '/msgid "Your cache is NOT working. Please check ';
  96. $pattern .= 'the settings in APP\/config\/core.php"\nmsgstr ""\n/';
  97. $this->assertPattern($pattern, $result);
  98. $pattern = '/msgid "Your database configuration file is present."\nmsgstr ""\n/';
  99. $this->assertPattern($pattern, $result);
  100. $pattern = '/msgid "Your database configuration file is NOT present."\nmsgstr ""\n/';
  101. $this->assertPattern($pattern, $result);
  102. $pattern = '/msgid "Rename config\/database.php.default to ';
  103. $pattern .= 'config\/database.php"\nmsgstr ""\n/';
  104. $this->assertPattern($pattern, $result);
  105. $pattern = '/msgid "Cake is able to connect to the database."\nmsgstr ""\n/';
  106. $this->assertPattern($pattern, $result);
  107. $pattern = '/msgid "Cake is NOT able to connect to the database."\nmsgstr ""\n/';
  108. $this->assertPattern($pattern, $result);
  109. $pattern = '/msgid "Editing this Page"\nmsgstr ""\n/';
  110. $this->assertPattern($pattern, $result);
  111. $pattern = '/msgid "To change the content of this page, edit: %s.*To change its layout, ';
  112. $pattern .= 'edit: %s.*You can also add some CSS styles for your pages at: %s"\nmsgstr ""/s';
  113. $this->assertPattern($pattern, $result);
  114. // extract.ctp
  115. $pattern = '/\#: (\\\\|\/)extract\.ctp:6\n';
  116. $pattern .= 'msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
  117. $this->assertPattern($pattern, $result);
  118. $pattern = '/\#: (\\\\|\/)extract\.ctp:7\n';
  119. $pattern .= 'msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
  120. $this->assertPattern($pattern, $result);
  121. $pattern = '/\#: (\\\\|\/)extract\.ctp:14\n';
  122. $pattern .= '\#: (\\\\|\/)home\.ctp:74\n';
  123. $pattern .= 'msgid "Editing this Page"\nmsgstr ""/';
  124. $this->assertPattern($pattern, $result);
  125. // extract.ctp - reading the domain.pot
  126. $result = file_get_contents($path . DS . 'domain.pot');
  127. $pattern = '/msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
  128. $this->assertNoPattern($pattern, $result);
  129. $pattern = '/msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
  130. $this->assertNoPattern($pattern, $result);
  131. $pattern = '/msgid "You have %d new message \(domain\)."\nmsgid_plural "You have %d new messages \(domain\)."/';
  132. $this->assertPattern($pattern, $result);
  133. $pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/';
  134. $this->assertPattern($pattern, $result);
  135. $Folder = new Folder($path);
  136. $Folder->delete();
  137. }
  138. function getTests() {
  139. return array('start', 'startCase', 'testExtractMultiplePaths', 'endCase', 'end');
  140. }
  141. /**
  142. * test extract can read more than one path.
  143. *
  144. * @return void
  145. */
  146. function testExtractMultiplePaths() {
  147. $path = TMP . 'tests' . DS . 'extract_task_test';
  148. new Folder($path . DS . 'locale', true);
  149. $this->Task->interactive = false;
  150. $this->Task->params['paths'] =
  151. TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages,' .
  152. TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'posts';
  153. $this->Task->params['output'] = $path . DS;
  154. $this->Task->Dispatch->expectNever('stderr');
  155. $this->Task->Dispatch->expectNever('_stop');
  156. $this->Task->execute();
  157. $result = file_get_contents($path . DS . 'default.pot');
  158. $pattern = '/msgid "Add User"/';
  159. $this->assertPattern($pattern, $result);
  160. }
  161. }