2015-10-03 21:52:37 +08:00
|
|
|
<?php
|
2016-07-21 23:09:48 +08:00
|
|
|
|
2016-08-09 17:54:42 +08:00
|
|
|
use PrivateBin\Data\Database;
|
2021-06-09 13:47:40 +08:00
|
|
|
use PrivateBin\Persistence\ServerSalt;
|
|
|
|
use PrivateBin\Persistence\TrafficLimiter;
|
2016-07-21 23:09:48 +08:00
|
|
|
|
2018-07-29 21:17:35 +08:00
|
|
|
require_once 'ControllerTest.php';
|
2015-10-03 21:52:37 +08:00
|
|
|
|
2018-07-29 21:17:35 +08:00
|
|
|
class ControllerWithDbTest extends ControllerTest
|
2015-10-03 21:52:37 +08:00
|
|
|
{
|
|
|
|
private $_options = array(
|
|
|
|
'usr' => null,
|
|
|
|
'pwd' => null,
|
|
|
|
'opt' => array(
|
2016-10-29 16:24:08 +08:00
|
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
|
|
PDO::ATTR_PERSISTENT => true,
|
2015-10-03 21:52:37 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2020-10-10 18:22:20 +08:00
|
|
|
public function setUp(): void
|
2015-10-03 21:52:37 +08:00
|
|
|
{
|
|
|
|
/* Setup Routine */
|
2016-07-15 23:02:59 +08:00
|
|
|
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
|
2016-07-26 14:19:35 +08:00
|
|
|
if (!is_dir($this->_path)) {
|
|
|
|
mkdir($this->_path);
|
|
|
|
}
|
2016-07-18 20:47:32 +08:00
|
|
|
$this->_options['dsn'] = 'sqlite:' . $this->_path . DIRECTORY_SEPARATOR . 'tst.sq3';
|
2022-10-28 07:01:02 +08:00
|
|
|
$this->_data = new Database($this->_options);
|
2021-06-09 13:47:40 +08:00
|
|
|
ServerSalt::setStore($this->_data);
|
|
|
|
TrafficLimiter::setStore($this->_data);
|
2015-10-03 21:52:37 +08:00
|
|
|
$this->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function reset()
|
|
|
|
{
|
|
|
|
parent::reset();
|
|
|
|
// but then inject a db config
|
2016-10-29 16:24:08 +08:00
|
|
|
$options = parse_ini_file(CONF, true);
|
2015-10-03 21:52:37 +08:00
|
|
|
$options['model'] = array(
|
2016-08-09 17:54:42 +08:00
|
|
|
'class' => 'Database',
|
2015-10-03 21:52:37 +08:00
|
|
|
);
|
2017-11-14 05:05:29 +08:00
|
|
|
$options['model_options'] = $this->_options;
|
2016-08-09 17:54:42 +08:00
|
|
|
Helper::createIniFile(CONF, $options);
|
2015-10-03 21:52:37 +08:00
|
|
|
}
|
2016-07-11 20:15:20 +08:00
|
|
|
}
|