Skip to content

Commit 4a31f3e

Browse files
author
Roman Ganin
committed
Merge remote-tracking branch 'origin/MAGETWO-37206' into MAGETWO-37201
2 parents 48d1e6b + ff1962a commit 4a31f3e

File tree

66 files changed

+2582
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2582
-424
lines changed

app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
/**
108
* Backend Catalog Price Rules controller
119
*
@@ -36,11 +34,15 @@ class Catalog extends Action
3634
protected $_coreRegistry = null;
3735

3836
/**
37+
* Date filter instance
38+
*
3939
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
4040
*/
4141
protected $_dateFilter;
4242

4343
/**
44+
* Constructor
45+
*
4446
* @param Context $context
4547
* @param Registry $coreRegistry
4648
* @param Date $dateFilter
@@ -53,6 +55,8 @@ public function __construct(Context $context, Registry $coreRegistry, Date $date
5355
}
5456

5557
/**
58+
* Init action
59+
*
5660
* @return $this
5761
*/
5862
protected function _initAction()
@@ -68,6 +72,8 @@ protected function _initAction()
6872
}
6973

7074
/**
75+
* Is access to section allowed
76+
*
7177
* @return bool
7278
*/
7379
protected function _isAllowed()
@@ -94,7 +100,8 @@ public function setDirtyRulesNoticeMessage($dirtyRulesNoticeMessage)
94100
public function getDirtyRulesNoticeMessage()
95101
{
96102
$defaultMessage = __(
97-
'There are rules that have been changed but were not applied. Please, click Apply Rules in order to see immediate effect in the catalog.'
103+
'There are rules that have been changed but were not applied. '
104+
. 'Please, click Apply Rules in order to see immediate effect in the catalog.'
98105
);
99106
return $this->_dirtyRulesNoticeMessage ? $this->_dirtyRulesNoticeMessage : $defaultMessage;
100107
}

