ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\CatalogGraphQl;
|
||||
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test class to verify category uid, available as product aggregation type
|
||||
*/
|
||||
class CategoryTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* Test for checking if graphQL query for category uid is available as product aggregation type
|
||||
*
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
|
||||
*/
|
||||
public function testCheckCategoryUidAsAggregation(): void
|
||||
{
|
||||
$query = $this->getSearchQueryWithSCategoryUID();
|
||||
$response = $this->graphQlQuery($query);
|
||||
$this->assertNotEmpty($response['products']);
|
||||
$this->assertEquals(1, count($response['products']['aggregations']));
|
||||
$this->assertNotEmpty($response['products']['aggregations']);
|
||||
$this->assertEquals('price', $response['products']['aggregations'][0]['attribute_code']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare search query with suggestions
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getSearchQueryWithSCategoryUID() : string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
products(filter: {category_uid: {eq: "Mg=="}}) {
|
||||
aggregations {
|
||||
__typename
|
||||
attribute_code
|
||||
}
|
||||
__typename
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\CatalogGraphQl;
|
||||
|
||||
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
|
||||
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
|
||||
use Magento\Eav\Model\Entity\Attribute\FrontendLabel;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Store\Test\Fixture\Store as StoreFixture;
|
||||
use Magento\TestFramework\Fixture\DataFixture;
|
||||
use Magento\TestFramework\Fixture\DataFixtureStorage;
|
||||
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test class to verify the translated price attribute option label based on the store view.
|
||||
*/
|
||||
class PriceAttributeOptionsLabelTranslateTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var DataFixtureStorage
|
||||
*/
|
||||
private $fixture;
|
||||
|
||||
/**
|
||||
* Setup
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->fixture = DataFixtureStorageManager::getStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
#[
|
||||
DataFixture(
|
||||
StoreFixture::class,
|
||||
[
|
||||
'code' => 'view2',
|
||||
'name' => 'view2'
|
||||
],
|
||||
as: 'view2'
|
||||
),
|
||||
DataFixture(
|
||||
ProductFixture::class,
|
||||
[
|
||||
'sku' => 'simple'
|
||||
],
|
||||
as: 'product'
|
||||
),
|
||||
]
|
||||
|
||||
public function testValidatePriceAttributeOptionsLabelTranslationForSecondStoreView(): void
|
||||
{
|
||||
$attributeCode = 'price';
|
||||
$secondStoreViewFixtureName = 'view2';
|
||||
$attributeStoreFrontLabelForSecondStoreView = 'Price View2';
|
||||
|
||||
//Updating price attribute storefront option label for the second store view.
|
||||
$attributeRepository = $this->objectManager->create(ProductAttributeRepositoryInterface::class);
|
||||
|
||||
$priceAttribute = $attributeRepository->get($attributeCode);
|
||||
|
||||
$frontendLabelAttribute = $this->objectManager->get(FrontendLabel::class);
|
||||
$frontendLabelAttribute->setStoreId(
|
||||
$this->fixture->get($secondStoreViewFixtureName)->getId()
|
||||
);
|
||||
$frontendLabelAttribute->setLabel($attributeStoreFrontLabelForSecondStoreView);
|
||||
|
||||
$frontendLabels = $priceAttribute->getFrontendLabels();
|
||||
$frontendLabels[] = $frontendLabelAttribute;
|
||||
|
||||
$priceAttribute->setFrontendLabels($frontendLabels);
|
||||
$attributeRepository->save($priceAttribute);
|
||||
|
||||
$query = $this->getProductsQueryWithAggregations();
|
||||
$headers = ['Store' => $secondStoreViewFixtureName];
|
||||
$response = $this->graphQlQuery($query, [], '', $headers);
|
||||
$this->assertNotEmpty($response['products']['aggregations']);
|
||||
$aggregationAttributes = $response['products']['aggregations'];
|
||||
$priceAttributeOptionLabel = '';
|
||||
|
||||
foreach ($aggregationAttributes as $attribute) {
|
||||
if ($attribute['attribute_code'] === $attributeCode) {
|
||||
$priceAttributeOptionLabel = $attribute['label'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals($priceAttributeOptionLabel, 'Price View2');
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare products query with aggregations
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getProductsQueryWithAggregations() : string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
products(
|
||||
currentPage: 1,
|
||||
pageSize:12,
|
||||
filter: {
|
||||
sku: {
|
||||
eq: "simple"
|
||||
}
|
||||
}, sort: {
|
||||
price: ASC
|
||||
}) {
|
||||
|
||||
aggregations {
|
||||
options {
|
||||
count,
|
||||
label,
|
||||
value
|
||||
}, attribute_code, count, label
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\CatalogGraphQl;
|
||||
|
||||
use Magento\GraphQl\GetCustomerAuthenticationHeader;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test class to verify catalog price rule is applied for
|
||||
* tier prices for different customer groups.
|
||||
*/
|
||||
class PriceRangeTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager|null
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var GetCustomerAuthenticationHeader
|
||||
*/
|
||||
private $getCustomerAuthenticationHeader;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->getCustomerAuthenticationHeader = $this->objectManager->get(GetCustomerAuthenticationHeader::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Store/_files/second_website_with_two_stores.php
|
||||
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_in_multiple_websites.php
|
||||
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_in_multiple_websites_with_special_price.php
|
||||
*/
|
||||
public function testMinimalPriceForConfigurableProductWithSpecialPrice() : void
|
||||
{
|
||||
$headerMapFirstStore['Store'] = 'default';
|
||||
$headerMapSecondStore['Store'] = 'fixture_second_store';
|
||||
$query = $this->getProductsBySkuQuery();
|
||||
$responseForFirstWebsite = $this->graphQlQuery($query, [], '', $headerMapFirstStore);
|
||||
$responseForSecondWebsite = $this->graphQlQuery($query, [], '', $headerMapSecondStore);
|
||||
|
||||
$this->assertNotEmpty($responseForFirstWebsite['products']);
|
||||
$priceRange = $responseForFirstWebsite['products']['items'][0]['price_range'];
|
||||
$this->assertEquals(10, $priceRange['minimum_price']['regular_price']['value']);
|
||||
$this->assertEquals(10, $priceRange['minimum_price']['final_price']['value']);
|
||||
$this->assertEquals(10, $priceRange['maximum_price']['regular_price']['value']);
|
||||
$this->assertEquals(10, $priceRange['maximum_price']['final_price']['value']);
|
||||
|
||||
$this->assertNotEmpty($responseForSecondWebsite['products']);
|
||||
$priceRange = $responseForSecondWebsite['products']['items'][0]['price_range'];
|
||||
$this->assertEquals(20, $priceRange['minimum_price']['regular_price']['value']);
|
||||
$this->assertEquals(4, $priceRange['minimum_price']['final_price']['value']);
|
||||
$this->assertEquals(20, $priceRange['maximum_price']['regular_price']['value']);
|
||||
$this->assertEquals(4, $priceRange['maximum_price']['final_price']['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for checking if catalog rule price has been applied for all customer group
|
||||
*
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
|
||||
* @magentoApiDataFixture Magento/CatalogRule/_files/catalog_rule_25_customer_group_all.php
|
||||
*/
|
||||
public function testCheckIfCatalogRuleIsAppliedForTierPriceForAllGroups(): void
|
||||
{
|
||||
$productSku = 'simple';
|
||||
$query = $this->getProductSearchQuery($productSku);
|
||||
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$this->assertNotEmpty($response['products']);
|
||||
$priceRange = $response['products']['items'][0]['price_range'];
|
||||
$this->assertEquals(10, $priceRange['minimum_price']['regular_price']['value']);
|
||||
$this->assertEquals(7.5, $priceRange['minimum_price']['final_price']['value']);
|
||||
$this->assertEquals(2.5, $priceRange['minimum_price']['discount']['amount_off']);
|
||||
$this->assertEquals(25, $priceRange['minimum_price']['discount']['percent_off']);
|
||||
$this->assertEquals(10, $priceRange['maximum_price']['regular_price']['value']);
|
||||
$this->assertEquals(7.5, $priceRange['maximum_price']['final_price']['value']);
|
||||
$this->assertEquals(2.5, $priceRange['maximum_price']['discount']['amount_off']);
|
||||
$this->assertEquals(25, $priceRange['maximum_price']['discount']['percent_off']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for checking if catalog rule price has been applied for registered customer
|
||||
*
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/simple_product_with_tier_prices_for_logged_in_group.php
|
||||
* @magentoApiDataFixture Magento/CatalogRule/_files/catalog_rule_50_registered_customer_group.php
|
||||
*/
|
||||
public function testCheckIfCatalogRuleIsAppliedForTierPriceForRegisteredCustomer(): void
|
||||
{
|
||||
$productSku = 'simple';
|
||||
$query = $this->getProductSearchQuery($productSku);
|
||||
$response = $this->graphQlQuery(
|
||||
$query,
|
||||
[],
|
||||
'',
|
||||
$this->getCustomerAuthenticationHeader->execute('customer@example.com', 'password')
|
||||
);
|
||||
|
||||
$this->assertNotEmpty($response['products']);
|
||||
$priceRange = $response['products']['items'][0]['price_range'];
|
||||
$this->assertEquals(10, $priceRange['minimum_price']['regular_price']['value']);
|
||||
$this->assertEquals(5, $priceRange['minimum_price']['final_price']['value']);
|
||||
$this->assertEquals(5, $priceRange['minimum_price']['discount']['amount_off']);
|
||||
$this->assertEquals(50, $priceRange['minimum_price']['discount']['percent_off']);
|
||||
$this->assertEquals(10, $priceRange['maximum_price']['regular_price']['value']);
|
||||
$this->assertEquals(5, $priceRange['maximum_price']['final_price']['value']);
|
||||
$this->assertEquals(5, $priceRange['maximum_price']['discount']['amount_off']);
|
||||
$this->assertEquals(50, $priceRange['maximum_price']['discount']['percent_off']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for checking if catalog rule price has been applied for guest
|
||||
*
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/simple_product_with_tier_prices_for_not_logged_in_group.php
|
||||
* @magentoApiDataFixture Magento/CatalogRule/_files/catalog_rule_10_off_not_logged.php
|
||||
*/
|
||||
public function testCheckIfCatalogRuleIsAppliedForTierPriceForGuest(): void
|
||||
{
|
||||
$productSku = 'simple';
|
||||
$query = $this->getProductSearchQuery($productSku);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$this->assertNotEmpty($response['products']);
|
||||
$priceRange = $response['products']['items'][0]['price_range'];
|
||||
$this->assertEquals(10, $priceRange['minimum_price']['regular_price']['value']);
|
||||
$this->assertEquals(9, $priceRange['minimum_price']['final_price']['value']);
|
||||
$this->assertEquals(1, $priceRange['minimum_price']['discount']['amount_off']);
|
||||
$this->assertEquals(10, $priceRange['minimum_price']['discount']['percent_off']);
|
||||
$this->assertEquals(10, $priceRange['maximum_price']['regular_price']['value']);
|
||||
$this->assertEquals(9, $priceRange['maximum_price']['final_price']['value']);
|
||||
$this->assertEquals(1, $priceRange['maximum_price']['discount']['amount_off']);
|
||||
$this->assertEquals(10, $priceRange['maximum_price']['discount']['percent_off']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to make sure tax amount is displayed correctly for a logged-in user
|
||||
*
|
||||
* @magentoConfigFixture default_store tax/display/type 2
|
||||
*
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer_shipping_address_36104.php
|
||||
* @magentoApiDataFixture Magento/Tax/_files/tax_rule_postal_36104.php
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
|
||||
*/
|
||||
public function testTaxDisplayAppliesToCustomer(): void
|
||||
{
|
||||
$productSku = 'simple';
|
||||
$query = $this->getProductSearchQuery($productSku);
|
||||
$response = $this->graphQlQuery(
|
||||
$query,
|
||||
[],
|
||||
'',
|
||||
$this->getCustomerAuthenticationHeader->execute('customer@example.com', 'password')
|
||||
);
|
||||
|
||||
$this->assertNotEmpty($response['products']);
|
||||
$priceRange = $response['products']['items'][0]['price_range'];
|
||||
$this->assertEquals(10.75, round($priceRange['minimum_price']['regular_price']['value'], 2));
|
||||
$this->assertEquals(10.75, round($priceRange['minimum_price']['final_price']['value'], 2));
|
||||
$this->assertEquals(10.75, round($priceRange['maximum_price']['regular_price']['value'], 2));
|
||||
$this->assertEquals(10.75, round($priceRange['maximum_price']['final_price']['value'], 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to make sure tax rule is not applied in display for guest
|
||||
*
|
||||
* @magentoConfigFixture default_store tax/display/type 2
|
||||
*
|
||||
* @magentoApiDataFixture Magento/Tax/_files/tax_rule_postal_36104.php
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
|
||||
*/
|
||||
public function testTaxDisplayDoesNotApplyToGuest(): void
|
||||
{
|
||||
$productSku = 'simple';
|
||||
$query = $this->getProductSearchQuery($productSku);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$this->assertNotEmpty($response['products']);
|
||||
$priceRange = $response['products']['items'][0]['price_range'];
|
||||
$this->assertEquals(10, $priceRange['minimum_price']['regular_price']['value']);
|
||||
$this->assertEquals(10, $priceRange['minimum_price']['final_price']['value']);
|
||||
$this->assertEquals(10, $priceRange['maximum_price']['regular_price']['value']);
|
||||
$this->assertEquals(10, $priceRange['maximum_price']['final_price']['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to make sure tax rule is applied for customer group
|
||||
*
|
||||
* @magentoConfigFixture default_store tax/display/type 2
|
||||
*
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer_with_group_and_address.php
|
||||
* @magentoApiDataFixture Magento/Tax/_files/tax_class_customer_group.php
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
|
||||
*/
|
||||
public function testTaxDisplayAppliesToCustomerGroup()
|
||||
{
|
||||
$productSku = 'simple';
|
||||
$query = $this->getProductSearchQuery($productSku);
|
||||
$response = $this->graphQlQuery(
|
||||
$query,
|
||||
[],
|
||||
'',
|
||||
$this->getCustomerAuthenticationHeader->execute('customer@example.com', 'password')
|
||||
);
|
||||
|
||||
$this->assertNotEmpty($response['products']);
|
||||
$priceRange = $response['products']['items'][0]['price_range'];
|
||||
$this->assertEquals(10.75, round($priceRange['minimum_price']['regular_price']['value'], 2));
|
||||
$this->assertEquals(10.75, round($priceRange['minimum_price']['final_price']['value'], 2));
|
||||
$this->assertEquals(10.75, round($priceRange['maximum_price']['regular_price']['value'], 2));
|
||||
$this->assertEquals(10.75, round($priceRange['maximum_price']['final_price']['value'], 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to make sure tax rule is not applied for a customer in the wrong group
|
||||
*
|
||||
* @magentoConfigFixture default_store tax/display/type 2
|
||||
*
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer_with_group_and_address.php
|
||||
* @magentoApiDataFixture Magento/Customer/_files/second_customer_with_group_and_address.php
|
||||
* @magentoApiDataFixture Magento/Tax/_files/tax_class_customer_group.php
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
|
||||
*/
|
||||
public function testTaxDisplayDoesNotApplyToWrongCustomerGroup(): void
|
||||
{
|
||||
$productSku = 'simple';
|
||||
$query = $this->getProductSearchQuery($productSku);
|
||||
$response = $this->graphQlQuery(
|
||||
$query,
|
||||
[],
|
||||
'',
|
||||
$this->getCustomerAuthenticationHeader->execute('secondcustomer@example.com', 'password')
|
||||
);
|
||||
|
||||
$this->assertNotEmpty($response['products']);
|
||||
$priceRange = $response['products']['items'][0]['price_range'];
|
||||
$this->assertEquals(10, $priceRange['minimum_price']['regular_price']['value']);
|
||||
$this->assertEquals(10, $priceRange['minimum_price']['final_price']['value']);
|
||||
$this->assertEquals(10, $priceRange['maximum_price']['regular_price']['value']);
|
||||
$this->assertEquals(10, $priceRange['maximum_price']['final_price']['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a query which user filter for product sku and returns price_tiers
|
||||
*
|
||||
* @param string $productSku
|
||||
* @return string
|
||||
*/
|
||||
private function getProductSearchQuery(string $productSku): string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
products(filter: {sku: {eq: "{$productSku}"}}) {
|
||||
items {
|
||||
name
|
||||
sku
|
||||
price_range {
|
||||
minimum_price {
|
||||
regular_price {
|
||||
value
|
||||
currency
|
||||
}
|
||||
final_price {
|
||||
value
|
||||
currency
|
||||
}
|
||||
discount {
|
||||
amount_off
|
||||
percent_off
|
||||
}
|
||||
}
|
||||
maximum_price {
|
||||
regular_price {
|
||||
value
|
||||
currency
|
||||
}
|
||||
final_price {
|
||||
value
|
||||
currency
|
||||
}
|
||||
discount {
|
||||
amount_off
|
||||
percent_off
|
||||
}
|
||||
}
|
||||
}
|
||||
price_tiers{
|
||||
discount{
|
||||
amount_off
|
||||
percent_off
|
||||
}
|
||||
final_price{
|
||||
value
|
||||
}
|
||||
quantity
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a query which user filter for product sku and returns price_range
|
||||
*
|
||||
* @param string $productSku
|
||||
* @return string
|
||||
*/
|
||||
private function getProductsBySkuQuery() : string
|
||||
{
|
||||
return <<<QUERY
|
||||
query getProductsBySku {
|
||||
products(filter: { sku: { eq: "configurable" } }) {
|
||||
items {
|
||||
sku
|
||||
name
|
||||
price_range {
|
||||
minimum_price {
|
||||
regular_price {
|
||||
value
|
||||
currency
|
||||
}
|
||||
discount {
|
||||
amount_off
|
||||
percent_off
|
||||
}
|
||||
final_price {
|
||||
value
|
||||
currency
|
||||
}
|
||||
}
|
||||
maximum_price {
|
||||
regular_price {
|
||||
value
|
||||
currency
|
||||
}
|
||||
discount {
|
||||
amount_off
|
||||
percent_off
|
||||
}
|
||||
final_price {
|
||||
value
|
||||
currency
|
||||
}
|
||||
}
|
||||
}
|
||||
... on ConfigurableProduct {
|
||||
variants {
|
||||
product {
|
||||
sku
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\CatalogGraphQl;
|
||||
|
||||
use Magento\GraphQl\GetCustomerAuthenticationHeader;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test class to verify product search, used for GraphQL resolver
|
||||
* for configurable product returns only visible products.
|
||||
*/
|
||||
class ProductSearchTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager|null
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var GetCustomerAuthenticationHeader
|
||||
*/
|
||||
private $getCustomerAuthenticationHeader;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->getCustomerAuthenticationHeader = $this->objectManager->get(GetCustomerAuthenticationHeader::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for checking if graphQL query fpr configurable product returns
|
||||
* expected visible items
|
||||
*
|
||||
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_products_with_different_super_attribute.php
|
||||
*/
|
||||
public function testCheckIfConfigurableProductVisibilityReturnsExpectedItem(): void
|
||||
{
|
||||
$productName = 'Configurable Product';
|
||||
$productSku = 'configurable';
|
||||
$query = $this->getProductSearchQuery($productName, $productSku);
|
||||
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$this->assertNotEmpty($response['products']);
|
||||
$this->assertEquals(1, $response['products']['total_count']);
|
||||
$this->assertNotEmpty($response['products']['items']);
|
||||
$this->assertEquals($productName, $response['products']['items'][0]['name']);
|
||||
$this->assertEquals($productSku, $response['products']['items'][0]['sku']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a query which user filter for product sku and search by product name
|
||||
*
|
||||
* @param string $productName
|
||||
* @param string $productSku
|
||||
* @return string
|
||||
*/
|
||||
private function getProductSearchQuery(string $productName, string $productSku): string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
products(filter: {sku: {eq: "{$productSku}"}}, search: "$productName", sort: {}, pageSize: 200, currentPage: 1) {
|
||||
total_count
|
||||
page_info {
|
||||
total_pages
|
||||
current_page
|
||||
page_size
|
||||
}
|
||||
items {
|
||||
name
|
||||
sku
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/products_with_layered_navigation_attribute.php
|
||||
*/
|
||||
public function testSearchSuggestions() : void
|
||||
{
|
||||
$query = $this->getSearchQueryWithSuggestions();
|
||||
$response = $this->graphQlQuery($query);
|
||||
$this->assertNotEmpty($response['products']);
|
||||
$this->assertEmpty($response['products']['items']);
|
||||
$this->assertNotEmpty($response['products']['suggestions']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare search query with suggestions
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getSearchQueryWithSuggestions() : string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
products(
|
||||
search: "smiple"
|
||||
) {
|
||||
items {
|
||||
name
|
||||
sku
|
||||
}
|
||||
suggestions {
|
||||
search
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user