|
3 | 3 | * Copyright © Magento, Inc. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
| 6 | + |
6 | 7 | namespace Magento\SalesRule\Test\Unit\Model\Rule\Condition;
|
7 | 8 |
|
| 9 | +use Magento\Directory\Model\CurrencyFactory; |
| 10 | +use Magento\Framework\App\ScopeResolverInterface; |
8 | 11 | use \Magento\Framework\DB\Adapter\AdapterInterface;
|
9 | 12 | use \Magento\Framework\DB\Select;
|
10 |
| -use \Magento\Framework\Model\AbstractModel; |
| 13 | +use Magento\Framework\Locale\Format; |
| 14 | +use Magento\Framework\Locale\ResolverInterface; |
11 | 15 | use Magento\Quote\Model\Quote\Item\AbstractItem;
|
12 | 16 | use \Magento\Rule\Model\Condition\Context;
|
13 | 17 | use \Magento\Backend\Helper\Data;
|
@@ -130,8 +134,12 @@ protected function setUp()
|
130 | 134 | $this->collectionMock = $this->getMockBuilder(Collection::class)
|
131 | 135 | ->disableOriginalConstructor()
|
132 | 136 | ->getMock();
|
133 |
| - $this->formatMock = $this->getMockBuilder(FormatInterface::class) |
134 |
| - ->getMockForAbstractClass(); |
| 137 | + $this->formatMock = new Format( |
| 138 | + $this->getMockBuilder(ScopeResolverInterface::class)->disableOriginalConstructor()->getMock(), |
| 139 | + $this->getMockBuilder(ResolverInterface::class)->disableOriginalConstructor()->getMock(), |
| 140 | + $this->getMockBuilder(CurrencyFactory::class)->disableOriginalConstructor()->getMock() |
| 141 | + ); |
| 142 | + |
135 | 143 | $this->model = new SalesRuleProduct(
|
136 | 144 | $this->contextMock,
|
137 | 145 | $this->backendHelperMock,
|
@@ -231,4 +239,83 @@ public function testValidateCategoriesIgnoresVisibility()
|
231 | 239 |
|
232 | 240 | $this->model->validate($item);
|
233 | 241 | }
|
| 242 | + |
| 243 | + /** |
| 244 | + * @param boolean $isValid |
| 245 | + * @param string $conditionValue |
| 246 | + * @param string $operator |
| 247 | + * @param double $productPrice |
| 248 | + * @dataProvider localisationProvider |
| 249 | + */ |
| 250 | + public function testQuoteLocaleFormatPrice($isValid, $conditionValue, $operator = '>=', $productPrice = 2000.00) |
| 251 | + { |
| 252 | + $attr = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\Db\AbstractDb::class) |
| 253 | + ->disableOriginalConstructor() |
| 254 | + ->setMethods(['getAttribute']) |
| 255 | + ->getMockForAbstractClass(); |
| 256 | + |
| 257 | + $attr->expects($this->any()) |
| 258 | + ->method('getAttribute') |
| 259 | + ->willReturn(''); |
| 260 | + |
| 261 | + /* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product */ |
| 262 | + $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) |
| 263 | + ->disableOriginalConstructor() |
| 264 | + ->setMethods(['setQuoteItemPrice', 'getResource', 'hasData', 'getData',]) |
| 265 | + ->getMock(); |
| 266 | + |
| 267 | + $product->expects($this->any()) |
| 268 | + ->method('setQuoteItemPrice') |
| 269 | + ->willReturnSelf(); |
| 270 | + |
| 271 | + $product->expects($this->any()) |
| 272 | + ->method('getResource') |
| 273 | + ->willReturn($attr); |
| 274 | + |
| 275 | + $product->expects($this->any()) |
| 276 | + ->method('hasData') |
| 277 | + ->willReturn(true); |
| 278 | + |
| 279 | + $product->expects($this->any()) |
| 280 | + ->method('getData') |
| 281 | + ->with('quote_item_price') |
| 282 | + ->willReturn($productPrice); |
| 283 | + |
| 284 | + /* @var AbstractItem|\PHPUnit_Framework_MockObject_MockObject $item */ |
| 285 | + $item = $this->getMockBuilder(AbstractItem::class) |
| 286 | + ->disableOriginalConstructor() |
| 287 | + ->setMethods(['getPrice', 'getProduct',]) |
| 288 | + ->getMockForAbstractClass(); |
| 289 | + |
| 290 | + $item->expects($this->any()) |
| 291 | + ->method('getPrice') |
| 292 | + ->willReturn($productPrice); |
| 293 | + |
| 294 | + $item->expects($this->any()) |
| 295 | + ->method('getProduct') |
| 296 | + ->willReturn($product); |
| 297 | + |
| 298 | + $this->model->setAttribute('quote_item_price') |
| 299 | + ->setOperator($operator); |
| 300 | + |
| 301 | + $this->assertEquals($isValid, $this->model->setValue($conditionValue)->validate($item)); |
| 302 | + } |
| 303 | + |
| 304 | + |
| 305 | + /** |
| 306 | + * DataProvider for testQuoteLocaleFormatPrice |
| 307 | + * |
| 308 | + * @return array |
| 309 | + */ |
| 310 | + public function localisationProvider(): array |
| 311 | + { |
| 312 | + return [ |
| 313 | + 'number' => [true, 500.01], |
| 314 | + 'locale' => [true, '1,500.03'], |
| 315 | + 'operation' => [true, '1,500.03', '!='], |
| 316 | + 'stringOperation' => [false, '1,500.03', '{}'], |
| 317 | + 'smallPrice' => [false, '1,500.03', '>=', 1000], |
| 318 | + ]; |
| 319 | + } |
| 320 | + |
234 | 321 | }
|
0 commit comments