mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Split tests of buildStatement()
This commit is contained in:
parent
abd7a257fe
commit
e18029064c
2 changed files with 58 additions and 10 deletions
|
@ -708,18 +708,17 @@ SQL;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test build statement
|
||||
* Test build statement with having option
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildStatement() {
|
||||
public function testBuildStatementWithHaving() {
|
||||
$db = $this->getMock('SqlserverTestDb', array('getVersion'), array($this->Dbo->config));
|
||||
|
||||
$db->expects($this->any())
|
||||
->method('getVersion')
|
||||
->will($this->returnValue('11.00.0000'));
|
||||
|
||||
// HAVING
|
||||
$query = array(
|
||||
'fields' => array('user_id', 'COUNT(*) AS count'),
|
||||
'table' => 'articles',
|
||||
|
@ -737,8 +736,20 @@ SQL;
|
|||
$sql = $db->buildStatement(array('offset' => 15) + $query, $this->model);
|
||||
$expected = 'SELECT user_id, COUNT(*) AS count FROM articles AS [Article] WHERE 1 = 1 GROUP BY user_id HAVING COUNT(*) > 10 ORDER BY COUNT(*) DESC OFFSET 15 ROWS FETCH FIRST 5 ROWS ONLY';
|
||||
$this->assertEquals($expected, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test build statement with lock option
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildStatementWithLockingHint() {
|
||||
$db = $this->getMock('SqlserverTestDb', array('getVersion'), array($this->Dbo->config));
|
||||
|
||||
$db->expects($this->any())
|
||||
->method('getVersion')
|
||||
->will($this->returnValue('11.00.0000'));
|
||||
|
||||
// WITH (UPDLOCK)
|
||||
$query = array(
|
||||
'fields' => array('id'),
|
||||
'table' => 'users',
|
||||
|
@ -758,18 +769,17 @@ SQL;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test build statement with legacy version
|
||||
* Test build statement with having option for legacy version
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildStatementWithLegacyVersion() {
|
||||
public function testBuildStatementWithHavingForLegacyVersion() {
|
||||
$db = $this->getMock('SqlserverTestDb', array('getVersion'), array($this->Dbo->config));
|
||||
|
||||
$db->expects($this->any())
|
||||
->method('getVersion')
|
||||
->will($this->returnValue('10.00.0000'));
|
||||
|
||||
// HAVING
|
||||
$query = array(
|
||||
'fields' => array('user_id', 'COUNT(*) AS count'),
|
||||
'table' => 'articles',
|
||||
|
@ -794,8 +804,20 @@ WHERE _cake_paging_._cake_page_rownum_ > 15
|
|||
ORDER BY _cake_paging_._cake_page_rownum_
|
||||
SQL;
|
||||
$this->assertEquals($expected, preg_replace('/^\s+|\s+$/m', '', $sql));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test build statement with lock option for legacy version
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildStatementWithLockingHintForLegacyVersion() {
|
||||
$db = $this->getMock('SqlserverTestDb', array('getVersion'), array($this->Dbo->config));
|
||||
|
||||
$db->expects($this->any())
|
||||
->method('getVersion')
|
||||
->will($this->returnValue('10.00.0000'));
|
||||
|
||||
// WITH (UPDLOCK)
|
||||
$query = array(
|
||||
'fields' => array('id'),
|
||||
'table' => 'users',
|
||||
|
|
|
@ -1473,8 +1473,21 @@ class DboSourceTest extends CakeTestCase {
|
|||
);
|
||||
$expected = 'SELECT DISTINCT(AssetsTag.asset_id) FROM assets_tags AS AssetsTag WHERE Tag.name = foo bar GROUP BY AssetsTag.asset_id';
|
||||
$this->assertEquals($expected, $subQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test build statement with having option
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildStatementWithHaving() {
|
||||
$conn = $this->getMock('MockPDO', array('quote'));
|
||||
$conn->expects($this->any())
|
||||
->method('quote')
|
||||
->will($this->returnArgument(0));
|
||||
$db = new DboTestSource();
|
||||
$db->setConnection($conn);
|
||||
|
||||
// HAVING
|
||||
$sql = $db->buildStatement(
|
||||
array(
|
||||
'fields' => array('user_id', 'COUNT(*) AS count'),
|
||||
|
@ -1489,8 +1502,21 @@ class DboSourceTest extends CakeTestCase {
|
|||
);
|
||||
$expected = 'SELECT user_id, COUNT(*) AS count FROM articles AS Article WHERE 1 = 1 GROUP BY user_id HAVING COUNT(*) > 10 ORDER BY COUNT(*) DESC LIMIT 5';
|
||||
$this->assertEquals($expected, $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test build statement with lock option
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildStatementWithLockingHint() {
|
||||
$conn = $this->getMock('MockPDO', array('quote'));
|
||||
$conn->expects($this->any())
|
||||
->method('quote')
|
||||
->will($this->returnArgument(0));
|
||||
$db = new DboTestSource();
|
||||
$db->setConnection($conn);
|
||||
|
||||
// FOR UPDATE
|
||||
$sql = $db->buildStatement(
|
||||
array(
|
||||
'fields' => array('id'),
|
||||
|
|
Loading…
Add table
Reference in a new issue