* @license GNU General Public License, version 2 (GPL-2.0) * * For full copyright and license information, please see * the docs/CREDITS.txt file. * */ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_TestCase { static private $already_connected; private $db_connections; protected $test_case_helpers; protected $fixture_xml_data; static protected $schema_file; static protected $phpbb_schema_copy; static protected $install_schema_file; public function __construct($name = NULL, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); $this->backupStaticAttributesBlacklist += array( 'PHP_CodeCoverage' => array('instance'), 'PHP_CodeCoverage_Filter' => array('instance'), 'PHP_CodeCoverage_Util' => array('ignoredLines', 'templateMethods'), 'PHP_Timer' => array('startTimes',), 'PHP_Token_Stream' => array('customTokens'), 'PHP_Token_Stream_CachingFactory' => array('cache'), 'phpbb_database_test_case' => array('already_connected'), ); $this->db_connections = array(); } /** * @return array List of extensions that should be set up */ static protected function setup_extensions() { return array(); } static public function setUpBeforeClass() { $setup_extensions = static::setup_extensions(); self::$schema_file = ''; if (!empty($setup_extensions)) { $schema_md5 = md5(serialize($setup_extensions)); self::$schema_file = __DIR__ . '/../tmp/' . $schema_md5 . '.json'; self::$phpbb_schema_copy = __DIR__ . '/../tmp/schema_phpbb_copy.json'; self::$install_schema_file = __DIR__ . '/../../phpBB/install/schemas/schema.json'; if (!file_exists(self::$schema_file)) { global $phpbb_root_path, $phpEx, $table_prefix; $finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx); $classes = $finder->core_path('phpbb/') ->core_directory('/db/migration/data') ->set_extensions($setup_extensions) ->extension_directory('migrations') ->get_classes(); $db = new \phpbb\db\driver\sqlite(); $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix); $schema_data = $schema_generator->get_schema(); file_put_contents(self::$schema_file, json_encode($schema_data)); } copy(self::$install_schema_file, self::$phpbb_schema_copy); copy(self::$schema_file, self::$install_schema_file); } parent::setUpBeforeClass(); } static public function tearDownAfterClass() { if (self::$schema_file !== '') { copy(self::$phpbb_schema_copy, self::$install_schema_file); unlink(self::$schema_file); } parent::tearDownAfterClass(); } protected function tearDown() { parent::tearDown(); // Close all database connections from this test if (!empty($this->db_connections)) { foreach ($this->db_connections as $db) { $db->sql_close(); } } } protected function setUp() { parent::setUp(); // Resynchronise tables if a fixture was loaded if (isset($this->fixture_xml_data)) { $config = $this->get_database_config(); $manager = $this->create_connection_manager($config); $manager->connect(); $manager->post_setup_synchronisation($this->fixture_xml_data); } } /** * Performs synchronisations for a given table/column set on the database * * @param array $table_column_map Information about the tables/columns to synchronise * * @return null */ protected function database_synchronisation($table_column_map) { $config = $this->get_database_config(); $manager = $this->create_connection_manager($config); $manager->connect(); $manager->database_synchronisation($table_column_map); } public function createXMLDataSet($path) { $db_config = $this->get_database_config(); // Firebird requires table and column names to be uppercase if ($db_config['dbms'] == 'phpbb\db\driver\firebird') { $xml_data = file_get_contents($path); $xml_data = preg_replace_callback('/(?:(