Skip to content
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/features/fixtures/project/public/bundles
/features/fixtures/project/public/uploaded
/features/fixtures/project/var/cache/*
/features/fixtures/project/var/logs/*
/features/fixtures/project/var/log/*
/features/fixtures/project/var/mysql/*
!/features/fixtures/project/var/.gitkeep
!/features/fixtures/project/var/data/.gitkeep
Expand Down
4 changes: 4 additions & 0 deletions Behat/Context/AdminContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use FSi\Bundle\AdminSecurityBundle\Behat\Page\Login;
use FSi\Bundle\AdminSecurityBundle\Behat\Page\Page;
use FSi\Bundle\AdminSecurityBundle\Behat\Page\PasswordResetRequest;
use FSi\Bundle\AdminSecurityBundle\Behat\Page\UserEdit;
use FSi\Bundle\AdminSecurityBundle\Behat\Page\UserList;
use FSi\Bundle\AdminSecurityBundle\Security\User\UserIdentifierHelper;
use InvalidArgumentException;
Expand Down Expand Up @@ -60,6 +61,9 @@ public function getPage(string $name): Page
case 'User list':
$page = $this->getPageObject(UserList::class);
break;
case 'User edit':
$page = $this->getPageObject(UserEdit::class);
break;
case 'Password reset request':
$page = $this->getPageObject(PasswordResetRequest::class);
break;
Expand Down
34 changes: 30 additions & 4 deletions Behat/Context/AdminUserManagementContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

use Assert\Assertion;
use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Driver\BrowserKitDriver;
use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException;
use FriendsOfBehat\SymfonyExtension\Driver\SymfonyDriver;
use FSi\Bundle\AdminSecurityBundle\Behat\Element\BatchAction;
use FSi\Bundle\AdminSecurityBundle\Behat\Element\Datagrid;
use FSi\Bundle\AdminSecurityBundle\Behat\Page\UserEdit;
use FSi\Bundle\AdminSecurityBundle\Behat\Page\UserList;

use function count;
Expand Down Expand Up @@ -91,14 +91,35 @@ public function iPressLink(string $name): void
$this->getUserListPage()->clickLink($name);
}

/**
* @When I click :name in :nthLiteral row
*/
public function iPressButtonInRow(string $name, string $nthLiteral): void
{
$nthRow = match ($nthLiteral) {
'first' => 1,
'second' => 2,
default => throw new \InvalidArgumentException(sprintf('Unknown row "%s"', $nthLiteral)),
};
$this->getUserListPage()->clickButtonInRow($name, $nthRow);
}

/**
* @Then I fill form with valid user data
*/
public function iFillFormWithValidUserData(): void
{
$userListPage = $this->getUserListPage();
$userListPage->fillField('Email', 'new-user@fsi.pl');
$userListPage->checkField('ROLE_ADMIN');
$userEditPage = $this->getUserEditPage();
$userEditPage->fillField('Email', 'new-user@fsi.pl');
$userEditPage->checkField('ROLE_ADMIN');
}

/**
* @Then I check :value
*/
public function iCheckField(string $value): void
{
$this->getUserEditPage()->checkField($value);
}

private function performBatchAction(string $action, int $cellIndex): void
Expand Down Expand Up @@ -139,6 +160,11 @@ private function getUserListPage(): UserList
return $this->getPageObject(UserList::class);
}

private function getUserEditPage(): UserEdit
{
return $this->getPageObject(UserEdit::class);
}

private function getDatagrid(): Datagrid
{
/** @var Datagrid $datagrid */
Expand Down
2 changes: 1 addition & 1 deletion Behat/Context/MailContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function thereShouldBeNoEmailSent(): void
Assertion::count(
$this->mailerCollector->getEmails(),
0,
'There were "%s" emails sent, where none should.'
'The email list must contain %d email addresses, but %d was provided.'
);
}

Expand Down
42 changes: 42 additions & 0 deletions Behat/Page/UserEdit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* (c) FSi sp. z o.o. <info@fsi.pl>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\AdminSecurityBundle\Behat\Page;

use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException;

final class UserEdit extends Page
{
/**
* @param array<string, string|null> $urlParameters
* @return void
* @throws UnexpectedPageException
*/
public function verify(array $urlParameters = []): void
{
parent::verify($urlParameters);

if (false === $this->getDocument()->has('css', '#page-header:contains("Edit element")')) {
throw new UnexpectedPageException(
sprintf("%s page is missing \"Edit element\" header", $this->getUrl($urlParameters))
);
}
}

/**
* @param array<string, string|null> $urlParameters
* @return string
*/
protected function getUrl(array $urlParameters = []): string
{
return $this->getParameter('base_url') . '/admin/en/form/admin_security_user/' . $urlParameters['id'];
}
}
13 changes: 11 additions & 2 deletions Behat/Page/UserList.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FSi\Bundle\AdminSecurityBundle\Behat\Page;

use Assert\Assertion;
use Behat\Mink\Element\NodeElement;
use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException;

Expand Down Expand Up @@ -62,13 +63,21 @@ public function getBatchActions(): array
);
}

public function clickButtonInRow(string $name, int $nth): void
{
$locator = sprintf('tbody > tr:nth-child(%d) > td a:contains("%s")', $nth, $name);
$element = $this->getElement('table')->find('css', $locator);
Assertion::notNull($element, sprintf('"%s" not found in row %d', $name, $nth));
$element->click();
}

