1
1
<?php
2
2
/**
3
- * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
3
+ * Copyright © 2015 Magento. All rights reserved.
4
+ * See COPYING.txt for license details.
4
5
*/
5
6
namespace Magento \Backup \Controller \Adminhtml \Index ;
6
7
7
8
class DownloadTest extends \PHPUnit_Framework_TestCase
8
9
{
10
+ /**
11
+ * @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject
12
+ */
13
+ protected $ response ;
14
+
15
+ /**
16
+ * @var \Magento\Backup\Model\BackupFactory|\PHPUnit_Framework_MockObject_MockObject
17
+ */
18
+ protected $ backupModelFactory ;
19
+
20
+ /**
21
+ * @var \Magento\Backup\Model\Backup|\PHPUnit_Framework_MockObject_MockObject
22
+ */
23
+ protected $ backup ;
24
+
25
+ /**
26
+ * @var \Magento\Framework\App\RequestInterface||\PHPUnit_Framework_MockObject_MockObject
27
+ */
28
+ protected $ request ;
29
+
30
+ public function setUp ()
31
+ {
32
+ $ this ->backup = $ this ->getMock (
33
+ '\Magento\Backup\Model\Backup ' ,
34
+ ['getTime ' , 'exists ' , 'getSize ' , 'output ' ],
35
+ [],
36
+ '' ,
37
+ false
38
+ );
39
+ $ this ->request = $ this ->getMock ('\Magento\Framework\App\RequestInterface ' , [], [], '' , false );
40
+ $ this ->backupModelFactory = $ this ->getMock ('\Magento\Backup\Model\BackupFactory ' , [], [], '' , false );
41
+ $ this ->response = $ this ->getMock ('\Magento\Framework\App\ResponseInterface ' , [], [], '' , false );
42
+ }
43
+
9
44
public function testExecuteBackupFound ()
10
45
{
11
46
$ time = 1 ;
@@ -14,44 +49,33 @@ public function testExecuteBackupFound()
14
49
$ size = 10 ;
15
50
$ output = 'test ' ;
16
51
17
- $ backup = $ this ->getMock (
18
- '\Magento\Backup\Model\Backup ' ,
19
- ['getTime ' , 'exists ' , 'getSize ' , 'output ' ],
20
- [],
21
- '' ,
22
- false
23
- );
24
- $ backup ->expects ($ this ->once ())->method ('getTime ' )->will ($ this ->returnValue ($ time ));
25
- $ backup ->expects ($ this ->once ())->method ('exists ' )->will ($ this ->returnValue (true ));
26
- $ backup ->expects ($ this ->once ())->method ('getSize ' )->will ($ this ->returnValue ($ size ));
27
- $ backup ->expects ($ this ->once ())->method ('output ' )->will ($ this ->returnValue ($ output ));
52
+ $ this ->backup ->expects ($ this ->once ())->method ('getTime ' )->will ($ this ->returnValue ($ time ));
53
+ $ this ->backup ->expects ($ this ->once ())->method ('exists ' )->will ($ this ->returnValue (true ));
54
+ $ this ->backup ->expects ($ this ->once ())->method ('getSize ' )->will ($ this ->returnValue ($ size ));
55
+ $ this ->backup ->expects ($ this ->once ())->method ('output ' )->will ($ this ->returnValue ($ output ));
28
56
29
- $ request = $ this ->getMock ('\Magento\Framework\App\RequestInterface ' , [], [], '' , false );
30
- $ request ->expects ($ this ->at (0 ))->method ('getParam ' )->with ('time ' )->will ($ this ->returnValue ($ time ));
31
- $ request ->expects ($ this ->at (1 ))->method ('getParam ' )->with ('type ' )->will ($ this ->returnValue ($ type ));
57
+ $ this ->request ->expects ($ this ->at (0 ))->method ('getParam ' )->with ('time ' )->will ($ this ->returnValue ($ time ));
58
+ $ this ->request ->expects ($ this ->at (1 ))->method ('getParam ' )->with ('type ' )->will ($ this ->returnValue ($ type ));
32
59
33
- $ backupModelFactory = $ this ->getMock ('\Magento\Backup\Model\BackupFactory ' , [], [], '' , false );
34
- $ backupModelFactory ->expects ($ this ->once ())->method ('create ' )->with ($ time , $ type )
35
- ->will ($ this ->returnValue ($ backup ));
60
+ $ this ->backupModelFactory ->expects ($ this ->once ())->method ('create ' )->with ($ time , $ type )
61
+ ->will ($ this ->returnValue ($ this ->backup ));
36
62
37
63
$ helper = $ this ->getMock ('Magento\Backup\Helper\Data ' , [], [], '' , false );
38
- $ helper ->expects ($ this ->once ())->method ('generateBackupDownloadName ' )->with ($ backup )
64
+ $ helper ->expects ($ this ->once ())->method ('generateBackupDownloadName ' )->with ($ this -> backup )
39
65
->will ($ this ->returnValue ($ filename ));
40
66
41
67
$ objectManager = $ this ->getMock ('\Magento\Framework\ObjectManagerInterface ' , [], [], '' , false );
42
68
$ objectManager ->expects ($ this ->once ())->method ('get ' )->with ('Magento\Backup\Helper\Data ' )
43
69
->will ($ this ->returnValue ($ helper ));
44
70
45
- $ response = $ this ->getMock ('\Magento\Framework\App\ResponseInterface ' , [], [], '' , false );
46
-
47
71
$ fileFactory = $ this ->getMock ('\Magento\Framework\App\Response\Http\FileFactory ' , [], [], '' , false );
48
72
$ fileFactory ->expects ($ this ->once ())->method ('create ' )->with (
49
73
$ filename ,
50
74
null ,
51
75
\Magento \Framework \App \Filesystem \DirectoryList::VAR_DIR ,
52
76
'application/octet-stream ' ,
53
77
$ size
54
- )->will ($ this ->returnValue ($ response ));
78
+ )->will ($ this ->returnValue ($ this -> response ));
55
79
56
80
$ resultRaw = $ this ->getMock ('\Magento\Framework\Controller\Result\Raw ' , [], [], '' , false );
57
81
$ resultRaw ->expects ($ this ->once ())->method ('setContents ' )->with ($ output );
@@ -66,15 +90,15 @@ public function testExecuteBackupFound()
66
90
$ resultRawFactory ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ resultRaw ));
67
91
68
92
$ context = $ this ->getMock ('\Magento\Backend\App\Action\Context ' , [], [], '' , false );
69
- $ context ->expects ($ this ->once ())->method ('getRequest ' )->will ($ this ->returnValue ($ request ));
93
+ $ context ->expects ($ this ->once ())->method ('getRequest ' )->will ($ this ->returnValue ($ this -> request ));
70
94
$ context ->expects ($ this ->once ())->method ('getObjectManager ' )->will ($ this ->returnValue ($ objectManager ));
71
- $ context ->expects ($ this ->once ())->method ('getResponse ' )->will ($ this ->returnValue ($ response ));
95
+ $ context ->expects ($ this ->once ())->method ('getResponse ' )->will ($ this ->returnValue ($ this -> response ));
72
96
73
97
/** @var Download|\PHPUnit_Framework_MockObject_MockObject $controller */
74
98
$ controller = (new \Magento \TestFramework \Helper \ObjectManager ($ this ))->getObject (
75
99
'Magento\Backup\Controller\Adminhtml\Index\Download ' ,
76
100
[
77
- 'backupModelFactory ' => $ backupModelFactory ,
101
+ 'backupModelFactory ' => $ this -> backupModelFactory ,
78
102
'context ' => $ context ,
79
103
'fileFactory ' => $ fileFactory ,
80
104
'resultRawFactory ' => $ resultRawFactory
@@ -84,7 +108,7 @@ public function testExecuteBackupFound()
84
108
}
85
109
86
110
/**
87
- * @dataProvider providerExecuteBackupNotFound
111
+ * @dataProvider executeBackupNotFoundDataProvider
88
112
* @param string $time
89
113
* @param bool $exists
90
114
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $existsCount
@@ -93,23 +117,19 @@ public function testExecuteBackupNotFound($time, $exists, $existsCount)
93
117
{
94
118
$ type = 'db ' ;
95
119
96
- $ backup = $ this ->getMock ('\Magento\Backup\Model\Backup ' , ['getTime ' , 'exists ' ], [], '' , false );
97
- $ backup ->expects ($ this ->once ())->method ('getTime ' )->will ($ this ->returnValue ($ time ));
98
- $ backup ->expects ($ existsCount )->method ('exists ' )->will ($ this ->returnValue ($ exists ));
99
-
100
- $ response = $ this ->getMock ('\Magento\Framework\App\ResponseInterface ' , [], [], '' , false );
120
+ $ this ->backup ->expects ($ this ->once ())->method ('getTime ' )->will ($ this ->returnValue ($ time ));
121
+ $ this ->backup ->expects ($ existsCount )->method ('exists ' )->will ($ this ->returnValue ($ exists ));
101
122
102
- $ request = $ this ->getMock ('\Magento\Framework\App\RequestInterface ' , [], [], '' , false );
103
- $ request ->expects ($ this ->at (0 ))->method ('getParam ' )->with ('time ' )->will ($ this ->returnValue ($ time ));
104
- $ request ->expects ($ this ->at (1 ))->method ('getParam ' )->with ('type ' )->will ($ this ->returnValue ($ type ));
123
+ $ this -> request = $ this ->getMock ('\Magento\Framework\App\RequestInterface ' , [], [], '' , false );
124
+ $ this -> request ->expects ($ this ->at (0 ))->method ('getParam ' )->with ('time ' )->will ($ this ->returnValue ($ time ));
125
+ $ this -> request ->expects ($ this ->at (1 ))->method ('getParam ' )->with ('type ' )->will ($ this ->returnValue ($ type ));
105
126
106
127
$ context = $ this ->getMock ('\Magento\Backend\App\Action\Context ' , [], [], '' , false );
107
- $ context ->expects ($ this ->once ())->method ('getRequest ' )->will ($ this ->returnValue ($ request ));
108
- $ context ->expects ($ this ->once ())->method ('getResponse ' )->will ($ this ->returnValue ($ response ));
128
+ $ context ->expects ($ this ->once ())->method ('getRequest ' )->will ($ this ->returnValue ($ this -> request ));
129
+ $ context ->expects ($ this ->once ())->method ('getResponse ' )->will ($ this ->returnValue ($ this -> response ));
109
130
110
- $ backupModelFactory = $ this ->getMock ('\Magento\Backup\Model\BackupFactory ' , [], [], '' , false );
111
- $ backupModelFactory ->expects ($ this ->once ())->method ('create ' )->with ($ time , $ type )
112
- ->will ($ this ->returnValue ($ backup ));
131
+ $ this ->backupModelFactory ->expects ($ this ->once ())->method ('create ' )->with ($ time , $ type )
132
+ ->will ($ this ->returnValue ($ this ->backup ));
113
133
114
134
$ resultRedirect = $ this ->getMock ('Magento\Backend\Model\View\Result\Redirect ' , [], [], '' , false );
115
135
$ resultRedirect ->expects ($ this ->once ())->method ('setPath ' )->with ('backup/* ' );
@@ -128,7 +148,7 @@ public function testExecuteBackupNotFound($time, $exists, $existsCount)
128
148
'Magento\Backup\Controller\Adminhtml\Index\Download ' ,
129
149
[
130
150
'context ' => $ context ,
131
- 'backupModelFactory ' => $ backupModelFactory ,
151
+ 'backupModelFactory ' => $ this -> backupModelFactory ,
132
152
'resultRedirectFactory ' => $ resultRedirectFactory
133
153
]
134
154
);
@@ -138,7 +158,7 @@ public function testExecuteBackupNotFound($time, $exists, $existsCount)
138
158
/**
139
159
* @return array
140
160
*/
141
- public function providerExecuteBackupNotFound ()
161
+ public function executeBackupNotFoundDataProvider ()
142
162
{
143
163
return [
144
164
[1 , false , $ this ->once ()],
0 commit comments