Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExportSearchCsvTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class ExportSearchCsvTest extends \PHPUnit\Framework\TestCase
13 {
17  private $controller;
18 
22  private $fileFactoryMock;
23 
27  private $objectManagerHelper;
28 
32  private $resultFactoryMock;
33 
34  protected function setUp()
35  {
36  $this->objectManagerHelper = new ObjectManagerHelper($this);
37  $this->fileFactoryMock = $this->createMock(\Magento\Framework\App\Response\Http\FileFactory::class);
38  $this->resultFactoryMock = $this->createMock(\Magento\Framework\Controller\ResultFactory::class);
39 
40  $this->controller = $this->objectManagerHelper->getObject(
41  \Magento\Search\Controller\Adminhtml\Term\ExportSearchCsv::class,
42  [
43  'fileFactory' => $this->fileFactoryMock,
44  'resultFactory' => $this->resultFactoryMock
45  ]
46  );
47  }
48 
49  public function testExecute()
50  {
51  $resultLayoutMock = $this->createMock(\Magento\Framework\View\Result\Layout::class);
52  $layoutMock = $this->createMock(\Magento\Framework\View\LayoutInterface::class);
53  $contentMock = $this->createPartialMock(\Magento\Framework\View\Element\AbstractBlock::class, ['getCsvFile']);
54  $this->resultFactoryMock
55  ->expects($this->once())
56  ->method('create')
57  ->with(ResultFactory::TYPE_LAYOUT)->willReturn($resultLayoutMock);
58  $resultLayoutMock->expects($this->once())->method('getLayout')->willReturn($layoutMock);
59  $layoutMock->expects($this->once())->method('getChildBlock')->willReturn($contentMock);
60  $contentMock->expects($this->once())->method('getCsvFile')->willReturn('csvFile');
61  $this->fileFactoryMock
62  ->expects($this->once())
63  ->method('create')
64  ->with('search.csv', 'csvFile', DirectoryList::VAR_DIR);
65  $this->controller->execute();
66  }
67 }