Skip to content

Commit 2142936

Browse files
Merge branch 'MAGETWO-52728' of https://github.com/magento-falcons/magento2ce into MAGETWO-56252
2 parents f2d309a + 680a015 commit 2142936

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product/Validator/Quantity.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*/
66
namespace Magento\CatalogImportExport\Model\Import\Product\Validator;
77

8-
use Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractImportValidator;
98
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;
109

10+
/**
11+
* Class Quantity
12+
*/
1113
class Quantity extends AbstractImportValidator implements RowValidatorInterface
1214
{
1315
/**
@@ -24,7 +26,7 @@ public function init($context)
2426
public function isValid($value)
2527
{
2628
$this->_clearMessages();
27-
if (!empty($value['qty']) && (!is_numeric($value['qty']) || $value['qty'] < 0)) {
29+
if (!empty($value['qty']) && !is_numeric($value['qty'])) {
2830
$this->_addMessages(
2931
[
3032
sprintf(
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogImportExport\Test\Unit\Model\Import\Product\Validator;
7+
8+
use Magento\CatalogImportExport\Model\Import\Product;
9+
use Magento\CatalogImportExport\Model\Import\Product\Validator\Quantity;
10+
11+
/**
12+
* Class QuantityTest
13+
*/
14+
class QuantityTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @var Quantity
18+
*/
19+
private $quantity;
20+
21+
protected function setUp()
22+
{
23+
$this->quantity = new Quantity();
24+
25+
$contextStub = $this->getMockBuilder(Product::class)
26+
->disableOriginalConstructor()
27+
->getMock();
28+
$contextStub->method('retrieveMessageTemplate')->willReturn(null);
29+
$this->quantity->init($contextStub);
30+
}
31+
32+
/**
33+
* @param bool $expectedResult
34+
* @param array $value
35+
* @dataProvider isValidDataProvider
36+
*/
37+
public function testIsValid($expectedResult, $value)
38+
{
39+
$result = $this->quantity->isValid($value);
40+
$this->assertEquals($expectedResult, $result);
41+
}
42+
43+
/**
44+
* @return array
45+
*/
46+
public function isValidDataProvider()
47+
{
48+
return [
49+
[true, ['qty' => 0]],
50+
[true, ['qty' => 1]],
51+
[true, ['qty' => 5]],
52+
[true, ['qty' => -1]],
53+
[true, ['qty' => -10]],
54+
[true, ['qty' => '']],
55+
[false, ['qty' => 'abc']],
56+
[false, ['qty' => true]],
57+
];
58+
}
59+
}

0 commit comments

Comments
 (0)