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

[BehatBridge] Create & Update page #152

Merged
merged 1 commit into from
Jan 21, 2025
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
8 changes: 8 additions & 0 deletions behat.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ imports:

default:
extensions:
Behat\MinkExtension:
base_url: "https://127.0.0.1:8080/"
default_session: symfony
sessions:
symfony:
symfony: ~
show_auto: false

FriendsOfBehat\SymfonyExtension:
bootstrap: tests/bootstrap.php

4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
"require-dev": {
"behat/behat": "^3.16",
"doctrine/doctrine-fixtures-bundle": "^3.6",
"friends-of-behat/mink": "^1.11",
"friends-of-behat/mink-browserkit-driver": "^1.6",
"friends-of-behat/mink-extension": "^2.7",
"friends-of-behat/page-object-extension": "^0.3.2",
"friends-of-behat/symfony-extension": "^2.6",
"matthiasnoback/symfony-config-test": "^5.1",
"matthiasnoback/symfony-dependency-injection-test": "^5.1",
Expand Down
5 changes: 2 additions & 3 deletions config/behat/suites/ui/book/managing_books.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ default:
suites:
ui_managing_books:
contexts:
- Sylius\BehatBridge\Behat\Context\Hook\DoctrineORMContext
- Sylius\BehatBridge\Behat\Context\Transform\SharedStorageContext

- MainTests\Sylius\Behat\Context\Setup\BookContext

- MainTests\Sylius\Behat\Context\Ui\ManagingBooksContext

- MainTests\Sylius\Behat\Context\Domain\BookContext
filters:
tags: "@managing_books&&@ui"
1 change: 1 addition & 0 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ security:
access_control:
- { path: ^/admin/login, roles: PUBLIC_ACCESS }
- { path: ^/admin/logout, roles: PUBLIC_ACCESS }
- { path: ^/admin/books, roles: PUBLIC_ACCESS } # TODO: to remove, just to simplify for now
- { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/, roles: PUBLIC_ACCESS }
# - { path: ^/profile, roles: ROLE_USER }
Expand Down
5 changes: 5 additions & 0 deletions config/services_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ services:
autowire: true
autoconfigure: true

# TODO should be autoconfigured on friends-of-behat/page-object-extension
_instanceof:
FriendsOfBehat\PageObjectExtension\Page\SymfonyPage:
bind:
$minkParameters: '@behat.mink.parameters'

MainTests\Sylius\Behat\:
resource: '../tests/Behat/*'
1 change: 1 addition & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
$ecsConfig->paths([
__DIR__ . '/app',
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$ecsConfig->import('vendor/sylius-labs/coding-standard/ecs.php');
Expand Down
14 changes: 14 additions & 0 deletions features/admin/book/managing_books/adding_books.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@managing_books
Feature: Adding a new book
In order to manage the library
As an Administrator
I want to add a new book

@ui
Scenario: Adding a new book
When I want to create a new book
And I name it "Carrie"
And I specify its author as "Stephen King"
And I add it
Then the book "Carrie" should be added
And the book "Carrie" should appear in the list
5 changes: 4 additions & 1 deletion features/admin/book/managing_books/editing_books.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ Feature: Editing books
I want to be able to edit the book

Background:
Given there is a book "Shinning"
Given there is a book "The Shining"

@ui
Scenario: Renaming a book
When I want to edit this book
And I rename it to "Carrie"
And I save my changes
Then this book title should be "Carrie"
9 changes: 9 additions & 0 deletions src/BehatBridge/config/services/behat/context.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sylius\BehatBridge\Behat\Context\Hook\DoctrineORMContext;
use Sylius\BehatBridge\Behat\Context\Transform\SharedStorageContext;

return function (ContainerConfigurator $configurator): void {
Expand All @@ -29,4 +30,12 @@
])
;
$services->alias(SharedStorageContext::class, 'sylius_behat_bridge.behat.context.transform.shared_storage');

$services
->set('sylius_behat_bridge.behat.context.hook.doctrine.orm', DoctrineORMContext::class)
->args([
service('doctrine.orm.entity_manager'),
])
;
$services->alias(DoctrineORMContext::class, 'sylius_behat_bridge.behat.context.hook.doctrine.orm');
};
52 changes: 52 additions & 0 deletions src/BehatBridge/config/services/behat/element/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sylius\BehatBridge\Behat\Element\Admin\Action\CancelActionElement;
use Sylius\BehatBridge\Behat\Element\Admin\Action\CancelActionElementInterface;
use Sylius\BehatBridge\Behat\Element\Admin\Action\CreateActionElement;
use Sylius\BehatBridge\Behat\Element\Admin\Action\CreateActionElementInterface;
use Sylius\BehatBridge\Behat\Element\Admin\Action\UpdateActionElement;
use Sylius\BehatBridge\Behat\Element\Admin\Action\UpdateActionElementInterface;

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

$services
->set('sylius_behat_bridge.behat.element.admin.action.cancel', CancelActionElement::class)
->args([
service('behat.mink.default_session'),
service('behat.mink.parameters'),
])
;
$services->alias(CancelActionElementInterface::class, 'sylius_behat_bridge.behat.element.admin.action.cancel');

$services
->set('sylius_behat_bridge.behat.element.admin.action.create', CreateActionElement::class)
->args([
service('behat.mink.default_session'),
service('behat.mink.parameters'),
])
;
$services->alias(CreateActionElementInterface::class, 'sylius_behat_bridge.behat.element.admin.action.create');

$services
->set('sylius_behat_bridge.behat.element.admin.action.update', UpdateActionElement::class)
->args([
service('behat.mink.default_session'),
service('behat.mink.parameters'),
])
;
$services->alias(UpdateActionElementInterface::class, 'sylius_behat_bridge.behat.element.admin.action.update');
};
35 changes: 35 additions & 0 deletions src/BehatBridge/src/Behat/Context/Hook/DoctrineORMContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\BehatBridge\Behat\Context\Hook;

