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) {
|
} elseif ($time[0] > 12) {
|
||||||
$meridian = 'pm';
|
$meridian = 'pm';
|
||||||
}
|
}
|
||||||
|
if ($time[0] == 0 && $timeFormat == '12') {
|
||||||
|
$time[0] = 12;
|
||||||
|
}
|
||||||
$hour = $time[0];
|
$hour = $time[0];
|
||||||
$min = $time[1];
|
$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.
|
* It will also allow whitespaces between specified tags.
|
||||||
*
|
*
|
||||||
* @param string $string An HTML/XHTML/XML string
|
* @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
|
* @param string $message SimpleTest failure output string
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function assertTags($string, $expected, $message = '%s') {
|
function assertTags($string, $expected, $fullDebug = false) {
|
||||||
$regex = array();
|
$regex = array();
|
||||||
$normalized = array();
|
$normalized = array();
|
||||||
foreach ($expected as $key => $val) {
|
foreach ($expected as $key => $val) {
|
||||||
|
@ -456,36 +456,62 @@ class CakeTestCase extends UnitTestCase {
|
||||||
$normalized[] = $val;
|
$normalized[] = $val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$i = 0;
|
||||||
foreach ($normalized as $tags) {
|
foreach ($normalized as $tags) {
|
||||||
|
$i++;
|
||||||
if (is_string($tags)) {
|
if (is_string($tags)) {
|
||||||
if ($tags{0} == '!') {
|
if (preg_match('/^\*?!/', $tags, $match)) {
|
||||||
$regex[] = '<[\s]*\/[\s]*'.substr($tags, 1).'[\s]*>';
|
$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;
|
continue;
|
||||||
}
|
}
|
||||||
if (!empty($tags) && preg_match('/^preg\:\/(.+)\/$/i', $tags, $matches)) {
|
if (!empty($tags) && preg_match('/^preg\:\/(.+)\/$/i', $tags, $matches)) {
|
||||||
$tags = $matches[1];
|
$tags = $matches[1];
|
||||||
|
$type = 'Regex matches';
|
||||||
} else {
|
} else {
|
||||||
$tags = preg_quote($tags, '/');
|
$tags = preg_quote($tags, '/');
|
||||||
|
$type = 'Text equals';
|
||||||
}
|
}
|
||||||
$regex[] = $tags;
|
$regex[] = array(
|
||||||
|
sprintf('%s "%s"', $type, $tags),
|
||||||
|
$tags,
|
||||||
|
$i,
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach ($tags as $tag => $attributes) {
|
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) {
|
if ($attributes === true) {
|
||||||
$attributes = array();
|
$attributes = array();
|
||||||
}
|
}
|
||||||
$attrs = array();
|
$attrs = array();
|
||||||
|
$explanations = array();
|
||||||
foreach ($attributes as $attr => $val) {
|
foreach ($attributes as $attr => $val) {
|
||||||
if (is_numeric($attr) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
|
if (is_numeric($attr) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
|
||||||
$attrs[] = $matches[1];
|
$attrs[] = $matches[1];
|
||||||
|
$explanations[] = sprintf('Regex "%s" matches', $matches[1]);
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if (is_numeric($attr)) {
|
if (is_numeric($attr)) {
|
||||||
$attr = $val;
|
$attr = $val;
|
||||||
$val = '.*?';
|
$val = '.+?';
|
||||||
|
$explanations[] = sprintf('Attribute "%s" present', $attr);
|
||||||
} else if (!empty($val) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
|
} else if (!empty($val) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
|
||||||
$val = $matches[1];
|
$val = $matches[1];
|
||||||
|
$explanations[] = sprintf('Attribute "%s" matches "%s"', $attr, $val);
|
||||||
} else {
|
} else {
|
||||||
|
$explanations[] = sprintf('Attribute "%s" == "%s"', $attr, $val);
|
||||||
$val = preg_quote($val, '/');
|
$val = preg_quote($val, '/');
|
||||||
}
|
}
|
||||||
$attrs[] = '[\s]+'.preg_quote($attr, '/').'="'.$val.'"';
|
$attrs[] = '[\s]+'.preg_quote($attr, '/').'="'.$val.'"';
|
||||||
|
@ -493,24 +519,48 @@ class CakeTestCase extends UnitTestCase {
|
||||||
}
|
}
|
||||||
if ($attrs) {
|
if ($attrs) {
|
||||||
$permutations = $this->__array_permute($attrs);
|
$permutations = $this->__array_permute($attrs);
|
||||||
$regex[] = '(';
|
$permutationTokens = array();
|
||||||
foreach ($permutations as $permutation) {
|
foreach ($permutations as $permutation) {
|
||||||
$regex = am($regex, $permutation);
|
$permutationTokens[] = join('', $permutation);
|
||||||
$regex[] = '|';
|
|
||||||
}
|
}
|
||||||
array_pop($regex);
|
$regex[] = array(
|
||||||
$regex[] =')';
|
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';
|
foreach ($regex as $i => $assertation) {
|
||||||
return $this->assertPattern($regex, $string, $message);
|
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.
|
* 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
|
* @return array
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue