mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/17337] Extend write tests with simple transaction test
PHPBB-17337
This commit is contained in:
parent
c2d91650bd
commit
f3460fe9eb
2 changed files with 42 additions and 1 deletions
|
@ -73,6 +73,47 @@ class phpbb_dbal_write_test extends phpbb_database_test_case
|
||||||
$db->sql_freeresult($result);
|
$db->sql_freeresult($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_delete_rollback()
|
||||||
|
{
|
||||||
|
$db = $this->new_dbal();
|
||||||
|
|
||||||
|
$db->sql_transaction('begin');
|
||||||
|
|
||||||
|
$sql = "DELETE FROM phpbb_config
|
||||||
|
WHERE config_name = 'config1'";
|
||||||
|
$db->sql_query($sql);
|
||||||
|
|
||||||
|
// Rollback and check that nothing was changed
|
||||||
|
$db->sql_transaction('rollback');
|
||||||
|
|
||||||
|
$sql = 'SELECT *
|
||||||
|
FROM phpbb_config';
|
||||||
|
$result = $db->sql_query($sql);
|
||||||
|
$rows = $db->sql_fetchrowset($result);
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$this->assertEquals(2, count($rows));
|
||||||
|
$this->assertEquals('config1', $rows[0]['config_name']);
|
||||||
|
|
||||||
|
$db->sql_transaction('begin');
|
||||||
|
|
||||||
|
$sql = "DELETE FROM phpbb_config
|
||||||
|
WHERE config_name = 'config1'";
|
||||||
|
$db->sql_query($sql);
|
||||||
|
|
||||||
|
// Commit and check that data was actually changed
|
||||||
|
$db->sql_transaction('commit');
|
||||||
|
|
||||||
|
$sql = 'SELECT *
|
||||||
|
FROM phpbb_config';
|
||||||
|
$result = $db->sql_query($sql);
|
||||||
|
$rows = $db->sql_fetchrowset($result);
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$this->assertEquals(1, count($rows));
|
||||||
|
$this->assertEquals('config2', $rows[0]['config_name']);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_multiple_insert()
|
public function test_multiple_insert()
|
||||||
{
|
{
|
||||||
$db = $this->new_dbal();
|
$db = $this->new_dbal();
|
||||||
|
|
|
@ -285,7 +285,7 @@ abstract class phpbb_database_test_case extends TestCase
|
||||||
return $this->createDefaultDBConnection($manager->get_pdo(), 'testdb');
|
return $this->createDefaultDBConnection($manager->get_pdo(), 'testdb');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function new_dbal()
|
public function new_dbal() : \phpbb\db\driver\driver_interface
|
||||||
{
|
{
|
||||||
$config = $this->get_database_config();
|
$config = $this->get_database_config();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue