Skip to content

Commit

Permalink
Moving method back to DboSourceTest, as it was very difficult to adap…
Browse files Browse the repository at this point in the history
…t it to use mock objects
  • Loading branch information
lorenzo committed Nov 11, 2010
1 parent 00a3eda commit 91e2d88
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 47 deletions.
47 changes: 0 additions & 47 deletions cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2846,53 +2846,6 @@ function testHasAny() {

}


/**
* testStatements method
*
* @access public
* @return void
*/
function testStatements() {
$this->skipIf(true, 'Fix me');
$this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'Attachment', 'ArticlesTag');
$Article = new Article();
//$this->Dbo = $this->getMock('DboMysql', array('connect', 'execute', '_execute'));

$result = $this->Dbo->update($Article, array('field1'), array('value1'));
$this->assertFalse($result);
$result = $this->Dbo->getLastQuery();
$this->assertPattern('/^\s*UPDATE\s+' . $this->Dbo->fullTableName('articles') . '\s+SET\s+`field1`\s*=\s*\'value1\'\s+WHERE\s+1 = 1\s*$/', $result);

$result = $this->Dbo->update($Article, array('field1'), array('2'), '2=2');
$this->assertFalse($result);
$result = $this->Dbo->getLastQuery();
$this->assertPattern('/^\s*UPDATE\s+' . $this->Dbo->fullTableName('articles') . ' AS `Article`\s+LEFT JOIN\s+' . $this->Dbo->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->Dbo->delete($Article);
$this->assertTrue($result);
$result = $this->Dbo->getLastQuery();
$this->assertPattern('/^\s*DELETE\s+FROM\s+' . $this->Dbo->fullTableName('articles') . '\s+WHERE\s+1 = 1\s*$/', $result);

$result = $this->Dbo->delete($Article, true);
$this->assertTrue($result);
$result = $this->Dbo->getLastQuery();
$this->assertPattern('/^\s*DELETE\s+`Article`\s+FROM\s+' . $this->Dbo->fullTableName('articles') . '\s+AS `Article`\s+LEFT JOIN\s+' . $this->Dbo->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+WHERE\s+1\s*=\s*1\s*$/', $result);

$result = $this->Dbo->delete($Article, '2=2');
$this->assertTrue($result);
$result = $this->Dbo->getLastQuery();
$this->assertPattern('/^\s*DELETE\s+`Article`\s+FROM\s+' . $this->Dbo->fullTableName('articles') . '\s+AS `Article`\s+LEFT JOIN\s+' . $this->Dbo->fullTableName('users') . ' AS `User` ON \(`Article`.`user_id` = `User`.`id`\)\s+WHERE\s+2\s*=\s*2\s*$/', $result);

$result = $this->Dbo->hasAny($Article, '1=2');
$this->assertFalse($result);

$result = $this->Dbo->insertMulti('articles', array('field'), array('(1)', '(2)'));
$this->assertNull($result);
$result = $this->Dbo->getLastQuery();
$this->assertPattern('/^\s*INSERT INTO\s+' . $this->Dbo->fullTableName('articles') . '\s+\(`field`\)\s+VALUES\s+\(1\),\s*\(2\)\s*$/', $result);
}

/**
* test fields generating usable virtual fields to use in query
*
Expand Down
40 changes: 40 additions & 0 deletions cake/tests/cases/libs/model/datasources/dbo_source.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,4 +800,44 @@ function testFieldsUsingMethodCache() {
$this->testDb->fields($Article, null, array('title', 'body', 'published'));
$this->assertTrue(empty($this->testDb->methodCache['fields']), 'Cache not empty');
}

/**
* testStatements method
*
* @access public
* @return void
*/
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->assertPattern('/^\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->assertPattern('/^\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->assertPattern('/^\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->assertPattern('/^\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->assertPattern('/^\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);
}
}

0 comments on commit 91e2d88

Please sign in to comment.