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)
|
||||
* 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)
|
||||
* 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)
|
||||
* parentid (optional) = in discussion, which comment this comment replies to.
|
||||
* pasteid (optional) = in discussion, which paste this comment belongs to.
|
||||
|
@ -148,9 +148,22 @@ class zerobin_db extends zerobin_abstract
|
||||
'postdate INT, ' .
|
||||
'expiredate 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
|
||||
if (!array_key_exists(self::$_prefix . 'comment', $tables))
|
||||
@ -183,7 +196,7 @@ class zerobin_db extends zerobin_abstract
|
||||
public function create($pasteid, $paste)
|
||||
{
|
||||
if (
|
||||
array_key_exists($pasteid, self::$_cache)
|
||||
array_key_exists($pasteid, self::$_cache)
|
||||
) {
|
||||
if(false !== self::$_cache[$pasteid]) {
|
||||
return false;
|
||||
@ -192,21 +205,30 @@ class zerobin_db extends zerobin_abstract
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!array_key_exists('opendiscussion', $paste['meta'])
|
||||
) $paste['meta']['opendiscussion'] = false;
|
||||
if (
|
||||
!array_key_exists('burnafterreading', $paste['meta'])
|
||||
) $paste['meta']['burnafterreading'] = false;
|
||||
$opendiscussion = $burnafterreading = false;
|
||||
$meta = $paste['meta'];
|
||||
unset($meta['postdate']);
|
||||
unset($meta['expire_date']);
|
||||
if (array_key_exists('opendiscussion', $paste['meta']))
|
||||
{
|
||||
$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(
|
||||
'INSERT INTO ' . self::$_prefix . 'paste VALUES(?,?,?,?,?,?)',
|
||||
'INSERT INTO ' . self::$_prefix . 'paste VALUES(?,?,?,?,?,?,?)',
|
||||
array(
|
||||
$pasteid,
|
||||
$paste['data'],
|
||||
$paste['meta']['postdate'],
|
||||
$paste['meta']['expire_date'],
|
||||
(int) $paste['meta']['opendiscussion'],
|
||||
(int) $paste['meta']['burnafterreading'],
|
||||
(int) $opendiscussion,
|
||||
(int) $burnafterreading,
|
||||
json_encode($meta),
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -233,7 +255,7 @@ class zerobin_db extends zerobin_abstract
|
||||
// create object
|
||||
self::$_cache[$pasteid] = new stdClass;
|
||||
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->expire_date = (int) $paste['expiredate'];
|
||||
if (
|
||||
|
@ -1,8 +1,6 @@
|
||||
<?php
|
||||
class RainTPLTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private static $data = '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}';
|
||||
|
||||
private static $error = 'foo bar';
|
||||
|
||||
private static $status = '!*#@?$+';
|
||||
@ -27,7 +25,7 @@ class RainTPLTest extends PHPUnit_Framework_TestCase
|
||||
$page::$path_replace = false;
|
||||
|
||||
// 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('STATUS', self::$status);
|
||||
$page->assign('VERSION', self::$version);
|
||||
@ -65,7 +63,7 @@ class RainTPLTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertTag(
|
||||
array(
|
||||
'id' => 'cipherdata',
|
||||
'content' => htmlspecialchars(self::$data, ENT_NOQUOTES)
|
||||
'content' => htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES)
|
||||
),
|
||||
$this->_content,
|
||||
'outputs data correctly'
|
||||
|
@ -9,6 +9,97 @@ require PATH . 'lib/auto.php';
|
||||
|
||||
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
|
||||
*
|
||||
|
@ -44,7 +44,7 @@ new configurationTestGenerator(array(
|
||||
'settings' => array('$_POST["opendiscussion"] = "neither 1 nor 0"'),
|
||||
'type' => 'False',
|
||||
'args' => array(
|
||||
'$this->_model->exists(self::$pasteid)',
|
||||
'$this->_model->exists(helper::getPasteId())',
|
||||
'when discussions are enabled, but invalid flag posted, paste is not created'
|
||||
),
|
||||
),
|
||||
@ -108,9 +108,9 @@ new configurationTestGenerator(array(
|
||||
'affects' => $vrd
|
||||
),
|
||||
),
|
||||
'main/syntaxhighlighting' => array(
|
||||
'main/defaultformatter' => array(
|
||||
array(
|
||||
'setting' => true,
|
||||
'setting' => 'syntaxhighlighting',
|
||||
'tests' => array(
|
||||
array(
|
||||
'type' => 'Tag',
|
||||
@ -143,7 +143,7 @@ new configurationTestGenerator(array(
|
||||
),
|
||||
'affects' => $vrd,
|
||||
), array(
|
||||
'setting' => false,
|
||||
'setting' => 'plaintext',
|
||||
'tests' => array(
|
||||
array(
|
||||
'type' => 'NotTag',
|
||||
@ -593,16 +593,6 @@ class configurationTestGenerator
|
||||
*/
|
||||
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 $_conf;
|
||||
@ -630,8 +620,8 @@ class configurationTest extends PHPUnit_Framework_TestCase
|
||||
$_POST = array();
|
||||
$_GET = array();
|
||||
$_SERVER = array();
|
||||
if ($this->_model->exists(self::$pasteid))
|
||||
$this->_model->delete(self::$pasteid);
|
||||
if ($this->_model->exists(helper::getPasteId()))
|
||||
$this->_model->delete(helper::getPasteId());
|
||||
helper::createIniFile($this->_conf, $configuration);
|
||||
}
|
||||
|
||||
@ -678,22 +668,22 @@ EOT;
|
||||
switch ($step) {
|
||||
case 'Create':
|
||||
$code .= PHP_EOL . <<<'EOT'
|
||||
$_POST = self::$paste;
|
||||
$_POST = helper::getPaste();
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
EOT;
|
||||
break;
|
||||
case 'Read':
|
||||
$code .= PHP_EOL . <<<'EOT'
|
||||
$this->_model->create(self::$pasteid, self::$paste);
|
||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
||||
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||
EOT;
|
||||
break;
|
||||
case 'Delete':
|
||||
$code .= PHP_EOL . <<<'EOT'
|
||||
$this->_model->create(self::$pasteid, self::$paste);
|
||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists before deleting data');
|
||||
$_GET['pasteid'] = self::$pasteid;
|
||||
$_GET['deletetoken'] = hash_hmac('sha1', self::$pasteid, serversalt::get());
|
||||
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists before deleting data');
|
||||
$_GET['pasteid'] = helper::getPasteId();
|
||||
$_GET['deletetoken'] = hash_hmac('sha1', helper::getPasteId(), serversalt::get());
|
||||
EOT;
|
||||
break;
|
||||
}
|
||||
@ -720,7 +710,7 @@ EOT;
|
||||
$this->assertTag(
|
||||
array(
|
||||
'id' => 'cipherdata',
|
||||
'content' => htmlspecialchars(json_encode(self::$paste), ENT_NOQUOTES)
|
||||
'content' => htmlspecialchars(json_encode(helper::getPaste()), ENT_NOQUOTES)
|
||||
),
|
||||
$content,
|
||||
'outputs data correctly'
|
||||
@ -738,7 +728,7 @@ EOT;
|
||||
$content,
|
||||
'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;
|
||||
break;
|
||||
}
|
||||
|
@ -3,6 +3,12 @@ class sjclTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
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->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');
|
||||
|
220
tst/zerobin.php
220
tst/zerobin.php
@ -1,28 +1,6 @@
|
||||
<?php
|
||||
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 $_model;
|
||||
@ -46,8 +24,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
$_POST = array();
|
||||
$_GET = array();
|
||||
$_SERVER = array();
|
||||
if ($this->_model->exists(self::$pasteid))
|
||||
$this->_model->delete(self::$pasteid);
|
||||
if ($this->_model->exists(helper::getPasteId()))
|
||||
$this->_model->delete(helper::getPasteId());
|
||||
if (is_file($this->_conf . '.bak'))
|
||||
rename($this->_conf . '.bak', $this->_conf);
|
||||
}
|
||||
@ -140,7 +118,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
public function testCreate()
|
||||
{
|
||||
$this->reset();
|
||||
$_POST = self::$paste;
|
||||
$_POST = helper::getPaste();
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
@ -161,14 +139,14 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
public function testCreateInvalidTimelimit()
|
||||
{
|
||||
$this->reset();
|
||||
$_POST = self::$paste;
|
||||
$_POST = helper::getPaste();
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$_POST = self::$paste;
|
||||
$_POST = helper::getPaste();
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$_POST = self::$paste;
|
||||
$_POST = helper::getPaste();
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] = '::1';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$this->_model->create(self::$pasteid, self::$paste);
|
||||
$_POST = self::$paste;
|
||||
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||
$_POST = helper::getPaste();
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$_POST = self::$paste;
|
||||
$_POST = helper::getPaste();
|
||||
$_POST['expire'] = '5min';
|
||||
$_POST['formatter'] = 'foo';
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
@ -275,7 +253,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$_POST = self::$paste;
|
||||
$_POST = helper::getPaste();
|
||||
$_POST['expire'] = 'foo';
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
ob_start();
|
||||
@ -302,7 +280,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$_POST = self::$paste;
|
||||
$_POST = helper::getPaste();
|
||||
$_POST['burnafterreading'] = 'neither 1 nor 0';
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
ob_start();
|
||||
@ -310,7 +288,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$_POST = self::$paste;
|
||||
$_POST = helper::getPaste();
|
||||
$_POST['opendiscussion'] = 'neither 1 nor 0';
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
ob_start();
|
||||
@ -332,7 +310,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$_POST = self::$paste;
|
||||
$_POST['attachment'] = self::$comment['data'];
|
||||
$_POST['attachmentname'] = self::$comment['meta']['nickname'];
|
||||
$_POST = helper::getPaste();
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
@ -375,8 +351,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$_POST = self::$paste;
|
||||
$_POST['nickname'] = self::$comment['meta']['nickname'];
|
||||
$_POST = helper::getPaste();
|
||||
$_POST['nickname'] = helper::getComment()['meta']['nickname'];
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
@ -402,7 +378,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
if (!is_file($this->_conf . '.bak') && is_file($this->_conf))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$_POST = self::$paste;
|
||||
$_POST = helper::getPaste();
|
||||
$_POST['nickname'] = 'foo';
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
ob_start();
|
||||
@ -410,7 +386,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$_POST = self::$comment;
|
||||
$_POST['pasteid'] = self::$pasteid;
|
||||
$_POST['parentid'] = self::$pasteid;
|
||||
$_POST = helper::getComment();
|
||||
$_POST['pasteid'] = helper::getPasteId();
|
||||
$_POST['parentid'] = helper::getPasteId();
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
$this->_model->create(self::$pasteid, self::$paste);
|
||||
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$_POST = self::$comment;
|
||||
$_POST['pasteid'] = self::$pasteid;
|
||||
$_POST = helper::getComment();
|
||||
$_POST['pasteid'] = helper::getPasteId();
|
||||
$_POST['parentid'] = 'foo';
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
$this->_model->create(self::$pasteid, self::$paste);
|
||||
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$_POST = self::$comment;
|
||||
$_POST['pasteid'] = self::$pasteid;
|
||||
$_POST['parentid'] = self::$pasteid;
|
||||
$_POST = helper::getComment();
|
||||
$_POST['pasteid'] = helper::getPasteId();
|
||||
$_POST['parentid'] = helper::getPasteId();
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
$paste = self::$paste;
|
||||
$paste['meta']['opendiscussion'] = false;
|
||||
$this->_model->create(self::$pasteid, $paste);
|
||||
$paste = helper::getPaste(array('opendiscussion' => false));
|
||||
$this->_model->create(helper::getPasteId(), $paste);
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$_POST = self::$comment;
|
||||
$_POST['pasteid'] = self::$pasteid;
|
||||
$_POST['parentid'] = self::$pasteid;
|
||||
$_POST = helper::getComment();
|
||||
$_POST['pasteid'] = helper::getPasteId();
|
||||
$_POST['parentid'] = helper::getPasteId();
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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))
|
||||
rename($this->_conf, $this->_conf . '.bak');
|
||||
helper::createIniFile($this->_conf, $options);
|
||||
$this->_model->create(self::$pasteid, self::$paste);
|
||||
$this->_model->createComment(self::$pasteid, self::$pasteid, self::$commentid, self::$comment);
|
||||
$this->assertTrue($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment exists before posting data');
|
||||
$_POST = self::$comment;
|
||||
$_POST['pasteid'] = self::$pasteid;
|
||||
$_POST['parentid'] = self::$pasteid;
|
||||
$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['pasteid'] = helper::getPasteId();
|
||||
$_POST['parentid'] = helper::getPasteId();
|
||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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()
|
||||
{
|
||||
$this->reset();
|
||||
$this->_model->create(self::$pasteid, self::$paste);
|
||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
||||
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
$this->assertTag(
|
||||
array(
|
||||
'id' => 'cipherdata',
|
||||
'content' => htmlspecialchars(json_encode(self::$paste), ENT_NOQUOTES)
|
||||
'content' => htmlspecialchars(json_encode(helper::getPaste()), ENT_NOQUOTES)
|
||||
),
|
||||
$content,
|
||||
'outputs data correctly'
|
||||
@ -583,7 +558,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
public function testReadNonexisting()
|
||||
{
|
||||
$this->reset();
|
||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
||||
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
@ -603,10 +578,9 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
public function testReadExpired()
|
||||
{
|
||||
$this->reset();
|
||||
$expiredPaste = self::$paste;
|
||||
$expiredPaste['meta']['expire_date'] = $expiredPaste['meta']['postdate'];
|
||||
$this->_model->create(self::$pasteid, $expiredPaste);
|
||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
||||
$expiredPaste = helper::getPaste(array('expire_date' => 1344803344));
|
||||
$this->_model->create(helper::getPasteId(), $expiredPaste);
|
||||
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
@ -626,10 +600,9 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
public function testReadBurn()
|
||||
{
|
||||
$this->reset();
|
||||
$burnPaste = self::$paste;
|
||||
$burnPaste['meta']['burnafterreading'] = true;
|
||||
$this->_model->create(self::$pasteid, $burnPaste);
|
||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
||||
$burnPaste = helper::getPaste(array('burnafterreading' => true));
|
||||
$this->_model->create(helper::getPasteId(), $burnPaste);
|
||||
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
@ -649,14 +622,14 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
public function testReadJson()
|
||||
{
|
||||
$this->reset();
|
||||
$this->_model->create(self::$pasteid, self::$paste);
|
||||
$_SERVER['QUERY_STRING'] = self::$pasteid . '&json';
|
||||
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||
$_SERVER['QUERY_STRING'] = helper::getPasteId() . '&json';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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()
|
||||
{
|
||||
$this->reset();
|
||||
$_SERVER['QUERY_STRING'] = self::$pasteid . '&json';
|
||||
$_SERVER['QUERY_STRING'] = helper::getPasteId() . '&json';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
@ -679,11 +652,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
public function testReadOldSyntax()
|
||||
{
|
||||
$this->reset();
|
||||
$oldPaste = self::$paste;
|
||||
$oldPaste['meta']['syntaxcoloring'] = true;
|
||||
$oldPaste = helper::getPaste(array('syntaxcoloring' => true));
|
||||
unset($oldPaste['meta']['formatter']);
|
||||
$this->_model->create(self::$pasteid, $oldPaste);
|
||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
||||
$this->_model->create(helper::getPasteId(), $oldPaste);
|
||||
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
@ -704,10 +676,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
public function testReadOldFormat()
|
||||
{
|
||||
$this->reset();
|
||||
$oldPaste = self::$paste;
|
||||
$oldPaste = helper::getPaste();
|
||||
unset($oldPaste['meta']['formatter']);
|
||||
$this->_model->create(self::$pasteid, $oldPaste);
|
||||
$_SERVER['QUERY_STRING'] = self::$pasteid;
|
||||
$this->_model->create(helper::getPasteId(), $oldPaste);
|
||||
$_SERVER['QUERY_STRING'] = helper::getPasteId();
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
@ -728,10 +700,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
public function testDelete()
|
||||
{
|
||||
$this->reset();
|
||||
$this->_model->create(self::$pasteid, self::$paste);
|
||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists before deleting data');
|
||||
$_GET['pasteid'] = self::$pasteid;
|
||||
$_GET['deletetoken'] = hash_hmac('sha1', self::$pasteid, serversalt::get());
|
||||
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists before deleting data');
|
||||
$_GET['pasteid'] = helper::getPasteId();
|
||||
$_GET['deletetoken'] = hash_hmac('sha1', helper::getPasteId(), serversalt::get());
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
@ -743,7 +715,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
$content,
|
||||
'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()
|
||||
{
|
||||
$this->reset();
|
||||
$this->_model->create(self::$pasteid, self::$paste);
|
||||
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||
$_GET['pasteid'] = 'foo';
|
||||
$_GET['deletetoken'] = 'bar';
|
||||
ob_start();
|
||||
@ -766,7 +738,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
$content,
|
||||
'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()
|
||||
{
|
||||
$this->reset();
|
||||
$_GET['pasteid'] = self::$pasteid;
|
||||
$_GET['pasteid'] = helper::getPasteId();
|
||||
$_GET['deletetoken'] = 'bar';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
@ -796,8 +768,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
public function testDeleteInvalidToken()
|
||||
{
|
||||
$this->reset();
|
||||
$this->_model->create(self::$pasteid, self::$paste);
|
||||
$_GET['pasteid'] = self::$pasteid;
|
||||
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||
$_GET['pasteid'] = helper::getPasteId();
|
||||
$_GET['deletetoken'] = 'bar';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
@ -810,7 +782,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
$content,
|
||||
'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()
|
||||
{
|
||||
$this->reset();
|
||||
$burnPaste = self::$paste;
|
||||
$burnPaste['meta']['burnafterreading'] = true;
|
||||
$this->_model->create(self::$pasteid, $burnPaste);
|
||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists before deleting data');
|
||||
$_GET['pasteid'] = self::$pasteid;
|
||||
$burnPaste = helper::getPaste(array('burnafterreading' => true));
|
||||
$this->_model->create(helper::getPasteId(), $burnPaste);
|
||||
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists before deleting data');
|
||||
$_GET['pasteid'] = helper::getPasteId();
|
||||
$_GET['deletetoken'] = 'burnafterreading';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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()
|
||||
{
|
||||
$this->reset();
|
||||
$this->_model->create(self::$pasteid, self::$paste);
|
||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists before deleting data');
|
||||
$_GET['pasteid'] = self::$pasteid;
|
||||
$this->_model->create(helper::getPasteId(), helper::getPaste());
|
||||
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists before deleting data');
|
||||
$_GET['pasteid'] = helper::getPasteId();
|
||||
$_GET['deletetoken'] = 'burnafterreading';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
$content = ob_get_contents();
|
||||
$response = json_decode($content, true);
|
||||
$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()
|
||||
{
|
||||
$this->reset();
|
||||
$expiredPaste = self::$paste;
|
||||
$expiredPaste['meta']['expire_date'] = 1000;
|
||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste does not exist before being created');
|
||||
$this->_model->create(self::$pasteid, $expiredPaste);
|
||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists before deleting data');
|
||||
$_GET['pasteid'] = self::$pasteid;
|
||||
$expiredPaste = helper::getPaste(array('expire_date' => 1000));
|
||||
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste does not exist before being created');
|
||||
$this->_model->create(helper::getPasteId(), $expiredPaste);
|
||||
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists before deleting data');
|
||||
$_GET['pasteid'] = helper::getPasteId();
|
||||
$_GET['deletetoken'] = 'does not matter in this context, but has to be set';
|
||||
ob_start();
|
||||
new zerobin;
|
||||
@ -875,6 +845,6 @@ class zerobinTest extends PHPUnit_Framework_TestCase
|
||||
$content,
|
||||
'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
|
||||
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 $_path;
|
||||
@ -43,28 +21,29 @@ class zerobin_dataTest extends PHPUnit_Framework_TestCase
|
||||
public function testFileBasedDataStoreWorks()
|
||||
{
|
||||
// storing pastes
|
||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste does not yet exist');
|
||||
$this->assertTrue($this->_model->create(self::$pasteid, self::$paste), 'store new paste');
|
||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists after storing it');
|
||||
$this->assertFalse($this->_model->create(self::$pasteid, self::$paste), 'unable to store the same paste twice');
|
||||
$this->assertEquals(json_decode(json_encode(self::$paste)), $this->_model->read(self::$pasteid));
|
||||
$paste = helper::getPaste(array('expire_date' => 1344803344));
|
||||
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste does not yet exist');
|
||||
$this->assertTrue($this->_model->create(helper::getPasteId(), $paste), 'store new paste');
|
||||
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists after storing it');
|
||||
$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
|
||||
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), '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->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment exists after storing it');
|
||||
$comment = json_decode(json_encode(self::$comment));
|
||||
$comment->meta->commentid = self::$commentid;
|
||||
$comment->meta->parentid = self::$pasteid;
|
||||
$this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment does not yet exist');
|
||||
$this->assertTrue($this->_model->createComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId(), helper::getComment()) !== false, 'store comment');
|
||||
$this->assertTrue($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment exists after storing it');
|
||||
$comment = json_decode(json_encode(helper::getComment()));
|
||||
$comment->meta->commentid = helper::getCommentId();
|
||||
$comment->meta->parentid = helper::getPasteId();
|
||||
$this->assertEquals(
|
||||
array($comment->meta->postdate => $comment),
|
||||
$this->_model->readComments(self::$pasteid)
|
||||
$this->_model->readComments(helper::getPasteId())
|
||||
);
|
||||
|
||||
// deleting pastes
|
||||
$this->_model->delete(self::$pasteid);
|
||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste successfully deleted');
|
||||
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment was deleted with paste');
|
||||
$this->assertFalse($this->_model->read(self::$pasteid), 'paste can no longer be found');
|
||||
$this->_model->delete(helper::getPasteId());
|
||||
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted');
|
||||
$this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment was deleted with paste');
|
||||
$this->assertFalse($this->_model->read(helper::getPasteId()), 'paste can no longer be found');
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,6 @@
|
||||
<?php
|
||||
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;
|
||||
|
||||
public function setUp()
|
||||
@ -40,30 +18,30 @@ class zerobin_dbTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testDatabaseBasedDataStoreWorks()
|
||||
{
|
||||
// storing pastes
|
||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste does not yet exist');
|
||||
$this->assertTrue($this->_model->create(self::$pasteid, self::$paste), 'store new paste');
|
||||
$this->assertTrue($this->_model->exists(self::$pasteid), 'paste exists after storing it');
|
||||
$this->assertFalse($this->_model->create(self::$pasteid, self::$paste), 'unable to store the same paste twice');
|
||||
$this->assertEquals(json_decode(json_encode(self::$paste)), $this->_model->read(self::$pasteid));
|
||||
$paste = helper::getPaste(array('expire_date' => 1344803344));
|
||||
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste does not yet exist');
|
||||
$this->assertTrue($this->_model->create(helper::getPasteId(), $paste), 'store new paste');
|
||||
$this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists after storing it');
|
||||
$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
|
||||
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), '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->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment exists after storing it');
|
||||
$comment = json_decode(json_encode(self::$comment));
|
||||
$comment->meta->commentid = self::$commentid;
|
||||
$comment->meta->parentid = self::$pasteid;
|
||||
$this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment does not yet exist');
|
||||
$this->assertTrue($this->_model->createComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId(), helper::getComment()) !== false, 'store comment');
|
||||
$this->assertTrue($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment exists after storing it');
|
||||
$comment = json_decode(json_encode(helper::getComment()));
|
||||
$comment->meta->commentid = helper::getCommentId();
|
||||
$comment->meta->parentid = helper::getPasteId();
|
||||
$this->assertEquals(
|
||||
array($comment->meta->postdate => $comment),
|
||||
$this->_model->readComments(self::$pasteid)
|
||||
$this->_model->readComments(helper::getPasteId())
|
||||
);
|
||||
|
||||
// deleting pastes
|
||||
$this->_model->delete(self::$pasteid);
|
||||
$this->assertFalse($this->_model->exists(self::$pasteid), 'paste successfully deleted');
|
||||
$this->assertFalse($this->_model->existsComment(self::$pasteid, self::$pasteid, self::$commentid), 'comment was deleted with paste');
|
||||
$this->assertFalse($this->_model->read(self::$pasteid), 'paste can no longer be found');
|
||||
$this->_model->delete(helper::getPasteId());
|
||||
$this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted');
|
||||
$this->assertFalse($this->_model->existsComment(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'comment was deleted with paste');
|
||||
$this->assertFalse($this->_model->read(helper::getPasteId()), 'paste can no longer be found');
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user