Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GridToCsvTest.php
Go to the documentation of this file.
1 <?php
7 
12 
13 class GridToCsvTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $controller;
19 
23  protected $context;
24 
28  protected $converter;
29 
33  protected $fileFactory;
34 
35  protected function setUp()
36  {
37  $this->context = $this->getMockBuilder(\Magento\Backend\App\Action\Context::class)
38  ->disableOriginalConstructor()
39  ->getMock();
40 
41  $this->converter = $this->getMockBuilder(\Magento\Ui\Model\Export\ConvertToCsv::class)
42  ->disableOriginalConstructor()
43  ->getMock();
44 
45  $this->fileFactory = $this->getMockBuilder(\Magento\Framework\App\Response\Http\FileFactory::class)
46  ->disableOriginalConstructor()
47  ->getMock();
48 
49  $this->controller = new GridToCsv(
50  $this->context,
51  $this->converter,
52  $this->fileFactory
53  );
54  }
55 
56  public function testExecute()
57  {
58  $content = 'test';
59 
60  $this->converter->expects($this->once())
61  ->method('getCsvFile')
62  ->willReturn($content);
63 
64  $this->fileFactory->expects($this->once())
65  ->method('create')
66  ->with('export.csv', $content, 'var')
67  ->willReturn($content);
68 
69  $this->assertEquals($content, $this->controller->execute());
70  }
71 }