Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release 3.4.1 into 3.5.x #755

Merged
merged 6 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
'phpdoc_types_order' => [
'null_adjustment' => 'always_last',
],
'phpdoc_to_comment' => [
'ignored_tags' => ['psalm-suppress'],
],
'php_unit_internal_class' => false,
'php_unit_test_class_requires_covers' => false,
'no_superfluous_phpdoc_tags' => [
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ All notable changes to this project will be documented in this file, in reverse

- Nothing.

## 3.4.1 - 2024-05-20


-----

### Release Notes for [3.4.1](https://github.com/nucleos/NucleosUserBundle/milestone/41)

3.4.x bugfix release (patch)

### 3.4.1

- Total issues resolved: **0**
- Total pull requests resolved: **2**
- Total contributors: **1**

#### Bug

- [754: Fix translation of auth provider messages](https://github.com/nucleos/NucleosUserBundle/pull/754) thanks to @core23

#### Enhancement

- [751: Add functional tests for all actions](https://github.com/nucleos/NucleosUserBundle/pull/751) thanks to @core23

## 3.4.0 - 2024-03-06


Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@
},
"require-dev": {
"ext-mongodb": "*",
"dama/doctrine-test-bundle": "^8.0",
"doctrine/doctrine-bundle": "^2.4",
"doctrine/mongodb-odm": "^2.3",
"doctrine/mongodb-odm-bundle": "^4.4 || ^5.0",
"doctrine/orm": "^2.18 || ^3.0",
"ergebnis/composer-normalize": "^2.0.1",
"symfony/browser-kit": "^6.4 || ^7.0",
"symfony/css-selector": "^6.4 || ^7.0",
"symfony/doctrine-bridge": "^6.4 || ^7.0",
"symfony/yaml": "^6.4 || ^7.0"
},
Expand Down
7 changes: 7 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
<coverage/>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
<env name="APP_DEBUG" value="false"/>
<env name="APP_ENV" value="test"/>
<env name="KERNEL_CLASS" value="Nucleos\UserBundle\Tests\App\AppKernel"/>
<ini name="date.timezone" value="UTC"/>
</php>
<testsuites>
<testsuite name="UserBundle Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<extensions>
<bootstrap class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension"/>
</extensions>
<source>
<include>
<directory suffix=".php">./src/</directory>
Expand Down
8 changes: 6 additions & 2 deletions src/Action/ResetAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ public function __invoke(Request $request, string $token): Response

private function changePassword(UserInterface $user, Resetting $formModel): void
{
$user->setPlainPassword($formModel->getPlainPassword());
$password = $formModel->getPlainPassword();

\assert(null !== $password);

$user->setPlainPassword($password);
$this->userManager->updateUser($user);

if (null !== $this->userManipulator) {
$this->userManipulator->changePassword($user->getUsername(), $formModel->getPlainPassword());
$this->userManipulator->changePassword($user->getUsername(), $password);
}
}
}
6 changes: 1 addition & 5 deletions src/DependencyInjection/NucleosUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
final class NucleosUserExtension extends Extension implements PrependExtensionInterface
{
/**
* @var array<string, array<string, string>>
* @var array<array{registry: string, tag: string, events: string[]}>
*/
private static array $doctrineDrivers = [
'orm' => [
Expand Down Expand Up @@ -103,10 +103,6 @@ public function load(array $configs, ContainerBuilder $container): void

if ($config['use_listener'] && isset(self::$doctrineDrivers[$config['db_driver']])) {
$listenerDefinition = $container->getDefinition('nucleos_user.user_listener');
if (isset(self::$doctrineDrivers[$config['db_driver']]['listener_class'])) {
$listenerDefinition->setClass(self::$doctrineDrivers[$config['db_driver']]['listener_class']);
}

foreach (self::$doctrineDrivers[$config['db_driver']]['events'] as $event) {
$listenerDefinition->addTag(self::$doctrineDrivers[$config['db_driver']]['tag'], ['event' => $event]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Type/LoginFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($authenticationUtils): void {
$error = $authenticationUtils->getLastAuthenticationError();
if (null !== $error) {
$message = $this->translator->trans($error->getMessageKey(), [], 'NucleosUserBundle');
$message = $this->translator->trans($error->getMessageKey(), [], 'security');

Check warning on line 61 in src/Form/Type/LoginFormType.php

View check run for this annotation

Codecov / codecov/patch

src/Form/Type/LoginFormType.php#L61

Added line #L61 was not covered by tests

$event->getForm()->addError(new FormError($message));
}
Expand Down
2 changes: 1 addition & 1 deletion src/NucleosUserBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ private function addRegisterMappingsPass(ContainerBuilder $container): void
if (class_exists(DoctrineOrmMappingsPass::class)) {
$container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings, ['nucleos_user.model_manager_name'], 'nucleos_user.backend_type_orm'));
}

if (class_exists(DoctrineMongoDBMappingsPass::class)) {
/** @psalm-suppress InternalClass, InternalMethod */
$container->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($mappings, ['nucleos_user.model_manager_name'], 'nucleos_user.backend_type_mongodb'));
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/Validator/Constraints/Pattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ final class Pattern extends Constraint

/**
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*
* @param array<string, mixed> $options
*/
public function __construct(
mixed $options = null,
Expand Down
10 changes: 8 additions & 2 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Nucleos\UserBundle\Tests\App;

use DAMA\DoctrineTestBundle\DAMADoctrineTestBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Nucleos\UserBundle\NucleosUserBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
Expand All @@ -26,9 +28,9 @@ final class AppKernel extends Kernel
{
use MicroKernelTrait;

public function __construct()
public function __construct(string $environment = 'test', bool $debug = false)
{
parent::__construct('test', false);
parent::__construct($environment, $debug);
}

public function registerBundles(): iterable
Expand All @@ -39,6 +41,10 @@ public function registerBundles(): iterable

yield new SecurityBundle();

yield new DoctrineBundle();

yield new DAMADoctrineTestBundle();

yield new NucleosUserBundle();
}

Expand Down
12 changes: 11 additions & 1 deletion tests/App/Entity/TestGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@

namespace Nucleos\UserBundle\Tests\App\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Nucleos\UserBundle\Model\Group;

class TestGroup extends Group {}
#[ORM\Entity]
#[ORM\Table(name: 'user__group')]
class TestGroup extends Group
{
#[ORM\Id]
#[ORM\Column(type: Types::INTEGER)]
#[ORM\GeneratedValue]
protected ?int $id = null;
}
35 changes: 34 additions & 1 deletion tests/App/Entity/TestUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,43 @@

namespace Nucleos\UserBundle\Tests\App\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Nucleos\UserBundle\Model\GroupInterface;
use Nucleos\UserBundle\Model\User;

/**
* @phpstan-extends User<GroupInterface>
*/
class TestUser extends User {}
#[ORM\Entity]
#[ORM\Table(name: 'user__user')]
class TestUser extends User
{
#[ORM\Id]
#[ORM\Column(type: Types::INTEGER)]
#[ORM\GeneratedValue]
protected int $id;

/**
* @var Collection<array-key, GroupInterface>
*/
#[ORM\ManyToMany(targetEntity: TestGroup::class)]
#[ORM\JoinTable(name: 'user__user_group')]
protected Collection $groups;
private static int $index = 1;

public function __construct()
{
parent::__construct();

$this->id = self::$index++;
$this->groups = new ArrayCollection();
}

public function getId(): int
{
return $this->id;
}
}
39 changes: 37 additions & 2 deletions tests/App/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,25 @@

$containerConfigurator->extension('framework', ['session' => ['storage_factory_id' => 'session.storage.factory.mock_file', 'handler_id' => null]]);

$containerConfigurator->extension('framework', [
'mailer' => [
'dsn' => 'null://null',
],
]);

$containerConfigurator->extension('twig', ['strict_variables' => true]);

$containerConfigurator->extension('twig', ['exception_controller' => null]);

$securityConfig = [
'firewalls' => ['main' => ['security' => true]],
'firewalls' => ['main' => [
'security' => true,
'form_login' => [
'login_path' => 'nucleos_user_security_login',
'check_path' => 'nucleos_user_security_check',
'default_target_path' => '/profile',
],
]],
];

// TODO: Remove if when dropping support of Symfony 5.4
Expand All @@ -50,6 +63,23 @@
'algorithm' => 'plaintext',
]]]);

$containerConfigurator->extension('doctrine', ['dbal' => ['url' => 'sqlite:///%kernel.cache_dir%/data.db', 'logging' => false, 'use_savepoints' => true]]);

$containerConfigurator->extension('doctrine', ['orm' => [
'auto_mapping' => true,
'mappings' => [
'App' => [
'is_bundle' => false,
'type' => 'attribute',
'dir' => '%kernel.project_dir%/Entity',
'prefix' => 'Nucleos\UserBundle\Tests\App\Entity',
'alias' => 'App',
],
],
]]);

$containerConfigurator->extension('nucleos_user', ['db_driver' => 'orm']);

$containerConfigurator->extension('nucleos_user', ['firewall_name' => 'main']);

$containerConfigurator->extension('nucleos_user', ['from_email' => 'no-reply@localhost']);
Expand All @@ -58,5 +88,10 @@

$containerConfigurator->extension('nucleos_user', ['group' => ['group_class' => TestGroup::class]]);

$containerConfigurator->extension('nucleos_user', ['loggedin' => ['route' => 'home']]);
$containerConfigurator->extension('nucleos_user', ['loggedin' => ['route' => 'nucleos_user_update_security']]);

$containerConfigurator->extension('nucleos_user', ['deletion' => [
]]);

$containerConfigurator->extension('dama_doctrine_test', ['enable_static_connection' => true, 'enable_static_meta_data_cache' => true, 'enable_static_query_cache' => true]);
};
76 changes: 76 additions & 0 deletions tests/Functional/Action/AccountDeletionWebTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/*
* This file is part of the NucleosUserBundle package.
*
* (c) Christian Gripp <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nucleos\UserBundle\Tests\Functional\Action;

use Nucleos\UserBundle\Action\AccountDeletionAction;
use Nucleos\UserBundle\Tests\Functional\DoctrineSetupTrait;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

#[CoversClass(AccountDeletionAction::class)]
final class AccountDeletionWebTest extends WebTestCase
{
use DoctrineSetupTrait;

#[Test]
public function execute(): void
{
$client = self::createClient();

$this->persist(
$user = self::createUser(),
);

$client->loginUser($user);
$client->request('GET', '/delete');

self::assertResponseIsSuccessful();

$client->submitForm('account_deletion_form[delete]', [
'account_deletion_form[current_password]' => $user->getPlainPassword(),
'account_deletion_form[confirm]' => true,
]);

self::assertResponseRedirects('/logout');
$client->followRedirect();

self::assertNull($this->getSecurity()->getUser());
self::assertNull($this->getUser($user->getId()));
}

#[Test]
public function executeWithInvalidPassword(): void
{
$client = self::createClient();

$this->persist(
$user = self::createUser(),
);

$client->loginUser($user);
$client->request('GET', '/delete');

self::assertResponseIsSuccessful();

$client->submitForm('account_deletion_form[delete]', [
'account_deletion_form[current_password]' => 'wrong',
'account_deletion_form[confirm]' => true,
]);

self::assertResponseIsSuccessful();

self::assertSelectorTextContains('#account_deletion_form', 'The entered password is invalid');

self::assertNotNull($this->getUser($user->getId()));
}
}
Loading
Loading