|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\GraphQl\LoginAsCustomerGraphQl; |
| 9 | + |
| 10 | +use Magento\Customer\Api\CustomerRepositoryInterface; |
| 11 | +use Magento\Framework\Registry; |
| 12 | +use Magento\TestFramework\Helper\Bootstrap; |
| 13 | +use Magento\TestFramework\TestCase\GraphQlAbstract; |
| 14 | + |
| 15 | +/** |
| 16 | + * Tests for create customer (V2) with allow_remote_shopping_assistance input/output |
| 17 | + */ |
| 18 | +class CreateCustomerV2Test extends GraphQlAbstract |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var Registry |
| 22 | + */ |
| 23 | + private $registry; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var CustomerRepositoryInterface |
| 27 | + */ |
| 28 | + private $customerRepository; |
| 29 | + |
| 30 | + protected function setUp(): void |
| 31 | + { |
| 32 | + parent::setUp(); |
| 33 | + |
| 34 | + $this->registry = Bootstrap::getObjectManager()->get(Registry::class); |
| 35 | + $this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Test setting allow_remote_shopping_assistance to true |
| 40 | + * |
| 41 | + * @throws \Exception |
| 42 | + */ |
| 43 | + public function testCreateCustomerAccountWithAllowTrue() |
| 44 | + { |
| 45 | + $newFirstname = 'Richard'; |
| 46 | + $newLastname = 'Rowe'; |
| 47 | + $currentPassword = 'test123#'; |
| 48 | + |
| 49 | + |
| 50 | + $query = <<<QUERY |
| 51 | +mutation { |
| 52 | + createCustomerV2( |
| 53 | + input: { |
| 54 | + firstname: "{$newFirstname}" |
| 55 | + lastname: "{$newLastname}" |
| 56 | + email: "{$newEmail}" |
| 57 | + password: "{$currentPassword}" |
| 58 | + is_subscribed: true |
| 59 | + allow_remote_shopping_assistance: true |
| 60 | + } |
| 61 | + ) { |
| 62 | + customer { |
| 63 | + id |
| 64 | + firstname |
| 65 | + lastname |
| 66 | + email |
| 67 | + is_subscribed |
| 68 | + allow_remote_shopping_assistance |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | +QUERY; |
| 73 | + $response = $this->graphQlMutation($query); |
| 74 | + |
| 75 | + $this->assertNull($response['createCustomerV2']['customer']['id']); |
| 76 | + $this->assertEquals($newFirstname, $response['createCustomerV2']['customer']['firstname']); |
| 77 | + $this->assertEquals($newLastname, $response['createCustomerV2']['customer']['lastname']); |
| 78 | + $this->assertEquals($newEmail, $response['createCustomerV2']['customer']['email']); |
| 79 | + $this->assertTrue($response['createCustomerV2']['customer']['is_subscribed']); |
| 80 | + $this->assertTrue($response['createCustomerV2']['customer']['allow_remote_shopping_assistance']); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Test setting allow_remote_shopping_assistance to false |
| 85 | + * |
| 86 | + * @throws \Exception |
| 87 | + */ |
| 88 | + public function testCreateCustomerAccountWithAllowFalse() |
| 89 | + { |
| 90 | + $newFirstname = 'Richard'; |
| 91 | + $newLastname = 'Rowe'; |
| 92 | + $currentPassword = 'test123#'; |
| 93 | + |
| 94 | + |
| 95 | + $query = <<<QUERY |
| 96 | +mutation { |
| 97 | + createCustomerV2( |
| 98 | + input: { |
| 99 | + firstname: "{$newFirstname}" |
| 100 | + lastname: "{$newLastname}" |
| 101 | + email: "{$newEmail}" |
| 102 | + password: "{$currentPassword}" |
| 103 | + is_subscribed: true |
| 104 | + allow_remote_shopping_assistance: false |
| 105 | + } |
| 106 | + ) { |
| 107 | + customer { |
| 108 | + id |
| 109 | + firstname |
| 110 | + lastname |
| 111 | + email |
| 112 | + is_subscribed |
| 113 | + allow_remote_shopping_assistance |
| 114 | + } |
| 115 | + } |
| 116 | +} |
| 117 | +QUERY; |
| 118 | + $response = $this->graphQlMutation($query); |
| 119 | + |
| 120 | + $this->assertNull($response['createCustomerV2']['customer']['id']); |
| 121 | + $this->assertEquals($newFirstname, $response['createCustomerV2']['customer']['firstname']); |
| 122 | + $this->assertEquals($newLastname, $response['createCustomerV2']['customer']['lastname']); |
| 123 | + $this->assertEquals($newEmail, $response['createCustomerV2']['customer']['email']); |
| 124 | + $this->assertTrue($response['createCustomerV2']['customer']['is_subscribed']); |
| 125 | + $this->assertFalse($response['createCustomerV2']['customer']['allow_remote_shopping_assistance']); |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * Test omitting allow_remote_shopping_assistance |
| 130 | + * |
| 131 | + * @throws \Exception |
| 132 | + */ |
| 133 | + public function testCreateCustomerAccountWithoutAllow() |
| 134 | + { |
| 135 | + $newFirstname = 'Richard'; |
| 136 | + $newLastname = 'Rowe'; |
| 137 | + $currentPassword = 'test123#'; |
| 138 | + |
| 139 | + |
| 140 | + $query = <<<QUERY |
| 141 | +mutation { |
| 142 | + createCustomerV2( |
| 143 | + input: { |
| 144 | + firstname: "{$newFirstname}" |
| 145 | + lastname: "{$newLastname}" |
| 146 | + email: "{$newEmail}" |
| 147 | + password: "{$currentPassword}" |
| 148 | + is_subscribed: true, |
| 149 | + } |
| 150 | + ) { |
| 151 | + customer { |
| 152 | + id |
| 153 | + firstname |
| 154 | + lastname |
| 155 | + email |
| 156 | + is_subscribed |
| 157 | + allow_remote_shopping_assistance |
| 158 | + } |
| 159 | + } |
| 160 | +} |
| 161 | +QUERY; |
| 162 | + $response = $this->graphQlMutation($query); |
| 163 | + |
| 164 | + $this->assertNull($response['createCustomerV2']['customer']['id']); |
| 165 | + $this->assertEquals($newFirstname, $response['createCustomerV2']['customer']['firstname']); |
| 166 | + $this->assertEquals($newLastname, $response['createCustomerV2']['customer']['lastname']); |
| 167 | + $this->assertEquals($newEmail, $response['createCustomerV2']['customer']['email']); |
| 168 | + $this->assertTrue($response['createCustomerV2']['customer']['is_subscribed']); |
| 169 | + $this->assertFalse($response['createCustomerV2']['customer']['allow_remote_shopping_assistance']); |
| 170 | + } |
| 171 | + |
| 172 | + protected function tearDown(): void |
| 173 | + { |
| 174 | + |
| 175 | + try { |
| 176 | + $customer = $this->customerRepository->get($newEmail); |
| 177 | + } catch (\Exception $exception) { |
| 178 | + return; |
| 179 | + } |
| 180 | + |
| 181 | + $this->registry->unregister('isSecureArea'); |
| 182 | + $this->registry->register('isSecureArea', true); |
| 183 | + $this->customerRepository->delete($customer); |
| 184 | + $this->registry->unregister('isSecureArea'); |
| 185 | + $this->registry->register('isSecureArea', false); |
| 186 | + parent::tearDown(); |
| 187 | + } |
| 188 | +} |
0 commit comments