Skip to content

Commit 440c07b

Browse files
committed
MAGETWO-89246: Product visibility is not considered in search
- skipping tests until fixed
1 parent d463713 commit 440c07b

File tree

3 files changed

+196
-0
lines changed

3 files changed

+196
-0
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Magento\TestFramework\ObjectManager;
1818
use Magento\TestFramework\TestCase\GraphQlAbstract;
1919
use Magento\Catalog\Model\Product;
20+
use Magento\Framework\App\Config\ScopeConfigInterface;
21+
use Magento\Framework\DataObject;
2022

2123
/**
2224
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
@@ -1153,6 +1155,55 @@ public function testQueryWithNoSearchOrFilterArgumentException()
11531155
$this->graphQlQuery($query);
11541156
}
11551157

1158+
/**
1159+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
1160+
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products_with_few_out_of_stock.php
1161+
*/
1162+
public function testFilterProductsThatAreOutOfStockWithConfigSettings()
1163+
{
1164+
$this->markTestSkipped('Skipped until visibility honors config settings is fixed in MAGETWO-89246');
1165+
$query
1166+
=<<<QUERY
1167+
{
1168+
products(
1169+
filter:
1170+
{
1171+
sku:{like:"simple%"}
1172+
}
1173+
pageSize:20
1174+
1175+
)
1176+
{
1177+
items
1178+
{
1179+
sku
1180+
name
1181+
category_ids
1182+
}
1183+
total_count
1184+
1185+
}
1186+
}
1187+
QUERY;
1188+
/** @var \Magento\Config\Model\ResourceModel\Config $config */
1189+
$config = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class);
1190+
$config->saveConfig(
1191+
\Magento\CatalogInventory\Model\Configuration::XML_PATH_SHOW_OUT_OF_STOCK,
1192+
0,
1193+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
1194+
0
1195+
);
1196+
ObjectManager::getInstance()->get(\Magento\Framework\App\Cache::class)
1197+
->clean(\Magento\Framework\App\Config::CACHE_TAG);
1198+
$response = $this->graphQlQuery($query);
1199+
$responseObject = new DataObject($response);
1200+
self::assertEquals(
1201+
'simple_visible_in_stock',
1202+
$responseObject->getData('products/items/0/sku')
1203+
);
1204+
$this->assertEquals(1, $response['products']['total_count']);
1205+
}
1206+
11561207
/**
11571208
* Asserts the different fields of items returned after search query is executed
11581209
*
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
/** @var \Magento\Catalog\Model\Category $category */
9+
$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Category::class);
10+
$category->isObjectNew(true);
11+
$category->setId(
12+
300
13+
)->setCreatedAt(
14+
'2014-06-23 09:50:07'
15+
)->setName(
16+
'Category 300'
17+
)->setParentId(
18+
2
19+
)->setPath(
20+
'1/2/3'
21+
)->setLevel(
22+
2
23+
)->setAvailableSortBy(
24+
'name'
25+
)->setDefaultSortBy(
26+
'name'
27+
)->setIsActive(
28+
true
29+
)->setPosition(
30+
1
31+
)->setAvailableSortBy(
32+
['position']
33+
)->save();
34+
35+
/** @var $product \Magento\Catalog\Model\Product */
36+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
37+
$product->isObjectNew(true);
38+
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
39+
->setId(64)
40+
->setAttributeSetId(4)
41+
->setName('Simple Product OOS')
42+
->setSku('simple_oos')
43+
->setTaxClassId('none')
44+
->setDescription('description')
45+
->setShortDescription('short description')
46+
->setOptionsContainer('container1')
47+
->setMsrpDisplayActualPriceType(\Magento\Msrp\Model\Product\Attribute\Source\Type::TYPE_IN_CART)
48+
->setPrice(10)
49+
->setWeight(1)
50+
->setMetaTitle('meta title')
51+
->setMetaKeyword('meta keyword')
52+
->setMetaDescription('meta description')
53+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
54+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
55+
->setWebsiteIds([1])
56+
->setCateroryIds([])
57+
->setCategoryIds(
58+
[300])
59+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 0, 'is_qty_decimal' => 0, 'is_in_stock' => 0])
60+
->setSpecialPrice('5.99')
61+
->save();
62+
63+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
64+
$product->isObjectNew(true);
65+
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
66+
->setId(65)
67+
->setAttributeSetId(4)
68+
->setName('Simple Product Not Visible')
69+
->setSku('simple2_not_visible')
70+
->setTaxClassId('none')
71+
->setDescription('description')
72+
->setShortDescription('short description')
73+
->setOptionsContainer('container1')
74+
->setMsrpDisplayActualPriceType(\Magento\Msrp\Model\Product\Attribute\Source\Type::TYPE_ON_GESTURE)
75+
->setPrice(20)
76+
->setWeight(1)
77+
->setMetaTitle('meta title')
78+
->setMetaKeyword('meta keyword')
79+
->setMetaDescription('meta description')
80+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE)
81+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
82+
->setWebsiteIds([1])
83+
->setCategoryIds(
84+
[300])
85+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 50, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
86+
->setSpecialPrice('15.99')
87+
->save();
88+
89+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
90+
$product->isObjectNew(true);
91+
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
92+
->setId(66)
93+
->setAttributeSetId(4)
94+
->setName('Simple Product Visible and InStock')
95+
->setSku('simple_visible_in_stock')
96+
->setTaxClassId('none')
97+
->setDescription('description')
98+
->setShortDescription('short description')
99+
->setPrice(30)
100+
->setWeight(1)
101+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_CATALOG)
102+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
103+
->setWebsiteIds([1])
104+
->setCategoryIds(
105+
[300])
106+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 140, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
107+
->setSpecialPrice('25.99')
108+
->save();
109+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
9+
10+
/** @var \Magento\Framework\Registry $registry */
11+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
12+
13+
$registry->unregister('isSecureArea');
14+
$registry->register('isSecureArea', true);
15+
16+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
17+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
18+
19+
foreach (['simple_oos', 'simple2_not_visible', 'simple_visible_in_stock'] as $sku) {
20+
try {
21+
$product = $productRepository->get($sku, false, null, true);
22+
$productRepository->delete($product);
23+
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
24+
//Product already removed
25+
}
26+
}
27+
28+
/** @var $category \Magento\Catalog\Model\Category */
29+
$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Category::class);
30+
$category->load(300);
31+
if ($category->getId()) {
32+
$category->delete();
33+
}
34+
35+
$registry->unregister('isSecureArea');
36+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)