/
I18nFormExtensionTest.php
81 lines (69 loc) · 2.27 KB
/
I18nFormExtensionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace Koff\Bundle\I18nFormBundle\Tests\DependencyInjection;
use Koff\Bundle\I18nFormBundle\DependencyInjection\I18nFormExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Yaml\Parser;
/**
* Class I18nFormExtensionTest
*
* @author Sadicov Vladimir <sadikoff@gmail.com>
*/
class I18nFormExtensionTest extends TestCase
{
/** @var ContainerBuilder */
protected $configuration;
protected function tearDown()
{
unset($this->configuration);
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*/
public function testUserLoadThrowsExceptionUnlessLocaleIsEmpty()
{
$loader = new I18nFormExtension();
$config = $this->getDefaultConfig();
$config['i18n_form']['locales'] = [];
$loader->load($config, $this->getTestContainer());
}
public function testDefineLocaleProvider()
{
$configuration = $this->getTestContainer();
$loader = new I18nFormExtension();
$config = $this->getDefaultConfig();
$loader->load($config, $configuration);
$this->assertTrue(($configuration->hasDefinition('koff_i18n_form.locale_provider') ?: $configuration->hasAlias('koff_i18n_form.locale_provider')));
}
public function testDefineFormManipulator()
{
$configuration = $this->getTestContainer();
$loader = new I18nFormExtension();
$config = $this->getDefaultConfig();
$loader->load($config, $configuration);
$this->assertTrue(($configuration->hasDefinition('koff_i18n_form.form_manipulator') ?: $configuration->hasAlias('koff_i18n_form.form_manipulator')));
}
/**
* getEmptyConfig.
*
* @return array
*/
private function getDefaultConfig()
{
$yaml = <<<EOF
i18n_form:
locales: 'en|de'
required_locales: 'en'
form_theme: 'bootstrap_4'
EOF;
$parser = new Parser();
return $parser->parse($yaml);
}
private function getTestContainer()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.default_locale', 'en');
$container->setParameter('twig.form.resources', []);
return $container;
}
}