Skip to content

Commit 02ae037

Browse files
committed
MAGETWO-62858: [Backport] - When category has products that are not visible to catalog the pager still shows is this expected behavior? - for 2.0
1 parent 6fad45d commit 02ae037

File tree

6 files changed

+84
-16
lines changed

6 files changed

+84
-16
lines changed

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ protected function _renderFiltersBefore()
207207
[]
208208
);
209209

210-
$this->_totalRecords = $this->queryResponse->count();
211-
212210
if ($this->order && 'relevance' === $this->order['field']) {
213211
$this->getSelect()->order('search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
214212
}

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/ListTest.php

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ class ListTest extends \PHPUnit_Framework_TestCase
2020

2121
protected function setUp()
2222
{
23-
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\App\State')
23+
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)
2424
->setAreaCode('frontend');
2525
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
26-
'Magento\Framework\View\LayoutInterface'
26+
\Magento\Framework\View\LayoutInterface::class
2727
)->createBlock(
28-
'Magento\Catalog\Block\Product\ListProduct'
28+
\Magento\Catalog\Block\Product\ListProduct::class
2929
);
3030
}
3131

3232
public function testGetLayer()
3333
{
34-
$this->assertInstanceOf('Magento\Catalog\Model\Layer', $this->_block->getLayer());
34+
$this->assertInstanceOf(\Magento\Catalog\Model\Layer::class, $this->_block->getLayer());
3535
}
3636

3737
public function testGetLoadedProductCollection()
3838
{
3939
$this->_block->setShowRootCategory(true);
4040
$collection = $this->_block->getLoadedProductCollection();
41-
$this->assertInstanceOf('Magento\Catalog\Model\ResourceModel\Product\Collection', $collection);
41+
$this->assertInstanceOf(\Magento\Catalog\Model\ResourceModel\Product\Collection::class, $collection);
4242
/* Check that root category was defined for Layer as current */
4343
$this->assertEquals(2, $this->_block->getLayer()->getCurrentCategory()->getId());
4444
}
@@ -52,11 +52,11 @@ public function testGetLoadedProductCollection()
5252
public function testToolbarCoverage()
5353
{
5454
/** @var $parent \Magento\Catalog\Block\Product\ListProduct */
55-
$parent = $this->_getLayout()->createBlock('Magento\Catalog\Block\Product\ListProduct', 'parent');
55+
$parent = $this->_getLayout()->createBlock(\Magento\Catalog\Block\Product\ListProduct::class, 'parent');
5656

5757
/* Prepare toolbar block */
5858
$toolbar = $parent->getToolbarBlock();
59-
$this->assertInstanceOf('Magento\Catalog\Block\Product\ProductList\Toolbar', $toolbar, 'Default Toolbar');
59+
$this->assertInstanceOf(\Magento\Catalog\Block\Product\ProductList\Toolbar::class, $toolbar, 'Default Toolbar');
6060

6161
$parent->setChild('toolbar', $toolbar);
6262
/* In order to initialize toolbar collection block toHtml should be called before toolbar toHtml */
@@ -65,6 +65,29 @@ public function testToolbarCoverage()
6565
$this->assertNotEmpty($parent->getToolbarHtml(), 'Toolbar HTML'); /* toolbar for one simple product */
6666
}
6767

68+
/**
69+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
70+
* @magentoDataFixture Magento/Catalog/_files/product_simple_search_visibility.php
71+
* @covers \Magento\Catalog\Block\Product\ListProduct::toHtml
72+
*/
73+
public function testToolbarCoverageWithSearchOnlyProducts()
74+
{
75+
/** @var $parent \Magento\Catalog\Block\Product\ListProduct */
76+
$parent = $this->_getLayout()->createBlock(\Magento\Catalog\Block\Product\ListProduct::class, 'productList');
77+
78+
/* Prepare toolbar block */
79+
$toolbar = $parent->getToolbarBlock();
80+
81+
$parent->setChild('toolbar', $toolbar);
82+
/* In order to initialize toolbar collection block toHtml should be called */
83+
$this->assertEmpty($parent->toHtml(), 'Block HTML'); /* Template not specified */
84+
$this->assertEquals(
85+
1,
86+
$parent->getLoadedProductCollection()->getSize(),
87+
'Search only products are invisible in catalog'
88+
); /* Search only products are invisible in catalog*/
89+
}
90+
6891
public function testGetAdditionalHtmlEmpty()
6992
{
7093
$this->_block->setLayout($this->_getLayout());
@@ -75,9 +98,9 @@ public function testGetAdditionalHtml()
7598
{
7699
$layout = $this->_getLayout();
77100
/** @var $parent \Magento\Catalog\Block\Product\ListProduct */
78-
$parent = $layout->createBlock('Magento\Catalog\Block\Product\ListProduct');
101+
$parent = $layout->createBlock(\Magento\Catalog\Block\Product\ListProduct::class);
79102
$childBlock = $layout->createBlock(
80-
'Magento\Framework\View\Element\Text',
103+
\Magento\Framework\View\Element\Text::class,
81104
'test',
82105
['data' => ['text' => 'test']]
83106
);
@@ -102,7 +125,7 @@ public function testPrepareSortableFieldsByCategory()
102125
{
103126
/** @var $category \Magento\Catalog\Model\Category */
104127
$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
105-
'Magento\Catalog\Model\Category'
128+
\Magento\Catalog\Model\Category::class
106129
);
107130
$category->setDefaultSortBy('name');
108131
$this->_block->prepareSortableFieldsByCategory($category);
@@ -112,7 +135,7 @@ public function testPrepareSortableFieldsByCategory()
112135
protected function _getLayout()
113136
{
114137
return \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
115-
'Magento\Framework\View\LayoutInterface'
138+
\Magento\Framework\View\LayoutInterface::class
116139
);
117140
}
118141
}

dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/** @var $product \Magento\Catalog\Model\Product */
88
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
9-
->create('Magento\Catalog\Model\Product');
9+
->create(\Magento\Catalog\Model\Product::class);
1010
$product->isObjectNew(true);
1111
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
1212
->setId(1)

dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_rollback.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66

77
/** @var \Magento\Framework\Registry $registry */
8-
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry');
8+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
99

1010
$registry->unregister('isSecureArea');
1111
$registry->register('isSecureArea', true);
1212

1313
/** @var $product \Magento\Catalog\Model\Product */
14-
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product');
14+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
1515
$product->load(1);
1616
if ($product->getId()) {
1717
$product->delete();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var $product2 \Magento\Catalog\Model\Product */
8+
$product2 = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
9+
->create(\Magento\Catalog\Model\Product::class);
10+
$product2
11+
->setTypeId('simple')
12+
->setId(6)
13+
->setAttributeSetId(4)
14+
->setWebsiteIds([1])
15+
->setName('Simple Product2')
16+
->setSku('simple2')
17+
->setPrice(10)
18+
->setMetaTitle('meta title2')
19+
->setMetaKeyword('meta keyword2')
20+
->setMetaDescription('meta description2')
21+
->setCategoryIds([2])
22+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_SEARCH)
23+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
24+
->setStockData(['use_config_manage_stock' => 0])
25+
->save();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var \Magento\Framework\Registry $registry */
8+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
9+
10+
$registry->unregister('isSecureArea');
11+
$registry->register('isSecureArea', true);
12+
13+
/** @var \Magento\Catalog\Model\Product $product */
14+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
15+
$product->load(6);
16+
17+
if ($product->getId()) {
18+
$product->delete();
19+
}
20+
21+
$registry->unregister('isSecureArea');
22+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)