This repository has been archived by the owner on Sep 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
131 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,11 @@ class FOSUserExtensionTest extends \PHPUnit_Framework_TestCase | |
protected $configuration; | ||
|
||
/** | ||
* @expectedException \InvalidArgumentException | ||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException | ||
*/ | ||
public function testUserLoadThrowsExceptionUnlessDatabaseDriverSet() | ||
{ | ||
$loader = new FOSUserExtension('testkernel'); | ||
$loader = new FOSUserExtension(); | ||
$config = $this->getEmptyConfig(); | ||
unset($config['db_driver']); | ||
$loader->load(array($config), new ContainerBuilder()); | ||
|
@@ -26,18 +26,40 @@ public function testUserLoadThrowsExceptionUnlessDatabaseDriverSet() | |
*/ | ||
public function testUserLoadThrowsExceptionUnlessDatabaseDriverIsValid() | ||
{ | ||
$loader = new FOSUserExtension('testkernel'); | ||
$loader = new FOSUserExtension(); | ||
$config = $this->getEmptyConfig(); | ||
$config['db_driver'] = 'foo'; | ||
$loader->load(array($config), new ContainerBuilder()); | ||
} | ||
|
||
/** | ||
* @expectedException \InvalidArgumentException | ||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException | ||
*/ | ||
public function testUserLoadThrowsExceptionUnlessProviderKeySet() | ||
{ | ||
$loader = new FOSUserExtension(); | ||
$config = $this->getEmptyConfig(); | ||
unset($config['provider_key']); | ||
$loader->load(array($config), new ContainerBuilder()); | ||
} | ||
|
||
/** | ||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException | ||
*/ | ||
public function testUserLoadThrowsExceptionUnlessGroupModelClassSet() | ||
{ | ||
$loader = new FOSUserExtension(); | ||
$config = $this->getEmptyConfig(); | ||
unset($config['class']['model']['group']); | ||
$loader->load(array($config), new ContainerBuilder()); | ||
} | ||
|
||
/** | ||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException | ||
*/ | ||
public function testUserLoadThrowsExceptionUnlessUserModelClassSet() | ||
{ | ||
$loader = new FOSUserExtension('testkernel'); | ||
$loader = new FOSUserExtension(); | ||
$config = $this->getEmptyConfig(); | ||
unset($config['class']['model']['user']); | ||
$loader->load(array($config), new ContainerBuilder()); | ||
|
@@ -47,14 +69,14 @@ public function testUserLoadModelClassWithDefaults() | |
{ | ||
$this->createEmptyConfiguration(); | ||
|
||
$this->assertParameter('Application\MyBundle\Document\User', 'fos_user.model.user.class'); | ||
$this->assertParameter('Acme\MyBundle\Document\User', 'fos_user.model.user.class'); | ||
} | ||
|
||
public function testUserLoadModelClass() | ||
{ | ||
$this->createFullConfiguration(); | ||
|
||
$this->assertParameter('user', 'fos_user.model.user.class'); | ||
$this->assertParameter('Acme\MyBundle\Entity\User', 'fos_user.model.user.class'); | ||
} | ||
|
||
public function testUserLoadManagerClassWithDefaults() | ||
|
@@ -76,70 +98,85 @@ public function testUserLoadFormClassWithDefaults() | |
$this->createEmptyConfiguration(); | ||
|
||
$this->assertParameter('FOS\UserBundle\Form\UserForm', 'fos_user.form.user.class'); | ||
$this->assertParameter('FOS\UserBundle\Form\GroupForm', 'fos_user.form.group.class'); | ||
$this->assertParameter('FOS\UserBundle\Form\ChangePasswordForm', 'fos_user.form.change_password.class'); | ||
$this->assertParameter('FOS\UserBundle\Form\ResetPasswordForm', 'fos_user.form.reset_password.class'); | ||
} | ||
|
||
public function testUserLoadFormClass() | ||
{ | ||
$this->createFullConfiguration(); | ||
|
||
$this->assertParameter('user', 'fos_user.form.user.class'); | ||
$this->assertParameter('change_password', 'fos_user.form.change_password.class'); | ||
$this->assertParameter('Acme\MyBundle\Form\User', 'fos_user.form.user.class'); | ||
$this->assertParameter('Acme\MyBundle\Form\Group', 'fos_user.form.group.class'); | ||
$this->assertParameter('Acme\MyBundle\Form\ChangePassword', 'fos_user.form.change_password.class'); | ||
$this->assertParameter('Acme\MyBundle\Form\ResetPassword', 'fos_user.form.reset_password.class'); | ||
} | ||
|
||
public function testUserLoadFormNameWithDefaults() | ||
{ | ||
$this->createEmptyConfiguration(); | ||
|
||
$this->assertParameter('fos_user_user_form', 'fos_user.form.user.name'); | ||
$this->assertParameter('fos_user_group_form', 'fos_user.form.group.name'); | ||
$this->assertParameter('fos_user_change_password_form', 'fos_user.form.change_password.name'); | ||
$this->assertParameter('fos_user_reset_password_form', 'fos_user.form.reset_password.name'); | ||
} | ||
|
||
public function testUserLoadFormName() | ||
{ | ||
$this->createFullConfiguration(); | ||
|
||
$this->assertParameter('user', 'fos_user.form.user.name'); | ||
$this->assertParameter('change_password', 'fos_user.form.change_password.name'); | ||
$this->assertParameter('acme_user_form', 'fos_user.form.user.name'); | ||
$this->assertParameter('acme_group_form', 'fos_user.form.group.name'); | ||
$this->assertParameter('acme_change_form', 'fos_user.form.change_password.name'); | ||
$this->assertParameter('acme_reset_form', 'fos_user.form.reset_password.name'); | ||
} | ||
|
||
public function testUserLoadFormServiceWithDefaults() | ||
{ | ||
$this->createEmptyConfiguration(); | ||
|
||
$this->assertHasDefinition('fos_user.form.user'); | ||
$this->assertHasDefinition('fos_user.form.group'); | ||
$this->assertHasDefinition('fos_user.form.change_password'); | ||
$this->assertHasDefinition('fos_user.form.reset_password'); | ||
} | ||
|
||
public function testUserLoadFormService() | ||
{ | ||
$this->createFullConfiguration(); | ||
|
||
$this->assertHasDefinition('fos_user.form.user'); | ||
$this->assertHasDefinition('fos_user.form.group'); | ||
$this->assertHasDefinition('fos_user.form.change_password'); | ||
$this->assertHasDefinition('fos_user.form.reset_password'); | ||
} | ||
|
||
public function testUserLoadControllerClassWithDefaults() | ||
{ | ||
$this->createEmptyConfiguration(); | ||
|
||
$this->assertParameter('FOS\UserBundle\Controller\UserController', 'fos_user.controller.user.class'); | ||
$this->assertParameter('FOS\UserBundle\Controller\GroupController', 'fos_user.controller.group.class'); | ||
$this->assertParameter('FOS\UserBundle\Controller\SecurityController', 'fos_user.controller.security.class'); | ||
} | ||
|
||
public function testUserLoadControllerClass() | ||
{ | ||
$this->createFullConfiguration(); | ||
|
||
$this->assertParameter('user', 'fos_user.controller.user.class'); | ||
$this->assertParameter('security', 'fos_user.controller.security.class'); | ||
$this->assertParameter('Acme\MyBundle\Controller\UserController', 'fos_user.controller.user.class'); | ||
$this->assertParameter('Acme\MyBundle\Controller\GroupController', 'fos_user.controller.group.class'); | ||
$this->assertParameter('Acme\MyBundle\Controller\SecurityController', 'fos_user.controller.security.class'); | ||
} | ||
|
||
public function testUserLoadControllerServiceWithDefaults() | ||
{ | ||
$this->createEmptyConfiguration(); | ||
|
||
$this->assertHasDefinition('fos_user.controller.user'); | ||
$this->assertHasDefinition('fos_user.controller.group'); | ||
$this->assertHasDefinition('fos_user.controller.security'); | ||
} | ||
|
||
|
@@ -148,6 +185,7 @@ public function testUserLoadControllerService() | |
$this->createFullConfiguration(); | ||
|
||
$this->assertHasDefinition('fos_user.controller.user'); | ||
$this->assertHasDefinition('fos_user.controller.group'); | ||
$this->assertHasDefinition('fos_user.controller.security'); | ||
} | ||
|
||
|
@@ -159,16 +197,18 @@ public function testUserLoadConfirmationEmailWithDefaults() | |
$this->assertParameter(array('[email protected]' => 'webmaster'), 'fos_user.email.from_email'); | ||
$this->assertParameter('FOSUserBundle:User:confirmationEmail', 'fos_user.email.confirmation.template'); | ||
$this->assertParameter('FOSUserBundle:User:resettingPasswordEmail', 'fos_user.email.resetting_password.template'); | ||
$this->assertParameter(86400, 'fos_user.email.resetting_password.token_ttl'); | ||
} | ||
|
||
public function testUserLoadConfirmationEmail() | ||
{ | ||
$this->createFullConfiguration(); | ||
|
||
$this->assertParameter('enabled', 'fos_user.email.confirmation.enabled'); | ||
$this->assertParameter('from_email', 'fos_user.email.from_email'); | ||
$this->assertParameter('template', 'fos_user.email.confirmation.template'); | ||
$this->assertParameter('template', 'fos_user.email.resetting_password.template'); | ||
$this->assertParameter(true, 'fos_user.email.confirmation.enabled'); | ||
$this->assertParameter(array('[email protected]' => 'Acme Corp'), 'fos_user.email.from_email'); | ||
$this->assertParameter('AcmeMyBundle:Mail:confirmation', 'fos_user.email.confirmation.template'); | ||
$this->assertParameter('AcmeMyBundle:Mail:resetting', 'fos_user.email.resetting_password.template'); | ||
$this->assertParameter(1800, 'fos_user.email.resetting_password.token_ttl'); | ||
} | ||
|
||
public function testUserLoadTemplateConfigWithDefaults() | ||
|
@@ -183,8 +223,8 @@ public function testUserLoadTemplateConfig() | |
{ | ||
$this->createFullConfiguration(); | ||
|
||
$this->assertParameter('engine', 'fos_user.template.engine'); | ||
$this->assertParameter('theme', 'fos_user.template.theme'); | ||
$this->assertParameter('php', 'fos_user.template.engine'); | ||
$this->assertParameter('AcmeMyBundle:Form:theme.html.twig', 'fos_user.template.theme'); | ||
} | ||
|
||
public function testUserLoadEncoderConfigWithDefaults() | ||
|
@@ -200,9 +240,9 @@ public function testUserLoadEncoderConfig() | |
{ | ||
$this->createFullConfiguration(); | ||
|
||
$this->assertParameter('algorithm', 'fos_user.encoder.algorithm'); | ||
$this->assertParameter('encode_as_base64', 'fos_user.encoder.encode_as_base64'); | ||
$this->assertParameter('iterations', 'fos_user.encoder.iterations'); | ||
$this->assertParameter('sha1', 'fos_user.encoder.algorithm'); | ||
$this->assertParameter(true, 'fos_user.encoder.encode_as_base64'); | ||
$this->assertParameter(3, 'fos_user.encoder.iterations'); | ||
} | ||
|
||
public function testUserLoadUtilClassWithDefaults() | ||
|
@@ -217,8 +257,22 @@ public function testUserLoadUtilClass() | |
{ | ||
$this->createFullConfiguration(); | ||
|
||
$this->assertParameter('email_canonicalizer', 'fos_user.util.email_canonicalizer.class'); | ||
$this->assertParameter('username_canonicalizer', 'fos_user.util.username_canonicalizer.class'); | ||
$this->assertParameter('Acme\MyBundle\Util\EmailCanonicalizer', 'fos_user.util.email_canonicalizer.class'); | ||
$this->assertParameter('Acme\MyBundle\Util\UsernameCanonicalizer', 'fos_user.util.username_canonicalizer.class'); | ||
} | ||
|
||
public function testUserLoadUtilServiceWithDefaults() | ||
{ | ||
$this->createEmptyConfiguration(); | ||
|
||
$this->assertAlias('fos_user.util.mailer.real', 'fos_user.util.mailer'); | ||
} | ||
|
||
public function testUserLoadUtilService() | ||
{ | ||
$this->createFullConfiguration(); | ||
|
||
$this->assertAlias('acme_my.util.mailer', 'fos_user.util.mailer'); | ||
} | ||
|
||
/** | ||
|
@@ -227,7 +281,7 @@ public function testUserLoadUtilClass() | |
protected function createEmptyConfiguration() | ||
{ | ||
$this->configuration = new ContainerBuilder(); | ||
$loader = new FOSUserExtension('testkernel'); | ||
$loader = new FOSUserExtension(); | ||
$config = $this->getEmptyConfig(); | ||
$loader->load(array($config), $this->configuration); | ||
$this->assertTrue($this->configuration instanceof ContainerBuilder); | ||
|
@@ -239,7 +293,7 @@ protected function createEmptyConfiguration() | |
protected function createFullConfiguration() | ||
{ | ||
$this->configuration = new ContainerBuilder(); | ||
$loader = new FOSUserExtension('testkernel'); | ||
$loader = new FOSUserExtension(); | ||
$config = $this->getFullConfig(); | ||
$loader->load(array($config), $this->configuration); | ||
$this->assertTrue($this->configuration instanceof ContainerBuilder); | ||
|
@@ -254,56 +308,75 @@ protected function getEmptyConfig() | |
{ | ||
$yaml = <<<EOF | ||
db_driver: mongodb | ||
provider_key: fos_user | ||
class: | ||
model: | ||
user: Acme\MyBundle\Document\User | ||
group: FOS\UserBundle\Document\DefaultGroup | ||
EOF; | ||
$parser = new Parser(); | ||
|
||
return $parser->parse($yaml); | ||
} | ||
|
||
protected function getFullConfig() | ||
{ | ||
$yaml = <<<EOF | ||
db_driver: orm | ||
provider_key: fos_user | ||
class: | ||
model: | ||
user: Application\MyBundle\Document\User | ||
user: Acme\MyBundle\Entity\User | ||
group: FOS\UserBundle\Entity\DefaultGroup | ||
form: | ||
user: ~ | ||
change_password: ~ | ||
user: Acme\MyBundle\Form\User | ||
group: Acme\MyBundle\Form\Group | ||
change_password: Acme\MyBundle\Form\ChangePassword | ||
reset_password: Acme\MyBundle\Form\ResetPassword | ||
controller: | ||
user: ~ | ||
security: ~ | ||
user: Acme\MyBundle\Controller\UserController | ||
group: Acme\MyBundle\Controller\GroupController | ||
security: Acme\MyBundle\Controller\SecurityController | ||
util: | ||
email_canonicalizer: Acme\MyBundle\Util\EmailCanonicalizer | ||
username_canonicalizer: Acme\MyBundle\Util\UsernameCanonicalizer | ||
service: | ||
util: | ||
email_canonicalizer: ~ | ||
username_canonicalizer: ~ | ||
mailer: acme_my.util.mailer | ||
encoder: | ||
algorithm: ~ | ||
encode_as_base64: ~ | ||
iterations: ~ | ||
algorithm: sha1 | ||
encode_as_base64: true | ||
iterations: 3 | ||
form_name: | ||
user: ~ | ||
change_password: ~ | ||
user: acme_user_form | ||
group: acme_group_form | ||
change_password: acme_change_form | ||
reset_password: acme_reset_form | ||
form_validation_groups: | ||
user: [test] | ||
group: [acme] | ||
change_password: [acme] | ||
reset_password: [acme] | ||
email: | ||
from_email: ~ | ||
from_email: { [email protected]: Acme Corp } | ||
confirmation: | ||
enabled: ~ | ||
template: ~ | ||
enabled: true | ||
template: AcmeMyBundle:Mail:confirmation | ||
resetting_password: | ||
template: ~ | ||
template: AcmeMyBundle:Mail:resetting | ||
token_ttl: 1800 | ||
template: | ||
engine: ~ | ||
theme: ~ | ||
engine: php | ||
theme: AcmeMyBundle:Form:theme.html.twig | ||
EOF; | ||
$parser = new Parser(); | ||
return $parser->parse($yaml); | ||
} | ||
|
||
protected function getFullConfig() | ||
{ | ||
$config = $this->getEmptyConfig(); | ||
array_walk_recursive($config, function(&$item, $key) { | ||
if (!is_array($item)) { | ||
$item = $key; | ||
} | ||
}); | ||
$config['db_driver'] = 'orm'; | ||
|
||
return $config; | ||
return $parser->parse($yaml); | ||
} | ||
|
||
public function assertAlias($value, $key) | ||
{ | ||
$this->assertEquals($value, $this->configuration->getAlias($key), sprintf('%s alias is correct', $key)); | ||
$this->assertEquals($value, (string) $this->configuration->getAlias($key), sprintf('%s alias is correct', $key)); | ||
} | ||
|
||
public function assertParameter($value, $key) | ||
|