diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php index 9c970fba9..81fa8e7b2 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php @@ -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', diff --git a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php index 8a1d02bbb..75e519136 100644 --- a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php @@ -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'),