mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Refactored CakeTestCase::assertTags to tokenize the validation process and give useful debug information on demand
Refactored all FormHelper test cases to work for the new approach and make use of new features Fixed a FormHelper::hour dateTime bug causing the hour 0 to be selected at 12pm git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6769 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
e2cca50ba9
commit
0a715f2afe
3 changed files with 348 additions and 415 deletions
|
@ -1350,6 +1350,9 @@ class FormHelper extends AppHelper {
|
|||
} elseif ($time[0] > 12) {
|
||||
$meridian = 'pm';
|
||||
}
|
||||
if ($time[0] == 0 && $timeFormat == '12') {
|
||||
$time[0] = 12;
|
||||
}
|
||||
$hour = $time[0];
|
||||
$min = $time[1];
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -442,11 +442,11 @@ class CakeTestCase extends UnitTestCase {
|
|||
* It will also allow whitespaces between specified tags.
|
||||
*
|
||||
* @param string $string An HTML/XHTML/XML string
|
||||
* @param string $expected An array, see above
|
||||
* @param array $expected An array, see above
|
||||
* @param string $message SimpleTest failure output string
|
||||
* @access public
|
||||
*/
|
||||
function assertTags($string, $expected, $message = '%s') {
|
||||
function assertTags($string, $expected, $fullDebug = false) {
|
||||
$regex = array();
|
||||
$normalized = array();
|
||||
foreach ($expected as $key => $val) {
|
||||
|
@ -456,36 +456,62 @@ class CakeTestCase extends UnitTestCase {
|
|||
$normalized[] = $val;
|
||||
}
|
||||
}
|
||||
$i = 0;
|
||||
foreach ($normalized as $tags) {
|
||||
$i++;
|
||||
if (is_string($tags)) {
|
||||
if ($tags{0} == '!') {
|
||||
$regex[] = '<[\s]*\/[\s]*'.substr($tags, 1).'[\s]*>';
|
||||
if (preg_match('/^\*?!/', $tags, $match)) {
|
||||
$prefix = array(null, null);
|
||||
if ($match[0] == '*!') {
|
||||
$prefix = array('Anything, ', '.*?');
|
||||
}
|
||||
$regex[] = array(
|
||||
sprintf('%sClose %s tag', $prefix[0], substr($tags, strlen($match[0]))),
|
||||
sprintf('%s<[\s]*\/[\s]*%s[\s]*>[\n\r]*', $prefix[1], substr($tags, strlen($match[0]))),
|
||||
$i,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if (!empty($tags) && preg_match('/^preg\:\/(.+)\/$/i', $tags, $matches)) {
|
||||
$tags = $matches[1];
|
||||
$type = 'Regex matches';
|
||||
} else {
|
||||
$tags = preg_quote($tags, '/');
|
||||
$type = 'Text equals';
|
||||
}
|
||||
$regex[] = $tags;
|
||||
$regex[] = array(
|
||||
sprintf('%s "%s"', $type, $tags),
|
||||
$tags,
|
||||
$i,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
foreach ($tags as $tag => $attributes) {
|
||||
$regex[] = '<'.preg_quote($tag, '/');
|
||||
$regex[] = array(
|
||||
sprintf('Open %s tag', $tag),
|
||||
sprintf('<%s', preg_quote($tag, '/')),
|
||||
$i,
|
||||
);
|
||||
if ($attributes === true) {
|
||||
$attributes = array();
|
||||
}
|
||||
$attrs = array();
|
||||
$explanations = array();
|
||||
foreach ($attributes as $attr => $val) {
|
||||
if (is_numeric($attr) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
|
||||
$attrs[] = $matches[1];
|
||||
$explanations[] = sprintf('Regex "%s" matches', $matches[1]);
|
||||
continue;
|
||||
} else {
|
||||
if (is_numeric($attr)) {
|
||||
$attr = $val;
|
||||
$val = '.*?';
|
||||
$val = '.+?';
|
||||
$explanations[] = sprintf('Attribute "%s" present', $attr);
|
||||
} else if (!empty($val) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
|
||||
$val = $matches[1];
|
||||
$explanations[] = sprintf('Attribute "%s" matches "%s"', $attr, $val);
|
||||
} else {
|
||||
$explanations[] = sprintf('Attribute "%s" == "%s"', $attr, $val);
|
||||
$val = preg_quote($val, '/');
|
||||
}
|
||||
$attrs[] = '[\s]+'.preg_quote($attr, '/').'="'.$val.'"';
|
||||
|
@ -493,24 +519,48 @@ class CakeTestCase extends UnitTestCase {
|
|||
}
|
||||
if ($attrs) {
|
||||
$permutations = $this->__array_permute($attrs);
|
||||
$regex[] = '(';
|
||||
$permutationTokens = array();
|
||||
foreach ($permutations as $permutation) {
|
||||
$regex = am($regex, $permutation);
|
||||
$regex[] = '|';
|
||||
$permutationTokens[] = join('', $permutation);
|
||||
}
|
||||
array_pop($regex);
|
||||
$regex[] =')';
|
||||
$regex[] = array(
|
||||
sprintf('%s', join(', ', $explanations)),
|
||||
$permutationTokens,
|
||||
$i,
|
||||
);
|
||||
}
|
||||
$regex[] = '[\s]*\/?[\s]*>[^<>]*';
|
||||
$regex[] = array(
|
||||
sprintf('End %s tag', $tag),
|
||||
'[\s]*\/?[\s]*>[\n\r]*',
|
||||
$i,
|
||||
);
|
||||
}
|
||||
}
|
||||
$regex = '/^'.join('\s*', $regex).'/Us';
|
||||
return $this->assertPattern($regex, $string, $message);
|
||||
foreach ($regex as $i => $assertation) {
|
||||
list($description, $expressions, $itemNum) = $assertation;
|
||||
$matches = false;
|
||||
foreach ((array)$expressions as $expression) {
|
||||
if (preg_match(sprintf('/^%s/s', $expression), $string, $match)) {
|
||||
$matches = true;
|
||||
$string = substr($string, strlen($match[0]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$matches) {
|
||||
$this->assert(new TrueExpectation(), false, sprintf('Item #%d / regex #%d failed: %s', $itemNum, $i, $description));
|
||||
if ($fullDebug) {
|
||||
debug($string, true);
|
||||
debug($regex, true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $this->assert(new TrueExpectation(), true, '%s');
|
||||
}
|
||||
/**
|
||||
* Generates all permutation of an array $items and returns them in a new array.
|
||||
*
|
||||
* @param string $items An array of items
|
||||
* @param array $items An array of items
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue