Skip to content

Commit 3839ade

Browse files
committed
Merge branch 'ACP2E-3448' of https://github.com/adobe-commerce-tier-4/inventory into PR-11-19-2024
2 parents f40e04e + 27227dc commit 3839ade

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

InventoryImportExport/Model/Import/Validator/QtyValidator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2017 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -39,6 +39,8 @@ public function validate(array $rowData, int $rowNumber)
3939

4040
if (!isset($rowData[Sources::COL_QTY])) {
4141
$errors[] = __('Missing required column "%column"', ['column' => Sources::COL_QTY]);
42+
} elseif (!is_numeric($rowData[Sources::COL_QTY])) {
43+
$errors[] = __('"%column" contains incorrect value', ['column' => Sources::COL_QTY]);
4244
}
4345

4446
return $this->validationResultFactory->create(['errors' => $errors]);
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InventoryImportExport\Test\Unit\Model\Import\Validator;
9+
10+
use Magento\Framework\Validation\ValidationResult;
11+
use Magento\Framework\Validation\ValidationResultFactory;
12+
use Magento\InventoryImportExport\Model\Import\Sources;
13+
use Magento\InventoryImportExport\Model\Import\Validator\QtyValidator;
14+
use PHPUnit\Framework\Attributes\DataProvider;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class QtyValidatorTest extends TestCase
19+
{
20+
/**
21+
* @var MockObject|null
22+
*/
23+
private ?MockObject $validationResultFactory;
24+
25+
/**
26+
* @var QtyValidator|null
27+
*/
28+
private ?QtyValidator $model;
29+
30+
protected function setUp(): void
31+
{
32+
parent::setUp();
33+
$this->validationResultFactory = $this->createMock(ValidationResultFactory::class);
34+
$this->model = new QtyValidator($this->validationResultFactory);
35+
}
36+
37+
#[DataProvider('validateDataProvider')]
38+
public function testValidate(array $data, array $errors = []): void
39+
{
40+
$rowNumber = 1;
41+
$result = new ValidationResult([]);
42+
$this->validationResultFactory
43+
->expects($this->once())->method('create')
44+
->with(['errors' => $errors])
45+
->willReturn($result);
46+
$this->assertSame($result, $this->model->validate($data, $rowNumber));
47+
}
48+
49+
public static function validateDataProvider(): array
50+
{
51+
return [
52+
[
53+
[Sources::COL_QTY => 1,],
54+
],
55+
[
56+
[Sources::COL_QTY => 0,],
57+
],
58+
[
59+
[Sources::COL_QTY => -1,],
60+
],
61+
[
62+
[Sources::COL_QTY => 0.1,],
63+
],
64+
[
65+
[Sources::COL_QTY => '1',],
66+
],
67+
[
68+
[Sources::COL_QTY => '0',],
69+
],
70+
[
71+
[Sources::COL_QTY => '-1',],
72+
],
73+
[
74+
[Sources::COL_QTY => '0.1',],
75+
],
76+
[
77+
[Sources::COL_QTY => 'abc',],
78+
[__('"%column" contains incorrect value', ['column' => Sources::COL_QTY])],
79+
],
80+
[
81+
['qty' => 1,],
82+
[__('Missing required column "%column"', ['column' => Sources::COL_QTY])],
83+
],
84+
];
85+
}
86+
}

InventoryImportExport/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
"Missing required column ""%column""","Missing required column ""%column"""
1111
"Source code ""%code"" does not exists","Source code ""%code"" does not exists"
1212
"Row Validator must implement %interface.","Row Validator must implement %interface."
13+
"""%column"" contains incorrect value","""%column"" contains incorrect value"

0 commit comments

Comments
 (0)