I'm using CakePHP and DBUnit for database testing. What I'd like to achieve is to test whether the form I've submitted on the website, inserts the data correctly into the DB. I have now a lot of UI tests, where I test the page itself, but I've only this small amount of DB test:
<?php
class testSchema extends PHPUnit_Extensions_Database_TestCase {
/*
** @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
*/
public function getConnection() {
$pdo = new PDO('mysql:dbname=job_manager;host=localhost','root','toor');
$pdo->exec("set foreign_key_checks=0");
return $this->createDefaultDBConnection($pdo, 'job_manager');
}
/*
** @return PHPUnit_Extensions_Database_DataSet_IDataSet
*/
public function getDataSet() {
$cascadeTruncates = true;
return $this->createMySQLXMLDataSet(dirname(__FILE__).'/default.xml');
}
public function testRowCounts() {
$this->assertEquals(3, $this->getConnection()->getRowCount('jobs'));
$this->assertEquals(1, $this->getConnection()->getRowCount('machines'));
$this->assertEquals(4, $this->getConnection()->getRowCount('users'));
}
}
?>
I've tried to do something like this:
$this->setBrowser('*firefox');
$this->setBrowserUrl('url');
$this->open('link');
Like I did in the UI tests, but it doesn't work (because this class is inherited from PHPUnit_Extensions_Database_TestCase and not from PHPUnit_Extensions_SeleniumTestCase)
Any ideas? Thanks
My solution at the end (maybe it can help someone later):
At the end I've created a bash script, and execute a UI test and a DB test after that. Also I had to modify the DB class such that:
public function getDataSet() {
$cascadeTruncates = true;
return $this->getConnection()->createDataSet();
}
So now it gets the dataset from the current DB.