Fixing glob() handling in extract shell, added extract shell test, partial fix for #6044, code formatting changes in CakeTestCase.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8026 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2009-02-13 06:22:34 +00:00
parent 712fea65ab
commit 440c629931
3 changed files with 114 additions and 16 deletions

View file

@ -668,6 +668,9 @@ class ExtractTask extends Shell{
$files = glob("$path*.{php,ctp,thtml,inc,tpl}", GLOB_BRACE);
$dirs = glob("$path*", GLOB_ONLYDIR);
$files = $files ? $files : array();
$dirs = $dirs ? $dirs : array();
foreach ($dirs as $dir) {
if (!preg_match("!(^|.+/)(CVS|.svn)$!", $dir)) {
$files = array_merge($files, $this->__searchDirectory("$dir" . DS));

View file

@ -0,0 +1,85 @@
<?php
/* SVN FILE: $Id: extract.test.php 7838 2008-11-07 10:41:52Z nate $ */
/**
* Test Case for i18n extraction shell task
*
*
*
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2006-2008, Cake Software Foundation, Inc.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs.
* @since CakePHP v 1.2.0.7726
* @version $Revision: 7838 $
* @modifiedby $LastChangedBy: DarkAngelBGE $
* @lastmodified $Date: 2008-11-07 05:41:52 -0500 (Fri, 07 Nov 2008) $
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('Core', 'Shell');
if (!defined('DISABLE_AUTO_DISPATCH')) {
define('DISABLE_AUTO_DISPATCH', true);
}
if (!class_exists('ShellDispatcher')) {
ob_start();
$argv = false;
require CAKE . 'console' . DS . 'cake.php';
ob_end_clean();
}
if (!class_exists('ExtractTask')) {
require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'extract.php';
}
class TestExtractShellDispatcher extends ShellDispatcher {
function _initEnvironment() {
}
function stdout($string, $newline = true) {
}
function stderr($string) {
}
function _stop($status = 0) {
$this->stopped = 'Stopped with status: ' . $status;
}
}
class MockExtractTast extends ExtractTask {
function searchDirectory($path = null) {
return parent::__searchDirectory($path);
}
}
class ExtractTaskTest extends CakeTestCase {
function setUp() {
$this->dispatcher = new TestExtractShellDispatcher();
$this->task = new MockExtractTast($this->dispatcher);
mkdir(TMP . '/extract_test');
}
function testDirectorySearching() {
$this->assertIdentical($this->task->searchDirectory(TMP . '/extract_test'), array());
}
function tearDown() {
unset($this->task, $this->dispatcher);
rmdir(TMP . '/extract_test');
}
}
?>

View file

@ -232,7 +232,8 @@ class CakeTestCase extends UnitTestCase {
/**
* Executes a Cake URL, and can get (depending on the $params['return'] value):
*
* 1. 'result': Whatever the action returns (and also specifies $this->params['requested'] for controller)
* 1. 'result': Whatever the action returns (and also specifies $this->params['requested']
* for controller)
* 2. 'view': The rendered view, without the layout
* 3. 'contents': The rendered view, within the layout.
* 4. 'vars': the view vars
@ -254,7 +255,6 @@ class CakeTestCase extends UnitTestCase {
if (is_string($params)) {
$params = array('return' => $params);
}
$params = array_merge($default, $params);
$toSave = array(
@ -408,7 +408,9 @@ class CakeTestCase extends UnitTestCase {
* @access public
*/
function after($method) {
if (isset($this->_fixtures) && isset($this->db) && !in_array(strtolower($method), array('start', 'end'))) {
$isTestMethod = !in_array(strtolower($method), array('start', 'end'));
if (isset($this->_fixtures) && isset($this->db) && $isTestMethod) {
foreach ($this->_fixtures as $fixture) {
$fixture->truncate($this->db);
}
@ -433,14 +435,17 @@ class CakeTestCase extends UnitTestCase {
* @access public
*/
function getTests() {
$methods = array_diff(parent::getTests(), array('testAction', 'testaction'));
$methods = array_merge(array_merge(array('start', 'startCase'), $methods), array('endCase', 'end'));
return $methods;
return array_merge(
array('start', 'startCase'),
array_diff(parent::getTests(), array('testAction', 'testaction')),
array('endCase', 'end')
);
}
/**
* Chooses which fixtures to load for a given test
*
* @param string $fixture Each parameter is a model name that corresponds to a fixture, i.e. 'Post', 'Author', etc.
* @param string $fixture Each parameter is a model name that corresponds to a
* fixture, i.e. 'Post', 'Author', etc.
* @access public
* @see CakeTestCase::$autoFixtures
*/
@ -453,14 +458,16 @@ class CakeTestCase extends UnitTestCase {
$fixture->truncate($this->db);
$fixture->insert($this->db);
} else {
trigger_error("Non-existent fixture class {$class} referenced in test", E_USER_WARNING);
trigger_error("Referenced fixture class {$class} not found", E_USER_WARNING);
}
}
}
/**
* Takes an array $expected and generates a regex from it to match the provided $string. Samples for $expected:
* Takes an array $expected and generates a regex from it to match the provided $string.
* Samples for $expected:
*
* Checks for an input tag with a name attribute (contains any non-empty value) and an id attribute that contains 'my-input':
* Checks for an input tag with a name attribute (contains any non-empty value) and an id
* attribute that contains 'my-input':
* array('input' => array('name', 'id' => 'my-input'))
*
* Checks for two p elements with some text in them:
@ -473,15 +480,15 @@ class CakeTestCase extends UnitTestCase {
* '/p'
* )
*
* You can also specify a pattern expression as part of the attribute values, or the tag being defined,
* if you prepend the value with preg: and enclose it with slashes, like so:
* You can also specify a pattern expression as part of the attribute values, or the tag
* being defined, if you prepend the value with preg: and enclose it with slashes, like so:
* array(
* array('input' => array('name', 'id' => 'preg:/FieldName\d+/')),
* 'preg:/My\s+field/'
* )
*
* Important: This function is very forgiving about whitespace and also accepts any permutation of attribute order.
* It will also allow whitespaces between specified tags.
* Important: This function is very forgiving about whitespace and also accepts any
* permutation of attribute order. It will also allow whitespaces between specified tags.
*
* @param string $string An HTML/XHTML/XML string
* @param array $expected An array, see above
@ -504,8 +511,11 @@ class CakeTestCase extends UnitTestCase {
if (is_string($tags) && $tags{0} == '<') {
$tags = array(substr($tags, 1) => array());
} elseif (is_string($tags)) {
if (preg_match('/^\*?\//', $tags, $match)) {
$tagsTrimmed = preg_replace('/\s+/m', '', $tags);
if (preg_match('/^\*?\//', $tags, $match) && $tagsTrimmed !== '//') {
$prefix = array(null, null);
if ($match[0] == '*/') {
$prefix = array('Anything, ', '.*?');
}