PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://code.google.com/
PHP | 134 lines | 76 code | 10 blank | 48 comment | 3 complexity | 6cfeab757654f000134ce11741bfb550 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * ExtractTaskTest file
  5. *
  6. * Test Case for i18n extraction 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.0.7726
  21. * @version $Revision$
  22. * @modifiedby $LastChangedBy$
  23. * @lastmodified $Date$
  24. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  25. */
  26. App::import('Core', array('Shell', 'Folder'));
  27. if (!defined('DISABLE_AUTO_DISPATCH')) {
  28. define('DISABLE_AUTO_DISPATCH', true);
  29. }
  30. if (!class_exists('ShellDispatcher')) {
  31. ob_start();
  32. $argv = false;
  33. require CAKE . 'console' . DS . 'cake.php';
  34. ob_end_clean();
  35. }
  36. if (!class_exists('ExtractTask')) {
  37. require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'extract.php';
  38. }
  39. Mock::generatePartial(
  40. 'ShellDispatcher', 'TestExtractTaskMockShellDispatcher',
  41. array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
  42. );
  43. /**
  44. * ExtractTaskTest class
  45. *
  46. * @package cake
  47. * @subpackage cake.tests.cases.console.libs.tasks
  48. */
  49. class ExtractTaskTest extends CakeTestCase {
  50. /**
  51. * setUp method
  52. *
  53. * @return void
  54. * @access public
  55. */
  56. function setUp() {
  57. $this->Dispatcher =& new TestExtractTaskMockShellDispatcher();
  58. $this->Task =& new ExtractTask($this->Dispatcher);
  59. }
  60. /**
  61. * tearDown method
  62. *
  63. * @return void
  64. * @access public
  65. */
  66. function tearDown() {
  67. ClassRegistry::flush();
  68. }
  69. /**
  70. * testExecute method
  71. *
  72. * @return void
  73. * @access public
  74. */
  75. function testExecute() {
  76. $path = TMP . 'extract_task_test';
  77. $folder1 = $path . DS . 'locale';
  78. new Folder($path, true);
  79. new Folder($folder1, true);
  80. $this->Task->interactive = false;
  81. $this->Task->params['path'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages';
  82. $this->Task->params['output'] = $path . DS;
  83. $this->Task->Dispatch->expectNever('stderr');
  84. $this->Task->Dispatch->expectNever('_stop');
  85. $this->Task->execute();
  86. $this->assertTrue(file_exists($path . DS . 'default.pot'));
  87. $result = file_get_contents($path . DS . 'default.pot');
  88. $pattern = '/"Content-Type\: text\/plain; charset\=utf-8/';
  89. $this->assertPattern($pattern, $result);
  90. $pattern = '/"Content-Transfer-Encoding\: 8bit/';
  91. $this->assertPattern($pattern, $result);
  92. $pattern = '/"Plural-Forms\: nplurals\=INTEGER; plural\=EXPRESSION;/';
  93. $this->assertPattern($pattern, $result);
  94. $pattern = '/msgid "Your tmp directory is writable."\nmsgstr ""\n/';
  95. $this->assertPattern($pattern, $result);
  96. $pattern = '/msgid "Your tmp directory is NOT writable."\nmsgstr ""\n/';
  97. $this->assertPattern($pattern, $result);
  98. $pattern = '/msgid "The %s is being used for caching. To change the config edit ';
  99. $pattern .= 'APP\/config\/core.php "\nmsgstr ""\n/';
  100. $this->assertPattern($pattern, $result);
  101. $pattern = '/msgid "Your cache is NOT working. Please check ';
  102. $pattern .= 'the settings in APP\/config\/core.php"\nmsgstr ""\n/';
  103. $this->assertPattern($pattern, $result);
  104. $pattern = '/msgid "Your database configuration file is present."\nmsgstr ""\n/';
  105. $this->assertPattern($pattern, $result);
  106. $pattern = '/msgid "Your database configuration file is NOT present."\nmsgstr ""\n/';
  107. $this->assertPattern($pattern, $result);
  108. $pattern = '/msgid "Rename config\/database.php.default to ';
  109. $pattern .= 'config\/database.php"\nmsgstr ""\n/';
  110. $this->assertPattern($pattern, $result);
  111. $pattern = '/msgid "Cake is able to connect to the database."\nmsgstr ""\n/';
  112. $this->assertPattern($pattern, $result);
  113. $pattern = '/msgid "Cake is NOT able to connect to the database."\nmsgstr ""\n/';
  114. $this->assertPattern($pattern, $result);
  115. $pattern = '/msgid "Editing this Page"\nmsgstr ""\n/';
  116. $this->assertPattern($pattern, $result);
  117. $pattern = '/msgid "To change the content of this page, edit: %s.*To change its layout, ';
  118. $pattern .= 'edit: %s.*You can also add some CSS styles for your pages at: %s"\nmsgstr ""/s';
  119. $this->assertPattern($pattern, $result);
  120. $Folder = new Folder($path);
  121. $Folder->delete();
  122. }
  123. }
  124. ?>