Skip to content

Commit ecda1b7

Browse files
Chhandak.BaruaChhandak.Barua
authored andcommitted
ACP2E-3172: Import button missing
1 parent ca7e3c7 commit ecda1b7

File tree

1 file changed

+103
-0
lines changed
  • app/code/Magento/ImportExport/Test/Unit/Controller/Adminhtml/Import

1 file changed

+103
-0
lines changed

app/code/Magento/ImportExport/Test/Unit/Controller/Adminhtml/Import/ValidateTest.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
use Magento\ImportExport\Model\Report\ReportProcessorInterface;
2525
use PHPUnit\Framework\MockObject\MockObject;
2626
use PHPUnit\Framework\TestCase;
27+
use Magento\ImportExport\Model\Import;
28+
use Magento\ImportExport\Model\Import\AbstractSource;
29+
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
2730

2831
/**
2932
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -55,6 +58,11 @@ class ValidateTest extends TestCase
5558
*/
5659
private $validate;
5760

61+
/**
62+
* @var Import
63+
*/
64+
private $importMock;
65+
5866
/**
5967
* @var Http|MockObject
6068
*/
@@ -70,6 +78,11 @@ class ValidateTest extends TestCase
7078
*/
7179
private $messageManagerMock;
7280

81+
/**
82+
* @var AbstractSourceMock|MockObject
83+
*/
84+
private $abstractSourceMock;
85+
7386
protected function setUp(): void
7487
{
7588
$objectManagerHelper = new ObjectManagerHelper($this);
@@ -126,12 +139,24 @@ protected function setUp(): void
126139
->disableOriginalConstructor()
127140
->getMock();
128141

142+
$this->importMock = $this->getMockBuilder(import::class)
143+
->disableOriginalConstructor()
144+
->getMock();
145+
146+
$this->abstractSourceMock = $this->getMockBuilder(AbstractSource::class)
147+
->disableOriginalConstructor()
148+
->getMockForAbstractClass();
149+
129150
$this->validate = new Validate(
130151
$this->contextMock,
131152
$this->reportProcessorMock,
132153
$this->historyMock,
133154
$this->reportHelperMock
134155
);
156+
$reflection = new \ReflectionClass($this->validate);
157+
$importProperty = $reflection->getProperty('import');
158+
$importProperty->setAccessible(true);
159+
$importProperty->setValue($this->validate, $this->importMock);
135160
}
136161

137162
/**
@@ -230,4 +255,82 @@ public function testFileWasNotUploaded()
230255

231256
$this->assertEquals($resultLayoutMock, $this->validate->execute());
232257
}
258+
259+
/**
260+
* Test execute() method
261+
*
262+
* Check the case in which the import file was not uploaded.
263+
*/
264+
public function testFileVerifiedWithImport()
265+
{
266+
$data = ['key' => 'value'];
267+
268+
$this->requestMock->expects($this->once())
269+
->method('getPostValue')
270+
->willReturn($data);
271+
272+
$resultBlock = $this->getMockBuilder(Result::class)
273+
->disableOriginalConstructor()
274+
->getMock();
275+
$resultBlock->expects($this->once())
276+
->method('addSuccess')
277+
->with(__('File is valid! To start import process press "Import" button'));
278+
279+
$layoutMock = $this->getMockBuilder(LayoutInterface::class)
280+
->getMockForAbstractClass();
281+
$layoutMock->expects($this->once())
282+
->method('getBlock')
283+
->with('import.frame.result')
284+
->willReturn($resultBlock);
285+
286+
$resultLayoutMock = $this->getMockBuilder(Layout::class)
287+
->disableOriginalConstructor()
288+
->getMock();
289+
$resultLayoutMock->expects($this->once())
290+
->method('getLayout')
291+
->willReturn($layoutMock);
292+
$this->importMock->expects($this->once())
293+
->method('setData')
294+
->with($data)
295+
->willReturn($this->importMock);
296+
$this->importMock->expects($this->once())
297+
->method('uploadFileAndGetSource')
298+
->willReturn($this->abstractSourceMock );
299+
$this->importMock->expects($this->once())
300+
->method('validateSource')
301+
->with($this->abstractSourceMock )
302+
->willReturn(true);
303+
304+
$resultBlock->expects($this->once())
305+
->method('addAction')
306+
->willReturn(
307+
['show', 'import_validation_container'],
308+
['value', Import::FIELD_IMPORT_IDS, [1, 2, 3]]
309+
);
310+
$this->importMock->expects($this->exactly(3))
311+
->method('getProcessedRowsCount')
312+
->willReturn(2);
313+
$this->importMock->expects($this->once())
314+
->method('isImportAllowed')
315+
->willReturn(true);
316+
317+
$this->importMock->expects($this->once())
318+
->method('getProcessedEntitiesCount')
319+
->willReturn(10);
320+
321+
$errorAggregatorMock = $this->createMock(ProcessingErrorAggregatorInterface::class);
322+
$this->importMock->expects($this->any())
323+
->method('getErrorAggregator')
324+
->willReturn($errorAggregatorMock);
325+
326+
$errorAggregatorMock->expects($this->exactly(3))
327+
->method('getErrorsCount')
328+
->willReturn(2);
329+
330+
$this->resultFactoryMock->expects($this->any())
331+
->method('create')
332+
->with(ResultFactory::TYPE_LAYOUT)
333+
->willReturn($resultLayoutMock);
334+
$this->assertEquals($resultLayoutMock, $this->validate->execute());
335+
}
233336
}

0 commit comments

Comments
 (0)