StandardTest::testView()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2026
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 = \TestHelper::context();
23
		$aimeos = \TestHelper::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
			->onlyMethods( ['iterate'] )
54
			->getMock();
55
56
		\Aimeos\MShop::inject( '\\Aimeos\\MShop\\Order\\Manager\\Standard', $orderManagerStub );
57
58
		$orderItem = $orderManagerStub->create();
59
60
		$orderManagerStub->expects( $this->exactly( 4 ) )->method( 'iterate' )
61
			->willReturn( map( [$orderItem] ), null, null, null );
62
63
		$object = $this->getMockBuilder( \Aimeos\Controller\Jobs\Order\Email\Payment\Standard::class )
64
			->setConstructorArgs( [$this->context, \TestHelper::getAimeos()] )
65
			->onlyMethods( ['notify'] )
66
			->getMock();
67
68
		$object->expects( $this->once() )->method( 'notify' );
69
70
		$object->run();
71
	}
72
73
74
	public function testAddress()
75
	{
76
		$manager = \Aimeos\MShop::create( $this->context, 'order' );
77
		$addrManager = \Aimeos\MShop::create( $this->context, 'order/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\Address\Iface::class, $result );
86
	}
87
88
89
	public function testAddressNone()
90
	{
91
		$manager = \Aimeos\MShop::create( $this->context, 'order' );
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, \TestHelper::getAimeos()] )
102
			->onlyMethods( ['update', 'send'] )
103
			->getMock();
104
105
		$object->expects( $this->once() )->method( 'update' );
106
		$object->expects( $this->once() )->method( 'send' );
107
108
109
		$orderItem = \Aimeos\MShop::create( $this->context, 'order' )->create();
110
111
		$this->access( 'notify' )->invokeArgs( $object, [map( [$orderItem] ), -1] );
112
	}
113
114
115
	public function testNotifyException()
116
	{
117
		$object = $this->getMockBuilder( \Aimeos\Controller\Jobs\Order\Email\Payment\Standard::class )
118
			->setConstructorArgs( [$this->context, \TestHelper::getAimeos()] )
119
			->onlyMethods( ['send'] )
120
			->getMock();
121
122
		$object->expects( $this->once() )->method( 'send' )->will( $this->throwException( new \RuntimeException() ) );
123
124
		$orderItem = \Aimeos\MShop::create( $this->context, 'order' )->create();
125
126
		$this->access( 'notify' )->invokeArgs( $object, [map( [$orderItem] ), -1] );
127
	}
128
129
130
	public function testSend()
131
	{
132
		$mailerStub = $this->getMockBuilder( '\\Aimeos\\Base\\Mail\\Manager\\None' )
133
			->disableOriginalConstructor()
134
			->getMock();
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
			->onlyMethods( ['send'] )
144
			->getMock();
145
146
		$mailerStub->expects( $this->once() )->method( 'get' )->willReturn( $mailStub );
147
		$mailStub->expects( $this->once() )->method( 'create' )->willReturn( $mailMsgStub );
148
		$mailMsgStub->expects( $this->once() )->method( 'send' );
149
150
		$this->context->setMail( $mailerStub );
151
152
153
		$object = $this->getMockBuilder( \Aimeos\Controller\Jobs\Order\Email\Payment\Standard::class )
154
			->setConstructorArgs( [$this->context, \TestHelper::getAimeos()] )
155
			->onlyMethods( ['update'] )
156
			->getMock();
157
158
		$addrItem = \Aimeos\MShop::create( $this->context, 'order/address' )->create()->setEmail( '[email protected]' );
159
		$orderItem = \Aimeos\MShop::create( $this->context, 'order' )->create( ['order.ctime' => '2000-01-01 00:00:00'] );
160
161
		$orderItem->addAddress( $addrItem, 'payment' );
162
163
		$this->access( 'send' )->invokeArgs( $object, [$orderItem] );
164
	}
165
166
167
	public function testView()
168
	{
169
		$orderItem = \Aimeos\MShop::create( $this->context, 'order' )->create();
170
		$addrItem = \Aimeos\MShop::create( $this->context, 'order/address' )->create()->setEmail( '[email protected]' );
171
172
		$result = $this->access( 'view' )->invokeArgs( $this->object, [$orderItem->addAddress( $addrItem, 'payment' )] );
173
174
		$this->assertInstanceof( \Aimeos\Base\View\Iface::class, $result );
175
	}
176
177
178
	protected function access( $name )
179
	{
180
		$class = new \ReflectionClass( \Aimeos\Controller\Jobs\Order\Email\Payment\Standard::class );
181
		$method = $class->getMethod( $name );
182
		$method->setAccessible( true );
183
184
		return $method;
185
	}
186
}
187