improving unit tests, fixing regression in DB model

This commit is contained in:
El RIDO
2015-09-27 14:36:20 +02:00
parent 694138c5d4
commit ce3f10f143
3 changed files with 77 additions and 9 deletions

View File

@@ -146,6 +146,7 @@ class modelTest extends PHPUnit_Framework_TestCase
$this->_model->getPaste(helper::getPasteId())->delete();
$paste = $this->_model->getPaste();
$paste->setData($pasteData['data']);
$paste->setBurnafterreading('0');
$paste->setOpendiscussion();
$paste->store();
@@ -166,4 +167,45 @@ class modelTest extends PHPUnit_Framework_TestCase
$this->assertFalse(model_paste::isValidId('foo'), 'invalid hex values');
$this->assertFalse(model_paste::isValidId('../bar/baz'), 'path attack');
}
/**
* @expectedException Exception
* @expectedExceptionCode 62
*/
public function testInvalidComment()
{
$paste = $this->_model->getPaste();
$comment = $paste->getComment(helper::getPasteId());
}
public function testExpiration()
{
$pasteData = helper::getPaste();
$this->_model->getPaste(helper::getPasteId())->delete();
$paste = $this->_model->getPaste(helper::getPasteId());
$this->assertFalse($paste->exists(), 'paste does not yet exist');
$paste = $this->_model->getPaste();
$paste->setData($pasteData['data']);
$paste->setExpiration('5min'); // = 300 seconds
$paste->store();
$paste = $paste->get();
$this->assertEquals(300, $paste->meta->remaining_time, 'remaining time is set correctly');
}
/**
* @expectedException Exception
* @expectedExceptionCode 64
*/
public function testCommentDeletion()
{
$pasteData = helper::getPaste();
$this->_model->getPaste(helper::getPasteId())->delete();
$paste = $this->_model->getPaste();
$paste->setData($pasteData['data']);
$paste->store();
$paste->getComment(helper::getPasteId())->delete();
}
}