Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moving tests and un-skipping them.

Adding tests for proper field quoting in conditions.
Closes #2369
  • Loading branch information...
commit 8d1edd72f2132140d9e4c1ae12729c374303239f 1 parent dd335cb
@markstory markstory authored
View
58 lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
@@ -3461,4 +3461,62 @@ public function testExceptionOnBrokenConnection() {
'database' => 'imaginary'
));
}
+
+/**
+ * testStatements method
+ *
+ * @return void
+ */
+ public function testUpdateStatements() {
+ $this->loadFixtures('Article', 'User');
+ $test = ConnectionManager::getDatasource('test');
+
+ $this->Dbo = $this->getMock('Mysql', array('execute'), array($test->config));
+
+ $this->Dbo->expects($this->at(0))->method('execute')
+ ->with("UPDATE `articles` SET `field1` = 'value1' WHERE 1 = 1");
+
+ $this->Dbo->expects($this->at(1))->method('execute')
+ ->with("UPDATE `articles` AS `Article` LEFT JOIN `users` AS `User` ON (`Article`.`user_id` = `User`.`id`)" .
+ " SET `Article`.`field1` = 2 WHERE 2=2");
+
+ $this->Dbo->expects($this->at(2))->method('execute')
+ ->with("UPDATE `articles` AS `Article` LEFT JOIN `users` AS `User` ON (`Article`.`user_id` = `User`.`id`)" .
+ " SET `Article`.`field1` = 'value' WHERE `index` = 'val'");
+
+ $Article = new Article();
+
+ $this->Dbo->update($Article, array('field1'), array('value1'));
+ $this->Dbo->update($Article, array('field1'), array('2'), '2=2');
+ $this->Dbo->update($Article, array('field1'), array("'value'"), array('index' => 'val'));
+
+ }
+
+/**
+ * Test deletes with a mock.
+ *
+ * @return void
+ */
+ public function testDeleteStatements() {
+ $this->loadFixtures('Article', 'User');
+ $test = ConnectionManager::getDatasource('test');
+
+ $this->Dbo = $this->getMock('Mysql', array('execute'), array($test->config));
+
+ $this->Dbo->expects($this->at(0))->method('execute')
+ ->with("DELETE FROM `articles` WHERE 1 = 1");
+
+ $this->Dbo->expects($this->at(1))->method('execute')
+ ->with("DELETE `Article` FROM `articles` AS `Article` LEFT JOIN `users` AS `User` ON (`Article`.`user_id` = `User`.`id`)" .
+ " WHERE 1 = 1");
+
+ $this->Dbo->expects($this->at(2))->method('execute')
+ ->with("DELETE `Article` FROM `articles` AS `Article` LEFT JOIN `users` AS `User` ON (`Article`.`user_id` = `User`.`id`)" .
+ " WHERE 2=2");
+ $Article = new Article();
+
+ $this->Dbo->delete($Article);
+ $this->Dbo->delete($Article, true);
+ $this->Dbo->delete($Article, '2=2');
+ }
}
View
39 lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
@@ -740,45 +740,6 @@ public function testFieldsUsingMethodCache() {
$this->assertTrue(empty(DboTestSource::$methodCache['fields']), 'Cache not empty');
}
-/**
- * testStatements method
- *
- * @return void
- */
- public function testStatements() {
- $this->skipIf(!$this->testDb instanceof DboMysql);
-
- $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'Attachment', 'ArticlesTag');
- $Article = new Article();
-
- $result = $this->testDb->update($Article, array('field1'), array('value1'));
- $this->assertFalse($result);
- $result = $this->testDb->getLastQuery();
- $this->assertRegExp('/^\s*UPDATE\s+' . $this->testDb->fullTableName('articles') . '\s+SET\s+`field1`\s*=\s*\'value1\'\s+WHERE\s+1 = 1\s*$/', $result);
-
- $result = $this->testDb->update($Article, array('field1'), array('2'), '2=2');
- $this->assertFalse($result);
- $result = $this->testDb->getLastQuery();
- $this->assertRegExp('/^\s*UPDATE\s+' . $this->testDb->fullTableName('articles') . ' AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+SET\s+`Article`\.`field1`\s*=\s*2\s+WHERE\s+2\s*=\s*2\s*$/', $result);
-
- $result = $this->testDb->delete($Article);
- $this->assertTrue($result);
- $result = $this->testDb->getLastQuery();
- $this->assertRegExp('/^\s*DELETE\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+WHERE\s+1 = 1\s*$/', $result);
-
- $result = $this->testDb->delete($Article, true);
- $this->assertTrue($result);
- $result = $this->testDb->getLastQuery();
- $this->assertRegExp('/^\s*DELETE\s+`Article`\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+WHERE\s+1\s*=\s*1\s*$/', $result);
-
- $result = $this->testDb->delete($Article, '2=2');
- $this->assertTrue($result);
- $result = $this->testDb->getLastQuery();
- $this->assertRegExp('/^\s*DELETE\s+`Article`\s+FROM\s+' . $this->testDb->fullTableName('articles') . '\s+AS `Article`\s+LEFT JOIN\s+' . $this->testDb->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+WHERE\s+2\s*=\s*2\s*$/', $result);
-
- $result = $this->testDb->hasAny($Article, '1=2');
- $this->assertFalse($result);
- }
/**
* Test that group works without a model
Please sign in to comment.
Something went wrong with that request. Please try again.