Skip to content

Commit

Permalink
fixed tl_quiz_evaluation toggle and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Wagner committed Feb 5, 2018
1 parent fd76cef commit af7c560
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 23 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"heimrichhannot/contao-list-bundle": "dev-master",
"heimrichhannot/contao-filter-bundle": "dev-master",
"heimrichhannot/contao-utils-bundle": "dev-master",
"heimrichhannot/contao-haste_plus": "^1.8"
"heimrichhannot/contao-haste_plus": "^1.8",
"heimrichhannot/contao-request": "^1.2"
},
"require-dev": {
"contao/test-case": "^1.1",
Expand Down
16 changes: 0 additions & 16 deletions src/Backend/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,6 @@ public function checkPermission(string $table, string $ptable)
}
}

/**
* @param $id
*
* @return int
*/
public function getPidFromId($id)
{
$evaluationModel = System::getContainer()->get('huh.quiz.evaluation.manager')->findOneBy('id', $id);

if (null === $evaluationModel) {
return 0;
}

return $evaluationModel->id;
}

/**
* Check access to a particular content element.
*
Expand Down
2 changes: 1 addition & 1 deletion src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getBundles(ParserInterface $parser)
*/
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');
$extensionConfigs = ContainerUtil::mergeConfigFile('huh_list', $extensionName, $extensionConfigs, __DIR__.'/../Resources/config/config.yml');

return $extensionConfigs;
}
Expand Down
4 changes: 0 additions & 4 deletions src/Form/QuizSubmissionForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,4 @@ protected function onSubmitCallback(\DataContainer $dc)
$submission->quizScore = $quizSession->getData(QuizSession::SCORE_NAME);
$submission->save();
}

protected function compile()
{
}
}
2 changes: 1 addition & 1 deletion src/Resources/contao/dca/tl_quiz_evaluation.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['toggle'],
'icon' => 'visible.gif',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
'button_callback' => ['tl_quiz_answer', 'toggleIcon'],
'button_callback' => ['tl_quiz_evaluation', 'toggleIcon'],
],
'show' => [
'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['show'],
Expand Down
51 changes: 51 additions & 0 deletions tests/ContaoManager/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\DelegatingParser;
use Contao\ManagerPlugin\Config\ContainerBuilder;
use Contao\ManagerPlugin\PluginLoader;
use Contao\TestCase\ContaoTestCase;
use HeimrichHannot\ListBundle\HeimrichHannotContaoListBundle;
use HeimrichHannot\QuizBundle\ContaoManager\Plugin;
Expand All @@ -22,6 +24,20 @@
*/
class PluginTest extends ContaoTestCase
{
/**
* @var ContainerBuilder
*/
private $container;

/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->container = new ContainerBuilder($this->mockPluginLoader($this->never()), []);
}

public function testInstantiation()
{
static::assertInstanceOf(Plugin::class, new Plugin());
Expand All @@ -39,4 +55,39 @@ public function testGetBundles()
static::assertEquals(HeimrichHannotContaoQuizBundle::class, $bundles[0]->getName());
static::assertEquals([ContaoCoreBundle::class, 'submissions_creator', 'submissions', HeimrichHannotContaoListBundle::class], $bundles[0]->getLoadAfter());
}

/**
* Test extend configuration.
*/
public function testGetExtensionConfig()
{
$plugin = new Plugin();
$extensionConfigs = $plugin->getExtensionConfig('huh_list', [[]], $this->container);
$this->assertNotEmpty($extensionConfigs);
$this->assertArrayHasKey('huh', $extensionConfigs);
$this->assertArrayHasKey('list', $extensionConfigs['huh']);
$this->assertArrayHasKey('templates', $extensionConfigs['huh']['list']);
$this->assertArrayHasKey('item', $extensionConfigs['huh']['list']['templates']);
$this->assertArrayHasKey('0', $extensionConfigs['huh']['list']['templates']['item']);
$this->assertArrayHasKey('name', $extensionConfigs['huh']['list']['templates']['item']['0']);
$this->assertSame('quiz-list-item', $extensionConfigs['huh']['list']['templates']['item']['0']['name']);
$this->assertArrayHasKey('template', $extensionConfigs['huh']['list']['templates']['item']['0']);
$this->assertSame('@HeimrichHannotContaoQuiz/item/list_item_quiz_default.html.twig', $extensionConfigs['huh']['list']['templates']['item']['0']['template']);
}

/**
* Mocks the plugin loader.
*
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedRecorder $expects
* @param array $plugins
*
* @return PluginLoader|\PHPUnit_Framework_MockObject_MockObject
*/
private function mockPluginLoader(\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder $expects, array $plugins = [])
{
$pluginLoader = $this->createMock(PluginLoader::class);
$pluginLoader->expects($expects)->method('getInstancesOf')->with(PluginLoader::EXTENSION_PLUGINS)->willReturn($plugins);

return $pluginLoader;
}
}

0 comments on commit af7c560

Please sign in to comment.