Skip to content

Commit

Permalink
added test and added list item template
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Wagner committed Feb 1, 2018
1 parent 924eb23 commit f04ba03
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 6 deletions.
22 changes: 20 additions & 2 deletions src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Contao\ManagerPlugin\Config\ContainerBuilder;
use Contao\ManagerPlugin\Config\ExtensionPluginInterface;
use HeimrichHannot\ListBundle\HeimrichHannotContaoListBundle;
use HeimrichHannot\QuizBundle\HeimrichHannotContaoQuizBundle;
use HeimrichHannot\UtilsBundle\Container\ContainerUtil;

class Plugin implements BundlePluginInterface
class Plugin implements BundlePluginInterface, ExtensionPluginInterface
{
/**
* @param ParserInterface $parser
Expand All @@ -24,7 +28,21 @@ class Plugin implements BundlePluginInterface
public function getBundles(ParserInterface $parser)
{
return [
BundleConfig::create(HeimrichHannotContaoQuizBundle::class)->setLoadAfter([ContaoCoreBundle::class, 'submissions_creator', 'submissions']),
BundleConfig::create(HeimrichHannotContaoQuizBundle::class)->setLoadAfter([ContaoCoreBundle::class, 'submissions_creator', 'submissions', HeimrichHannotContaoListBundle::class]),
];
}

/**
* @param $extensionName
* @param array $extensionConfigs
* @param ContainerBuilder $container
*
* @return array
*/
public function getExtensionConfig($extensionName, array $extensionConfigs, ContainerBuilder $container)
{
$extensionConfigs = ContainerUtil::mergeConfigFile('huh_list', $extensionName, $extensionConfigs, $container->getParameter('kernel.project_dir').'/vendor/heimrichhannot/contao-quiz-bundle/src/Resources/config/config.yml');

return $extensionConfigs;
}
}
2 changes: 1 addition & 1 deletion src/Manager/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ public function parseModel(Model $item, string $text, string $table, string $css
$templateData['class'] = $cssClass;
$this->addImage($item, $templateData, $imgSize);

return $twig->render('@HeimrichHannotContaoQuiz/quiz/quiz_item.html.twig', $templateData);
return $twig->render('@HeimrichHannotContaoQuiz/item/quiz_item.html.twig', $templateData);
}
}
3 changes: 3 additions & 0 deletions src/Module/ModuleQuizReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ protected function parseQuizEvaluation()
$score = $this->session->getData(QuizSession::SCORE_NAME);
$templateData['score'] = System::getContainer()->get('translator')->transChoice('huh.quiz.answer.score', $score, ['%score%' => $score, '%possibleScore%' => $this->count]);
$quizEvaluationModel = System::getContainer()->get('huh.quiz.evaluation.manager')->findPublishedByPid($this->quiz);
$quiz = System::getContainer()->get('huh.quiz.manager')->findOneBy('id', $this->quiz);
$templateData['text'] = $quiz->text;
$templateData['title'] = $quiz->title;
if (null === $quizEvaluationModel) {
return $this->twig->render('@HeimrichHannotContaoQuiz/quiz/quiz_evaluation.html.twig', $templateData);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
huh:
list:
templates:
item:
- { name: quiz-list-item, template: "@HeimrichHannotContaoQuiz/item/list_item_quiz_default.html.twig" }
8 changes: 8 additions & 0 deletions src/Resources/views/item/list_item_quiz_default.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="{{ class }}">
<a class="share" href="{{ detailsUrl }}">
<div class="title">{{ title }}</div>
</a>
<div class="text">
{{ text|raw }}
</div>
</div>
2 changes: 2 additions & 0 deletions src/Resources/views/quiz/quiz_evaluation.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<div class="quiz-evaluation">
<h1 class="quiz-title">{{ title|raw }}</h1>
<div class="quiz-text">{{ text|raw }}</div>
<div class="quiz-score">{{ score }}</div>
{{ evaluation|raw }}
</div>
3 changes: 2 additions & 1 deletion tests/ContaoManager/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\DelegatingParser;
use HeimrichHannot\ListBundle\HeimrichHannotContaoListBundle;
use HeimrichHannot\QuizBundle\ContaoManager\Plugin;
use HeimrichHannot\QuizBundle\HeimrichHannotContaoQuizBundle;
use PHPUnit\Framework\TestCase;
Expand All @@ -36,6 +37,6 @@ public function testGetBundles()
static::assertCount(1, $bundles);
static::assertInstanceOf(BundleConfig::class, $bundles[0]);
static::assertEquals(HeimrichHannotContaoQuizBundle::class, $bundles[0]->getName());
static::assertEquals([ContaoCoreBundle::class, 'submissions_creator', 'submissions'], $bundles[0]->getLoadAfter());
static::assertEquals([ContaoCoreBundle::class, 'submissions_creator', 'submissions', HeimrichHannotContaoListBundle::class], $bundles[0]->getLoadAfter());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* Copyright (c) 2018 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/

namespace HeimrichHannot\QuizBundle\Test\DependencyInjection;

use HeimrichHannot\QuizBundle\DependencyInjection\HeimrichHannotContaoQuizExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;

class HeimrichHannotContaoQuizExtensionTest extends TestCase
{
/**
* @var ContainerBuilder
*/
private $container;

/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->container = new ContainerBuilder(new ParameterBag(['kernel.debug' => false]));
$extension = new \HeimrichHannot\QuizBundle\DependencyInjection\HeimrichHannotContaoQuizExtension();
$extension->load([], $this->container);
}

/**
* Tests the object instantiation.
*/
public function testCanBeInstantiated()
{
$extension = new HeimrichHannotContaoQuizExtension();
$this->assertInstanceOf(HeimrichHannotContaoQuizExtension::class, $extension);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use HeimrichHannot\QuizBundle\HeimrichHannotContaoQuizBundle;
use PHPUnit\Framework\TestCase;

class HeimrichHannotContaoQuizExtensionTest extends TestCase
class HeimrichHannotContaoQuizBundleTest extends TestCase
{
public function testGetContainerExtension()
{
Expand Down
1 change: 0 additions & 1 deletion tests/Manager/QuizQuestionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public function testFindOnePublishedByPidNotInQuestions()

public function testCountPublishedByPid()
{
$quizQuestionModel = $this->createMock(QuizQuestionModel::class);
$quizQuestionAdapter = $this->mockAdapter(['countPublishedByPid', 'countBy']);

$quizQuestionAdapter->method('countPublishedByPid')->willReturn(1);
Expand Down

0 comments on commit f04ba03

Please sign in to comment.