|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016-2021 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Client\Html\Account\Download; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $context; |
|
15
|
|
|
private $object; |
|
16
|
|
|
private $view; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
protected function setUp() : void |
|
20
|
|
|
{ |
|
21
|
|
|
\Aimeos\MShop::cache( true ); |
|
22
|
|
|
|
|
23
|
|
|
$this->view = \TestHelperHtml::getView(); |
|
24
|
|
|
$this->context = \TestHelperHtml::getContext(); |
|
25
|
|
|
$this->context->setUserId( \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]' )->getId() ); |
|
26
|
|
|
|
|
27
|
|
|
$this->object = new \Aimeos\Client\Html\Account\Download\Standard( $this->context ); |
|
28
|
|
|
$this->object->setView( $this->view ); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
protected function tearDown() : void |
|
33
|
|
|
{ |
|
34
|
|
|
\Aimeos\MShop::cache( false ); |
|
35
|
|
|
unset( $this->object ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
public function testBody() |
|
40
|
|
|
{ |
|
41
|
|
|
$output = $this->object->body(); |
|
42
|
|
|
$this->assertEquals( '', $output ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
public function testHeader() |
|
47
|
|
|
{ |
|
48
|
|
|
$output = $this->object->header(); |
|
49
|
|
|
$this->assertEquals( '', $output ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
public function testGetSubClientInvalid() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
|
56
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
public function testGetSubClientInvalidName() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
|
63
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
public function testInit() |
|
68
|
|
|
{ |
|
69
|
|
|
$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock(); |
|
70
|
|
|
$response->expects( $this->once() )->method( 'withHeader' )->will( $this->returnSelf() ); |
|
71
|
|
|
$response->expects( $this->once() )->method( 'withStatus' )->will( $this->returnSelf() ); |
|
72
|
|
|
|
|
73
|
|
|
$helper = new \Aimeos\MW\View\Helper\Response\Standard( $this->view, $response ); |
|
74
|
|
|
$this->view->addHelper( 'response', $helper ); |
|
75
|
|
|
|
|
76
|
|
|
$this->object->init(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
public function testInitOK() |
|
81
|
|
|
{ |
|
82
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, ['dl_id' => '-1'] ); |
|
83
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
84
|
|
|
|
|
85
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Account\Download\Standard::class ) |
|
86
|
|
|
->setConstructorArgs( [$this->context] ) |
|
87
|
|
|
->setMethods( array( 'checkAccess', 'checkDownload' ) ) |
|
88
|
|
|
->getMock(); |
|
89
|
|
|
$object->setView( $this->view ); |
|
90
|
|
|
|
|
91
|
|
|
$object->expects( $this->once() )->method( 'checkAccess' )->will( $this->returnValue( true ) ); |
|
92
|
|
|
$object->expects( $this->once() )->method( 'checkDownload' )->will( $this->returnValue( true ) ); |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
$attrManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Base\\Product\\Attribute\\Standard' ) |
|
96
|
|
|
->setConstructorArgs( array( $this->context ) ) |
|
97
|
|
|
->setMethods( ['get'] ) |
|
98
|
|
|
->getMock(); |
|
99
|
|
|
|
|
100
|
|
|
$attrManagerStub->expects( $this->once() )->method( 'get' ) |
|
101
|
|
|
->will( $this->returnValue( $attrManagerStub->create() ) ); |
|
102
|
|
|
|
|
103
|
|
|
\Aimeos\MShop::inject( 'order/base/product/attribute', $attrManagerStub ); |
|
104
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
$stream = $this->getMockBuilder( \Psr\Http\Message\StreamInterface::class )->getMock(); |
|
107
|
|
|
$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock(); |
|
108
|
|
|
$response->expects( $this->exactly( 7 ) )->method( 'withHeader' )->will( $this->returnSelf() ); |
|
109
|
|
|
|
|
110
|
|
|
$helper = $this->getMockBuilder( \Aimeos\MW\View\Helper\Response\Standard::class ) |
|
111
|
|
|
->setConstructorArgs( array( $this->view, $response ) ) |
|
112
|
|
|
->setMethods( array( 'createStream' ) ) |
|
113
|
|
|
->getMock(); |
|
114
|
|
|
$helper->expects( $this->once() )->method( 'createStream' )->will( $this->returnValue( $stream ) ); |
|
115
|
|
|
$this->view->addHelper( 'response', $helper ); |
|
116
|
|
|
|
|
117
|
|
|
$object->init(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
public function testInitCheckAccess() |
|
122
|
|
|
{ |
|
123
|
|
|
$this->assertFalse( $this->access( 'checkAccess' )->invokeArgs( $this->object, [-1, -2] ) ); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
public function testInitCheckDownload() |
|
128
|
|
|
{ |
|
129
|
|
|
$customerStub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Customer\Standard::class ) |
|
130
|
|
|
->setConstructorArgs( array( $this->context ) ) |
|
131
|
|
|
->setMethods( array( 'addListItem', 'store' ) ) |
|
132
|
|
|
->getMock(); |
|
133
|
|
|
|
|
134
|
|
|
$customerStub->expects( $this->once() )->method( 'addListItem' )->will( $this->returnValue( $customerStub ) ); |
|
135
|
|
|
$customerStub->expects( $this->once() )->method( 'store' )->will( $this->returnValue( $customerStub ) ); |
|
136
|
|
|
|
|
137
|
|
|
\Aimeos\Controller\Frontend\Customer\Factory::injectController( '\Aimeos\Controller\Frontend\Customer\Standard', $customerStub ); |
|
138
|
|
|
$this->assertTrue( $this->access( 'checkDownload' )->invokeArgs( $this->object, [-1, -2] ) ); |
|
139
|
|
|
\Aimeos\Controller\Frontend\Customer\Factory::injectController( '\Aimeos\Controller\Frontend\Customer\Standard', null ); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
public function testInitCheckDownloadMaxCount() |
|
144
|
|
|
{ |
|
145
|
|
|
$this->context->getConfig()->set( 'client/html/account/download/maxcount', 0 ); |
|
146
|
|
|
|
|
147
|
|
|
$this->assertFalse( $this->access( 'checkDownload' )->invokeArgs( $this->object, [-1, -2] ) ); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
public function testAddDownload() |
|
152
|
|
|
{ |
|
153
|
|
|
$fs = $this->context->getFilesystemManager()->get( 'fs-secure' ); |
|
154
|
|
|
$fs->write( 'tmp/download/test.txt', 'test' ); |
|
155
|
|
|
|
|
156
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'order/base/product/attribute' )->create(); |
|
157
|
|
|
$item->setValue( 'tmp/download/test.txt' ); |
|
158
|
|
|
$item->setName( 'test download' ); |
|
159
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
$stream = $this->getMockBuilder( \Psr\Http\Message\StreamInterface::class )->getMock(); |
|
162
|
|
|
$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock(); |
|
163
|
|
|
$response->expects( $this->exactly( 7 ) )->method( 'withHeader' )->will( $this->returnSelf() ); |
|
164
|
|
|
|
|
165
|
|
|
$helper = $this->getMockBuilder( \Aimeos\MW\View\Helper\Response\Standard::class ) |
|
166
|
|
|
->setConstructorArgs( array( $this->view, $response ) ) |
|
167
|
|
|
->setMethods( array( 'createStream' ) ) |
|
168
|
|
|
->getMock(); |
|
169
|
|
|
$helper->expects( $this->once() )->method( 'createStream' )->will( $this->returnValue( $stream ) ); |
|
170
|
|
|
$this->view->addHelper( 'response', $helper ); |
|
171
|
|
|
|
|
172
|
|
|
$this->access( 'addDownload' )->invokeArgs( $this->object, [$item] ); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
public function testAddDownloadRedirect() |
|
177
|
|
|
{ |
|
178
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'order/base/product/attribute' )->create(); |
|
179
|
|
|
$item->setValue( 'http://localhost/dl/test.txt' ); |
|
180
|
|
|
$item->setName( 'test download' ); |
|
181
|
|
|
|
|
182
|
|
|
|
|
183
|
|
|
$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock(); |
|
184
|
|
|
$response->expects( $this->once() )->method( 'withHeader' )->will( $this->returnSelf() ); |
|
185
|
|
|
$response->expects( $this->once() )->method( 'withStatus' )->will( $this->returnSelf() ); |
|
186
|
|
|
|
|
187
|
|
|
$helper = new \Aimeos\MW\View\Helper\Response\Standard( $this->view, $response ); |
|
188
|
|
|
$this->view->addHelper( 'response', $helper ); |
|
189
|
|
|
|
|
190
|
|
|
$this->access( 'addDownload' )->invokeArgs( $this->object, [$item] ); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
public function testAddDownloadNotFound() |
|
195
|
|
|
{ |
|
196
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'order/base/product/attribute' )->create(); |
|
197
|
|
|
$item->setValue( 'test.txt' ); |
|
198
|
|
|
$item->setName( 'test download' ); |
|
199
|
|
|
|
|
200
|
|
|
|
|
201
|
|
|
$response = $this->getMockBuilder( \Psr\Http\Message\ResponseInterface::class )->getMock(); |
|
202
|
|
|
$response->expects( $this->never() )->method( 'withHeader' )->will( $this->returnSelf() ); |
|
203
|
|
|
$response->expects( $this->once() )->method( 'withStatus' )->will( $this->returnSelf() ); |
|
204
|
|
|
|
|
205
|
|
|
$helper = new \Aimeos\MW\View\Helper\Response\Standard( $this->view, $response ); |
|
206
|
|
|
$this->view->addHelper( 'response', $helper ); |
|
207
|
|
|
|
|
208
|
|
|
$this->access( 'addDownload' )->invokeArgs( $this->object, [$item] ); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
|
|
212
|
|
|
protected function access( $name ) |
|
213
|
|
|
{ |
|
214
|
|
|
$class = new \ReflectionClass( \Aimeos\Client\Html\Account\Download\Standard::class ); |
|
215
|
|
|
$method = $class->getMethod( $name ); |
|
216
|
|
|
$method->setAccessible( true ); |
|
217
|
|
|
|
|
218
|
|
|
return $method; |
|
219
|
|
|
} |
|
220
|
|
|
} |
|
221
|
|
|
|