improving unit tests, fixing #38
This commit is contained in:
parent
0686087cfd
commit
0de9f868fa
|
@ -203,6 +203,7 @@ class zerobin
|
||||||
* formatter (optional) = format to display the paste as (plaintext,syntaxhighlighting,markdown) (default:syntaxhighlighting)
|
* formatter (optional) = format to display the paste as (plaintext,syntaxhighlighting,markdown) (default:syntaxhighlighting)
|
||||||
* burnafterreading (optional) = if this paste may only viewed once ? (0/1) (default:0)
|
* burnafterreading (optional) = if this paste may only viewed once ? (0/1) (default:0)
|
||||||
* opendiscusssion (optional) = is the discussion allowed on this paste ? (0/1) (default:0)
|
* opendiscusssion (optional) = is the discussion allowed on this paste ? (0/1) (default:0)
|
||||||
|
* attachmentname = json encoded SJCL encrypted text (containing keys: iv,v,iter,ks,ts,mode,adata,cipher,salt,ct)
|
||||||
* nickname (optional) = in discussion, encoded SJCL encrypted text nickname of author of comment (containing keys: iv,v,iter,ks,ts,mode,adata,cipher,salt,ct)
|
* nickname (optional) = in discussion, encoded SJCL encrypted text nickname of author of comment (containing keys: iv,v,iter,ks,ts,mode,adata,cipher,salt,ct)
|
||||||
* parentid (optional) = in discussion, which comment this comment replies to.
|
* parentid (optional) = in discussion, which comment this comment replies to.
|
||||||
* pasteid (optional) = in discussion, which paste this comment belongs to.
|
* pasteid (optional) = in discussion, which paste this comment belongs to.
|
||||||
|
|
|
@ -148,9 +148,22 @@ class zerobin_db extends zerobin_abstract
|
||||||
'postdate INT, ' .
|
'postdate INT, ' .
|
||||||
'expiredate INT, ' .
|
'expiredate INT, ' .
|
||||||
'opendiscussion INT, ' .
|
'opendiscussion INT, ' .
|
||||||
'burnafterreading INT );'
|
'burnafterreading INT, ' .
|
||||||
|
'meta TEXT );'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// check if the meta column exists
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
self::$_db->exec('SELECT meta FROM ' . self::$_prefix . 'paste LIMIT 1;');
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
if ($e->getCode() == 'HY000')
|
||||||
|
{
|
||||||
|
self::$_db->exec('ALTER TABLE ' . self::$_prefix . 'paste ADD COLUMN meta TEXT;');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// create comment table if needed
|
// create comment table if needed
|
||||||
if (!array_key_exists(self::$_prefix . 'comment', $tables))
|
if (!array_key_exists(self::$_prefix . 'comment', $tables))
|
||||||
|
@ -183,7 +196,7 @@ class zerobin_db extends zerobin_abstract
|
||||||
public function create($pasteid, $paste)
|
public function create($pasteid, $paste)
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
array_key_exists($pasteid, self::$_cache)
|
array_key_exists($pasteid, self::$_cache)
|
||||||
) {
|
) {
|
||||||
if(false !== self::$_cache[$pasteid]) {
|
if(false !== self::$_cache[$pasteid]) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -192,21 +205,30 @@ class zerobin_db extends zerobin_abstract
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
$opendiscussion = $burnafterreading = false;
|
||||||
!array_key_exists('opendiscussion', $paste['meta'])
|
$meta = $paste['meta'];
|
||||||
) $paste['meta']['opendiscussion'] = false;
|
unset($meta['postdate']);
|
||||||
if (
|
unset($meta['expire_date']);
|
||||||
!array_key_exists('burnafterreading', $paste['meta'])
|
if (array_key_exists('opendiscussion', $paste['meta']))
|
||||||
) $paste['meta']['burnafterreading'] = false;
|
{
|
||||||
|
$opendiscussion = (bool) $paste['meta']['opendiscussion'];
|
||||||
|
unset($meta['opendiscussion']);
|
||||||
|
}
|
||||||
|
if (array_key_exists('burnafterreading', $paste['meta']))
|
||||||
|
{
|
||||||
|
$burnafterreading = (bool) $paste['meta']['burnafterreading'];
|
||||||
|
unset($meta['burnafterreading']);
|
||||||
|
}
|
||||||
return self::_exec(
|
return self::_exec(
|
||||||
'INSERT INTO ' . self::$_prefix . 'paste VALUES(?,?,?,?,?,?)',
|
'INSERT INTO ' . self::$_prefix . 'paste VALUES(?,?,?,?,?,?,?)',
|
||||||
array(
|
array(
|
||||||
$pasteid,
|
$pasteid,
|
||||||
$paste['data'],
|
$paste['data'],
|
||||||
$paste['meta']['postdate'],
|
$paste['meta']['postdate'],
|
||||||
$paste['meta']['expire_date'],
|
$paste['meta']['expire_date'],
|
||||||
(int) $paste['meta']['opendiscussion'],
|
(int) $opendiscussion,
|
||||||
(int) $paste['meta']['burnafterreading'],
|
(int) $burnafterreading,
|
||||||
|
json_encode($meta),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +255,7 @@ class zerobin_db extends zerobin_abstract
|
||||||
// create object
|
// create object
|
||||||
self::$_cache[$pasteid] = new stdClass;
|
self::$_cache[$pasteid] = new stdClass;
|
||||||
self::$_cache[$pasteid]->data = $paste['data'];
|
self::$_cache[$pasteid]->data = $paste['data'];
|
||||||
self::$_cache[$pasteid]->meta = new stdClass;
|
self::$_cache[$pasteid]->meta = json_decode($paste['meta']);
|
||||||
self::$_cache[$pasteid]->meta->postdate = (int) $paste['postdate'];
|
self::$_cache[$pasteid]->meta->postdate = (int) $paste['postdate'];
|
||||||
self::$_cache[$pasteid]->meta->expire_date = (int) $paste['expiredate'];
|
self::$_cache[$pasteid]->meta->expire_date = (int) $paste['expiredate'];
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
class RainTPLTest extends PHPUnit_Framework_TestCase
|
class RainTPLTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private static $data = '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}';
|
|
||||||
|
|
||||||
private static $error = 'foo bar';
|
private static $error = 'foo bar';
|
||||||
|
|
||||||
private static $status = '!*#@?$+';
|
private static $status = '!*#@?$+';
|
||||||
|
@ -27,7 +25,7 @@ class RainTPLTest extends PHPUnit_Framework_TestCase
|
||||||
$page::$path_replace = false;
|
$page::$path_replace = false;
|
||||||
|
|
||||||
// We escape it here because ENT_NOQUOTES can't be used in RainTPL templates.
|
// We escape it here because ENT_NOQUOTES can't be used in RainTPL templates.
|
||||||
$page->assign('CIPHERDATA', htmlspecialchars(self::$data, ENT_NOQUOTES));
|
$page->assign('CIPHERDATA', htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES));
|
||||||
$page->assign('ERROR', self::$error);
|
$page->assign('ERROR', self::$error);
|
||||||
$page->assign('STATUS', self::$status);
|
$page->assign('STATUS', self::$status);
|
||||||
$page->assign('VERSION', self::$version);
|
$page->assign('VERSION', self::$version);
|
||||||
|
@ -65,7 +63,7 @@ class RainTPLTest extends PHPUnit_Framework_TestCase
|
||||||
$this->assertTag(
|
$this->assertTag(
|
||||||
array(
|
array(
|
||||||
'id' => 'cipherdata',
|
'id' => 'cipherdata',
|
||||||
'content' => htmlspecialchars(self::$data, ENT_NOQUOTES)
|
'content' => htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES)
|
||||||
),
|
),
|
||||||
$this->_content,
|
$this->_content,
|
||||||
'outputs data correctly'
|
'outputs data correctly'
|
||||||
|
|
|
@ -9,6 +9,97 @@ require PATH . 'lib/auto.php';
|
||||||
|
|
||||||
class helper
|
class helper
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* example ID of a paste
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $pasteid = '5e9bc25c89fb3bf9';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* example paste
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $paste = array(
|
||||||
|
'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}',
|
||||||
|
'meta' => array(
|
||||||
|
'postdate' => 1344803344,
|
||||||
|
'opendiscussion' => true,
|
||||||
|
'formatter' => 'plaintext',
|
||||||
|
'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"}',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* example ID of a comment
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $commentid = '5a52eebf11c4c94b';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* example comment
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $comment = array(
|
||||||
|
'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
|
||||||
|
'meta' => array(
|
||||||
|
'nickname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
|
||||||
|
'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=',
|
||||||
|
'postdate' => 1344803528,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get example paste ID
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getPasteId()
|
||||||
|
{
|
||||||
|
return self::$pasteid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get example paste
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getPaste($meta = array())
|
||||||
|
{
|
||||||
|
$example = self::$paste;
|
||||||
|
$example['meta'] = array_merge($example['meta'], $meta);
|
||||||
|
return $example;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get example paste ID
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getCommentId()
|
||||||
|
{
|
||||||
|
return self::$commentid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get example comment
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getComment($meta = array())
|
||||||
|
{
|
||||||
|
$example = self::$comment;
|
||||||
|
$example['meta'] = array_merge($example['meta'], $meta);
|
||||||
|
return $example;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delete directory and all its contents recursively
|
* delete directory and all its contents recursively
|
||||||
*
|
*
|
||||||
|
|
|
@ -44,7 +44,7 @@ new configurationTestGenerator(array(
|
||||||
'settings' => array('$_POST["opendiscussion"] = "neither 1 nor 0"'),
|
'settings' => array('$_POST["opendiscussion"] = "neither 1 nor 0"'),
|
||||||
'type' => 'False',
|
'type' => 'False',
|
||||||
'args' => array(
|
'args' => array(
|
||||||
'$this->_model->exists(self::$pasteid)',
|
'$this->_model->exists(helper::getPasteId())',
|
||||||
'when discussions are enabled, but invalid flag posted, paste is not created'
|
'when discussions are enabled, but invalid flag posted, paste is not created'
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -108,9 +108,9 @@ new configurationTestGenerator(array(
|
||||||
'affects' => $vrd
|
'affects' => $vrd
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'main/syntaxhighlighting' => array(
|
'main/defaultformatter' => array(
|
||||||
array(
|
array(
|
||||||
'setting' => true,
|
'setting' => 'syntaxhighlighting',
|
||||||
'tests' => array(
|
'tests' => array(
|
||||||
array(
|
array(
|
||||||
'type' => 'Tag',
|
'type' => 'Tag',
|
||||||
|
@ -143,7 +143,7 @@ new configurationTestGenerator(array(
|
||||||
),
|
),
|
||||||
'affects' => $vrd,
|
'affects' => $vrd,
|
||||||
), array(
|
), array(
|
||||||
'setting' => false,
|
'setting' => 'plaintext',
|
||||||
'tests' => array(
|
'tests' => array(
|
||||||
array(
|
array(
|
||||||
'type' => 'NotTag',
|
'type' => 'NotTag',
|
||||||
|
@ -593,16 +593,6 @@ class configurationTestGenerator
|
||||||
*/
|
*/
|
||||||
class configurationTest extends PHPUnit_Framework_TestCase
|
class configurationTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private static $pasteid = '5e9bc25c89fb3bf9';
|
|
||||||
|
|
||||||
private static $paste = array(
|
|
||||||
'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}',
|
|
||||||
'meta' => array(
|
|
||||||
'postdate' => 1344803344,
|
|
||||||
'opendiscussion' => true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
private $_model;
|
private $_model;
|
||||||
|
|
||||||
private $_conf;
|
private $_conf;
|
||||||
|
@ -630,8 +620,8 @@ class configurationTest extends PHPUnit_Framework_TestCase
|
||||||
$_POST = array();
|
$_POST = array();
|
||||||
$_GET = array();
|
$_GET = array();
|
||||||
$_SERVER = array();
|
$_SERVER = array();
|
||||||
if ($this->_model->exists(self::$pasteid))
|
if ($this->_model->exists(helper::getPasteId()))
|
||||||
$this->_model->delete(self::$pasteid);
|
$this->_model->delete(helper::getPasteId());
|
||||||
helper::createIniFile($this->_conf, $configuration);
|
helper::createIniFile($this->_conf, $configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,22 +668,22 @@ EOT;
|
||||||
switch ($step) {
|
switch ($step) {
|
||||||
case 'Create':
|
case 'Create':
|
||||||
$code .= PHP_EOL . <<<'EOT'
|
$code .= PHP_EOL . <<<'EOT'
|
||||||
$_POST = self::$paste;
|
$_POST = helper::getPaste();
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
EOT;
|
EOT;
|
||||||
break;
|
break;
|
||||||
case 'Read':
|
case 'Read':
|
||||||
$code .= PHP_EOL . <<<'EOT'
|
$code .= PHP_EOL . <<<'EOT'
|
||||||
$this->_model->create(self::$pasteid, self::$paste);
|
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||||
EOT;
|
EOT;
|
||||||
break;
|
break;
|
||||||
case 'Delete':
|
case 'Delete':
|
||||||
$code .= PHP_EOL . <<<'EOT'
|
$code .= PHP_EOL . <<<'EOT'
|
||||||
$this->_model->create(self::$pasteid, self::$paste);
|
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists before deleting data');
|
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists before deleting data');
|
||||||
$_GET['pasteid'] = self::$pasteid;
|
$_GET['pasteid'] = helper::getPasteId();
|
||||||
$_GET['deletetoken'] = hash_hmac('sha1', self::$pasteid, serversalt::get());
|
$_GET['deletetoken'] = hash_hmac('sha1', helper::getPasteId(), serversalt::get());
|
||||||
EOT;
|
EOT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -720,7 +710,7 @@ EOT;
|
||||||
$this->assertTag(
|
$this->assertTag(
|
||||||
array(
|
array(
|
||||||
'id' => 'cipherdata',
|
'id' => 'cipherdata',
|
||||||
'content' => htmlspecialchars(json_encode(self::$paste), ENT_NOQUOTES)
|
'content' => htmlspecialchars(json_encode(helper::getPaste()), ENT_NOQUOTES)
|
||||||
),
|
),
|
||||||
$content,
|
$content,
|
||||||
'outputs data correctly'
|
'outputs data correctly'
|
||||||
|
@ -738,7 +728,7 @@ EOT;
|
||||||
$content,
|
$content,
|
||||||
'outputs deleted status correctly'
|
'outputs deleted status correctly'
|
||||||
);
|
);
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste successfully deleted');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted');
|
||||||
EOT;
|
EOT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,12 @@ class sjclTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSjclValidatorValidatesCorrectly()
|
public function testSjclValidatorValidatesCorrectly()
|
||||||
{
|
{
|
||||||
|
$paste = helper::getPaste();
|
||||||
|
$this->assertTrue(sjcl::isValid($paste['data']), 'valid sjcl');
|
||||||
|
$this->assertTrue(sjcl::isValid($paste['meta']['attachment']), 'valid sjcl');
|
||||||
|
$this->assertTrue(sjcl::isValid($paste['meta']['attachmentname']), 'valid sjcl');
|
||||||
|
$this->assertTrue(sjcl::isValid(helper::getComment()['data']), 'valid sjcl');
|
||||||
|
|
||||||
$this->assertTrue(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'valid sjcl');
|
$this->assertTrue(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'valid sjcl');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"$","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid base64 encoding of iv');
|
$this->assertFalse(sjcl::isValid('{"iv":"$","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"Gx1vA2/gQ3U","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid base64 encoding of iv');
|
||||||
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"$","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid base64 encoding of salt');
|
$this->assertFalse(sjcl::isValid('{"iv":"83Ax/OdUav3SanDW9dcQPg","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"$","ct":"j7ImByuE5xCqD2YXm6aSyA"}'), 'invalid base64 encoding of salt');
|
||||||
|
|
220
tst/zerobin.php
220
tst/zerobin.php
|
@ -1,28 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
class zerobinTest extends PHPUnit_Framework_TestCase
|
class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private static $pasteid = '5e9bc25c89fb3bf9';
|
|
||||||
|
|
||||||
private static $paste = array(
|
|
||||||
'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}',
|
|
||||||
'meta' => array(
|
|
||||||
'postdate' => 1344803344,
|
|
||||||
'opendiscussion' => true,
|
|
||||||
'formatter' => 'syntaxhighlighting',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
private static $commentid = '5a52eebf11c4c94b';
|
|
||||||
|
|
||||||
private static $comment = array(
|
|
||||||
'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
|
|
||||||
'meta' => array(
|
|
||||||
'nickname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
|
|
||||||
'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=',
|
|
||||||
'postdate' => 1344803528,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
private $_conf;
|
private $_conf;
|
||||||
|
|
||||||
private $_model;
|
private $_model;
|
||||||
|
@ -46,8 +24,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$_POST = array();
|
$_POST = array();
|
||||||
$_GET = array();
|
$_GET = array();
|
||||||
$_SERVER = array();
|
$_SERVER = array();
|
||||||
if ($this->_model->exists(self::$pasteid))
|
if ($this->_model->exists(helper::getPasteId()))
|
||||||
$this->_model->delete(self::$pasteid);
|
$this->_model->delete(helper::getPasteId());
|
||||||
if (is_file($this->_conf . '.bak'))
|
if (is_file($this->_conf . '.bak'))
|
||||||
rename($this->_conf . '.bak', $this->_conf);
|
rename($this->_conf . '.bak', $this->_conf);
|
||||||
}
|
}
|
||||||
|
@ -140,7 +118,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testCreate()
|
public function testCreate()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$_POST = self::$paste;
|
$_POST = helper::getPaste();
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
|
@ -161,14 +139,14 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testCreateInvalidTimelimit()
|
public function testCreateInvalidTimelimit()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$_POST = self::$paste;
|
$_POST = helper::getPaste();
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(1, $response['status'], 'outputs error status');
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste exists after posting data');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste exists after posting data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -183,14 +161,14 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$_POST = self::$paste;
|
$_POST = helper::getPaste();
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(1, $response['status'], 'outputs error status');
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste exists after posting data');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste exists after posting data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -204,14 +182,14 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$_POST = self::$paste;
|
$_POST = helper::getPaste();
|
||||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '::1';
|
$_SERVER['HTTP_X_FORWARDED_FOR'] = '::1';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(1, $response['status'], 'outputs error status');
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste exists after posting data');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste exists after posting data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -225,15 +203,15 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$this->_model->create(self::$pasteid, self::$paste);
|
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||||
$_POST = self::$paste;
|
$_POST = helper::getPaste();
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(1, $response['status'], 'outputs error status');
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
||||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists after posting data');
|
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists after posting data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -247,7 +225,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$_POST = self::$paste;
|
$_POST = helper::getPaste();
|
||||||
$_POST['expire'] = '5min';
|
$_POST['expire'] = '5min';
|
||||||
$_POST['formatter'] = 'foo';
|
$_POST['formatter'] = 'foo';
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
|
@ -275,7 +253,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$_POST = self::$paste;
|
$_POST = helper::getPaste();
|
||||||
$_POST['expire'] = 'foo';
|
$_POST['expire'] = 'foo';
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -302,7 +280,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$_POST = self::$paste;
|
$_POST = helper::getPaste();
|
||||||
$_POST['burnafterreading'] = 'neither 1 nor 0';
|
$_POST['burnafterreading'] = 'neither 1 nor 0';
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -310,7 +288,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(1, $response['status'], 'outputs error status');
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste exists after posting data');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste exists after posting data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -324,7 +302,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$_POST = self::$paste;
|
$_POST = helper::getPaste();
|
||||||
$_POST['opendiscussion'] = 'neither 1 nor 0';
|
$_POST['opendiscussion'] = 'neither 1 nor 0';
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -332,7 +310,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(1, $response['status'], 'outputs error status');
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste exists after posting data');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste exists after posting data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -347,9 +325,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$_POST = self::$paste;
|
$_POST = helper::getPaste();
|
||||||
$_POST['attachment'] = self::$comment['data'];
|
|
||||||
$_POST['attachmentname'] = self::$comment['meta']['nickname'];
|
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
|
@ -375,8 +351,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$_POST = self::$paste;
|
$_POST = helper::getPaste();
|
||||||
$_POST['nickname'] = self::$comment['meta']['nickname'];
|
$_POST['nickname'] = helper::getComment()['meta']['nickname'];
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
|
@ -402,7 +378,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$_POST = self::$paste;
|
$_POST = helper::getPaste();
|
||||||
$_POST['nickname'] = 'foo';
|
$_POST['nickname'] = 'foo';
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -410,7 +386,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(1, $response['status'], 'outputs error status');
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste exists after posting data');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste exists after posting data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -424,17 +400,17 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$_POST = self::$comment;
|
$_POST = helper::getComment();
|
||||||
$_POST['pasteid'] = self::$pasteid;
|
$_POST['pasteid'] = helper::getPasteId();
|
||||||
$_POST['parentid'] = self::$pasteid;
|
$_POST['parentid'] = helper::getPasteId();
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
$this->_model->create(self::$pasteid, self::$paste);
|
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(0, $response['status'], 'outputs status');
|
$this->assertEquals(0, $response['status'], 'outputs status');
|
||||||
$this->assertTrue($this->_model->existsComment(self::$pasteid, self::$pasteid, $response['id']), 'paste exists after posting data');
|
$this->assertTrue($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), $response['id']), 'paste exists after posting data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -448,17 +424,17 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$_POST = self::$comment;
|
$_POST = helper::getComment();
|
||||||
$_POST['pasteid'] = self::$pasteid;
|
$_POST['pasteid'] = helper::getPasteId();
|
||||||
$_POST['parentid'] = 'foo';
|
$_POST['parentid'] = 'foo';
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
$this->_model->create(self::$pasteid, self::$paste);
|
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(1, $response['status'], 'outputs error status');
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
||||||
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'paste exists after posting data');
|
$this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'paste exists after posting data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -472,19 +448,18 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$_POST = self::$comment;
|
$_POST = helper::getComment();
|
||||||
$_POST['pasteid'] = self::$pasteid;
|
$_POST['pasteid'] = helper::getPasteId();
|
||||||
$_POST['parentid'] = self::$pasteid;
|
$_POST['parentid'] = helper::getPasteId();
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
$paste = self::$paste;
|
$paste = helper::getPaste(array('opendiscussion' => false));
|
||||||
$paste['meta']['opendiscussion'] = false;
|
$this->_model->create(helper::getPasteId(), $paste);
|
||||||
$this->_model->create(self::$pasteid, $paste);
|
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(1, $response['status'], 'outputs error status');
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
||||||
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'paste exists after posting data');
|
$this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'paste exists after posting data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -498,16 +473,16 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$_POST = self::$comment;
|
$_POST = helper::getComment();
|
||||||
$_POST['pasteid'] = self::$pasteid;
|
$_POST['pasteid'] = helper::getPasteId();
|
||||||
$_POST['parentid'] = self::$pasteid;
|
$_POST['parentid'] = helper::getPasteId();
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(1, $response['status'], 'outputs error status');
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
||||||
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'paste exists after posting data');
|
$this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'paste exists after posting data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -521,19 +496,19 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||||
rename($this->_conf, $this->_conf . '.bak');
|
rename($this->_conf, $this->_conf . '.bak');
|
||||||
helper::createIniFile($this->_conf, $options);
|
helper::createIniFile($this->_conf, $options);
|
||||||
$this->_model->create(self::$pasteid, self::$paste);
|
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||||
$this->_model->createComment(self::$pasteid, self::$pasteid, self::$commentid, self::$comment);
|
$this->_model->createComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId(), helper::getComment());
|
||||||
$this->assertTrue($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment exists before posting data');
|
$this->assertTrue($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment exists before posting data');
|
||||||
$_POST = self::$comment;
|
$_POST = helper::getComment();
|
||||||
$_POST['pasteid'] = self::$pasteid;
|
$_POST['pasteid'] = helper::getPasteId();
|
||||||
$_POST['parentid'] = self::$pasteid;
|
$_POST['parentid'] = helper::getPasteId();
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(1, $response['status'], 'outputs error status');
|
$this->assertEquals(1, $response['status'], 'outputs error status');
|
||||||
$this->assertTrue($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'paste exists after posting data');
|
$this->assertTrue($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'paste exists after posting data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -542,15 +517,15 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testRead()
|
public function testRead()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$this->_model->create(self::$pasteid, self::$paste);
|
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$this->assertTag(
|
$this->assertTag(
|
||||||
array(
|
array(
|
||||||
'id' => 'cipherdata',
|
'id' => 'cipherdata',
|
||||||
'content' => htmlspecialchars(json_encode(self::$paste), ENT_NOQUOTES)
|
'content' => htmlspecialchars(json_encode(helper::getPaste()), ENT_NOQUOTES)
|
||||||
),
|
),
|
||||||
$content,
|
$content,
|
||||||
'outputs data correctly'
|
'outputs data correctly'
|
||||||
|
@ -583,7 +558,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testReadNonexisting()
|
public function testReadNonexisting()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
|
@ -603,10 +578,9 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testReadExpired()
|
public function testReadExpired()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$expiredPaste = self::$paste;
|
$expiredPaste = helper::getPaste(array('expire_date' => 1344803344));
|
||||||
$expiredPaste['meta']['expire_date'] = $expiredPaste['meta']['postdate'];
|
$this->_model->create(helper::getPasteId(), $expiredPaste);
|
||||||
$this->_model->create(self::$pasteid, $expiredPaste);
|
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
|
@ -626,10 +600,9 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testReadBurn()
|
public function testReadBurn()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$burnPaste = self::$paste;
|
$burnPaste = helper::getPaste(array('burnafterreading' => true));
|
||||||
$burnPaste['meta']['burnafterreading'] = true;
|
$this->_model->create(helper::getPasteId(), $burnPaste);
|
||||||
$this->_model->create(self::$pasteid, $burnPaste);
|
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
|
@ -649,14 +622,14 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testReadJson()
|
public function testReadJson()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$this->_model->create(self::$pasteid, self::$paste);
|
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||||
$_SERVER['QUERY_STRING'] = self::$pasteid . '&json';
|
$_SERVER['QUERY_STRING'] = helper::getPasteId() . '&json';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(0, $response['status'], 'outputs success status');
|
$this->assertEquals(0, $response['status'], 'outputs success status');
|
||||||
$this->assertEquals(array(self::$paste), $response['messages'], 'outputs data correctly');
|
$this->assertEquals(array(helper::getPaste()), $response['messages'], 'outputs data correctly');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -665,7 +638,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testReadInvalidJson()
|
public function testReadInvalidJson()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$_SERVER['QUERY_STRING'] = self::$pasteid . '&json';
|
$_SERVER['QUERY_STRING'] = helper::getPasteId() . '&json';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
|
@ -679,11 +652,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testReadOldSyntax()
|
public function testReadOldSyntax()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$oldPaste = self::$paste;
|
$oldPaste = helper::getPaste(array('syntaxcoloring' => true));
|
||||||
$oldPaste['meta']['syntaxcoloring'] = true;
|
|
||||||
unset($oldPaste['meta']['formatter']);
|
unset($oldPaste['meta']['formatter']);
|
||||||
$this->_model->create(self::$pasteid, $oldPaste);
|
$this->_model->create(helper::getPasteId(), $oldPaste);
|
||||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
|
@ -704,10 +676,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testReadOldFormat()
|
public function testReadOldFormat()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$oldPaste = self::$paste;
|
$oldPaste = helper::getPaste();
|
||||||
unset($oldPaste['meta']['formatter']);
|
unset($oldPaste['meta']['formatter']);
|
||||||
$this->_model->create(self::$pasteid, $oldPaste);
|
$this->_model->create(helper::getPasteId(), $oldPaste);
|
||||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
|
@ -728,10 +700,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testDelete()
|
public function testDelete()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$this->_model->create(self::$pasteid, self::$paste);
|
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists before deleting data');
|
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists before deleting data');
|
||||||
$_GET['pasteid'] = self::$pasteid;
|
$_GET['pasteid'] = helper::getPasteId();
|
||||||
$_GET['deletetoken'] = hash_hmac('sha1', self::$pasteid, serversalt::get());
|
$_GET['deletetoken'] = hash_hmac('sha1', helper::getPasteId(), serversalt::get());
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
|
@ -743,7 +715,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$content,
|
$content,
|
||||||
'outputs deleted status correctly'
|
'outputs deleted status correctly'
|
||||||
);
|
);
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste successfully deleted');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -752,7 +724,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testDeleteInvalidId()
|
public function testDeleteInvalidId()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$this->_model->create(self::$pasteid, self::$paste);
|
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||||
$_GET['pasteid'] = 'foo';
|
$_GET['pasteid'] = 'foo';
|
||||||
$_GET['deletetoken'] = 'bar';
|
$_GET['deletetoken'] = 'bar';
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -766,7 +738,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$content,
|
$content,
|
||||||
'outputs delete error correctly'
|
'outputs delete error correctly'
|
||||||
);
|
);
|
||||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists after failing to delete data');
|
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists after failing to delete data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -775,7 +747,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testDeleteInexistantId()
|
public function testDeleteInexistantId()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$_GET['pasteid'] = self::$pasteid;
|
$_GET['pasteid'] = helper::getPasteId();
|
||||||
$_GET['deletetoken'] = 'bar';
|
$_GET['deletetoken'] = 'bar';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
|
@ -796,8 +768,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testDeleteInvalidToken()
|
public function testDeleteInvalidToken()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$this->_model->create(self::$pasteid, self::$paste);
|
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||||
$_GET['pasteid'] = self::$pasteid;
|
$_GET['pasteid'] = helper::getPasteId();
|
||||||
$_GET['deletetoken'] = 'bar';
|
$_GET['deletetoken'] = 'bar';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
|
@ -810,7 +782,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$content,
|
$content,
|
||||||
'outputs delete error correctly'
|
'outputs delete error correctly'
|
||||||
);
|
);
|
||||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists after failing to delete data');
|
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists after failing to delete data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -819,18 +791,17 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testDeleteBurnAfterReading()
|
public function testDeleteBurnAfterReading()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$burnPaste = self::$paste;
|
$burnPaste = helper::getPaste(array('burnafterreading' => true));
|
||||||
$burnPaste['meta']['burnafterreading'] = true;
|
$this->_model->create(helper::getPasteId(), $burnPaste);
|
||||||
$this->_model->create(self::$pasteid, $burnPaste);
|
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists before deleting data');
|
||||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists before deleting data');
|
$_GET['pasteid'] = helper::getPasteId();
|
||||||
$_GET['pasteid'] = self::$pasteid;
|
|
||||||
$_GET['deletetoken'] = 'burnafterreading';
|
$_GET['deletetoken'] = 'burnafterreading';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(0, $response['status'], 'outputs status');
|
$this->assertEquals(0, $response['status'], 'outputs status');
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste successfully deleted');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -839,16 +810,16 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testDeleteInvalidBurnAfterReading()
|
public function testDeleteInvalidBurnAfterReading()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$this->_model->create(self::$pasteid, self::$paste);
|
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists before deleting data');
|
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists before deleting data');
|
||||||
$_GET['pasteid'] = self::$pasteid;
|
$_GET['pasteid'] = helper::getPasteId();
|
||||||
$_GET['deletetoken'] = 'burnafterreading';
|
$_GET['deletetoken'] = 'burnafterreading';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
$response = json_decode($content, true);
|
$response = json_decode($content, true);
|
||||||
$this->assertEquals(1, $response['status'], 'outputs status');
|
$this->assertEquals(1, $response['status'], 'outputs status');
|
||||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste successfully deleted');
|
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste successfully deleted');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -857,12 +828,11 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
public function testDeleteExpired()
|
public function testDeleteExpired()
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$expiredPaste = self::$paste;
|
$expiredPaste = helper::getPaste(array('expire_date' => 1000));
|
||||||
$expiredPaste['meta']['expire_date'] = 1000;
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste does not exist before being created');
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste does not exist before being created');
|
$this->_model->create(helper::getPasteId(), $expiredPaste);
|
||||||
$this->_model->create(self::$pasteid, $expiredPaste);
|
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists before deleting data');
|
||||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists before deleting data');
|
$_GET['pasteid'] = helper::getPasteId();
|
||||||
$_GET['pasteid'] = self::$pasteid;
|
|
||||||
$_GET['deletetoken'] = 'does not matter in this context, but has to be set';
|
$_GET['deletetoken'] = 'does not matter in this context, but has to be set';
|
||||||
ob_start();
|
ob_start();
|
||||||
new zerobin;
|
new zerobin;
|
||||||
|
@ -875,6 +845,6 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||||
$content,
|
$content,
|
||||||
'outputs error correctly'
|
'outputs error correctly'
|
||||||
);
|
);
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste successfully deleted');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted');
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,28 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
class zerobin_dataTest extends PHPUnit_Framework_TestCase
|
class zerobin_dataTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private static $pasteid = '5e9bc25c89fb3bf9';
|
|
||||||
|
|
||||||
private static $paste = array(
|
|
||||||
'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}',
|
|
||||||
'meta' => array(
|
|
||||||
'postdate' => 1344803344,
|
|
||||||
'expire_date' => 1344803644,
|
|
||||||
'opendiscussion' => true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
private static $commentid = '5a52eebf11c4c94b';
|
|
||||||
|
|
||||||
private static $comment = array(
|
|
||||||
'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
|
|
||||||
'meta' => array(
|
|
||||||
'nickname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
|
|
||||||
'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=',
|
|
||||||
'postdate' => 1344803528,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
private $_model;
|
private $_model;
|
||||||
|
|
||||||
private $_path;
|
private $_path;
|
||||||
|
@ -43,28 +21,29 @@ class zerobin_dataTest extends PHPUnit_Framework_TestCase
|
||||||
public function testFileBasedDataStoreWorks()
|
public function testFileBasedDataStoreWorks()
|
||||||
{
|
{
|
||||||
// storing pastes
|
// storing pastes
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste does not yet exist');
|
$paste = helper::getPaste(array('expire_date' => 1344803344));
|
||||||
$this->assertTrue($this->_model->create(self::$pasteid, self::$paste), 'store new paste');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste does not yet exist');
|
||||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists after storing it');
|
$this->assertTrue($this->_model->create(helper::getPasteId(), $paste), 'store new paste');
|
||||||
$this->assertFalse($this->_model->create(self::$pasteid, self::$paste), 'unable to store the same paste twice');
|
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists after storing it');
|
||||||
$this->assertEquals(json_decode(json_encode(self::$paste)), $this->_model->read(self::$pasteid));
|
$this->assertFalse($this->_model->create(helper::getPasteId(), $paste), 'unable to store the same paste twice');
|
||||||
|
$this->assertEquals(json_decode(json_encode($paste)), $this->_model->read(helper::getPasteId()));
|
||||||
|
|
||||||
// storing comments
|
// storing comments
|
||||||
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment does not yet exist');
|
$this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment does not yet exist');
|
||||||
$this->assertTrue($this->_model->createComment(self::$pasteid, self::$pasteid, self::$commentid, self::$comment) !== false, 'store comment');
|
$this->assertTrue($this->_model->createComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId(), helper::getComment()) !== false, 'store comment');
|
||||||
$this->assertTrue($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment exists after storing it');
|
$this->assertTrue($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment exists after storing it');
|
||||||
$comment = json_decode(json_encode(self::$comment));
|
$comment = json_decode(json_encode(helper::getComment()));
|
||||||
$comment->meta->commentid = self::$commentid;
|
$comment->meta->commentid = helper::getCommentId();
|
||||||
$comment->meta->parentid = self::$pasteid;
|
$comment->meta->parentid = helper::getPasteId();
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array($comment->meta->postdate => $comment),
|
array($comment->meta->postdate => $comment),
|
||||||
$this->_model->readComments(self::$pasteid)
|
$this->_model->readComments(helper::getPasteId())
|
||||||
);
|
);
|
||||||
|
|
||||||
// deleting pastes
|
// deleting pastes
|
||||||
$this->_model->delete(self::$pasteid);
|
$this->_model->delete(helper::getPasteId());
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste successfully deleted');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted');
|
||||||
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment was deleted with paste');
|
$this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment was deleted with paste');
|
||||||
$this->assertFalse($this->_model->read(self::$pasteid), 'paste can no longer be found');
|
$this->assertFalse($this->_model->read(helper::getPasteId()), 'paste can no longer be found');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
class zerobin_dbTest extends PHPUnit_Framework_TestCase
|
class zerobin_dbTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private static $pasteid = '5e9bc25c89fb3bf9';
|
|
||||||
|
|
||||||
private static $paste = array(
|
|
||||||
'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}',
|
|
||||||
'meta' => array(
|
|
||||||
'postdate' => 1344803344,
|
|
||||||
'expire_date' => 1344803644,
|
|
||||||
'opendiscussion' => true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
private static $commentid = '5a52eebf11c4c94b';
|
|
||||||
|
|
||||||
private static $comment = array(
|
|
||||||
'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
|
|
||||||
'meta' => array(
|
|
||||||
'nickname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
|
|
||||||
'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=',
|
|
||||||
'postdate' => 1344803528,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
private $_model;
|
private $_model;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
|
@ -40,30 +18,30 @@ class zerobin_dbTest extends PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testDatabaseBasedDataStoreWorks()
|
public function testDatabaseBasedDataStoreWorks()
|
||||||
{
|
{
|
||||||
// storing pastes
|
$paste = helper::getPaste(array('expire_date' => 1344803344));
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste does not yet exist');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste does not yet exist');
|
||||||
$this->assertTrue($this->_model->create(self::$pasteid, self::$paste), 'store new paste');
|
$this->assertTrue($this->_model->create(helper::getPasteId(), $paste), 'store new paste');
|
||||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists after storing it');
|
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists after storing it');
|
||||||
$this->assertFalse($this->_model->create(self::$pasteid, self::$paste), 'unable to store the same paste twice');
|
$this->assertFalse($this->_model->create(helper::getPasteId(), $paste), 'unable to store the same paste twice');
|
||||||
$this->assertEquals(json_decode(json_encode(self::$paste)), $this->_model->read(self::$pasteid));
|
$this->assertEquals(json_decode(json_encode($paste)), $this->_model->read(helper::getPasteId()));
|
||||||
|
|
||||||
// storing comments
|
// storing comments
|
||||||
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment does not yet exist');
|
$this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment does not yet exist');
|
||||||
$this->assertTrue($this->_model->createComment(self::$pasteid, self::$pasteid, self::$commentid, self::$comment) !== false, 'store comment');
|
$this->assertTrue($this->_model->createComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId(), helper::getComment()) !== false, 'store comment');
|
||||||
$this->assertTrue($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment exists after storing it');
|
$this->assertTrue($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment exists after storing it');
|
||||||
$comment = json_decode(json_encode(self::$comment));
|
$comment = json_decode(json_encode(helper::getComment()));
|
||||||
$comment->meta->commentid = self::$commentid;
|
$comment->meta->commentid = helper::getCommentId();
|
||||||
$comment->meta->parentid = self::$pasteid;
|
$comment->meta->parentid = helper::getPasteId();
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array($comment->meta->postdate => $comment),
|
array($comment->meta->postdate => $comment),
|
||||||
$this->_model->readComments(self::$pasteid)
|
$this->_model->readComments(helper::getPasteId())
|
||||||
);
|
);
|
||||||
|
|
||||||
// deleting pastes
|
// deleting pastes
|
||||||
$this->_model->delete(self::$pasteid);
|
$this->_model->delete(helper::getPasteId());
|
||||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste successfully deleted');
|
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted');
|
||||||
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment was deleted with paste');
|
$this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment was deleted with paste');
|
||||||
$this->assertFalse($this->_model->read(self::$pasteid), 'paste can no longer be found');
|
$this->assertFalse($this->_model->read(helper::getPasteId()), 'paste can no longer be found');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue