Skip to content

Commit 40c0e1c

Browse files
author
Roman Ganin
committed
MAGETWO-39957: Catalog Price Rule does not apply to Group price
- tests
1 parent 8782ef0 commit 40c0e1c

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,9 @@ protected function getRuleProductsStmt($websiteId, $productId = null)
665665
);
666666
$select->columns([
667667
'default_price' => $this->getReadAdapter()->getIfNullSql(
668-
'gp.value',
669-
$this->getReadAdapter()->getIfNullSql($tableAlias . '.value', 'pp_default.value')
670-
),
668+
'gp.value',
669+
$this->getReadAdapter()->getIfNullSql($tableAlias . '.value', 'pp_default.value')
670+
),
671671
]);
672672

673673
return $read->query($select);

app/code/Magento/CatalogRule/Test/Unit/Model/Indexer/IndexBuilderTest.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected function setUp()
148148
$this->priceCurrency = $this->getMock('Magento\Framework\Pricing\PriceCurrencyInterface');
149149
$this->dateFormat = $this->getMock('Magento\Framework\Stdlib\DateTime', [], [], '', false);
150150
$this->dateTime = $this->getMock('Magento\Framework\Stdlib\DateTime\DateTime', [], [], '', false);
151-
$this->eavConfig = $this->getMock('Magento\Eav\Model\Config', [], [], '', false);
151+
$this->eavConfig = $this->getMock('Magento\Eav\Model\Config', ['getAttribute'], [], '', false);
152152
$this->product = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
153153
$this->productFactory = $this->getMock('Magento\Catalog\Model\ProductFactory', ['create'], [], '', false);
154154

@@ -182,7 +182,6 @@ protected function setUp()
182182

183183
$this->combine->expects($this->any())->method('validate')->will($this->returnValue(true));
184184
$this->attribute->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
185-
$this->eavConfig->expects($this->any())->method('getAttribute')->will($this->returnValue($this->attribute));
186185
$this->productFactory->expects($this->any())->method('create')->will($this->returnValue($this->product));
187186

188187
$this->indexBuilder = new \Magento\CatalogRule\Model\Indexer\IndexBuilder(
@@ -206,6 +205,45 @@ protected function setUp()
206205
*/
207206
public function testUpdateCatalogRuleGroupWebsiteData()
208207
{
208+
$groupPriceAttrMock = $this->getMock(
209+
'Magento\Catalog\Model\Entity\AttributeGroup',
210+
['getBackend'],
211+
[],
212+
'',
213+
false
214+
);
215+
$backendModelMock = $this->getMock(
216+
'Magento\Catalog\Model\Product\Attribute\Backend\GroupPrice',
217+
['getResource'],
218+
[],
219+
'',
220+
false
221+
);
222+
$resourceMock = $this->getMock(
223+
'Magento\Catalog\Model\Resource\Product\Attribute\Backend\GroupPrice',
224+
['getMainTable'],
225+
[],
226+
'',
227+
false
228+
);
229+
$resourceMock->expects($this->once())
230+
->method('getMainTable')
231+
->will($this->returnValue('catalog_product_entity_group_price'));
232+
$backendModelMock->expects($this->once())
233+
->method('getResource')
234+
->will($this->returnValue($resourceMock));
235+
$groupPriceAttrMock->expects($this->once())
236+
->method('getBackend')
237+
->will($this->returnValue($backendModelMock));
238+
$this->eavConfig->expects($this->at(0))
239+
->method('getAttribute')
240+
->with(\Magento\Catalog\Model\Product::ENTITY, 'group_price')
241+
->will($this->returnValue($groupPriceAttrMock));
242+
$this->eavConfig->expects($this->at(1))
243+
->method('getAttribute')
244+
->with(\Magento\Catalog\Model\Product::ENTITY, 'price')
245+
->will($this->returnValue($this->attribute));
246+
209247
$this->select->expects($this->once())->method('insertFromSelect')->with('catalogrule_group_website');
210248

211249
$this->indexBuilder->reindexByIds([1]);

0 commit comments

Comments
 (0)