Stats: Added questions test
This commit is contained in:
parent
e16e0b2644
commit
8fc159f287
|
@ -6,6 +6,7 @@ use Carbon\Carbon;
|
|||
use Engelsystem\Database\Database;
|
||||
use Engelsystem\Models\EventConfig;
|
||||
use Engelsystem\Models\News;
|
||||
use Engelsystem\Models\Question;
|
||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||
use Illuminate\Database\Query\Expression as QueryExpression;
|
||||
|
||||
|
@ -221,13 +222,10 @@ class Stats
|
|||
/**
|
||||
* @param bool $answered
|
||||
* @return int
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function questions($answered = null)
|
||||
{
|
||||
$query = $this
|
||||
->getQuery('questions');
|
||||
|
||||
$query = Question::query();
|
||||
if (!is_null($answered)) {
|
||||
if ($answered) {
|
||||
$query->whereNotNull('answerer_id');
|
||||
|
|
|
@ -6,6 +6,7 @@ use Carbon\Carbon;
|
|||
use Engelsystem\Controllers\Metrics\Stats;
|
||||
use Engelsystem\Models\LogEntry;
|
||||
use Engelsystem\Models\News;
|
||||
use Engelsystem\Models\Question;
|
||||
use Engelsystem\Models\User\PasswordReset;
|
||||
use Engelsystem\Models\User\PersonalData;
|
||||
use Engelsystem\Models\User\State;
|
||||
|
@ -91,6 +92,24 @@ class StatsTest extends TestCase
|
|||
$this->assertEquals(1, $stats->announcements(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Engelsystem\Controllers\Metrics\Stats::questions
|
||||
*/
|
||||
public function testQuestions()
|
||||
{
|
||||
$this->addUsers();
|
||||
$questionsData = ['text' => 'Lorem Ipsum', 'user_id' => 1];
|
||||
|
||||
(new Question($questionsData))->save();
|
||||
(new Question($questionsData))->save();
|
||||
(new Question($questionsData + ['answerer_id' => 2, 'answer' => 'Dolor sit!']))->save();
|
||||
|
||||
$stats = new Stats($this->database);
|
||||
$this->assertEquals(3, $stats->questions());
|
||||
$this->assertEquals(2, $stats->questions(false));
|
||||
$this->assertEquals(1, $stats->questions(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Engelsystem\Controllers\Metrics\Stats::arrivedUsers
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue