Stats: Added questions test

main
Igor Scheller 5 years ago
parent e16e0b2644
commit 8fc159f287

@ -6,6 +6,7 @@ use Carbon\Carbon;
use Engelsystem\Database\Database; use Engelsystem\Database\Database;
use Engelsystem\Models\EventConfig; use Engelsystem\Models\EventConfig;
use Engelsystem\Models\News; use Engelsystem\Models\News;
use Engelsystem\Models\Question;
use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Database\Query\Expression as QueryExpression; use Illuminate\Database\Query\Expression as QueryExpression;
@ -221,13 +222,10 @@ class Stats
/** /**
* @param bool $answered * @param bool $answered
* @return int * @return int
* @codeCoverageIgnore
*/ */
public function questions($answered = null) public function questions($answered = null)
{ {
$query = $this $query = Question::query();
->getQuery('questions');
if (!is_null($answered)) { if (!is_null($answered)) {
if ($answered) { if ($answered) {
$query->whereNotNull('answerer_id'); $query->whereNotNull('answerer_id');

@ -6,6 +6,7 @@ use Carbon\Carbon;
use Engelsystem\Controllers\Metrics\Stats; use Engelsystem\Controllers\Metrics\Stats;
use Engelsystem\Models\LogEntry; use Engelsystem\Models\LogEntry;
use Engelsystem\Models\News; use Engelsystem\Models\News;
use Engelsystem\Models\Question;
use Engelsystem\Models\User\PasswordReset; use Engelsystem\Models\User\PasswordReset;
use Engelsystem\Models\User\PersonalData; use Engelsystem\Models\User\PersonalData;
use Engelsystem\Models\User\State; use Engelsystem\Models\User\State;
@ -91,6 +92,24 @@ class StatsTest extends TestCase
$this->assertEquals(1, $stats->announcements(true)); $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 * @covers \Engelsystem\Controllers\Metrics\Stats::arrivedUsers
*/ */

Loading…
Cancel
Save