5
5
*/
6
6
namespace Magento \ImportExport \Test \Unit \Block \Adminhtml \Grid \Column \Renderer ;
7
7
8
+ use Magento \Backend \Block \Context ;
9
+ use Magento \Backend \Model \Url ;
10
+ use Magento \Framework \DataObject ;
11
+ use Magento \Framework \Escaper ;
8
12
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
13
+ use Magento \ImportExport \Block \Adminhtml \Grid \Column \Renderer \Download ;
9
14
15
+ /**
16
+ * Test for \Magento\ImportExport\Block\Adminhtml\Grid\Column\Renderer\Download class.
17
+ */
10
18
class DownloadTest extends \PHPUnit \Framework \TestCase
11
19
{
12
20
/**
13
- * @var \Magento\Backend\Block\ Context
21
+ * @var Context
14
22
*/
15
23
protected $ context ;
16
24
@@ -20,24 +28,31 @@ class DownloadTest extends \PHPUnit\Framework\TestCase
20
28
protected $ objectManagerHelper ;
21
29
22
30
/**
23
- * @var \Magento\ImportExport\Block\Adminhtml\Grid\Column\Renderer\ Download
31
+ * @var Download
24
32
*/
25
33
protected $ download ;
26
34
35
+ /**
36
+ * @var Escaper|\PHPUnit_Framework_MockObject_MockObjecti
37
+ */
38
+ private $ escaperMock ;
39
+
27
40
/**
28
41
* Set up
29
42
*/
30
43
protected function setUp ()
31
44
{
32
- $ urlModel = $ this ->createPartialMock (\Magento \Backend \Model \Url::class, ['getUrl ' ]);
45
+ $ this ->escaperMock = $ this ->createMock (Escaper::class);
46
+ $ urlModel = $ this ->createPartialMock (Url::class, ['getUrl ' ]);
33
47
$ urlModel ->expects ($ this ->any ())->method ('getUrl ' )->willReturn ('url ' );
34
- $ this ->context = $ this ->createPartialMock (\ Magento \ Backend \ Block \ Context::class, ['getUrlBuilder ' ]);
48
+ $ this ->context = $ this ->createPartialMock (Context::class, ['getUrlBuilder ' , ' getEscaper ' ]);
35
49
$ this ->context ->expects ($ this ->any ())->method ('getUrlBuilder ' )->willReturn ($ urlModel );
50
+ $ this ->context ->expects ($ this ->any ())->method ('getEscaper ' )->willReturn ($ this ->escaperMock );
36
51
$ data = [];
37
52
38
53
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
39
54
$ this ->download = $ this ->objectManagerHelper ->getObject (
40
- \ Magento \ ImportExport \ Block \ Adminhtml \ Grid \ Column \ Renderer \ Download::class,
55
+ Download::class,
41
56
[
42
57
'context ' => $ this ->context ,
43
58
'data ' => $ data
@@ -51,7 +66,16 @@ protected function setUp()
51
66
public function testGetValue ()
52
67
{
53
68
$ data = ['imported_file ' => 'file.csv ' ];
54
- $ row = new \Magento \Framework \DataObject ($ data );
69
+ $ row = new DataObject ($ data );
70
+ $ this ->escaperMock ->expects ($ this ->at (0 ))
71
+ ->method ('escapeHtml ' )
72
+ ->with ('file.csv ' )
73
+ ->willReturn ('file.csv ' );
74
+ $ this ->escaperMock ->expects ($ this ->once ())->method ('escapeUrl ' )->willReturn ('url ' );
75
+ $ this ->escaperMock ->expects ($ this ->at (2 ))
76
+ ->method ('escapeHtml ' )
77
+ ->with ('Download ' )
78
+ ->willReturn ('Download ' );
55
79
$ this ->assertEquals ('<p> file.csv</p><a href="url">Download</a> ' , $ this ->download ->_getValue ($ row ));
56
80
}
57
81
}
0 commit comments