| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831 |
- <?php
- class zerobinTest extends PHPUnit_Framework_TestCase
- {
- private $_model;
- public function setUp()
- {
- /* Setup Routine */
- $this->_model = zerobin_data::getInstance(array('dir' => PATH . 'data'));
- serversalt::setPath(PATH . 'data');
- $this->reset();
- }
- public function tearDown()
- {
- /* Tear Down Routine */
- }
- public function reset()
- {
- $_POST = array();
- $_GET = array();
- $_SERVER = array();
- if ($this->_model->exists(helper::getPasteId()))
- $this->_model->delete(helper::getPasteId());
- helper::confRestore();
- }
- /**
- * @runInSeparateProcess
- */
- public function testView()
- {
- $this->reset();
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $this->assertTag(
- array(
- 'tag' => 'title',
- 'content' => 'ZeroBin'
- ),
- $content,
- 'outputs title correctly'
- );
- }
- /**
- * @runInSeparateProcess
- */
- public function testViewLanguageSelection()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['main']['languageselection'] = true;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_COOKIE['lang'] = 'de';
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $this->assertTag(
- array(
- 'tag' => 'title',
- 'content' => 'ZeroBin'
- ),
- $content,
- 'outputs title correctly'
- );
- }
- /**
- * @runInSeparateProcess
- */
- public function testHtaccess()
- {
- $this->reset();
- $dirs = array('cfg', 'lib');
- foreach ($dirs as $dir) {
- $file = PATH . $dir . DIRECTORY_SEPARATOR . '.htaccess';
- @unlink($file);
- }
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- foreach ($dirs as $dir) {
- $file = PATH . $dir . DIRECTORY_SEPARATOR . '.htaccess';
- $this->assertFileExists(
- $file,
- "$dir htaccess recreated"
- );
- }
- }
- /**
- * @expectedException Exception
- * @expectedExceptionCode 2
- */
- public function testConf()
- {
- $this->reset();
- helper::confBackup();
- file_put_contents(CONF, '');
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreate()
- {
- $this->reset();
- $_POST = helper::getPaste();
- $_SERVER['REMOTE_ADDR'] = '::1';
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $response = json_decode($content, true);
- $this->assertEquals(0, $response['status'], 'outputs status');
- $this->assertEquals(
- hash_hmac('sha1', $response['id'], serversalt::get()),
- $response['deletetoken'],
- 'outputs valid delete token'
- );
- $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateInvalidTimelimit()
- {
- $this->reset();
- $_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(helper::getPasteId()), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateInvalidSize()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['main']['sizelimit'] = 10;
- $options['traffic']['limit'] = 0;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_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(helper::getPasteId()), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateProxyHeader()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['header'] = 'X_FORWARDED_FOR';
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_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(helper::getPasteId()), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateDuplicateId()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['limit'] = 0;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $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(helper::getPasteId()), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateValidExpire()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['limit'] = 0;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_POST = helper::getPaste();
- $_POST['expire'] = '5min';
- $_POST['formatter'] = 'foo';
- $_SERVER['REMOTE_ADDR'] = '::1';
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $response = json_decode($content, true);
- $this->assertEquals(0, $response['status'], 'outputs status');
- $this->assertEquals(
- hash_hmac('sha1', $response['id'], serversalt::get()),
- $response['deletetoken'],
- 'outputs valid delete token'
- );
- $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateInvalidExpire()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['limit'] = 0;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_POST = helper::getPaste();
- $_POST['expire'] = 'foo';
- $_SERVER['REMOTE_ADDR'] = '::1';
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $response = json_decode($content, true);
- $this->assertEquals(0, $response['status'], 'outputs status');
- $this->assertEquals(
- hash_hmac('sha1', $response['id'], serversalt::get()),
- $response['deletetoken'],
- 'outputs valid delete token'
- );
- $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateInvalidBurn()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['limit'] = 0;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_POST = helper::getPaste();
- $_POST['burnafterreading'] = 'neither 1 nor 0';
- $_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(helper::getPasteId()), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateInvalidOpenDiscussion()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['limit'] = 0;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_POST = helper::getPaste();
- $_POST['opendiscussion'] = 'neither 1 nor 0';
- $_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(helper::getPasteId()), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateAttachment()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['limit'] = 0;
- $options['main']['fileupload'] = true;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_POST = helper::getPaste();
- $_POST['attachment'] = $_POST['meta']['attachment'];
- $_POST['attachmentname'] = $_POST['meta']['attachmentname'];
- $_SERVER['REMOTE_ADDR'] = '::1';
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $response = json_decode($content, true);
- $this->assertEquals(0, $response['status'], 'outputs status');
- $this->assertEquals(
- hash_hmac('sha1', $response['id'], serversalt::get()),
- $response['deletetoken'],
- 'outputs valid delete token'
- );
- $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateValidNick()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['limit'] = 0;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_POST = helper::getPaste();
- $_POST['nickname'] = helper::getComment()['meta']['nickname'];
- $_SERVER['REMOTE_ADDR'] = '::1';
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $response = json_decode($content, true);
- $this->assertEquals(0, $response['status'], 'outputs status');
- $this->assertEquals(
- hash_hmac('sha1', $response['id'], serversalt::get()),
- $response['deletetoken'],
- 'outputs valid delete token'
- );
- $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateInvalidNick()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['limit'] = 0;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_POST = helper::getPaste();
- $_POST['nickname'] = 'foo';
- $_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(helper::getPasteId()), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateComment()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['limit'] = 0;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_POST = helper::getComment();
- $_POST['pasteid'] = helper::getPasteId();
- $_POST['parentid'] = helper::getPasteId();
- $_SERVER['REMOTE_ADDR'] = '::1';
- $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(helper::getPasteId(), helper::getPasteId(), $response['id']), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateInvalidComment()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['limit'] = 0;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_POST = helper::getComment();
- $_POST['pasteid'] = helper::getPasteId();
- $_POST['parentid'] = 'foo';
- $_SERVER['REMOTE_ADDR'] = '::1';
- $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(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateCommentDiscussionDisabled()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['limit'] = 0;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_POST = helper::getComment();
- $_POST['pasteid'] = helper::getPasteId();
- $_POST['parentid'] = helper::getPasteId();
- $_SERVER['REMOTE_ADDR'] = '::1';
- $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(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateCommentInvalidPaste()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['limit'] = 0;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $_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(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testCreateDuplicateComment()
- {
- $this->reset();
- $options = parse_ini_file(CONF, true);
- $options['traffic']['limit'] = 0;
- helper::confBackup();
- helper::createIniFile(CONF, $options);
- $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(helper::getPasteId(), helper::getPasteId(), helper::getCommentId()), 'paste exists after posting data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testRead()
- {
- $this->reset();
- $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(helper::getPaste()), ENT_NOQUOTES)
- ),
- $content,
- 'outputs data correctly'
- );
- }
- /**
- * @runInSeparateProcess
- */
- public function testReadInvalidId()
- {
- $this->reset();
- $_SERVER['QUERY_STRING'] = 'foo';
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $this->assertTag(
- array(
- 'id' => 'errormessage',
- 'content' => 'Invalid paste ID'
- ),
- $content,
- 'outputs error correctly'
- );
- }
- /**
- * @runInSeparateProcess
- */
- public function testReadNonexisting()
- {
- $this->reset();
- $_SERVER['QUERY_STRING'] = helper::getPasteId();
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $this->assertTag(
- array(
- 'id' => 'errormessage',
- 'content' => 'Paste does not exist'
- ),
- $content,
- 'outputs error correctly'
- );
- }
- /**
- * @runInSeparateProcess
- */
- public function testReadExpired()
- {
- $this->reset();
- $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();
- $this->assertTag(
- array(
- 'id' => 'errormessage',
- 'content' => 'Paste does not exist'
- ),
- $content,
- 'outputs error correctly'
- );
- }
- /**
- * @runInSeparateProcess
- */
- public function testReadBurn()
- {
- $this->reset();
- $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();
- $this->assertTag(
- array(
- 'id' => 'cipherdata',
- 'content' => htmlspecialchars(json_encode($burnPaste), ENT_NOQUOTES)
- ),
- $content,
- 'outputs data correctly'
- );
- }
- /**
- * @runInSeparateProcess
- */
- public function testReadJson()
- {
- $this->reset();
- $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(helper::getPaste()), $response['messages'], 'outputs data correctly');
- }
- /**
- * @runInSeparateProcess
- */
- public function testReadInvalidJson()
- {
- $this->reset();
- $_SERVER['QUERY_STRING'] = helper::getPasteId() . '&json';
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $response = json_decode($content, true);
- $this->assertEquals(1, $response['status'], 'outputs error status');
- }
- /**
- * @runInSeparateProcess
- */
- public function testReadOldSyntax()
- {
- $this->reset();
- $oldPaste = helper::getPaste(array('syntaxcoloring' => true));
- unset($oldPaste['meta']['formatter']);
- $this->_model->create(helper::getPasteId(), $oldPaste);
- $_SERVER['QUERY_STRING'] = helper::getPasteId();
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $oldPaste['meta']['formatter'] = 'syntaxhighlighting';
- $this->assertTag(
- array(
- 'id' => 'cipherdata',
- 'content' => htmlspecialchars(json_encode($oldPaste), ENT_NOQUOTES)
- ),
- $content,
- 'outputs data correctly'
- );
- }
- /**
- * @runInSeparateProcess
- */
- public function testReadOldFormat()
- {
- $this->reset();
- $oldPaste = helper::getPaste();
- unset($oldPaste['meta']['formatter']);
- $this->_model->create(helper::getPasteId(), $oldPaste);
- $_SERVER['QUERY_STRING'] = helper::getPasteId();
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $oldPaste['meta']['formatter'] = 'plaintext';
- $this->assertTag(
- array(
- 'id' => 'cipherdata',
- 'content' => htmlspecialchars(json_encode($oldPaste), ENT_NOQUOTES)
- ),
- $content,
- 'outputs data correctly'
- );
- }
- /**
- * @runInSeparateProcess
- */
- public function testDelete()
- {
- $this->reset();
- $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();
- $this->assertTag(
- array(
- 'id' => 'status',
- 'content' => 'Paste was properly deleted'
- ),
- $content,
- 'outputs deleted status correctly'
- );
- $this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted');
- }
- /**
- * @runInSeparateProcess
- */
- public function testDeleteInvalidId()
- {
- $this->reset();
- $this->_model->create(helper::getPasteId(), helper::getPaste());
- $_GET['pasteid'] = 'foo';
- $_GET['deletetoken'] = 'bar';
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $this->assertTag(
- array(
- 'id' => 'errormessage',
- 'content' => 'Invalid paste ID'
- ),
- $content,
- 'outputs delete error correctly'
- );
- $this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists after failing to delete data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testDeleteInexistantId()
- {
- $this->reset();
- $_GET['pasteid'] = helper::getPasteId();
- $_GET['deletetoken'] = 'bar';
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $this->assertTag(
- array(
- 'id' => 'errormessage',
- 'content' => 'Paste does not exist'
- ),
- $content,
- 'outputs delete error correctly'
- );
- }
- /**
- * @runInSeparateProcess
- */
- public function testDeleteInvalidToken()
- {
- $this->reset();
- $this->_model->create(helper::getPasteId(), helper::getPaste());
- $_GET['pasteid'] = helper::getPasteId();
- $_GET['deletetoken'] = 'bar';
- ob_start();
- new zerobin;
- $content = ob_get_contents();
- $this->assertTag(
- array(
- 'id' => 'errormessage',
- 'content' => 'Wrong deletion token'
- ),
- $content,
- 'outputs delete error correctly'
- );
- $this->assertTrue($this->_model->exists(helper::getPasteId()), 'paste exists after failing to delete data');
- }
- /**
- * @runInSeparateProcess
- */
- public function testDeleteBurnAfterReading()
- {
- $this->reset();
- $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(helper::getPasteId()), 'paste successfully deleted');
- }
- /**
- * @runInSeparateProcess
- */
- public function testDeleteInvalidBurnAfterReading()
- {
- $this->reset();
- $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(helper::getPasteId()), 'paste successfully deleted');
- }
- /**
- * @runInSeparateProcess
- */
- public function testDeleteExpired()
- {
- $this->reset();
- $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;
- $content = ob_get_contents();
- $this->assertTag(
- array(
- 'id' => 'errormessage',
- 'content' => 'Paste does not exist'
- ),
- $content,
- 'outputs error correctly'
- );
- $this->assertFalse($this->_model->exists(helper::getPasteId()), 'paste successfully deleted');
- }
- }
|