privatebinWithDb.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. use PrivateBin\data\db;
  3. use PrivateBin\privatebin;
  4. use PrivateBin\serversalt;
  5. use PrivateBin\trafficlimiter;
  6. require_once 'privatebin.php';
  7. class privatebinWithDbTest extends privatebinTest
  8. {
  9. private $_options = array(
  10. 'usr' => null,
  11. 'pwd' => null,
  12. 'opt' => array(
  13. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  14. PDO::ATTR_PERSISTENT => true
  15. ),
  16. );
  17. private $_path;
  18. public function setUp()
  19. {
  20. /* Setup Routine */
  21. $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
  22. if (!is_dir($this->_path)) {
  23. mkdir($this->_path);
  24. }
  25. $this->_options['dsn'] = 'sqlite:' . $this->_path . DIRECTORY_SEPARATOR . 'tst.sq3';
  26. $this->_model = db::getInstance($this->_options);
  27. $this->reset();
  28. }
  29. public function tearDown()
  30. {
  31. /* Tear Down Routine */
  32. parent::tearDown();
  33. helper::rmdir($this->_path);
  34. }
  35. public function reset()
  36. {
  37. parent::reset();
  38. // but then inject a db config
  39. $options = parse_ini_file(CONF, true);
  40. $options['model'] = array(
  41. 'class' => 'privatebin_db',
  42. );
  43. $options['model_options'] = $this->_options;
  44. helper::confBackup();
  45. helper::createIniFile(CONF, $options);
  46. }
  47. }