-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from RadnoK/clear-wishlists-on-login
Clear wishlists on login
- Loading branch information
Showing
10 changed files
with
565 additions
and
14 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/vendor/ | ||
/node_modules/ | ||
/composer.lock | ||
/phpspec.yml | ||
|
||
/etc/build/* | ||
!/etc/build/.gitignore | ||
|
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@wishlist | ||
Feature: Clearing wishlist on logout | ||
In order to not see other users wishlists | ||
As a Visitor | ||
I want to have cleared wishlist after logout | ||
|
||
Background: | ||
Given the store operates on a single channel in "United States" | ||
|
||
@ui | ||
Scenario: Clearing wishlist on logout | ||
Given the store has a product "Jack Daniels Gentleman" priced at "$10.00" | ||
And I have this product in my wishlist | ||
When I log in | ||
And I log out | ||
And I go to the wishlist page | ||
And I should have 0 products in my wishlist |
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
62 changes: 62 additions & 0 deletions
62
spec/EventListener/ClearCookieWishlistItemsListenerSpec.php
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\BitBag\SyliusWishlistPlugin\EventListener; | ||
|
||
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface; | ||
use BitBag\SyliusWishlistPlugin\Entity\WishlistProductInterface; | ||
use BitBag\SyliusWishlistPlugin\EventListener\ClearCookieWishlistItemsListener; | ||
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface; | ||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
use Sylius\Component\Core\Model\AdminUserInterface; | ||
use Sylius\Component\Core\Model\ShopUserInterface; | ||
use Sylius\Component\Resource\Storage\StorageInterface; | ||
use Symfony\Component\HttpFoundation\ParameterBag; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | ||
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; | ||
|
||
final class ClearCookieWishlistItemsListenerSpec extends ObjectBehavior | ||
{ | ||
public function let(StorageInterface $cookieStorage): void | ||
{ | ||
$this->beConstructedWith($cookieStorage, 'bitbag_sylius_wishlist'); | ||
} | ||
|
||
function it_is_initializable(): void | ||
{ | ||
$this->shouldHaveType(ClearCookieWishlistItemsListener::class); | ||
} | ||
|
||
function it_does_nothing_if_not_shop_user( | ||
InteractiveLoginEvent $interactiveLoginEvent, | ||
TokenInterface $token, | ||
AdminUserInterface $adminUser, | ||
StorageInterface $cookieStorage | ||
): void { | ||
$interactiveLoginEvent->getAuthenticationToken()->willReturn($token); | ||
$token->getUser()->willReturn($adminUser); | ||
|
||
$cookieStorage->set('bitbag_sylius_wishlist', null)->shouldNotBeCalled(); | ||
|
||
$this->onInteractiveLogin($interactiveLoginEvent); | ||
} | ||
|
||
function it_adds_cookie_items_to_user_items_if_both_exist( | ||
InteractiveLoginEvent $interactiveLoginEvent, | ||
TokenInterface $token, | ||
ShopUserInterface $shopUser, | ||
StorageInterface $cookieStorage | ||
): void { | ||
$interactiveLoginEvent->getAuthenticationToken()->willReturn($token); | ||
$token->getUser()->willReturn($shopUser); | ||
|
||
$cookieStorage->set('bitbag_sylius_wishlist', null)->shouldBeCalled(); | ||
|
||
$this->onInteractiveLogin($interactiveLoginEvent); | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* another great project. | ||
* You can find more information about us on https://bitbag.shop and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusWishlistPlugin\EventListener; | ||
|
||
use Sylius\Component\Core\Model\ShopUserInterface; | ||
use Sylius\Component\Resource\Storage\StorageInterface; | ||
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; | ||
|
||
final class ClearCookieWishlistItemsListener | ||
{ | ||
/** @var StorageInterface */ | ||
private $cookieStorage; | ||
|
||
/** @var string */ | ||
private $wishlistCookieToken; | ||
|
||
public function __construct(StorageInterface $cookieStorage, string $wishlistCookieToken) | ||
{ | ||
$this->cookieStorage = $cookieStorage; | ||
$this->wishlistCookieToken = $wishlistCookieToken; | ||
} | ||
|
||
public function onInteractiveLogin(InteractiveLoginEvent $interactiveLoginEvent): void | ||
{ | ||
$user = $interactiveLoginEvent->getAuthenticationToken()->getUser(); | ||
|
||
if (!$user instanceof ShopUserInterface) { | ||
return; | ||
} | ||
|
||
$this->cookieStorage->set($this->wishlistCookieToken, null); | ||
} | ||
} |
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
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
Oops, something went wrong.