adding UI tests for database configuration, fixed an issue with comment

table creation
pull/17/head
El RIDO 9 years ago
parent 7ec94e0db5
commit add980d36f

@ -22,7 +22,7 @@ abstract class zerobin_abstract
*
* @access protected
* @static
* @var zerobin
* @var zerobin_abstract
*/
protected static $_instance = null;

@ -166,7 +166,7 @@ class zerobin_db extends zerobin_abstract
}
// create comment table if needed
if (!array_key_exists(self::$_prefix . 'comment', $tables))
if (!in_array(self::$_prefix . 'comment', $tables))
{
self::$_db->exec(
'CREATE TABLE ' . self::$_prefix . 'comment ( ' .
@ -182,7 +182,7 @@ class zerobin_db extends zerobin_abstract
}
}
return parent::$_instance;
return self::$_instance;
}
/**

@ -27,9 +27,9 @@ class helper
'attachment' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
'attachmentname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
'meta' => array(
'formatter' => 'plaintext',
'postdate' => 1344803344,
'opendiscussion' => true,
'formatter' => 'plaintext',
),
);
@ -110,6 +110,19 @@ class helper
return $example;
}
/**
* get example comment
*
* @return array
*/
public static function getCommentPost($meta = array())
{
$example = self::getComment($meta);
$example['nickname'] = $example['meta']['nickname'];
unset($example['meta']['nickname']);
return $example;
}
/**
* delete directory and all its contents recursively
*

@ -1,7 +1,7 @@
<?php
class zerobinTest extends PHPUnit_Framework_TestCase
{
private $_model;
protected $_model;
public function setUp()
{
@ -14,6 +14,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
public function tearDown()
{
/* Tear Down Routine */
helper::confRestore();
}
public function reset()
@ -112,6 +113,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase
public function testCreate()
{
$this->reset();
$options = parse_ini_file(CONF, true);
$options['traffic']['limit'] = 0;
helper::confBackup();
helper::createIniFile(CONF, $options);
$_POST = helper::getPaste();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST';
@ -139,6 +144,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REMOTE_ADDR'] = '::1';
trafficlimiter::canPass();
ob_start();
new zerobin;
$content = ob_get_contents();
@ -390,7 +396,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
$options['traffic']['limit'] = 0;
helper::confBackup();
helper::createIniFile(CONF, $options);
$_POST = helper::getComment();
$_POST = helper::getCommentPost();
$_POST['pasteid'] = helper::getPasteId();
$_POST['parentid'] = helper::getPasteId();
$_POST['nickname'] = 'foo';
@ -416,7 +422,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
$options['traffic']['limit'] = 0;
helper::confBackup();
helper::createIniFile(CONF, $options);
$_POST = helper::getComment();
$_POST = helper::getCommentPost();
$_POST['pasteid'] = helper::getPasteId();
$_POST['parentid'] = helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
@ -441,7 +447,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
$options['traffic']['limit'] = 0;
helper::confBackup();
helper::createIniFile(CONF, $options);
$_POST = helper::getComment();
$_POST = helper::getCommentPost();
$_POST['pasteid'] = helper::getPasteId();
$_POST['parentid'] = 'foo';
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
@ -466,7 +472,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
$options['traffic']['limit'] = 0;
helper::confBackup();
helper::createIniFile(CONF, $options);
$_POST = helper::getComment();
$_POST = helper::getCommentPost();
$_POST['pasteid'] = helper::getPasteId();
$_POST['parentid'] = helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
@ -492,7 +498,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
$options['traffic']['limit'] = 0;
helper::confBackup();
helper::createIniFile(CONF, $options);
$_POST = helper::getComment();
$_POST = helper::getCommentPost();
$_POST['pasteid'] = helper::getPasteId();
$_POST['parentid'] = helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
@ -519,7 +525,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
$this->_model->create(helper::getPasteId(), helper::getPaste());
$this->_model->createComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId(), helper::getComment());
$this->assertTrue($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment exists before posting data');
$_POST = helper::getComment();
$_POST = helper::getCommentPost();
$_POST['pasteid'] = helper::getPasteId();
$_POST['parentid'] = helper::getPasteId();
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
@ -676,8 +682,12 @@ class zerobinTest extends PHPUnit_Framework_TestCase
public function testReadOldSyntax()
{
$this->reset();
$oldPaste = helper::getPaste(array('syntaxcoloring' => true));
unset($oldPaste['meta']['formatter']);
$oldPaste = helper::getPaste();
$oldPaste['meta'] = array(
'syntaxcoloring' => true,
'postdate' => $oldPaste['meta']['postdate'],
'opendiscussion' => $oldPaste['meta']['opendiscussion'],
);
$this->_model->create(helper::getPasteId(), $oldPaste);
$_SERVER['QUERY_STRING'] = helper::getPasteId();
ob_start();

@ -0,0 +1,43 @@
<?php
require_once 'zerobin.php';
class zerobinWithDbTest extends zerobinTest
{
private $_options = array(
'dsn' => 'sqlite:../data/tst.sq3',
'usr' => null,
'pwd' => null,
'opt' => array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_PERSISTENT => true
),
);
public function setUp()
{
/* Setup Routine */
$this->_model = zerobin_db::getInstance($this->_options);
serversalt::setPath(PATH . 'data');
$this->reset();
}
public function tearDown()
{
/* Tear Down Routine */
parent::tearDown();
@unlink('../data/tst.sq3');
}
public function reset()
{
parent::reset();
// but then inject a db config
$options = parse_ini_file(CONF, true);
$options['model'] = array(
'class' => 'zerobin_db',
);
$options['model_options'] = $this->_options;
helper::confBackup();
helper::createIniFile(CONF, $options);
}
}
Loading…
Cancel
Save