privatebinWithDb.php 1.2 KB

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