mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 19:38:26 +00:00
Added tests from Ticket #2357, Ticket #2358 Fixed failing DboSourceTest: source:/branches/1.2.x.x/cake/tests/cases/libs/model/datasources/dbo_source.test.php@4778#L1080 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4801 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
48f3349c9a
commit
d5fa0a961b
2 changed files with 57 additions and 28 deletions
|
@ -1403,13 +1403,7 @@ class DboSource extends DataSource {
|
||||||
|
|
||||||
for($i = 0; $i < $pregCount; $i++) {
|
for($i = 0; $i < $pregCount; $i++) {
|
||||||
if (!empty($match['1'][$i]) && !is_numeric($match['1'][$i])) {
|
if (!empty($match['1'][$i]) && !is_numeric($match['1'][$i])) {
|
||||||
$conditions = preg_replace('/^' . $match['0'][$i] . '(?=[^\\w])/', ' ' . $this->name($match['1'][$i]), $conditions . ' ');
|
$conditions = preg_replace('/\b' . $match['0'][$i] . '\b/', $this->name($match['1'][$i]), $conditions);}
|
||||||
if (strpos($conditions, '(' . $match['0'][$i]) === false) {
|
|
||||||
$conditions = preg_replace('/[^\w]' . $match['0'][$i] . '(?=[^\\w])/', ' '.$this->name($match['1'][$i]), $conditions);
|
|
||||||
} else {
|
|
||||||
$conditions = preg_replace('/' . $match['0'][$i] . '(?=[^\\w])/', ' '.$this->name($match['1'][$i]), $conditions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$conditions = rtrim($conditions);
|
$conditions = rtrim($conditions);
|
||||||
}
|
}
|
||||||
|
@ -1510,12 +1504,39 @@ class DboSource extends DataSource {
|
||||||
$data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2'];
|
$data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2'];
|
||||||
} else {
|
} else {
|
||||||
if (!empty($match['2']) && $quoteValues) {
|
if (!empty($match['2']) && $quoteValues) {
|
||||||
|
if (strpos($match['2'], '()') === false) {
|
||||||
$match['2'] = $this->value($match['2']);
|
$match['2'] = $this->value($match['2']);
|
||||||
|
}
|
||||||
|
|
||||||
$match['2'] = str_replace(' AND ', "' AND '", $match['2']);
|
$match['2'] = str_replace(' AND ', "' AND '", $match['2']);
|
||||||
}
|
}
|
||||||
|
$start = null;
|
||||||
|
$end = null;
|
||||||
|
|
||||||
|
if (!empty($this->startQuote)) {
|
||||||
|
$start = '\\\\' . $this->startQuote . '\\\\';
|
||||||
|
}
|
||||||
|
$end = $this->endQuote;
|
||||||
|
|
||||||
|
if (!empty($this->endQuote)) {
|
||||||
|
$end = '\\\\' . $this->endQuote . '\\\\';
|
||||||
|
}
|
||||||
|
$key = str_replace(array($this->startQuote, $this->endQuote), '', $key);
|
||||||
|
preg_match_all('/(?:\'[^\'\\\]*(?:\\\.[^\'\\\]*)*\')|([a-z0-9_' . $start . $end . ']*\\.[a-z0-9_' . $start . $end . ']*)/i', $key, $replace, PREG_PATTERN_ORDER);
|
||||||
|
|
||||||
|
if (isset($replace['1']['0'])) {
|
||||||
|
$pregCount = count($replace['1']);
|
||||||
|
|
||||||
|
for($i = 0; $i < $pregCount; $i++) {
|
||||||
|
if (!empty($replace['1'][$i]) && !is_numeric($replace['1'][$i])) {
|
||||||
|
$key = preg_replace('/\b' . $replace['0'][$i] . '\b/', $this->name($replace['1'][$i]), $key);}
|
||||||
|
}
|
||||||
|
$data = $key . ' ' . $match['1'] . ' ' . $match['2'];
|
||||||
|
} else {
|
||||||
$data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2'];
|
$data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($data != null) {
|
if ($data != null) {
|
||||||
$out[] = $data;
|
$out[] = $data;
|
||||||
|
|
|
@ -940,11 +940,11 @@ class DboSourceTest extends UnitTestCase {
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->conditions("SUM(Post.comments_count) > 500");
|
$result = $this->db->conditions("SUM(Post.comments_count) > 500");
|
||||||
$expected = " WHERE SUM( `Post`.`comments_count`) > 500";
|
$expected = " WHERE SUM(`Post`.`comments_count`) > 500";
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->conditions("(Post.created < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)");
|
$result = $this->db->conditions("(Post.created < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)");
|
||||||
$expected = " WHERE ( `Post`.`created` < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR( `Post`.`created`), MONTH( `Post`.`created`)";
|
$expected = " WHERE (`Post`.`created` < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`)";
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->conditions("score BETWEEN 90.1 AND 95.7");
|
$result = $this->db->conditions("score BETWEEN 90.1 AND 95.7");
|
||||||
|
@ -956,7 +956,7 @@ class DboSourceTest extends UnitTestCase {
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->conditions("(Post.created < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)");
|
$result = $this->db->conditions("(Post.created < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)");
|
||||||
$expected = " WHERE ( `Post`.`created` < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR( `Post`.`created`), MONTH( `Post`.`created`)";
|
$expected = " WHERE (`Post`.`created` < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`)";
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->conditions('Sportstaette.sportstaette LIKE "%ru%" AND Sportstaette.sportstaettenart_id = 2');
|
$result = $this->db->conditions('Sportstaette.sportstaette LIKE "%ru%" AND Sportstaette.sportstaettenart_id = 2');
|
||||||
|
@ -969,15 +969,15 @@ class DboSourceTest extends UnitTestCase {
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->conditions('SUM(Post.comments_count) > 500 AND NOT Post.title IS NULL AND NOT Post.extended_title IS NULL');
|
$result = $this->db->conditions('SUM(Post.comments_count) > 500 AND NOT Post.title IS NULL AND NOT Post.extended_title IS NULL');
|
||||||
$expected = ' WHERE SUM( `Post`.`comments_count`) > 500 AND NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL';
|
$expected = ' WHERE SUM(`Post`.`comments_count`) > 500 AND NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->conditions('NOT Post.title IS NULL AND NOT Post.extended_title IS NULL AND SUM(Post.comments_count) > 500');
|
$result = $this->db->conditions('NOT Post.title IS NULL AND NOT Post.extended_title IS NULL AND SUM(Post.comments_count) > 500');
|
||||||
$expected = ' WHERE NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL AND SUM( `Post`.`comments_count`) > 500';
|
$expected = ' WHERE NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL AND SUM(`Post`.`comments_count`) > 500';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->conditions('NOT Post.extended_title IS NULL AND NOT Post.title IS NULL AND Post.title != "" AND SPOON(SUM(Post.comments_count) + 1.1) > 500');
|
$result = $this->db->conditions('NOT Post.extended_title IS NULL AND NOT Post.title IS NULL AND Post.title != "" AND SPOON(SUM(Post.comments_count) + 1.1) > 500');
|
||||||
$expected = ' WHERE NOT `Post`.`extended_title` IS NULL AND NOT `Post`.`title` IS NULL AND `Post`.`title` != "" AND SPOON(SUM( `Post`.`comments_count`) + 1.1) > 500';
|
$expected = ' WHERE NOT `Post`.`extended_title` IS NULL AND NOT `Post`.`title` IS NULL AND `Post`.`title` != "" AND SPOON(SUM(`Post`.`comments_count`) + 1.1) > 500';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->conditions('NOT Post.title_extended IS NULL AND NOT Post.title IS NULL AND Post.title_extended != Post.title');
|
$result = $this->db->conditions('NOT Post.title_extended IS NULL AND NOT Post.title IS NULL AND Post.title_extended != Post.title');
|
||||||
|
@ -989,11 +989,15 @@ class DboSourceTest extends UnitTestCase {
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->conditions("lower(Article.title) LIKE 'a%'");
|
$result = $this->db->conditions("lower(Article.title) LIKE 'a%'");
|
||||||
$expected = " WHERE lower( `Article`.`title`) LIKE 'a%'";
|
$expected = " WHERE lower(`Article`.`title`) LIKE 'a%'";
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->conditions('((MATCH(Video.title) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 2) + (MATCH( Video.description) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 0.4) + (MATCH(Video.tags) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 1.5))');
|
$result = $this->db->conditions('((MATCH(Video.title) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 2) + (MATCH(Video.description) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 0.4) + (MATCH(Video.tags) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 1.5))');
|
||||||
$expected = ' WHERE ((MATCH( `Video`.`title`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 2) + (MATCH( `Video`.`description`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 0.4) + (MATCH( `Video`.`tags`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 1.5))';
|
$expected = ' WHERE ((MATCH(`Video`.`title`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 2) + (MATCH(`Video`.`description`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 0.4) + (MATCH(`Video`.`tags`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 1.5))';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->db->conditions('DATEDIFF(NOW(),Article.published) < 1 && Article.live=1');
|
||||||
|
$expected = " WHERE DATEDIFF(NOW(),`Article`.`published`) < 1 && `Article`.`live`=1";
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1077,8 +1081,12 @@ class DboSourceTest extends UnitTestCase {
|
||||||
$result = $this->db->conditions(array('(Usergroup.permissions) & 4' => 4));
|
$result = $this->db->conditions(array('(Usergroup.permissions) & 4' => 4));
|
||||||
$this->assertPattern('/^\s*WHERE\s+\(`Usergroup`\.`permissions`\)\s+& 4\s+=\s+4\s*$/', $result);
|
$this->assertPattern('/^\s*WHERE\s+\(`Usergroup`\.`permissions`\)\s+& 4\s+=\s+4\s*$/', $result);
|
||||||
|
|
||||||
//$result = $this->db->conditions(array('((Usergroup.permissions) & 4)' => 4));
|
$result = $this->db->conditions(array('((Usergroup.permissions) & 4)' => 4));
|
||||||
//$this->assertPattern('/^\s*WHERE\s+\(\(`Usergroup`\.`permissions`\)\s+& 4\)\s+=\s+4\s*$/', $result);
|
$this->assertPattern('/^\s*WHERE\s+\(\(`Usergroup`\.`permissions`\)\s+& 4\)\s+=\s+4\s*$/', $result);
|
||||||
|
|
||||||
|
$result = $this->db->conditions(array('Post.modified' => '>= DATE_SUB(NOW(), INTERVAL 7 DAY)'));
|
||||||
|
$expected = " WHERE `Post`.`modified` >= DATE_SUB(NOW(), INTERVAL 7 DAY)";
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$result = $this->db->conditions(array(
|
$result = $this->db->conditions(array(
|
||||||
'NOT' => array('Course.id' => null, 'Course.vet' => 'N', 'level_of_education_id' => array(912,999)),
|
'NOT' => array('Course.id' => null, 'Course.vet' => 'N', 'level_of_education_id' => array(912,999)),
|
||||||
|
|
Loading…
Reference in a new issue