removing dead code and improving code coverage
This commit is contained in:
parent
5b67721a6a
commit
be1e7babc0
5 changed files with 19 additions and 21 deletions
|
@ -145,7 +145,7 @@ class Comment extends AbstractModel
|
||||||
public function getParentId()
|
public function getParentId()
|
||||||
{
|
{
|
||||||
if (!array_key_exists('parentid', $this->_data)) {
|
if (!array_key_exists('parentid', $this->_data)) {
|
||||||
$this->_data['parentid'] = '';
|
$this->_data['parentid'] = $this->getPaste()->getId();
|
||||||
}
|
}
|
||||||
return $this->_data['parentid'];
|
return $this->_data['parentid'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,23 +183,6 @@ class Paste extends AbstractModel
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if paste is of burn-after-reading type.
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @throws Exception
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isBurnafterreading()
|
|
||||||
{
|
|
||||||
if (!array_key_exists('adata', $this->_data) && !array_key_exists('data', $this->_data)) {
|
|
||||||
$this->get();
|
|
||||||
}
|
|
||||||
return
|
|
||||||
(array_key_exists('adata', $this->_data) && $this->_data['adata'][3] === 1) ||
|
|
||||||
(array_key_exists('burnafterreading', $this->_data['meta']) && $this->_data['meta']['burnafterreading']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if paste has discussions enabled.
|
* Check if paste has discussions enabled.
|
||||||
*
|
*
|
||||||
|
|
|
@ -26,6 +26,7 @@ class I18nTest extends PHPUnit_Framework_TestCase
|
||||||
$messageId = 'It does not matter if the message ID exists';
|
$messageId = 'It does not matter if the message ID exists';
|
||||||
I18n::loadTranslations();
|
I18n::loadTranslations();
|
||||||
$this->assertEquals($messageId, I18n::_($messageId), 'fallback to en');
|
$this->assertEquals($messageId, I18n::_($messageId), 'fallback to en');
|
||||||
|
I18n::getLanguageLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCookieLanguageDeDetection()
|
public function testCookieLanguageDeDetection()
|
||||||
|
@ -40,7 +41,7 @@ class I18nTest extends PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testBrowserLanguageDeDetection()
|
public function testBrowserLanguageDeDetection()
|
||||||
{
|
{
|
||||||
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-CH,de;q=0.8,en-GB;q=0.6,en-US;q=0.4,en;q=0.2';
|
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-CH,de;q=0.8,en-GB;q=0.6,en-US;q=0.4,en;q=0.2,fr;q=0.0';
|
||||||
I18n::loadTranslations();
|
I18n::loadTranslations();
|
||||||
$this->assertEquals($this->_translations['en'], I18n::_('en'), 'browser language de');
|
$this->assertEquals($this->_translations['en'], I18n::_('en'), 'browser language de');
|
||||||
$this->assertEquals('0 Stunden', I18n::_('%d hours', 0), '0 hours in German');
|
$this->assertEquals('0 Stunden', I18n::_('%d hours', 0), '0 hours in German');
|
||||||
|
@ -50,7 +51,7 @@ class I18nTest extends PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testBrowserLanguageFrDetection()
|
public function testBrowserLanguageFrDetection()
|
||||||
{
|
{
|
||||||
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'fr-CH,fr;q=0.8,en-GB;q=0.6,en-US;q=0.4,en;q=0.2';
|
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'fr-CH,fr;q=0.8,en-GB;q=0.6,en-US;q=0.4,en;q=0.2,de;q=0.0';
|
||||||
I18n::loadTranslations();
|
I18n::loadTranslations();
|
||||||
$this->assertEquals('fr', I18n::_('en'), 'browser language fr');
|
$this->assertEquals('fr', I18n::_('en'), 'browser language fr');
|
||||||
$this->assertEquals('0 heure', I18n::_('%d hours', 0), '0 hours in French');
|
$this->assertEquals('0 heure', I18n::_('%d hours', 0), '0 hours in French');
|
||||||
|
|
|
@ -52,6 +52,7 @@ class JsonApiTest extends PHPUnit_Framework_TestCase
|
||||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
|
||||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
|
$_SERVER['REQUEST_URI'] = '/';
|
||||||
ob_start();
|
ob_start();
|
||||||
new Controller;
|
new Controller;
|
||||||
$content = ob_get_contents();
|
$content = ob_get_contents();
|
||||||
|
|
|
@ -4,6 +4,7 @@ use Identicon\Identicon;
|
||||||
use PrivateBin\Configuration;
|
use PrivateBin\Configuration;
|
||||||
use PrivateBin\Data\Database;
|
use PrivateBin\Data\Database;
|
||||||
use PrivateBin\Model;
|
use PrivateBin\Model;
|
||||||
|
use PrivateBin\Model\Comment;
|
||||||
use PrivateBin\Model\Paste;
|
use PrivateBin\Model\Paste;
|
||||||
use PrivateBin\Persistence\ServerSalt;
|
use PrivateBin\Persistence\ServerSalt;
|
||||||
use PrivateBin\Persistence\TrafficLimiter;
|
use PrivateBin\Persistence\TrafficLimiter;
|
||||||
|
@ -85,7 +86,6 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$comment = $paste->getComment(Helper::getPasteId());
|
$comment = $paste->getComment(Helper::getPasteId());
|
||||||
$comment->setData($commentData);
|
$comment->setData($commentData);
|
||||||
//$comment->getParentId();
|
|
||||||
$comment->store();
|
$comment->store();
|
||||||
|
|
||||||
$comments = $this->_model->getPaste(Helper::getPasteId())->get()['comments'];
|
$comments = $this->_model->getPaste(Helper::getPasteId())->get()['comments'];
|
||||||
|
@ -102,6 +102,19 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
||||||
$this->assertEquals(array(), $paste->getComments(), 'comment was deleted with paste');
|
$this->assertEquals(array(), $paste->getComments(), 'comment was deleted with paste');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCommentDefaults()
|
||||||
|
{
|
||||||
|
$comment = new Comment(
|
||||||
|
$this->_conf,
|
||||||
|
forward_static_call(
|
||||||
|
'PrivateBin\\Data\\' . $this->_conf->getKey('class', 'model') . '::getInstance',
|
||||||
|
$this->_conf->getSection('model_options')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$comment->setPaste($this->_model->getPaste(Helper::getPasteId()));
|
||||||
|
$this->assertEquals(Helper::getPasteId(), $comment->getParentId(), 'comment parent ID gets initialized to paste ID');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Exception
|
* @expectedException Exception
|
||||||
* @expectedExceptionCode 75
|
* @expectedExceptionCode 75
|
||||||
|
|
Loading…
Reference in a new issue