privatebinWithDb.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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)) mkdir($this->_path);
  23. $this->_options['dsn'] = 'sqlite:' . $this->_path . DIRECTORY_SEPARATOR . 'tst.sq3';
  24. $this->_model = db::getInstance($this->_options);
  25. $this->reset();
  26. }
  27. public function tearDown()
  28. {
  29. /* Tear Down Routine */
  30. parent::tearDown();
  31. helper::rmdir($this->_path);
  32. }
  33. public function reset()
  34. {
  35. parent::reset();
  36. // but then inject a db config
  37. $options = parse_ini_file(CONF, true);
  38. $options['model'] = array(
  39. 'class' => 'privatebin_db',
  40. );
  41. $options['model_options'] = $this->_options;
  42. helper::confBackup();
  43. helper::createIniFile(CONF, $options);
  44. }
  45. }