app/code/Magento/CatalogRule/Helper/Data.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
class Data extends \Magento\Framework\App\Helper\AbstractHelper
1313
{
1414
/**
15-
* Algorithm for calculating price rule
15+
* Algorithm for calculating price by rule
1616
*
1717
* @param string $actionOperator
1818
* @param int $ruleAmount
1919
* @param float $price
2020
* @return float|int
21-
* @api
2221
*/
2322
public function calcPriceRule($actionOperator, $ruleAmount, $price)
2423
{
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogRule\Test\Unit\Helper;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
11+
class DataTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* Helper object
15+
*
16+
* @var \Magento\CatalogRule\Helper\Data
17+
*/
18+
protected $helper;
19+
20+
protected function setUp()
21+
{
22+
$this->helper = (new ObjectManager($this))->getObject('Magento\CatalogRule\Helper\Data');
23+
}
24+
25+
/**
26+
* Test price rule calculation
27+
*
28+
* @param string $actionOperator
29+
* @param int|float $ruleAmount
30+
* @param int|float $price
31+
* @param int|float $expectedAmount
32+
*
33+
* @dataProvider calcPriceRuleDataProvider
34+
*/
35+
public function testCalcPriceRule($actionOperator, $ruleAmount, $price, $expectedAmount)
36+
{
37+
$this->assertEquals($expectedAmount, $this->helper->calcPriceRule($actionOperator, $ruleAmount, $price));
38+
}
39+
40+
/**
41+
* Data provider for cal price rule test
42+
*
43+
* @return array
44+
*/
45+
public function calcPriceRuleDataProvider()
46+
{
47+
return [
48+
['to_fixed', 10, 10, 10],
49+
['to_fixed', 0, 10, 0],
50+
['to_fixed', 10, 0, 0],
51+
['to_fixed', 0, 0, 0],
52+
['to_percent', 100, 100, 100],
53+
['to_percent', 10, 100, 10],
54+
['to_percent', 10, 70, 7],
55+
['to_percent', 100, 10, 10],
56+
['by_fixed', 100, 100, 0],
57+
['by_fixed', 10, 100, 90],
58+
['by_fixed', 100, 10, 0],
59+
['by_percent', 100, 100, 0],
60+
['by_percent', 100, 10, 0],
61+
['by_percent', 100, 1, 0],
62+
['by_percent', 10, 100, 90],
63+
['by_percent', 10, 10, 9],
64+
['by_percent', 1, 10, 9.90],
65+
];
66+
}
67+
}

app/code/Magento/CatalogRule/Test/Unit/Model/CronTest.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,42 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\CatalogRule\Test\Unit\Model;
108

119
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1210

1311
class CronTest extends \PHPUnit_Framework_TestCase
1412
{
1513
/**
14+
* Processor
15+
*
1616
* @var \Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor|\PHPUnit_Framework_MockObject_MockObject
1717
*/
1818
protected $ruleProductProcessor;
1919

2020
/**
21+
* Cron object
22+
*
2123
* @var \Magento\CatalogRule\Model\Cron
2224
*/
2325
protected $cron;
2426

2527
protected function setUp()
2628
{
27-
$this->ruleProductProcessor = $this->getMock('Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor',
28-
[], [], '', false);
29-
30-
$this->cron = (new ObjectManager($this))->getObject('Magento\CatalogRule\Model\Cron', [
31-
'ruleProductProcessor' => $this->ruleProductProcessor,
32-
]);
29+
$this->ruleProductProcessor = $this->getMock(
30+
'Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor',
31+
[],
32+
[],
33+
'',
34+
false
35+
);
36+
37+
$this->cron = (new ObjectManager($this))->getObject(
38+
'Magento\CatalogRule\Model\Cron',
39+
[
40+
'ruleProductProcessor' => $this->ruleProductProcessor,
41+
]
42+
);
3343
}
3444

3545
public function testDailyCatalogUpdate()

app/code/Magento/CatalogRule/Test/Unit/Plugin/Indexer/CategoryTest.php

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\CatalogRule\Test\Unit\Plugin\Indexer;
108

119
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
@@ -29,20 +27,37 @@ class CategoryTest extends \PHPUnit_Framework_TestCase
2927

3028
protected function setUp()
3129
{
32-
$this->productRuleProcessor = $this->getMock('Magento\CatalogRule\Model\Indexer\Product\ProductRuleProcessor',
33-
[], [], '', false);
34-
$this->subject = $this->getMock('Magento\Catalog\Model\Category', ['getAffectedProductIds', '__wakeUp'], [],
35-
'', false);
36-
37-
$this->plugin = (new ObjectManager($this))->getObject('Magento\CatalogRule\Plugin\Indexer\Category', [
38-
'productRuleProcessor' => $this->productRuleProcessor,
39-
]);
30+
$this->productRuleProcessor = $this->getMock(
31+
'Magento\CatalogRule\Model\Indexer\Product\ProductRuleProcessor',
32+
[],
33+
[],
34+
'',
35+
false
36+
);
37+
$this->subject = $this->getMock(
38+
'Magento\Catalog\Model\Category',
39+
['getAffectedProductIds', '__wakeUp'],
40+
[],
41+
'',
42+
false
43+
);
44+
45+
$this->plugin = (new ObjectManager($this))->getObject(
46+
'Magento\CatalogRule\Plugin\Indexer\Category',
47+
[
48+
'productRuleProcessor' => $this->productRuleProcessor,
49+
]
50+
);
4051
}
4152

4253
public function testAfterSaveWithoutAffectedProductIds()
4354
{
44-
$this->subject->expects($this->any())->method('getAffectedProductIds')->will($this->returnValue([]));
45-
$this->productRuleProcessor->expects($this->never())->method('reindexList');
55+
$this->subject->expects($this->any())
56+
->method('getAffectedProductIds')
57+
->will($this->returnValue([]));
58+
59+
$this->productRuleProcessor->expects($this->never())
60+
->method('reindexList');
4661

4762
$this->assertEquals($this->subject, $this->plugin->afterSave($this->subject, $this->subject));
4863
}
@@ -51,15 +66,21 @@ public function testAfterSave()
5166
{
5267
$productIds = [1, 2, 3];
5368

54-
$this->subject->expects($this->any())->method('getAffectedProductIds')->will($this->returnValue($productIds));
55-
$this->productRuleProcessor->expects($this->once())->method('reindexList')->with($productIds);
69+
$this->subject->expects($this->any())
70+
->method('getAffectedProductIds')
71+
->will($this->returnValue($productIds));
72+
73+
$this->productRuleProcessor->expects($this->once())
74+
->method('reindexList')
75+
->with($productIds);
5676

5777
$this->assertEquals($this->subject, $this->plugin->afterSave($this->subject, $this->subject));
5878
}
5979

6080
public function testAfterDelete()
6181
{
62-
$this->productRuleProcessor->expects($this->once())->method('markIndexerAsInvalid');
82+
$this->productRuleProcessor->expects($this->once())
83+
->method('markIndexerAsInvalid');
6384

6485
$this->assertEquals($this->subject, $this->plugin->afterDelete($this->subject, $this->subject));
6586
}

app/code/Magento/CatalogRule/Test/Unit/Plugin/Indexer/CustomerGroupTest.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,62 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\CatalogRule\Test\Unit\Plugin\Indexer;
108

119
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1210

1311
class CustomerGroupTest extends \PHPUnit_Framework_TestCase
1412
{
1513
/**
14+
* Rule processor mock
15+
*
1616
* @var \Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor|\PHPUnit_Framework_MockObject_MockObject
1717
*/
1818
protected $ruleProductProcessor;
1919

2020
/**
21+
* Subject group
22+
*
2123
* @var \Magento\Customer\Model\Group|\PHPUnit_Framework_MockObject_MockObject
2224
*/
2325
protected $subject;
2426

2527
/**
28+
* Tested plugin
29+
*
2630
* @var \Magento\CatalogRule\Plugin\Indexer\CustomerGroup
2731
*/
2832
protected $plugin;
2933

3034
protected function setUp()
3135
{
32-
$this->ruleProductProcessor = $this->getMock('Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor',
33-
[], [], '', false);
34-
$this->subject = $this->getMock('Magento\Customer\Model\Group', [], [], '', false);
36+
$this->ruleProductProcessor = $this->getMock(
37+
'Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor',
38+
[],
39+
[],
40+
'',
41+
false
42+
);
43+
$this->subject = $this->getMock(
44+
'Magento\Customer\Model\Group',
45+
[],
46+
[],
47+
'',
48+
false
49+
);
3550

36-
$this->plugin = (new ObjectManager($this))->getObject('Magento\CatalogRule\Plugin\Indexer\CustomerGroup', [
37-
'ruleProductProcessor' => $this->ruleProductProcessor,
38-
]);
51+
$this->plugin = (new ObjectManager($this))->getObject(
52+
'Magento\CatalogRule\Plugin\Indexer\CustomerGroup',
53+
[
54+
'ruleProductProcessor' => $this->ruleProductProcessor,
55+
]
56+
);
3957
}
4058

4159
public function testAfterDelete()
4260
{
43-
$this->ruleProductProcessor->expects($this->once())->method('markIndexerAsInvalid');
61+
$this->ruleProductProcessor->expects($this->once())
62+
->method('markIndexerAsInvalid');
4463

4564
$this->assertEquals($this->subject, $this->plugin->afterDelete($this->subject, $this->subject));
4665
}

0 commit comments

Comments
 (0)