use Behat\Behat\Context\Context;
use Behat\Hook\BeforeScenario;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\ORM\EntityManagerInterface;

final class DoctrineORMContext implements Context
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
) {
}

#[BeforeScenario]
public function purgeDatabase(): void
{
$purger = new ORMPurger($this->entityManager);
$purger->purge();
$this->entityManager->clear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\BehatBridge\Behat\Element\Admin\Action;

use FriendsOfBehat\PageObjectExtension\Element\Element;

final class CancelActionElement extends Element implements CancelActionElementInterface
{
public function cancel(): void
{
$this->getElement('cancel_button')->click();
}

protected function getDefinedElements(): array
{
return [
'cancel_button' => '[data-test-cancel-changes-button]',
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\BehatBridge\Behat\Element\Admin\Action;

interface CancelActionElementInterface
{
public function cancel(): void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\BehatBridge\Behat\Element\Admin\Action;

use FriendsOfBehat\PageObjectExtension\Element\Element;

final class CreateActionElement extends Element implements CreateActionElementInterface
{
public function create(): void
{
$this->getElement('create_button')->click();
}

protected function getDefinedElements(): array
{
return [
'create_button' => '[type=submit]:contains("Create")',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need data-test attribute for this as well?

];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\BehatBridge\Behat\Element\Admin\Action;

interface CreateActionElementInterface
{
public function create(): void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\BehatBridge\Behat\Element\Admin\Action;

use FriendsOfBehat\PageObjectExtension\Element\Element;

final class UpdateActionElement extends Element implements UpdateActionElementInterface
{
public function update(): void
{
$this->getElement('update_button')->click();
}

protected function getDefinedElements(): array
{
return [
'update_button' => '[data-test-update-changes-button]',
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\BehatBridge\Behat\Element\Admin\Action;

interface UpdateActionElementInterface
{
public function update(): void;
}
Loading
Loading