adding UI tests for database configuration, fixed an issue with comment
table creation
This commit is contained in:
parent
7ec94e0db5
commit
add980d36f
5 changed files with 79 additions and 13 deletions
|
@ -22,7 +22,7 @@ abstract class zerobin_abstract
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @static
|
* @static
|
||||||
* @var zerobin
|
* @var zerobin_abstract
|
||||||
*/
|
*/
|
||||||
protected static $_instance = null;
|
protected static $_instance = null;
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ class zerobin_db extends zerobin_abstract
|
||||||
}
|
}
|
||||||
|
|
||||||
// create comment table if needed
|
// create comment table if needed
|
||||||
if (!array_key_exists(self::$_prefix . 'comment', $tables))
|
if (!in_array(self::$_prefix . 'comment', $tables))
|
||||||
{
|
{
|
||||||
self::$_db->exec(
|
self::$_db->exec(
|
||||||
'CREATE TABLE ' . self::$_prefix . 'comment ( ' .
|
'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"}',
|
'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"}',
|
'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(
|
'meta' => array(
|
||||||
|
'formatter' => 'plaintext',
|
||||||
'postdate' => 1344803344,
|
'postdate' => 1344803344,
|
||||||
'opendiscussion' => true,
|
'opendiscussion' => true,
|
||||||
'formatter' => 'plaintext',
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -110,6 +110,19 @@ class helper
|
||||||
return $example;
|
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
|
* delete directory and all its contents recursively
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
class zerobinTest extends PHPUnit_Framework_TestCase
|
class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private $_model;
|
protected $_model;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
@ -14,6 +14,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
/* Tear Down Routine */
|
/* Tear Down Routine */
|
||||||
|
helper::confRestore();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reset()
|
public function reset()
|
||||||
|
@ -112,6 +113,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testCreate()
|
public function testCreate()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
|
$options = parse_ini_file(CONF, true);
|
||||||
|
$options['traffic']['limit'] = 0;
|
||||||
|
helper::confBackup();
|
||||||
|
helper::createIniFile(CONF, $options);
|
||||||
$_POST = helper::getPaste();
|
$_POST = helper::getPaste();
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
||||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||||
|
@ -139,6 +144,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
||||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
|
trafficlimiter::canPass();
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
|
@ -390,7 +396,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$options['traffic']['limit'] = 0;
|
$options['traffic']['limit'] = 0;
|
||||||
helper::confBackup();
|
helper::confBackup();
|
||||||
helper::createIniFile(CONF, $options);
|
helper::createIniFile(CONF, $options);
|
||||||
$_POST = helper::getComment();
|
$_POST = helper::getCommentPost();
|
||||||
$_POST['pasteid'] = helper::getPasteId();
|
$_POST['pasteid'] = helper::getPasteId();
|
||||||
$_POST['parentid'] = helper::getPasteId();
|
$_POST['parentid'] = helper::getPasteId();
|
||||||
$_POST['nickname'] = 'foo';
|
$_POST['nickname'] = 'foo';
|
||||||
|
@ -416,7 +422,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$options['traffic']['limit'] = 0;
|
$options['traffic']['limit'] = 0;
|
||||||
helper::confBackup();
|
helper::confBackup();
|
||||||
helper::createIniFile(CONF, $options);
|
helper::createIniFile(CONF, $options);
|
||||||
$_POST = helper::getComment();
|
$_POST = helper::getCommentPost();
|
||||||
$_POST['pasteid'] = helper::getPasteId();
|
$_POST['pasteid'] = helper::getPasteId();
|
||||||
$_POST['parentid'] = helper::getPasteId();
|
$_POST['parentid'] = helper::getPasteId();
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
||||||
|
@ -441,7 +447,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$options['traffic']['limit'] = 0;
|
$options['traffic']['limit'] = 0;
|
||||||
helper::confBackup();
|
helper::confBackup();
|
||||||
helper::createIniFile(CONF, $options);
|
helper::createIniFile(CONF, $options);
|
||||||
$_POST = helper::getComment();
|
$_POST = helper::getCommentPost();
|
||||||
$_POST['pasteid'] = helper::getPasteId();
|
$_POST['pasteid'] = helper::getPasteId();
|
||||||
$_POST['parentid'] = 'foo';
|
$_POST['parentid'] = 'foo';
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
||||||
|
@ -466,7 +472,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$options['traffic']['limit'] = 0;
|
$options['traffic']['limit'] = 0;
|
||||||
helper::confBackup();
|
helper::confBackup();
|
||||||
helper::createIniFile(CONF, $options);
|
helper::createIniFile(CONF, $options);
|
||||||
$_POST = helper::getComment();
|
$_POST = helper::getCommentPost();
|
||||||
$_POST['pasteid'] = helper::getPasteId();
|
$_POST['pasteid'] = helper::getPasteId();
|
||||||
$_POST['parentid'] = helper::getPasteId();
|
$_POST['parentid'] = helper::getPasteId();
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
||||||
|
@ -492,7 +498,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$options['traffic']['limit'] = 0;
|
$options['traffic']['limit'] = 0;
|
||||||
helper::confBackup();
|
helper::confBackup();
|
||||||
helper::createIniFile(CONF, $options);
|
helper::createIniFile(CONF, $options);
|
||||||
$_POST = helper::getComment();
|
$_POST = helper::getCommentPost();
|
||||||
$_POST['pasteid'] = helper::getPasteId();
|
$_POST['pasteid'] = helper::getPasteId();
|
||||||
$_POST['parentid'] = helper::getPasteId();
|
$_POST['parentid'] = helper::getPasteId();
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
$_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->create(helper::getPasteId(), helper::getPaste());
|
||||||
$this->_model->createComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId(), helper::getComment());
|
$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');
|
$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['pasteid'] = helper::getPasteId();
|
||||||
$_POST['parentid'] = helper::getPasteId();
|
$_POST['parentid'] = helper::getPasteId();
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
||||||
|
@ -676,8 +682,12 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testReadOldSyntax()
|
public function testReadOldSyntax()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$oldPaste = helper::getPaste(array('syntaxcoloring' => true));
|
$oldPaste = helper::getPaste();
|
||||||
unset($oldPaste['meta']['formatter']);
|
$oldPaste['meta'] = array(
|
||||||
|
'syntaxcoloring' => true,
|
||||||
|
'postdate' => $oldPaste['meta']['postdate'],
|
||||||
|
'opendiscussion' => $oldPaste['meta']['opendiscussion'],
|
||||||
|
);
|
||||||
$this->_model->create(helper::getPasteId(), $oldPaste);
|
$this->_model->create(helper::getPasteId(), $oldPaste);
|
||||||
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
43
tst/zerobinWithDb.php
Normal file
43
tst/zerobinWithDb.php
Normal file
|
@ -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…
Reference in a new issue