Passed
Push — master ( ed6c8e...268125 )
by Aimeos
03:53
created

StandardTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 52
dl 0
loc 111
rs 10
c 0
b 0
f 0
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetSubClientInvalidName() 0 4 1
A setUpBeforeClass() 0 13 2
A testGetSubClientInvalid() 0 4 1
A setUp() 0 13 1
A tearDown() 0 3 1
A testBodyFiles() 0 7 1
A testBodyFilesException() 0 7 1
A testBody() 0 4 1
A testHeader() 0 23 1
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-2021
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
		$manager = \Aimeos\MShop\Order\Manager\Factory::create( \TestHelperHtml::getContext() );
25
		$orderBaseManager = $manager->getSubManager( 'base' );
26
27
		$search = $manager->filter();
28
		$search->setConditions( $search->compare( '==', 'order.datepayment', '2008-02-15 12:34:56' ) );
29
30
		if( ( self::$orderItem = $manager->search( $search )->first() ) === null ) {
31
			throw new \RuntimeException( 'No order found' );
32
		}
33
34
		self::$orderBaseItem = $orderBaseManager->load( self::$orderItem->getBaseId() );
35
	}
36
37
38
	protected function setUp() : void
39
	{
40
		$this->context = \TestHelperHtml::getContext();
41
		$this->emailMock = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\Message\\None' )->getMock();
42
43
		$view = \TestHelperHtml::getView( 'unittest', $this->context->getConfig() );
44
		$view->extOrderItem = self::$orderItem;
45
		$view->extOrderBaseItem = self::$orderBaseItem;
46
		$view->extAddressItem = self::$orderBaseItem->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, 0 );
47
		$view->addHelper( 'mail', new \Aimeos\MW\View\Helper\Mail\Standard( $view, $this->emailMock ) );
48
49
		$this->object = new \Aimeos\Client\Html\Email\Payment\Standard( $this->context );
50
		$this->object->setView( $view );
51
	}
52
53
54
	protected function tearDown() : void
55
	{
56
		unset( $this->object );
57
	}
58
59
60
	public function testHeader()
61
	{
62
		$config = $this->context->getConfig();
63
		$config->set( 'client/html/email/from-email', '[email protected]' );
64
		$config->set( 'client/html/email/from-name', 'My company' );
65
66
		$this->emailMock->expects( $this->once() )->method( 'addHeader' )
67
			->with( $this->equalTo( 'X-MailGenerator' ), $this->equalTo( 'Aimeos' ) );
68
69
		$this->emailMock->expects( $this->once() )->method( 'addTo' )
70
			->with( $this->equalTo( '[email protected]' ), $this->equalTo( 'Our Unittest' ) );
71
72
		$this->emailMock->expects( $this->once() )->method( 'addFrom' )
73
			->with( $this->equalTo( '[email protected]' ), $this->equalTo( 'My company' ) );
74
75
		$this->emailMock->expects( $this->once() )->method( 'addReplyTo' )
76
			->with( $this->equalTo( '[email protected]' ), $this->equalTo( 'My company' ) );
77
78
		$this->emailMock->expects( $this->once() )->method( 'setSubject' )
79
			->with( $this->stringContains( 'Your order' ) );
80
81
		$output = $this->object->header();
82
		$this->assertNotNull( $output );
83
	}
84
85
86
	public function testBody()
87
	{
88
		$output = $this->object->body();
89
		$this->assertNotNull( $output );
90
	}
91
92
93
	public function testBodyFiles()
94
	{
95
		$config = $this->context->getConfig();
96
		$config->set( 'client/html/email/payment/attachments', array( __FILE__ ) );
97
98
		$output = $this->object->body();
99
		$this->assertNotNull( $output );
100
	}
101
102
103
	public function testBodyFilesException()
104
	{
105
		$config = $this->context->getConfig();
106
		$config->set( 'client/html/email/payment/attachments', array( 'invalid' ) );
107
108
		$this->expectException( \Aimeos\Client\Html\Exception::class );
109
		$this->object->body();
110
	}
111
112
113
	public function testGetSubClientInvalid()
114
	{
115
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
116
		$this->object->getSubClient( 'invalid', 'invalid' );
117
	}
118
119
120
	public function testGetSubClientInvalidName()
121
	{
122
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
123
		$this->object->getSubClient( '$$$', '$$$' );
124
	}
125
}
126