File tree Expand file tree Collapse file tree 2 files changed +63
-2
lines changed
app/code/Magento/CatalogImportExport
Model/Import/Product/Validator
Test/Unit/Model/Import/Product/Validator Expand file tree Collapse file tree 2 files changed +63
-2
lines changed Original file line number Diff line number Diff line change 5
5
*/
6
6
namespace Magento \CatalogImportExport \Model \Import \Product \Validator ;
7
7
8
- use Magento \CatalogImportExport \Model \Import \Product \Validator \AbstractImportValidator ;
9
8
use Magento \CatalogImportExport \Model \Import \Product \RowValidatorInterface ;
10
9
10
+ /**
11
+ * Class Quantity
12
+ */
11
13
class Quantity extends AbstractImportValidator implements RowValidatorInterface
12
14
{
13
15
/**
@@ -24,7 +26,7 @@ public function init($context)
24
26
public function isValid ($ value )
25
27
{
26
28
$ this ->_clearMessages ();
27
- if (!empty ($ value ['qty ' ]) && ( !is_numeric ($ value ['qty ' ]) || $ value [ ' qty ' ] < 0 )) {
29
+ if (!empty ($ value ['qty ' ]) && !is_numeric ($ value ['qty ' ])) {
28
30
$ this ->_addMessages (
29
31
[
30
32
sprintf (
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments