/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerSharingOptionsTest.php
212 строк
6 KB
Raj Mohan R
AC-16236::Upgrade Core Test Framework to PHPUnit 12 and Migrate from PHPUnit 10
11 фев 2026, 13:51
11 фев 2026, 13:51
152ed41
Код
Авторство
О чём код?
<?php /** * Copyright 2020 Adobe * All Rights Reserved. */ declare(strict_types=1); namespace Magento\Customer\Api; use Magento\Customer\Api\Data\CustomerInterface; use Magento\Customer\Model\CustomerRegistry; use Magento\Framework\Registry; use Magento\Framework\Webapi\Rest\Request; use Magento\Integration\Api\CustomerTokenServiceInterface; use Magento\Integration\Model\Oauth\Token as TokenModel; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\Helper\Customer as CustomerHelper; use Magento\TestFramework\TestCase\WebapiAbstract; use PHPUnit\Framework\Attributes\DataProvider; /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Store/_files/second_website_with_two_stores.php */ class CustomerSharingOptionsTest extends WebapiAbstract { public const RESOURCE_PATH = '/V1/customers/me'; public const REPO_SERVICE = 'customerCustomerRepositoryV1'; public const SERVICE_VERSION = 'V1'; /** * @var CustomerRepositoryInterface */ private $customerRepository; /** * @var CustomerRegistry */ private $customerRegistry; /** * @var CustomerHelper */ private $customerHelper; /** * @var TokenModel */ private $token; /** * @var CustomerInterface */ private $customerData; /** * @var CustomerTokenServiceInterface */ private $tokenService; /** * Execute per test initialization. */ public function setUp(): void { $this->customerRegistry = Bootstrap::getObjectManager()->get( \Magento\Customer\Model\CustomerRegistry::class ); $this->customerRepository = Bootstrap::getObjectManager()->get( CustomerRepositoryInterface::class, ['customerRegistry' => $this->customerRegistry] ); $this->customerHelper = new CustomerHelper($this->name()); $this->customerData = $this->customerHelper->createSampleCustomer(); $this->tokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class); // get token $this->resetTokenForCustomerSampleData(); } /** * Ensure that fixture customer and his addresses are deleted. */ public function tearDown(): void { $this->customerRepository = null; /** @var Registry $registry */ $registry = Bootstrap::getObjectManager()->get(Registry::class); $registry->unregister('isSecureArea'); $registry->register('isSecureArea', true); $registry->unregister('isSecureArea'); $registry->register('isSecureArea', false); parent::tearDown(); } /** * @param string $storeCode * @param bool $expectingException * @magentoConfigFixture default_store customer/account_share/scope 1 */ #[DataProvider('getCustomerDataWebsiteScopeDataProvider')] public function testGetCustomerDataWebsiteScope(string $storeCode, bool $expectingException) { $this->_markTestAsRestOnly('SOAP is difficult to generate exception messages, inconsistencies in WSDL'); $this->processGetCustomerData($storeCode, $expectingException); } /** * @param string $storeCode * @param bool $expectingException * @magentoConfigFixture customer/account_share/scope 0 */ #[DataProvider('getCustomerDataGlobalScopeDataProvider')] public function testGetCustomerDataGlobalScope(string $storeCode, bool $expectingException) { $this->processGetCustomerData($storeCode, $expectingException); } /** * @param string $storeCode * @param bool $expectingException */ private function processGetCustomerData(string $storeCode, bool $expectingException) { $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH, 'httpMethod' => Request::HTTP_METHOD_GET, 'token' => $this->token, ], 'soap' => [ 'service' => self::REPO_SERVICE, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::REPO_SERVICE . 'GetSelf', 'token' => $this->token ] ]; $arguments = []; if (TESTS_WEB_API_ADAPTER === 'soap') { $arguments['customerId'] = 0; } if ($expectingException) { self::expectException(\Exception::class); self::expectExceptionMessage("The consumer isn't authorized to access %resources."); } $this->_webApiCall($serviceInfo, $arguments, null, $storeCode); } /** * Data provider for testGetCustomerDataWebsiteScope. * * @return array */ public static function getCustomerDataWebsiteScopeDataProvider(): array { return [ 'Default Store View' => [ 'default', // storeCode false // expectingException ], 'Custom Store View' => [ 'fixture_second_store', // storeCode true // expectingException ] ]; } /** * Data provider for testGetCustomerDataGlobalScope. * * @return array */ public static function getCustomerDataGlobalScopeDataProvider(): array { return [ 'Default Store View' => [ 'default', // storeCode false // expectingException ], 'Custom Store View' => [ 'fixture_second_store', // storeCode false // expectingException ] ]; } /** * Sets the test's access token for the created customer sample data */ private function resetTokenForCustomerSampleData() { $this->resetTokenForCustomer($this->customerData[CustomerInterface::EMAIL], 'test@123'); } /** * Sets the test's access token for a particular username and password. * * @param string $username * @param string $password */ private function resetTokenForCustomer($username, $password) { $this->token = $this->tokenService->createCustomerAccessToken($username, $password); $this->customerRegistry->remove($this->customerRepository->get($username)->getId()); } }