|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2022 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Jobs\Order\Email\Payment; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $context; |
|
15
|
|
|
private $object; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() : void |
|
19
|
|
|
{ |
|
20
|
|
|
\Aimeos\MShop::cache( true ); |
|
21
|
|
|
|
|
22
|
|
|
$this->context = \TestHelperJobs::context(); |
|
23
|
|
|
$aimeos = \TestHelperJobs::getAimeos(); |
|
24
|
|
|
|
|
25
|
|
|
$this->object = new \Aimeos\Controller\Jobs\Order\Email\Payment\Standard( $this->context, $aimeos ); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
protected function tearDown() : void |
|
30
|
|
|
{ |
|
31
|
|
|
\Aimeos\MShop::cache( false ); |
|
32
|
|
|
unset( $this->object ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
public function testGetName() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->assertEquals( 'Order payment related e-mails', $this->object->getName() ); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
public function testGetDescription() |
|
43
|
|
|
{ |
|
44
|
|
|
$text = 'Sends order confirmation or payment status update e-mails'; |
|
45
|
|
|
$this->assertEquals( $text, $this->object->getDescription() ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
public function testRun() |
|
50
|
|
|
{ |
|
51
|
|
|
$orderManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Order\\Manager\\Standard' ) |
|
52
|
|
|
->setConstructorArgs( [$this->context] ) |
|
53
|
|
|
->setMethods( ['search'] ) |
|
54
|
|
|
->getMock(); |
|
55
|
|
|
|
|
56
|
|
|
\Aimeos\MShop::inject( 'order', $orderManagerStub ); |
|
57
|
|
|
|
|
58
|
|
|
$orderItem = $orderManagerStub->create(); |
|
59
|
|
|
|
|
60
|
|
|
$orderManagerStub->expects( $this->exactly( 4 ) )->method( 'search' ) |
|
61
|
|
|
->will( $this->onConsecutiveCalls( map( [$orderItem] ), map(), map(), map() ) ); |
|
62
|
|
|
|
|
63
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Jobs\Order\Email\Payment\Standard::class ) |
|
64
|
|
|
->setConstructorArgs( [$this->context, \TestHelperJobs::getAimeos()] ) |
|
65
|
|
|
->setMethods( ['notify'] ) |
|
66
|
|
|
->getMock(); |
|
67
|
|
|
|
|
68
|
|
|
$object->expects( $this->exactly( 4 ) )->method( 'notify' ); |
|
69
|
|
|
|
|
70
|
|
|
$object->run(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
public function testAddress() |
|
75
|
|
|
{ |
|
76
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'order/base' ); |
|
77
|
|
|
$addrManager = \Aimeos\MShop::create( $this->context, 'order/base/address' ); |
|
78
|
|
|
|
|
79
|
|
|
$item = $manager->create(); |
|
80
|
|
|
$item->addAddress( $addrManager->create()->setEmail( '[email protected]' ), 'payment' ); |
|
81
|
|
|
$item->addAddress( $addrManager->create()->setEmail( '[email protected]' ), 'delivery' ); |
|
82
|
|
|
|
|
83
|
|
|
$result = $this->access( 'address' )->invokeArgs( $this->object, [$item] ); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertInstanceof( \Aimeos\MShop\Order\Item\Base\Address\Iface::class, $result ); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
public function testAddressNone() |
|
90
|
|
|
{ |
|
91
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'order/base' ); |
|
92
|
|
|
|
|
93
|
|
|
$this->expectException( \Aimeos\Controller\Jobs\Exception::class ); |
|
94
|
|
|
$this->access( 'address' )->invokeArgs( $this->object, [$manager->create()] ); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
public function testNotify() |
|
99
|
|
|
{ |
|
100
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Jobs\Order\Email\Payment\Standard::class ) |
|
101
|
|
|
->setConstructorArgs( [$this->context, \TestHelperJobs::getAimeos()] ) |
|
102
|
|
|
->setMethods( ['address', 'status', 'send'] ) |
|
103
|
|
|
->getMock(); |
|
104
|
|
|
|
|
105
|
|
|
$addrItem = \Aimeos\MShop::create( $this->context, 'order/base/address' )->create()->setEmail( '[email protected]' ); |
|
106
|
|
|
$object->expects( $this->exactly( 2 ) )->method( 'address' )->will( $this->returnValue( $addrItem ) ); |
|
107
|
|
|
$object->expects( $this->once() )->method( 'status' ); |
|
108
|
|
|
$object->expects( $this->once() )->method( 'send' ); |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
$orderItem = \Aimeos\MShop::create( $this->context, 'order' )->create()->setBaseId( '-1' ) |
|
112
|
|
|
->setBaseItem( \Aimeos\MShop::create( $this->context, 'order/base' )->create() ); |
|
113
|
|
|
|
|
114
|
|
|
$this->access( 'notify' )->invokeArgs( $object, [map( [$orderItem] ), -1] ); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
public function testNotifyException() |
|
119
|
|
|
{ |
|
120
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Jobs\Order\Email\Payment\Standard::class ) |
|
121
|
|
|
->setConstructorArgs( [$this->context, \TestHelperJobs::getAimeos()] ) |
|
122
|
|
|
->setMethods( ['view'] ) |
|
123
|
|
|
->getMock(); |
|
124
|
|
|
|
|
125
|
|
|
$object->expects( $this->once() )->method( 'view' )->will( $this->throwException( new \RuntimeException() ) ); |
|
126
|
|
|
|
|
127
|
|
|
$orderItem = \Aimeos\MShop::create( $this->context, 'order' )->create()->setBaseId( '-1' ) |
|
128
|
|
|
->setBaseItem( \Aimeos\MShop::create( $this->context, 'order/base' )->create() ); |
|
129
|
|
|
|
|
130
|
|
|
$this->access( 'notify' )->invokeArgs( $object, [map( [$orderItem] ), -1] ); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
public function testSend() |
|
135
|
|
|
{ |
|
136
|
|
|
$mailStub = $this->getMockBuilder( '\\Aimeos\\Base\\Mail\\None' ) |
|
137
|
|
|
->disableOriginalConstructor() |
|
138
|
|
|
->getMock(); |
|
139
|
|
|
|
|
140
|
|
|
$mailMsgStub = $this->getMockBuilder( '\\Aimeos\\Base\\Mail\\Message\\None' ) |
|
141
|
|
|
->disableOriginalConstructor() |
|
142
|
|
|
->disableOriginalClone() |
|
143
|
|
|
->setMethods( ['send'] ) |
|
144
|
|
|
->getMock(); |
|
145
|
|
|
|
|
146
|
|
|
$mailStub->expects( $this->once() )->method( 'create' )->will( $this->returnValue( $mailMsgStub ) ); |
|
147
|
|
|
$mailMsgStub->expects( $this->once() )->method( 'send' ); |
|
148
|
|
|
|
|
149
|
|
|
$this->context->setMail( $mailStub ); |
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Jobs\Order\Email\Payment\Standard::class ) |
|
153
|
|
|
->setConstructorArgs( [$this->context, \TestHelperJobs::getAimeos()] ) |
|
154
|
|
|
->setMethods( ['status'] ) |
|
155
|
|
|
->getMock(); |
|
156
|
|
|
|
|
157
|
|
|
$baseItem = \Aimeos\MShop::create( $this->context, 'order/base' )->create(); |
|
158
|
|
|
$addrItem = \Aimeos\MShop::create( $this->context, 'order/base/address' )->create()->setEmail( '[email protected]' ); |
|
159
|
|
|
$orderItem = \Aimeos\MShop::create( $this->context, 'order' )->create( ['order.ctime' => '2000-01-01 00:00:00'] ); |
|
160
|
|
|
|
|
161
|
|
|
$view = $this->access( 'view' )->invokeArgs( $object, [$baseItem->addAddress( $addrItem, 'payment' )] ); |
|
162
|
|
|
$view->summaryBasket = $baseItem; |
|
163
|
|
|
$view->addressItem = $addrItem; |
|
164
|
|
|
$view->orderItem = $orderItem; |
|
165
|
|
|
|
|
166
|
|
|
$this->access( 'send' )->invokeArgs( $object, [$view, 'RE-001'] ); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
|
|
170
|
|
|
public function testView() |
|
171
|
|
|
{ |
|
172
|
|
|
$baseItem = \Aimeos\MShop::create( $this->context, 'order/base' )->create(); |
|
173
|
|
|
$addrItem = \Aimeos\MShop::create( $this->context, 'order/base/address' )->create()->setEmail( '[email protected]' ); |
|
174
|
|
|
|
|
175
|
|
|
$result = $this->access( 'view' )->invokeArgs( $this->object, [$baseItem->addAddress( $addrItem, 'payment' )] ); |
|
176
|
|
|
|
|
177
|
|
|
$this->assertInstanceof( \Aimeos\MW\View\Iface::class, $result ); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
|
|
181
|
|
|
protected function access( $name ) |
|
182
|
|
|
{ |
|
183
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Jobs\Order\Email\Payment\Standard::class ); |
|
184
|
|
|
$method = $class->getMethod( $name ); |
|
185
|
|
|
$method->setAccessible( true ); |
|
186
|
|
|
|
|
187
|
|
|
return $method; |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|