From 5a3c4bdbf9dd313da9e2f75b8932cac30c1fcb34 Mon Sep 17 00:00:00 2001 From: Olivier ALLAIN Date: Sun, 17 Sep 2023 18:30:41 +0200 Subject: [PATCH 1/2] export customer with cart --- ...moveCartBeforeExportCustomerSubscriber.php | 39 +++++++++++++++++++ .../Controller/ExportDataControllerTest.php | 37 ++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/EventSubscriber/RemoveCartBeforeExportCustomerSubscriber.php create mode 100644 tests/PHPUnit/Controller/ExportDataControllerTest.php diff --git a/src/EventSubscriber/RemoveCartBeforeExportCustomerSubscriber.php b/src/EventSubscriber/RemoveCartBeforeExportCustomerSubscriber.php new file mode 100644 index 0000000..211e003 --- /dev/null +++ b/src/EventSubscriber/RemoveCartBeforeExportCustomerSubscriber.php @@ -0,0 +1,39 @@ + ['process'], + ]; + } + + public function process(BeforeExportCustomerData $beforeExportCustomerData): void + { + $carts = $this->orderRepository->findBy([ + 'customer' => $beforeExportCustomerData->getCustomer(), + 'state' => OrderInterface::STATE_CART, + ]); + + /** @var CoreOrderInterface $cart */ + foreach ($carts as $cart) { + $this->orderRepository->remove($cart); + } + } +} diff --git a/tests/PHPUnit/Controller/ExportDataControllerTest.php b/tests/PHPUnit/Controller/ExportDataControllerTest.php new file mode 100644 index 0000000..67aa0ff --- /dev/null +++ b/tests/PHPUnit/Controller/ExportDataControllerTest.php @@ -0,0 +1,37 @@ +get('sylius.repository.shop_user')->findOneBy([]); + $client->loginUser($shopUser); + + // go to product page + $client->request('GET', '/en_US/products/sport-basic-white-t-shirt'); + $this->assertSelectorTextContains('h1', 'Sport basic white T-Shirt'); + + // add product to cart + $client->submitForm('Add to cart'); + $client->request('GET', '/en_US/cart/'); + $this->assertSelectorTextContains('h1', 'Your shopping cart'); + + // login as admin and go to customer page + $adminUser = static::getContainer()->get('sylius.repository.admin_user')->findOneBy([]); + $client->loginUser($adminUser, 'admin'); + $client->request('GET', sprintf('/admin/customers/%s', $shopUser->getId())); + + // export data for this user + $client->clickLink('Export data'); + $this->assertResponseIsSuccessful(); + } +} From 74764348bac185d9d27f6f186904e9fe1fa72592 Mon Sep 17 00:00:00 2001 From: Olivier ALLAIN Date: Sun, 17 Sep 2023 22:54:54 +0200 Subject: [PATCH 2/2] followRedirects in tests --- tests/PHPUnit/Controller/ExportDataControllerTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/PHPUnit/Controller/ExportDataControllerTest.php b/tests/PHPUnit/Controller/ExportDataControllerTest.php index 67aa0ff..480cb84 100644 --- a/tests/PHPUnit/Controller/ExportDataControllerTest.php +++ b/tests/PHPUnit/Controller/ExportDataControllerTest.php @@ -5,11 +5,16 @@ namespace Tests\Synolia\SyliusGDPRPlugin\PHPUnit\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\HttpKernel\Kernel; class ExportDataControllerTest extends WebTestCase { public function testExportDataWithCart(): void { + if (Kernel::MAJOR_VERSION < 6) { + $this->markTestSkipped('Test on for Symfony 6+'); + } + $client = static::createClient(); // login a user