DarwinOnLine /
DoLLdapBundle
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace DoL\LdapBundle\Tests\DependencyInjection; |
||||||
| 4 | |||||||
| 5 | use DoL\LdapBundle\DependencyInjection\DoLLdapExtension; |
||||||
| 6 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||||||
| 7 | |||||||
| 8 | class DoLLdapExtensionTest extends \PHPUnit_Framework_TestCase |
||||||
| 9 | { |
||||||
| 10 | use ConfigurationTrait; |
||||||
| 11 | |||||||
| 12 | /** @var ContainerBuilder */ |
||||||
| 13 | public $container; |
||||||
| 14 | |||||||
| 15 | public function testConfigurationNamespace() |
||||||
| 16 | { |
||||||
| 17 | $this->container = new ContainerBuilder(); |
||||||
| 18 | $this->container->registerExtension(new DoLLdapExtension()); |
||||||
| 19 | self::assertTrue($this->container->hasExtension('dol_ldap')); |
||||||
| 20 | } |
||||||
| 21 | |||||||
| 22 | public function testLoadMinimalConfiguration() |
||||||
| 23 | { |
||||||
| 24 | $minRequiredConfig = [ |
||||||
| 25 | 'domains' => [ |
||||||
| 26 | 'server1' => [ |
||||||
| 27 | 'driver' => [ |
||||||
| 28 | 'host' => 'ldap.hostname.local', |
||||||
| 29 | ], |
||||||
| 30 | 'user' => [ |
||||||
| 31 | 'baseDn' => 'ou=Persons,dc=example,dc=com', |
||||||
| 32 | ], |
||||||
| 33 | ], |
||||||
| 34 | ], |
||||||
| 35 | ]; |
||||||
| 36 | |||||||
| 37 | $defaultConfig = $this->getDefaultConfig(); |
||||||
| 38 | |||||||
| 39 | $this->container = new ContainerBuilder(); |
||||||
| 40 | $extension = new DoLLdapExtension(); |
||||||
| 41 | |||||||
| 42 | $extension->load([$minRequiredConfig], $this->container); |
||||||
| 43 | |||||||
| 44 | self::assertHasDefinition('dol_ldap.ldap_driver'); |
||||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||||
| 45 | self::assertHasDefinition('dol_ldap.ldap_manager.default'); |
||||||
| 46 | |||||||
| 47 | self::assertParameter($defaultConfig['domains'], 'dol_ldap.domains.parameters'); |
||||||
|
0 ignored issues
–
show
The method
DoL\LdapBundle\Tests\Dep...Test::assertParameter() is not static, but was called statically.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 48 | |||||||
| 49 | self::assertAlias('dol_ldap.user_hydrator.default', 'dol_ldap.user_hydrator'); |
||||||
|
0 ignored issues
–
show
The method
DoL\LdapBundle\Tests\Dep...sionTest::assertAlias() is not static, but was called statically.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 50 | self::assertAlias('dol_ldap.ldap_manager.default', 'dol_ldap.ldap_manager'); |
||||||
| 51 | self::assertAlias('dol_ldap.ldap_driver.zend', 'dol_ldap.ldap_driver'); |
||||||
| 52 | } |
||||||
| 53 | |||||||
| 54 | public function testLoadFullConfiguration() |
||||||
| 55 | { |
||||||
| 56 | $config = $this->getDefaultConfig(); |
||||||
| 57 | $config['domains']['server1']['driver']['username'] = null; |
||||||
| 58 | $config['domains']['server1']['driver']['password'] = null; |
||||||
| 59 | $config['domains']['server1']['driver']['optReferrals'] = false; |
||||||
| 60 | |||||||
| 61 | $this->container = new ContainerBuilder(); |
||||||
| 62 | $extension = new DoLLdapExtension(); |
||||||
| 63 | |||||||
| 64 | $extension->load([$config], $this->container); |
||||||
| 65 | |||||||
| 66 | self::assertEquals($config['domains'], $this->container->getParameter('dol_ldap.domains.parameters')); |
||||||
| 67 | } |
||||||
| 68 | |||||||
| 69 | public function testLoadDriverConfiguration() |
||||||
| 70 | { |
||||||
| 71 | $config = $this->getDefaultConfig(); |
||||||
| 72 | $config['domains']['server1']['driver']['accountFilterFormat'] = '(%(uid=%s))'; |
||||||
| 73 | |||||||
| 74 | $this->container = new ContainerBuilder(); |
||||||
| 75 | $extension = new DoLLdapExtension(); |
||||||
| 76 | |||||||
| 77 | $extension->load([$config], $this->container); |
||||||
| 78 | |||||||
| 79 | $loadedConfig = $this->container->getParameter('dol_ldap.domains.parameters'); |
||||||
| 80 | self::assertEquals($config['domains']['server1']['driver'], $loadedConfig['server1']['driver']); |
||||||
| 81 | self::assertEquals($config['domains']['server1']['user'], $loadedConfig['server1']['user']); |
||||||
| 82 | } |
||||||
| 83 | |||||||
| 84 | public function testSslConfiguration() |
||||||
| 85 | { |
||||||
| 86 | $config = $this->getDefaultConfig(); |
||||||
| 87 | $config['domains']['server1']['driver']['useSsl'] = true; |
||||||
| 88 | $config['domains']['server1']['driver']['useStartTls'] = false; |
||||||
| 89 | |||||||
| 90 | $this->container = new ContainerBuilder(); |
||||||
| 91 | $extension = new DoLLdapExtension(); |
||||||
| 92 | |||||||
| 93 | $extension->load([$config], $this->container); |
||||||
| 94 | |||||||
| 95 | $loadedConfig = $this->container->getParameter('dol_ldap.domains.parameters'); |
||||||
| 96 | self::assertEquals($config['domains']['server1']['driver'], $loadedConfig['server1']['driver']); |
||||||
| 97 | } |
||||||
| 98 | |||||||
| 99 | public function testTlsConfiguration() |
||||||
| 100 | { |
||||||
| 101 | $config = $this->getDefaultConfig(); |
||||||
| 102 | $config['domains']['server1']['driver']['useSsl'] = false; |
||||||
| 103 | $config['domains']['server1']['driver']['useStartTls'] = true; |
||||||
| 104 | |||||||
| 105 | $this->container = new ContainerBuilder(); |
||||||
| 106 | $extension = new DoLLdapExtension(); |
||||||
| 107 | |||||||
| 108 | $extension->load([$config], $this->container); |
||||||
| 109 | |||||||
| 110 | $loadedConfig = $this->container->getParameter('dol_ldap.domains.parameters'); |
||||||
| 111 | self::assertEquals($config['domains']['server1']['driver'], $loadedConfig['server1']['driver']); |
||||||
| 112 | } |
||||||
| 113 | |||||||
| 114 | /** |
||||||
| 115 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||||||
| 116 | */ |
||||||
| 117 | public function testSslTlsExclusiveConfiguration() |
||||||
| 118 | { |
||||||
| 119 | $config = $this->getDefaultConfig(); |
||||||
| 120 | $config['domains']['server1']['driver']['useSsl'] = true; |
||||||
| 121 | $config['domains']['server1']['driver']['useStartTls'] = true; |
||||||
| 122 | |||||||
| 123 | $this->container = new ContainerBuilder(); |
||||||
| 124 | $extension = new DoLLdapExtension(); |
||||||
| 125 | |||||||
| 126 | $extension->load([$config], $this->container); |
||||||
| 127 | } |
||||||
| 128 | |||||||
| 129 | private function assertAlias($value, $key) |
||||||
| 130 | { |
||||||
| 131 | self::assertEquals($value, (string) $this->container->getAlias($key), sprintf('%s alias is not correct', $key)); |
||||||
| 132 | } |
||||||
| 133 | |||||||
| 134 | private function assertParameter($value, $key) |
||||||
| 135 | { |
||||||
| 136 | self::assertEquals($value, $this->container->getParameter($key), sprintf('%s parameter is not correct', $key)); |
||||||
| 137 | } |
||||||
| 138 | |||||||
| 139 | private function assertHasDefinition($id) |
||||||
| 140 | { |
||||||
| 141 | self::assertTrue(($this->container->hasDefinition($id) ?: $this->container->hasAlias($id)), sprintf('%s definition is not set', $id)); |
||||||
| 142 | } |
||||||
| 143 | |||||||
| 144 | protected function tearDown() |
||||||
| 145 | { |
||||||
| 146 | unset($this->container); |
||||||
| 147 | } |
||||||
| 148 | } |
||||||
| 149 |