PageRenderTime 56ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/msadouni/cakephp2x
PHP | 158 lines | 92 code | 19 blank | 47 comment | 3 complexity | ae1e372c457305afc349dab96c867d9b MD5 | raw file
  1. <?php
  2. /**
  3. * ExtractTaskTest file
  4. *
  5. * Test Case for i18n extraction shell task
  6. *
  7. * PHP Version 5.x
  8. *
  9. * CakePHP : Rapid Development Framework (http://cakephp.org)
  10. * Copyright 2006-2009, 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-2009, 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. if (!class_exists('ExtractTask')) {
  34. require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'extract.php';
  35. }
  36. Mock::generatePartial(
  37. 'ShellDispatcher', 'TestExtractTaskMockShellDispatcher',
  38. array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
  39. );
  40. /**
  41. * ExtractTaskTest class
  42. *
  43. * @package cake
  44. * @subpackage cake.tests.cases.console.libs.tasks
  45. */
  46. class ExtractTaskTest extends CakeTestCase {
  47. /**
  48. * setUp method
  49. *
  50. * @return void
  51. * @access public
  52. */
  53. function setUp() {
  54. $this->Dispatcher = new TestExtractTaskMockShellDispatcher();
  55. $this->Task = new ExtractTask($this->Dispatcher);
  56. }
  57. /**
  58. * tearDown method
  59. *
  60. * @return void
  61. * @access public
  62. */
  63. function tearDown() {
  64. ClassRegistry::flush();
  65. }
  66. /**
  67. * testExecute method
  68. *
  69. * @return void
  70. * @access public
  71. */
  72. function testExecute() {
  73. $path = TMP . 'tests' . DS . 'extract_task_test';
  74. new Folder($path . DS . 'locale', true);
  75. $this->Task->interactive = false;
  76. $this->Task->params['paths'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages';
  77. $this->Task->params['output'] = $path . DS;
  78. $this->Task->Dispatch->expectNever('stderr');
  79. $this->Task->Dispatch->expectNever('_stop');
  80. $this->Task->execute();
  81. $this->assertTrue(file_exists($path . DS . 'default.pot'));
  82. $result = file_get_contents($path . DS . 'default.pot');
  83. $pattern = '/"Content-Type\: text\/plain; charset\=utf-8/';
  84. $this->assertPattern($pattern, $result);
  85. $pattern = '/"Content-Transfer-Encoding\: 8bit/';
  86. $this->assertPattern($pattern, $result);
  87. $pattern = '/"Plural-Forms\: nplurals\=INTEGER; plural\=EXPRESSION;/';
  88. $this->assertPattern($pattern, $result);
  89. // home.ctp
  90. $pattern = '/msgid "Your tmp directory is writable."\nmsgstr ""\n/';
  91. $this->assertPattern($pattern, $result);
  92. $pattern = '/msgid "Your tmp directory is NOT writable."\nmsgstr ""\n/';
  93. $this->assertPattern($pattern, $result);
  94. $pattern = '/msgid "The %s is being used for caching. To change the config edit ';
  95. $pattern .= 'APP\/config\/core.php "\nmsgstr ""\n/';
  96. $this->assertPattern($pattern, $result);
  97. $pattern = '/msgid "Your cache is NOT working. Please check ';
  98. $pattern .= 'the settings in APP\/config\/core.php"\nmsgstr ""\n/';
  99. $this->assertPattern($pattern, $result);
  100. $pattern = '/msgid "Your database configuration file is present."\nmsgstr ""\n/';
  101. $this->assertPattern($pattern, $result);
  102. $pattern = '/msgid "Your database configuration file is NOT present."\nmsgstr ""\n/';
  103. $this->assertPattern($pattern, $result);
  104. $pattern = '/msgid "Rename config\/database.php.default to ';
  105. $pattern .= 'config\/database.php"\nmsgstr ""\n/';
  106. $this->assertPattern($pattern, $result);
  107. $pattern = '/msgid "Cake is able to connect to the database."\nmsgstr ""\n/';
  108. $this->assertPattern($pattern, $result);
  109. $pattern = '/msgid "Cake is NOT able to connect to the database."\nmsgstr ""\n/';
  110. $this->assertPattern($pattern, $result);
  111. $pattern = '/msgid "Editing this Page"\nmsgstr ""\n/';
  112. $this->assertPattern($pattern, $result);
  113. $pattern = '/msgid "To change the content of this page, edit: %s.*To change its layout, ';
  114. $pattern .= 'edit: %s.*You can also add some CSS styles for your pages at: %s"\nmsgstr ""/s';
  115. $this->assertPattern($pattern, $result);
  116. // extract.ctp
  117. $pattern = '/msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
  118. $this->assertPattern($pattern, $result);
  119. $pattern = '/msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
  120. $this->assertPattern($pattern, $result);
  121. $pattern = '/msgid "You have %d new message \(domain\)."\nmsgid_plural "You have %d new messages \(domain\)."/';
  122. $this->assertPattern($pattern, $result);
  123. $pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/';
  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. }
  139. ?>