mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding tests for single quoted attributes to assertTags(). Because of the __array_permute works ensuring quotes match is a non-trivial problem. Fixing single quoted attributes not being matchable with assertTags(). Fixes #539
This commit is contained in:
parent
45ccba5d94
commit
d990c6ed44
2 changed files with 39 additions and 5 deletions
|
@ -138,7 +138,7 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
'My link',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTrue($this->Case->assertTags($input, $pattern));
|
||||
$this->assertTrue($this->Case->assertTags($input, $pattern), 'Attributes in wrong order. %s');
|
||||
|
||||
$input = "<a href=\"/test.html\"\t\n\tclass=\"active\"\tid=\"primary\">\t<span>My link</span></a>";
|
||||
$pattern = array(
|
||||
|
@ -148,7 +148,7 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
'/span',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTrue($this->Case->assertTags($input, $pattern));
|
||||
$this->assertTrue($this->Case->assertTags($input, $pattern), 'Whitespace consumption %s');
|
||||
|
||||
$input = '<p class="info"><a href="/test.html" class="active"><strong onClick="alert(\'hey\');">My link</strong></a></p>';
|
||||
$pattern = array(
|
||||
|
@ -163,6 +163,37 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
$this->assertTrue($this->Case->assertTags($input, $pattern));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that assertTags knows how to handle correct quoting.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testAssertTagsQuotes() {
|
||||
$input = '<a href="/test.html" class="active">My link</a>';
|
||||
$pattern = array(
|
||||
'a' => array('href' => '/test.html', 'class' => 'active'),
|
||||
'My link',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTrue($this->Case->assertTags($input, $pattern), 'Double quoted attributes %s');
|
||||
|
||||
$input = "<a href='/test.html' class='active'>My link</a>";
|
||||
$pattern = array(
|
||||
'a' => array('href' => '/test.html', 'class' => 'active'),
|
||||
'My link',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTrue($this->Case->assertTags($input, $pattern), 'Single quoted attributes %s');
|
||||
|
||||
$input = "<a href='/test.html' class='active'>My link</a>";
|
||||
$pattern = array(
|
||||
'a' => array('href' => 'preg:/.*\.html/', 'class' => 'active'),
|
||||
'My link',
|
||||
'/a'
|
||||
);
|
||||
$this->assertTrue($this->Case->assertTags($input, $pattern), 'Single quoted attributes %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* testNumericValuesInExpectationForAssertTags
|
||||
*
|
||||
|
|
|
@ -631,19 +631,20 @@ class CakeTestCase extends UnitTestCase {
|
|||
}
|
||||
$attrs = array();
|
||||
$explanations = array();
|
||||
$i = 1;
|
||||
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 {
|
||||
$quotes = '"';
|
||||
$quotes = '["\']';
|
||||
if (is_numeric($attr)) {
|
||||
$attr = $val;
|
||||
$val = '.+?';
|
||||
$explanations[] = sprintf('Attribute "%s" present', $attr);
|
||||
} elseif (!empty($val) && preg_match('/^preg\:\/(.+)\/$/i', $val, $matches)) {
|
||||
$quotes = '"?';
|
||||
$quotes = '["\']?';
|
||||
$val = $matches[1];
|
||||
$explanations[] = sprintf('Attribute "%s" matches "%s"', $attr, $val);
|
||||
} else {
|
||||
|
@ -652,9 +653,11 @@ class CakeTestCase extends UnitTestCase {
|
|||
}
|
||||
$attrs[] = '[\s]+' . preg_quote($attr, '/') . '=' . $quotes . $val . $quotes;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
if ($attrs) {
|
||||
$permutations = $this->__array_permute($attrs);
|
||||
|
||||
$permutationTokens = array();
|
||||
foreach ($permutations as $permutation) {
|
||||
$permutationTokens[] = implode('', $permutation);
|
||||
|
|
Loading…
Reference in a new issue