|
6 | 6 |
|
7 | 7 | namespace Magento\Customer\Api;
|
8 | 8 |
|
| 9 | +use Magento\Authorization\Test\Fixture\Role as RoleFixture; |
9 | 10 | use Magento\Customer\Api\Data\AddressInterface as Address;
|
| 11 | +use Magento\Customer\Api\Data\CustomerInterface as Customer; |
10 | 12 | use Magento\Customer\Api\Data\CustomerInterfaceFactory;
|
11 | 13 | use Magento\Customer\Model\CustomerRegistry;
|
12 | 14 | use Magento\Framework\Api\DataObjectHelper;
|
13 |
| -use Magento\Customer\Api\Data\CustomerInterface as Customer; |
14 | 15 | use Magento\Framework\Api\FilterBuilder;
|
15 | 16 | use Magento\Framework\Api\Search\FilterGroupBuilder;
|
16 | 17 | use Magento\Framework\Api\SearchCriteriaBuilder;
|
|
23 | 24 | use Magento\Framework\Exception\NoSuchEntityException;
|
24 | 25 | use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
|
25 | 26 | use Magento\Framework\Webapi\Rest\Request;
|
| 27 | +use Magento\Integration\Api\AdminTokenServiceInterface; |
26 | 28 | use Magento\Integration\Api\CustomerTokenServiceInterface;
|
27 | 29 | use Magento\Integration\Api\IntegrationServiceInterface;
|
28 | 30 | use Magento\Integration\Api\OauthServiceInterface;
|
29 | 31 | use Magento\Integration\Model\Integration;
|
| 32 | +use Magento\TestFramework\Fixture\AppArea; |
| 33 | +use Magento\TestFramework\Fixture\AppIsolation; |
| 34 | +use Magento\TestFramework\Fixture\DataFixture; |
| 35 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
| 36 | +use Magento\TestFramework\Fixture\DbIsolation; |
30 | 37 | use Magento\TestFramework\Helper\Bootstrap;
|
31 | 38 | use Magento\TestFramework\Helper\Customer as CustomerHelper;
|
32 | 39 | use Magento\TestFramework\TestCase\WebapiAbstract;
|
| 40 | +use Magento\User\Test\Fixture\User as UserFixture; |
33 | 41 |
|
34 | 42 | /**
|
35 | 43 | * Test for \Magento\Customer\Api\CustomerRepositoryInterface.
|
@@ -1297,4 +1305,100 @@ public static function customerValidNameDataProvider(): array
|
1297 | 1305 | ],
|
1298 | 1306 | ];
|
1299 | 1307 | }
|
| 1308 | + |
| 1309 | + /** |
| 1310 | + * Verify with an admin access token that customers' default addresses are successfully altered |
| 1311 | + * without requiring an address ID key. |
| 1312 | + * |
| 1313 | + * @throws InputException |
| 1314 | + * @throws LocalizedException |
| 1315 | + * @throws \Magento\Framework\Exception\AuthenticationException |
| 1316 | + */ |
| 1317 | + #[ |
| 1318 | + DbIsolation(false), |
| 1319 | + AppIsolation(true), |
| 1320 | + AppArea('webapi_rest'), |
| 1321 | + DataFixture(RoleFixture::class, as: 'restrictedRole'), |
| 1322 | + DataFixture(UserFixture::class, ['role_id' => '$restrictedRole.id$'], 'restrictedUser'), |
| 1323 | + DataFixture( |
| 1324 | + \Magento\Customer\Test\Fixture\Customer::class, |
| 1325 | + [ |
| 1326 | + 'email' => 'john@doe.com', |
| 1327 | + 'password' => 'test@123', |
| 1328 | + 'addresses' => [ |
| 1329 | + [ |
| 1330 | + 'country_id' => 'US', |
| 1331 | + 'region_id' => 32, |
| 1332 | + 'city' => 'Boston', |
| 1333 | + 'street' => ['10 Milk Street'], |
| 1334 | + 'postcode' => '02108', |
| 1335 | + 'telephone' => '1234567890', |
| 1336 | + 'default_billing' => true, |
| 1337 | + 'default_shipping' => true, |
| 1338 | + ], |
| 1339 | + ], |
| 1340 | + ], |
| 1341 | + 'customer' |
| 1342 | + ), |
| 1343 | + ] |
| 1344 | + public function testCustomerAddressUpdateOperation(): void |
| 1345 | + { |
| 1346 | + $fixtures = DataFixtureStorageManager::getStorage(); |
| 1347 | + $customer = $fixtures->get('customer'); |
| 1348 | + $restrictedUser = $fixtures->get('restrictedUser'); |
| 1349 | + |
| 1350 | + // get admin user token |
| 1351 | + $adminTokens = Bootstrap::getObjectManager()->get(AdminTokenServiceInterface::class); |
| 1352 | + $accessToken = $adminTokens->createAdminAccessToken( |
| 1353 | + $restrictedUser->getData('username'), |
| 1354 | + \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD |
| 1355 | + ); |
| 1356 | + |
| 1357 | + $serviceInfo = [ |
| 1358 | + 'rest' => [ |
| 1359 | + 'resourcePath' => self::RESOURCE_PATH . "/{$customer->getId()}", |
| 1360 | + 'httpMethod' => Request::HTTP_METHOD_PUT, |
| 1361 | + 'token' => $accessToken, |
| 1362 | + ], |
| 1363 | + 'soap' => [ |
| 1364 | + 'service' => self::SERVICE_NAME, |
| 1365 | + 'serviceVersion' => self::SERVICE_VERSION, |
| 1366 | + 'operation' => self::SERVICE_NAME . 'Save', |
| 1367 | + 'token' => $accessToken |
| 1368 | + ] |
| 1369 | + ]; |
| 1370 | + |
| 1371 | + $address = current($customer->getAddresses())->getData(); |
| 1372 | + $newCustomerDataObject = [ |
| 1373 | + 'email' => $customer->getEmail(), |
| 1374 | + 'firstname' => $customer->getFirstname(), |
| 1375 | + 'lastname' => $customer->getLastname(), |
| 1376 | + 'addresses' => [ |
| 1377 | + [ |
| 1378 | + 'region' => [ |
| 1379 | + 'region_code' => $address['region_code'], |
| 1380 | + 'region' => $address['region'], |
| 1381 | + 'region_id' => $address['region_id'], |
| 1382 | + ], |
| 1383 | + 'country_id' => $address['country_id'], |
| 1384 | + 'street' => [$address['street']], |
| 1385 | + 'telephone' => $address['telephone'], |
| 1386 | + 'postcode' => $address['postcode'], |
| 1387 | + 'city' => $address['city'], |
| 1388 | + 'firstname' => $address['firstname'], |
| 1389 | + 'lastname' => $address['lastname'], |
| 1390 | + 'default_shipping' => true, |
| 1391 | + 'default_billing' => true |
| 1392 | + ] |
| 1393 | + ] |
| 1394 | + ]; |
| 1395 | + |
| 1396 | + $requestData['customer'] = TESTS_WEB_API_ADAPTER === self::ADAPTER_REST |
| 1397 | + ? $newCustomerDataObject |
| 1398 | + : array_merge([Customer::ID => $customer->getId()], $newCustomerDataObject); |
| 1399 | + |
| 1400 | + $response = $this->_webApiCall($serviceInfo, $requestData); |
| 1401 | + $this->assertIsArray($response); |
| 1402 | + $this->assertArrayHasKey('addresses', $response); |
| 1403 | + } |
1300 | 1404 | }
|
0 commit comments