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

[Shop] Disabling customer when email has been changed #11944

Merged
merged 9 commits into from
Oct 19, 2020
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
},
"conflict": {
"behat/behat": "3.6.0",
"doctrine/inflector": "^1.4",
"symfony/symfony": "3.4.7",
"symfony/doctrine-bridge": "3.4.37",
"sylius/grid-bundle": "1.7.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@ Feature: Editing a customer profile
Then I should be notified that it has been successfully edited
And my name should be "Will Conway"

@ui @email
Scenario: Changing my email if channel requires verification
When I want to modify my profile
And I specify the customer email as "frank@underwood.com"
And I save my changes
Then I should be notified that it has been successfully edited
And I should be notified that the verification email has been sent
And it should be sent to "frank@underwood.com"
And I should not be logged in

@ui
Scenario: Changing my email
Scenario: Changing my email if channel does not require verification
Given "United States" channel has account verification disabled
When I want to modify my profile
And I specify the customer email as "frank@underwood.com"
And I save my changes
Then I should be notified that it has been successfully edited
And my account should not be verified
And my email should be "frank@underwood.com"
36 changes: 36 additions & 0 deletions src/Sylius/Behat/Context/Ui/Shop/AccountContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\Behat\Context\Ui\Shop;

use Behat\Behat\Context\Context;
use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Page\Shop\Account\ChangePasswordPageInterface;
use Sylius\Behat\Page\Shop\Account\DashboardPageInterface;
Expand Down Expand Up @@ -455,4 +456,39 @@ public function theShipmentStatusShouldBe(string $shipmentStatus): void
{
Assert::same($this->orderShowPage->getShipmentStatus(), $shipmentStatus);
}

/**
* @Then I should be notified that the verification email has been sent
*/
public function iShouldBeNotifiedThatTheVerificationEmailHasBeenSent(): void
{
$this->notificationChecker->checkNotification(
'An email with the verification link has been sent to your email address.',
NotificationType::success()
);
}

/**
* @Then /^(?:my|his|her) account should not be verified$/
*/
public function myAccountShouldNotBeVerified(): void
{
$this->dashboardPage->open();

Assert::false($this->dashboardPage->isVerified());
}

/**
* @Then I should not be logged in
*/
public function iShouldNotBeLoggedIn(): void
{
try {
$this->dashboardPage->open();
} catch (UnexpectedPageException $exception) {
return;
}

throw new \InvalidArgumentException('Dashboard has been openned, but it shouldn\'t as customer should not be logged in');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ default:
- sylius.behat.context.ui.shop.checkout.payment
- sylius.behat.context.ui.shop.checkout.complete
- sylius.behat.context.ui.shop.currency
- sylius.behat.context.ui.email

filters:
tags: "@customer_account && @ui"
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<argument>%fos_oauth_server.model.client.class%</argument>
</service>

<service id="sylius.section_resolver.admin_api_uri_based_section_resolver" class="Sylius\Bundle\AdminApiBundle\SectionResolver\AdminApiUriBasedSectionResolver">
<argument>/api</argument>
<tag name="sylius.uri_based_section_resolver" priority="10" />
</service>

<service id="sylius.listener.api.add_to_cart" class="Sylius\Bundle\AdminApiBundle\EventListener\CartChangeListener">
<argument type="service" id="sylius.order_processing.order_processor.composite" />
<argument type="service" id="sylius.manager.order" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* 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\Bundle\AdminApiBundle\SectionResolver;

use Sylius\Bundle\CoreBundle\SectionResolver\SectionInterface;

class AdminApiSection implements SectionInterface
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Bundle\AdminApiBundle\SectionResolver;

use Sylius\Bundle\CoreBundle\SectionResolver\SectionCannotBeResolvedException;
use Sylius\Bundle\CoreBundle\SectionResolver\SectionInterface;
use Sylius\Bundle\CoreBundle\SectionResolver\UriBasedSectionResolverInterface;

final class AdminApiUriBasedSectionResolver implements UriBasedSectionResolverInterface
{
/** @var string */
private $adminApiUriBeginning;

public function __construct(string $adminApiUriBeginning)
{
$this->adminApiUriBeginning = $adminApiUriBeginning;
}

public function getSection(string $uri): SectionInterface
{
if (0 === strpos($uri, $this->adminApiUriBeginning)) {
return new AdminApiSection();
}

throw new SectionCannotBeResolvedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace spec\Sylius\Bundle\AdminApiBundle\SectionResolver;

use PhpSpec\ObjectBehavior;
use Sylius\Bundle\AdminApiBundle\SectionResolver\AdminApiSection;
use Sylius\Bundle\CoreBundle\SectionResolver\SectionCannotBeResolvedException;
use Sylius\Bundle\CoreBundle\SectionResolver\UriBasedSectionResolverInterface;

final class AdminApiUriBasedSectionResolverSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith('/api');
}

function it_it_uri_based_section_resolver(): void
{
$this->shouldImplement(UriBasedSectionResolverInterface::class);
}

function it_returns_admin_api_section_if_path_starts_with_slash_api(): void
{
$this->getSection('/api/something')->shouldBeLike(new AdminApiSection());
$this->getSection('/api')->shouldBeLike(new AdminApiSection());
}

function it_throws_exception_if_path_does_not_start_with_slash_api(): void
{
$this->shouldThrow(SectionCannotBeResolvedException::class)->during('getSection', ['/ap']);
$this->shouldThrow(SectionCannotBeResolvedException::class)->during('getSection', ['/shop']);
$this->shouldThrow(SectionCannotBeResolvedException::class)->during('getSection', ['/admin/asd']);
$this->shouldThrow(SectionCannotBeResolvedException::class)->during('getSection', ['/en_US/api']);
}
}
5 changes: 5 additions & 0 deletions src/Sylius/Bundle/AdminBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<tag name="sylius.context.locale" priority="128" />
</service>

<service id="sylius.section_resolver.admin_uri_based_section_resolver" class="Sylius\Bundle\AdminBundle\SectionResolver\AdminUriBasedSectionResolver">
<argument>/admin</argument>
<tag name="sylius.uri_based_section_resolver" priority="20" />
</service>

<service id="sylius.twig.extension.widget.admin_notification" class="Sylius\Bundle\AdminBundle\Twig\NotificationWidgetExtension">
<argument>%sylius.admin.notification.enabled%</argument>
<argument>%sylius.admin.notification.frequency%</argument>
Expand Down
20 changes: 20 additions & 0 deletions src/Sylius/Bundle/AdminBundle/SectionResolver/AdminSection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* 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\Bundle\AdminBundle\SectionResolver;

use Sylius\Bundle\CoreBundle\SectionResolver\SectionInterface;

class AdminSection implements SectionInterface
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Bundle\AdminBundle\SectionResolver;

use Sylius\Bundle\CoreBundle\SectionResolver\SectionCannotBeResolvedException;
use Sylius\Bundle\CoreBundle\SectionResolver\SectionInterface;
use Sylius\Bundle\CoreBundle\SectionResolver\UriBasedSectionResolverInterface;

final class AdminUriBasedSectionResolver implements UriBasedSectionResolverInterface
{
/** @var string */
private $adminUriBeginning;

public function __construct(string $adminUriBeginning)
{
$this->adminUriBeginning = $adminUriBeginning;
}

public function getSection(string $uri): SectionInterface
{
if (0 === strpos($uri, $this->adminUriBeginning)) {
return new AdminSection();
}

throw new SectionCannotBeResolvedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace spec\Sylius\Bundle\AdminBundle\SectionResolver;

use PhpSpec\ObjectBehavior;
use Sylius\Bundle\AdminBundle\SectionResolver\AdminSection;
use Sylius\Bundle\CoreBundle\SectionResolver\SectionCannotBeResolvedException;
use Sylius\Bundle\CoreBundle\SectionResolver\UriBasedSectionResolverInterface;

final class AdminUriBasedSectionResolverSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith('/admin');
}

function it_it_uri_based_section_resolver(): void
{
$this->shouldImplement(UriBasedSectionResolverInterface::class);
}

function it_returns_admin_if_path_starts_with_slash_admin(): void
{
$this->getSection('/admin/something')->shouldBeLike(new AdminSection());
$this->getSection('/admin')->shouldBeLike(new AdminSection());
}

function it_throws_exception_if_path_does_not_start_with_slash_admin(): void
{
$this->shouldThrow(SectionCannotBeResolvedException::class)->during('getSection', ['/admi']);
$this->shouldThrow(SectionCannotBeResolvedException::class)->during('getSection', ['/shop']);
$this->shouldThrow(SectionCannotBeResolvedException::class)->during('getSection', ['/api/asd']);
$this->shouldThrow(SectionCannotBeResolvedException::class)->during('getSection', ['/en_US/admin']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* 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\Bundle\CoreBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

final class RegisterUriBasedSectionResolverPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('sylius.section_resolver.uri_based_section_resolver')) {
return;
}

$uriBasedSectionResolver = $container->getDefinition('sylius.section_resolver.uri_based_section_resolver');
$uriBasedSectionProviders = [];

foreach ($container->findTaggedServiceIds('sylius.uri_based_section_resolver') as $id => $tags) {
foreach ($tags as $attributes) {
$uriBasedSectionProviders[] = ['id' => new Reference($id), 'priority' => $attributes['priority'] ?? 0];
}
}

usort($uriBasedSectionProviders, static function (array $a, array $b): int {
return -($a['priority'] <=> $b['priority']);
});

$uriBasedSectionResolver->setArgument(1, array_column($uriBasedSectionProviders, 'id'));
}
}
5 changes: 5 additions & 0 deletions src/Sylius/Bundle/CoreBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@
<argument type="string">%locale%</argument>
</service>

<service id="sylius.section_resolver.uri_based_section_resolver" class="Sylius\Bundle\CoreBundle\SectionResolver\UriBasedSectionProvider">
<argument type="service" id="request_stack" />
<argument type="collection" />
</service>

<service id="sylius.reviewer_reviews_remover" class="Sylius\Bundle\CoreBundle\Remover\ReviewerReviewsRemover">
<argument type="service" id="sylius.repository.product_review" />
<argument type="service" id="sylius.manager.product_review" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Sylius\Bundle\CoreBundle\SectionResolver;

final class SectionCannotBeResolvedException extends \RuntimeException
{
}
Loading