2013-03-27 11:45:45 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package testing
|
|
|
|
* @copyright (c) 2013 phpBB Group
|
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case
|
|
|
|
{
|
2013-03-27 23:45:10 +01:00
|
|
|
protected $db;
|
|
|
|
protected $buffer;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->db = $this->new_dbal();
|
|
|
|
$this->buffer = new phpbb_db_sql_insert_buffer($this->db, 'phpbb_config', 2);
|
|
|
|
}
|
|
|
|
|
2013-03-27 11:45:45 +01:00
|
|
|
public function getDataSet()
|
|
|
|
{
|
|
|
|
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
|
|
|
|
}
|
|
|
|
|
2013-03-27 20:54:20 +01:00
|
|
|
public function test_multi_insert_disabled_insert_and_flush()
|
2013-03-27 11:45:45 +01:00
|
|
|
{
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->db->multi_insert = false;
|
2013-03-27 20:54:20 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(2);
|
2013-03-27 20:54:20 +01:00
|
|
|
|
|
|
|
// This call can be buffered
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assertTrue($this->buffer->insert($this->get_row(1)));
|
2013-03-27 20:54:20 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(3);
|
2013-03-27 20:54:20 +01:00
|
|
|
|
|
|
|
// Manually flush
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assertFalse($this->buffer->flush());
|
2013-03-27 20:54:20 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(3);
|
2013-03-27 11:45:45 +01:00
|
|
|
}
|
|
|
|
|
2013-03-27 20:54:20 +01:00
|
|
|
public function test_multi_insert_enabled_insert_and_flush()
|
2013-03-27 11:45:45 +01:00
|
|
|
{
|
2013-03-27 23:45:10 +01:00
|
|
|
if (!$this->db->multi_insert)
|
2013-03-27 20:54:20 +01:00
|
|
|
{
|
|
|
|
$this->markTestSkipped('Database does not support multi_insert');
|
|
|
|
}
|
2013-03-27 11:45:45 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(2);
|
2013-03-27 11:45:45 +01:00
|
|
|
|
|
|
|
// This call can be buffered
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assertFalse($this->buffer->insert($this->get_row(1)));
|
2013-03-27 11:45:45 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(2);
|
2013-03-27 11:45:45 +01:00
|
|
|
|
|
|
|
// Manually flush
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assertTrue($this->buffer->flush());
|
2013-03-27 11:45:45 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(3);
|
2013-03-27 11:45:45 +01:00
|
|
|
}
|
|
|
|
|
2013-03-27 20:54:20 +01:00
|
|
|
public function test_multi_insert_disabled_insert_with_flush()
|
2013-03-27 11:45:45 +01:00
|
|
|
{
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->db->multi_insert = false;
|
2013-03-27 11:45:45 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(2);
|
2013-03-27 11:45:45 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assertTrue($this->buffer->insert($this->get_row(1)));
|
2013-03-27 11:45:45 +01:00
|
|
|
|
|
|
|
// This call flushes the values
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assertTrue($this->buffer->insert($this->get_row(2)));
|
2013-03-27 11:45:45 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(4);
|
2013-03-27 11:45:45 +01:00
|
|
|
}
|
|
|
|
|
2013-03-27 20:54:20 +01:00
|
|
|
public function test_multi_insert_enabled_insert_with_flush()
|
2013-03-27 11:45:45 +01:00
|
|
|
{
|
2013-03-27 23:45:10 +01:00
|
|
|
if (!$this->db->multi_insert)
|
2013-03-27 20:54:20 +01:00
|
|
|
{
|
|
|
|
$this->markTestSkipped('Database does not support multi_insert');
|
|
|
|
}
|
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(2);
|
2013-03-27 20:54:20 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assertFalse($this->buffer->insert($this->get_row(1)));
|
2013-03-27 20:54:20 +01:00
|
|
|
|
|
|
|
// This call flushes the values
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assertTrue($this->buffer->insert($this->get_row(2)));
|
2013-03-27 20:54:20 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(4);
|
2013-03-27 20:54:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_multi_insert_disabled_insert_all_and_flush()
|
|
|
|
{
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->db->multi_insert = false;
|
2013-03-27 11:45:45 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(2);
|
2013-03-27 11:45:45 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assertTrue($this->buffer->insert_all($this->get_three_rows()));
|
2013-03-27 11:45:45 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(5);
|
2013-03-27 20:54:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_multi_insert_enabled_insert_all_and_flush()
|
|
|
|
{
|
2013-03-27 23:45:10 +01:00
|
|
|
if (!$this->db->multi_insert)
|
2013-03-27 20:54:20 +01:00
|
|
|
{
|
|
|
|
$this->markTestSkipped('Database does not support multi_insert');
|
2013-03-27 11:45:45 +01:00
|
|
|
}
|
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(2);
|
2013-03-27 20:54:20 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assertTrue($this->buffer->insert_all($this->get_three_rows()));
|
2013-03-27 20:54:20 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(4);
|
2013-03-27 20:54:20 +01:00
|
|
|
|
|
|
|
// Manually flush
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assertTrue($this->buffer->flush());
|
2013-03-27 20:54:20 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
$this->assert_config_count(5);
|
2013-03-27 11:45:45 +01:00
|
|
|
}
|
2013-03-27 23:21:29 +01:00
|
|
|
|
2013-03-27 23:45:10 +01:00
|
|
|
protected function assert_config_count($num_configs)
|
2013-03-27 23:21:29 +01:00
|
|
|
{
|
|
|
|
$sql = 'SELECT COUNT(*) AS num_configs
|
|
|
|
FROM phpbb_config';
|
2013-03-27 23:45:10 +01:00
|
|
|
$result = $this->db->sql_query($sql);
|
|
|
|
$this->assertEquals($num_configs, $this->db->sql_fetchfield('num_configs'));
|
|
|
|
$this->db->sql_freeresult($result);
|
2013-03-27 23:21:29 +01:00
|
|
|
}
|
2013-03-27 23:30:23 +01:00
|
|
|
|
2013-03-27 23:33:13 +01:00
|
|
|
protected function get_row($rownum)
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'config_name' => "name$rownum",
|
|
|
|
'config_value' => "value$rownum",
|
|
|
|
'is_dynamic' => '0',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-03-27 23:30:23 +01:00
|
|
|
protected function get_three_rows()
|
|
|
|
{
|
|
|
|
return array(
|
2013-03-27 23:33:13 +01:00
|
|
|
$this->get_row(1),
|
|
|
|
$this->get_row(2),
|
|
|
|
$this->get_row(3),
|
2013-03-27 23:30:23 +01:00
|
|
|
);
|
|
|
|
}
|
2013-03-27 11:45:45 +01:00
|
|
|
}
|