ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\Api\Search;
|
||||
|
||||
use Magento\TestFramework\TestCase\WebapiAbstract;
|
||||
|
||||
class SearchTest extends WebapiAbstract
|
||||
{
|
||||
const SERVICE_NAME = 'searchV1';
|
||||
const SERVICE_VERSION = 'V1';
|
||||
const RESOURCE_PATH = '/V1/search';
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
|
||||
* @covers \Magento\Framework\Search\Search::search
|
||||
*/
|
||||
public function testCatalogSearch()
|
||||
{
|
||||
$searchCriteria = [
|
||||
'searchCriteria' => [
|
||||
'request_name' => 'quick_search_container',
|
||||
'filter_groups' => [
|
||||
[
|
||||
'filters' => [
|
||||
[
|
||||
'field' => 'search_term',
|
||||
'value' => 'simple',
|
||||
'condition_type' => 'eq'
|
||||
],
|
||||
[
|
||||
'field' => 'price_dynamic_algorithm',
|
||||
'value' => 'auto',
|
||||
'condition_type' => 'eq'
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'page_size' => 300,
|
||||
'current_page' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
$serviceInfo = [
|
||||
'rest' => [
|
||||
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria),
|
||||
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
|
||||
],
|
||||
'soap' => [
|
||||
'service' => self::SERVICE_NAME,
|
||||
'serviceVersion' => self::SERVICE_VERSION,
|
||||
'operation' => self::SERVICE_NAME . 'Search',
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->_webApiCall($serviceInfo, $searchCriteria);
|
||||
|
||||
$this->assertArrayHasKey('search_criteria', $response);
|
||||
$this->assertArrayHasKey('total_count', $response);
|
||||
$this->assertArrayHasKey('items', $response);
|
||||
|
||||
$this->assertEquals($searchCriteria['searchCriteria'], $response['search_criteria']);
|
||||
$this->assertTrue($response['total_count'] > 0);
|
||||
$this->assertTrue(count($response['items']) > 0);
|
||||
|
||||
$this->assertNotNull($response['items'][0]['id']);
|
||||
$this->assertTrue(
|
||||
in_array(
|
||||
$response['items'][0]['custom_attributes'][0]['attribute_code'],
|
||||
[
|
||||
'score', // mysql
|
||||
'_score' // elasticsearch score
|
||||
]
|
||||
)
|
||||
);
|
||||
$this->assertTrue($response['items'][0]['custom_attributes'][0]['value'] > 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\Model\Entity;
|
||||
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Reflection\DataObjectProcessor;
|
||||
use Magento\TestFramework\Helper\Customer as CustomerHelper;
|
||||
|
||||
class HydratorTest extends \Magento\TestFramework\TestCase\WebapiAbstract
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var CustomerHelper
|
||||
*/
|
||||
protected $customerHelper;
|
||||
|
||||
/**
|
||||
* @var \Magento\Customer\Api\Data\CustomerInterface
|
||||
*/
|
||||
protected $customerData;
|
||||
|
||||
/**
|
||||
* @var DataObjectProcessor
|
||||
*/
|
||||
protected $dataObjectProcessor;
|
||||
|
||||
const PASSWORD = 'test@123';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_markTestAsRestOnly('Hydrator can be tested using REST adapter only');
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->customerHelper = $this->objectManager->get(CustomerHelper::class);
|
||||
$this->dataObjectProcessor = $this->objectManager->create(DataObjectProcessor::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Customer/_files/attribute_user_defined_custom_attribute.php
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
$serviceInfo = [
|
||||
'rest' => [
|
||||
'resourcePath' => '/V1/TestModuleDefaultHydrator',
|
||||
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
|
||||
]
|
||||
];
|
||||
$requestData = ['customer' => $this->generateCustomerData(), 'password' => self::PASSWORD];
|
||||
$expectedData = $this->_webApiCall($serviceInfo, $requestData);
|
||||
|
||||
$customerId = $expectedData['id'];
|
||||
$actualData = $this->loadCustomerViaWebApi($customerId);
|
||||
$this->validateCustomerData($expectedData, $actualData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Customer/_files/attribute_user_defined_custom_attribute.php
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
$fixtureCustomerId = 1;
|
||||
|
||||
$serviceInfo = [
|
||||
'rest' => [
|
||||
'resourcePath' => "/V1/TestModuleDefaultHydrator/{$fixtureCustomerId}",
|
||||
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
|
||||
]
|
||||
];
|
||||
|
||||
$expectedData = $this->_webApiCall($serviceInfo, ['customer' => $this->generateCustomerData()]);
|
||||
$actualData = $this->loadCustomerViaWebApi($fixtureCustomerId);
|
||||
$this->validateCustomerData($expectedData, $actualData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
$fixtureCustomerId = 1;
|
||||
$serviceInfo = [
|
||||
'rest' => [
|
||||
'resourcePath' => '/V1/TestModuleDefaultHydrator/' . $fixtureCustomerId,
|
||||
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE,
|
||||
]
|
||||
];
|
||||
|
||||
$isDeleted = $this->_webApiCall($serviceInfo);
|
||||
$this->assertTrue($isDeleted);
|
||||
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class);
|
||||
$this->expectException(NoSuchEntityException::class);
|
||||
$this->expectExceptionMessage("No such entity with customerId = {$fixtureCustomerId}");
|
||||
$customerRepository->getById($fixtureCustomerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate customer data.
|
||||
*
|
||||
* @param array $expectedData
|
||||
* @param array $actualData
|
||||
*/
|
||||
private function validateCustomerData($expectedData, $actualData)
|
||||
{
|
||||
unset(
|
||||
$actualData['addresses'][0]['region_id'],
|
||||
$actualData['addresses'][0]['id'],
|
||||
$actualData['addresses'][1]['region_id'],
|
||||
$actualData['addresses'][1]['id'],
|
||||
$expectedData['addresses'][0]['default_shipping'],
|
||||
$expectedData['addresses'][0]['default_billing'],
|
||||
$expectedData['addresses'][1]['default_shipping'],
|
||||
$expectedData['addresses'][1]['default_billing'],
|
||||
$expectedData['created_at'],
|
||||
$expectedData['updated_at'],
|
||||
$actualData['created_at'],
|
||||
$actualData['updated_at'],
|
||||
$actualData['disable_auto_group_change']
|
||||
);
|
||||
|
||||
$this->assertEquals($expectedData, $actualData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function generateCustomerData()
|
||||
{
|
||||
$customer = $this->customerHelper->createSampleCustomerDataObject();
|
||||
|
||||
/** @var \Magento\TestModuleDefaultHydrator\Api\Data\ExtensionAttributeInterface $extensionAttribute */
|
||||
$extensionAttribute = $this->objectManager->create(
|
||||
\Magento\TestModuleDefaultHydrator\Api\Data\ExtensionAttributeInterface::class
|
||||
);
|
||||
$extensionAttribute->setValue('extension attribute value');
|
||||
|
||||
/** @var \Magento\Customer\Api\Data\CustomerExtensionInterface $customerExtension */
|
||||
$customerExtension = $this->objectManager->create(
|
||||
\Magento\Customer\Api\Data\CustomerExtension::class
|
||||
);
|
||||
$customerExtension->setExtensionAttribute($extensionAttribute);
|
||||
$customer->setExtensionAttributes($customerExtension);
|
||||
$customer->setCustomAttribute('custom_attribute1', 'custom attribute value');
|
||||
|
||||
$customerData = $this->dataObjectProcessor->buildOutputDataArray(
|
||||
$customer,
|
||||
\Magento\Customer\Api\Data\CustomerInterface::class
|
||||
);
|
||||
return $customerData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customerId
|
||||
* @return array
|
||||
*/
|
||||
private function loadCustomerViaWebApi($customerId)
|
||||
{
|
||||
$serviceInfo = [
|
||||
'rest' => [
|
||||
'resourcePath' => '/V1/TestModuleDefaultHydrator/' . $customerId,
|
||||
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
|
||||
]
|
||||
];
|
||||
$customerData = $this->_webApiCall($serviceInfo);
|
||||
return $customerData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
namespace Magento\Framework\Stdlib;
|
||||
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\HttpClient\CurlClientWithCookies;
|
||||
|
||||
/**
|
||||
* End to end test of the Cookie Manager, using curl.
|
||||
*
|
||||
* Uses controllers in TestModule1 to set and delete cookies and verify 'Set-Cookie' headers that come back.
|
||||
*/
|
||||
class CookieManagerTest extends \Magento\TestFramework\TestCase\WebapiAbstract
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $cookieTesterUrl = 'testmoduleone/CookieTester';
|
||||
|
||||
/** @var CurlClientWithCookies */
|
||||
protected $curlClient;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->curlClient = $objectManager->get(
|
||||
\Magento\TestFramework\TestCase\HttpClient\CurlClientWithCookies::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a sensitive Cookie and delete it.
|
||||
*
|
||||
*/
|
||||
public function testSensitiveCookie()
|
||||
{
|
||||
$url = $this->cookieTesterUrl . '/SetSensitiveCookie';
|
||||
$cookieParams =
|
||||
[
|
||||
'cookie_name' => 'test-sensitive-cookie',
|
||||
'cookie_value' => 'test-sensitive-cookie-value',
|
||||
];
|
||||
$response = $this->curlClient->get($url, $cookieParams);
|
||||
|
||||
$cookie = $this->findCookie($cookieParams['cookie_name'], $response['cookies']);
|
||||
$this->assertNotNull($cookie);
|
||||
$this->assertEquals($cookieParams['cookie_name'], $cookie['name']);
|
||||
$this->assertEquals($cookieParams['cookie_value'], $cookie['value']);
|
||||
$this->assertFalse(isset($cookie['domain']));
|
||||
$this->assertFalse(isset($cookie['path']));
|
||||
$this->assertEquals('true', $cookie['httponly']);
|
||||
$this->assertFalse(isset($cookie['secure']));
|
||||
$this->assertFalse(isset($cookie['max-age']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a public cookie
|
||||
*
|
||||
*/
|
||||
public function testPublicCookieNameValue()
|
||||
{
|
||||
$url = $this->cookieTesterUrl . '/SetPublicCookie';
|
||||
$cookieParams =
|
||||
[
|
||||
'cookie_name' => 'test-cookie',
|
||||
'cookie_value' => 'test-cookie-value',
|
||||
];
|
||||
|
||||
$response = $this->curlClient->get($url, $cookieParams);
|
||||
|
||||
$cookie = $this->findCookie($cookieParams['cookie_name'], $response['cookies']);
|
||||
$this->assertNotNull($cookie);
|
||||
$this->assertEquals($cookieParams['cookie_name'], $cookie['name']);
|
||||
$this->assertEquals($cookieParams['cookie_value'], $cookie['value']);
|
||||
$this->assertFalse(isset($cookie['domain']));
|
||||
$this->assertFalse(isset($cookie['path']));
|
||||
$this->assertFalse(isset($cookie['httponly']));
|
||||
$this->assertFalse(isset($cookie['secure']));
|
||||
$this->assertFalse(isset($cookie['max-age']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a public cookie
|
||||
*
|
||||
*/
|
||||
public function testPublicCookieAll()
|
||||
{
|
||||
$url = $this->cookieTesterUrl . '/SetPublicCookie';
|
||||
$cookieParams =
|
||||
[
|
||||
'cookie_name' => 'test-cookie',
|
||||
'cookie_value' => 'test-cookie-value',
|
||||
'cookie_domain' => 'www.example.com',
|
||||
'cookie_path' => '/test/path',
|
||||
'cookie_httponly' => 'true',
|
||||
'cookie_secure' => 'true',
|
||||
'cookie_duration' => '600',
|
||||
];
|
||||
|
||||
$response = $this->curlClient->get($url, $cookieParams);
|
||||
|
||||
$cookie = $this->findCookie($cookieParams['cookie_name'], $response['cookies']);
|
||||
$this->assertNotNull($cookie);
|
||||
$this->assertEquals($cookieParams['cookie_name'], $cookie['name']);
|
||||
$this->assertEquals($cookieParams['cookie_value'], $cookie['value']);
|
||||
$this->assertEquals($cookieParams['cookie_domain'], $cookie['domain']);
|
||||
$this->assertEquals($cookieParams['cookie_path'], $cookie['path']);
|
||||
$this->assertEquals($cookieParams['cookie_httponly'], $cookie['httponly']);
|
||||
$this->assertEquals($cookieParams['cookie_secure'], $cookie['secure']);
|
||||
if (isset($cookie['max-age'])) {
|
||||
$this->assertEquals($cookieParams['cookie_duration'], $cookie['max-age']);
|
||||
}
|
||||
$this->assertTrue(isset($cookie['expires']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cookie
|
||||
*
|
||||
*/
|
||||
public function testDeleteCookie()
|
||||
{
|
||||
$url = $this->cookieTesterUrl . '/DeleteCookie';
|
||||
$cookieParams =
|
||||
[
|
||||
'cookie_name' => 'test-cookie',
|
||||
'cookie_value' => 'test-cookie-value',
|
||||
];
|
||||
|
||||
$response = $this->curlClient->get(
|
||||
$url,
|
||||
$cookieParams,
|
||||
['Cookie: test-cookie=test-cookie-value; anothertestcookie=anothertestcookievalue']
|
||||
);
|
||||
|
||||
$cookie = $this->findCookie($cookieParams['cookie_name'], $response['cookies']);
|
||||
$this->assertNotNull($cookie);
|
||||
$this->assertEquals($cookieParams['cookie_name'], $cookie['name']);
|
||||
$this->assertEquals('deleted', $cookie['value']);
|
||||
$this->assertFalse(isset($cookie['domain']));
|
||||
$this->assertFalse(isset($cookie['path']));
|
||||
$this->assertFalse(isset($cookie['httponly']));
|
||||
$this->assertFalse(isset($cookie['secure']));
|
||||
if (isset($cookie['max-age'])) {
|
||||
$this->assertEquals(0, $cookie['max-age']);
|
||||
}
|
||||
$this->assertEquals(
|
||||
date('D, j-M-o H:i:s T', strtotime('Thu, 01-Jan-1970 00:00:01 GMT')),
|
||||
date('D, j-M-o H:i:s T', strtotime($cookie['expires']))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find cookie with given name in the list of cookies
|
||||
*
|
||||
* @param string $cookieName
|
||||
* @param array $cookies
|
||||
* @return $cookie|null
|
||||
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
|
||||
*/
|
||||
private function findCookie($cookieName, $cookies)
|
||||
{
|
||||
foreach ($cookies as $cookieIndex => $cookie) {
|
||||
if ($cookie['name'] === $cookieName) {
|
||||
return $cookie;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user