/**
* @return array<string, string>
*/
protected function getDefinedElements(): array
{
return [
'table' => '#admin_security_user',
'table' => 'table#admin_security_user',
'batch actions' => '#batch_action_action',
];
}
Expand All @@ -79,6 +88,6 @@ protected function getDefinedElements(): array
*/
protected function getUrl(array $urlParameters = []): string
{
return $this->getParameter('base_url') . '/admin/en/list/admin_security_user';
return $this->getParameter('base_url') . '/admin/en/list/user';
}
}
8 changes: 7 additions & 1 deletion EventListener/PrepareUserListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FSi\Bundle\AdminSecurityBundle\EventListener;

use FSi\Bundle\AdminBundle\Doctrine\Admin\Element;
use FSi\Bundle\AdminBundle\Event\FormDataPreSaveEvent;
use FSi\Bundle\AdminBundle\Event\FormEvent;
use FSi\Bundle\AdminSecurityBundle\Event\UserCreatedEvent;
Expand Down Expand Up @@ -47,8 +48,13 @@ public function prepareAndDispatchUserCreated(FormEvent $event): void
return;
}

$element = $event->getElement();
if (false === $element instanceof Element) {
return;
}

// do not dispatch event and do not set random password for existing users
if (null !== $entity->getPassword()) {
if (true === $element->getObjectManager()->contains($entity)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Resources/translations/FSiAdminSecurity.pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ crud:
datagrid:
boolean:
yes: Tak
no: Nie
no: Nie
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"symfony/monolog-bridge": "^5.4|^6.0|^7.0",
"symfony/monolog-bundle": "^3.8",
"symfony/routing": "^5.4|^6.0|^7.0",
"symfony/twig-bridge": "^5.4|^6.0|^7.0",
"symfony/twig-bridge": "~5.4.48|^6.0|^7.0",
"symfony/var-dumper": "^5.4|^6.0|^7.0",
"symfony/var-exporter": "^5.4|^6.0|^7.0",
"rize/uri-template": "^0.3.5|^0.4.0"
Expand Down
9 changes: 9 additions & 0 deletions features/admin/user_managment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,12 @@ Feature: User management
| from | activation@fsi.pl |
| to | new-user@fsi.pl |
| reply_to | do-not-reply@example.com |

@email
Scenario: Edit User
Given I am on the "User list" page
And I click "Edit" in second row
And I check "ROLE_ADMIN"
And I press "Save" button
And I should be redirected to "User list" page
And no emails were sent
2 changes: 1 addition & 1 deletion features/fixtures/project/config/admin_menu.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
menu:
- news
- { id: page_settings, name: Page settings }
- { id: admin_security_user, name: Users }
- { id: user, name: Users }
4 changes: 2 additions & 2 deletions features/fixtures/project/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
FSi\Component\Translatable\Integration\Symfony\TranslatableBundle::class => ['all' => true],
FSi\Bundle\ResourceRepositoryBundle\FSiResourceRepositoryBundle::class => ['all' => true],
FSi\Bundle\AdminBundle\FSiAdminBundle::class => ['all' => true],
FSi\FixturesBundle\FSiFixturesBundle::class => ['all' => true],
FSi\Bundle\AdminSecurityBundle\FSiAdminSecurityBundle::class => ['all' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['all' => true]
FSi\FixturesBundle\FSiFixturesBundle::class => ['all' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['all' => true],
];
39 changes: 39 additions & 0 deletions features/fixtures/project/config/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

use FSi\Bundle\AdminSecurityBundle\Behat\Context\DataContext;
use FSi\FixturesBundle\Admin\News;
use FSi\FixturesBundle\Admin\PageSettings;
use FSi\FixturesBundle\Listener\MailCollector;
use FSi\FixturesBundle\Time\Clock;
use Psr\Clock\ClockInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services();

$services->defaults()
->autowire()
->autoconfigure()
->private()
->bind('$session', service('behat.mink.default_session'))
->bind('$minkParameters', service('behat.mink.parameters'));

$services->load(
'FSi\\Bundle\\AdminSecurityBundle\\Behat\\Context\\',
'../../../../Behat/Context'
);

$services->set(DataContext::class)
->arg('$container', service('behat.driver.service_container')->nullOnInvalid());

$services->set(News::class);
$services->set(PageSettings::class);
$services->set(MailCollector::class);

$services->set(Clock::class);
$services->alias(ClockInterface::class, Clock::class)->public();
};
33 changes: 33 additions & 0 deletions features/fixtures/project/src/Admin/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* (c) FSi sp. z o.o. <info@fsi.pl>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\FixturesBundle\Admin;

use FSi\Bundle\AdminSecurityBundle\Doctrine\Admin\UserElement;
use FSi\Component\DataGrid\DataGridFactoryInterface;
use FSi\Component\DataGrid\DataGridInterface;
use FSi\FixturesBundle\Entity\User as UserEntity;

/**
* @template-extends UserElement<UserEntity, UserEntity>
*/
class User extends UserElement
{
public function getId(): string
{
return 'user';
}

protected function initDataGrid(DataGridFactoryInterface $factory): DataGridInterface
{
return $factory->createDataGrid('admin_security_user');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
namespace FSi\FixturesBundle\DependencyInjection;

use Composer\InstalledVersions;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Security\Core\User\InMemoryUser;

Expand Down Expand Up @@ -44,7 +42,5 @@ public function prepend(ContainerBuilder $container): void
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
}
}
Loading