1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2013 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2018 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\Client\Html\Email\Payment; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private static $orderItem; |
16
|
|
|
private static $orderBaseItem; |
17
|
|
|
private $object; |
18
|
|
|
private $context; |
19
|
|
|
private $emailMock; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
public static function setUpBeforeClass() : void |
23
|
|
|
{ |
24
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::create( \TestHelperHtml::getContext() ); |
25
|
|
|
$orderBaseManager = $orderManager->getSubManager( 'base' ); |
26
|
|
|
|
27
|
|
|
$search = $orderManager->createSearch(); |
28
|
|
|
$search->setConditions( $search->compare( '==', 'order.datepayment', '2008-02-15 12:34:56' ) ); |
29
|
|
|
$result = $orderManager->searchItems( $search ); |
30
|
|
|
|
31
|
|
|
if( ( self::$orderItem = reset( $result ) ) === false ) { |
32
|
|
|
throw new \RuntimeException( 'No order found' ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
self::$orderBaseItem = $orderBaseManager->load( self::$orderItem->getBaseId() ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
protected function setUp() : void |
40
|
|
|
{ |
41
|
|
|
$this->context = \TestHelperHtml::getContext(); |
42
|
|
|
$this->emailMock = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\Message\\None' )->getMock(); |
43
|
|
|
|
44
|
|
|
$view = \TestHelperHtml::getView( 'unittest', $this->context->getConfig() ); |
45
|
|
|
$view->extOrderItem = self::$orderItem; |
46
|
|
|
$view->extOrderBaseItem = self::$orderBaseItem; |
47
|
|
|
$view->extAddressItem = self::$orderBaseItem->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, 0 ); |
48
|
|
|
$view->addHelper( 'mail', new \Aimeos\MW\View\Helper\Mail\Standard( $view, $this->emailMock ) ); |
49
|
|
|
|
50
|
|
|
$this->object = new \Aimeos\Client\Html\Email\Payment\Standard( $this->context ); |
51
|
|
|
$this->object->setView( $view ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
protected function tearDown() : void |
56
|
|
|
{ |
57
|
|
|
unset( $this->object ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
public function testGetHeader() |
62
|
|
|
{ |
63
|
|
|
$config = $this->context->getConfig(); |
64
|
|
|
$config->set( 'client/html/email/from-email', 'me@localhost' ); |
65
|
|
|
$config->set( 'client/html/email/from-name', 'My company' ); |
66
|
|
|
|
67
|
|
|
$this->emailMock->expects( $this->once() )->method( 'addHeader' ) |
68
|
|
|
->with( $this->equalTo( 'X-MailGenerator' ), $this->equalTo( 'Aimeos' ) ); |
69
|
|
|
|
70
|
|
|
$this->emailMock->expects( $this->once() )->method( 'addTo' ) |
71
|
|
|
->with( $this->equalTo( '[email protected]' ), $this->equalTo( 'Our Unittest' ) ); |
72
|
|
|
|
73
|
|
|
$this->emailMock->expects( $this->once() )->method( 'addFrom' ) |
74
|
|
|
->with( $this->equalTo( 'me@localhost' ), $this->equalTo( 'My company' ) ); |
75
|
|
|
|
76
|
|
|
$this->emailMock->expects( $this->once() )->method( 'addReplyTo' ) |
77
|
|
|
->with( $this->equalTo( 'me@localhost' ), $this->equalTo( 'My company' ) ); |
78
|
|
|
|
79
|
|
|
$this->emailMock->expects( $this->once() )->method( 'setSubject' ) |
80
|
|
|
->with( $this->stringContains( 'Your order' ) ); |
81
|
|
|
|
82
|
|
|
$output = $this->object->getHeader(); |
83
|
|
|
$this->assertNotNull( $output ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
public function testGetBody() |
88
|
|
|
{ |
89
|
|
|
$output = $this->object->getBody(); |
90
|
|
|
$this->assertNotNull( $output ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
public function testGetBodyFiles() |
95
|
|
|
{ |
96
|
|
|
$config = $this->context->getConfig(); |
97
|
|
|
$config->set( 'client/html/email/payment/attachments', array( __FILE__ ) ); |
98
|
|
|
|
99
|
|
|
$output = $this->object->getBody(); |
100
|
|
|
$this->assertNotNull( $output ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
public function testGetBodyFilesException() |
105
|
|
|
{ |
106
|
|
|
$config = $this->context->getConfig(); |
107
|
|
|
$config->set( 'client/html/email/payment/attachments', array( 'invalid' ) ); |
108
|
|
|
|
109
|
|
|
$this->expectException( \Aimeos\Client\Html\Exception::class ); |
110
|
|
|
$this->object->getBody(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
public function testGetSubClientInvalid() |
115
|
|
|
{ |
116
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
117
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
public function testGetSubClientInvalidName() |
122
|
|
|
{ |
123
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
124
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|