Passed
Push — master ( 6501cb...0fb630 )
by Aimeos
03:18
created

StandardTest::testProcess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018
6
 */
7
8
9
namespace Aimeos\Client\Html\Email\Voucher;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private static $orderItem;
15
	private static $orderBaseItem;
16
	private $object;
17
	private $context;
18
	private $emailMock;
19
20
21
	public static function setUpBeforeClass() : void
22
	{
23
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::create( \TestHelperHtml::getContext() );
24
		$orderBaseManager = $orderManager->getSubManager( 'base' );
25
26
		$search = $orderManager->createSearch();
27
		$search->setConditions( $search->compare( '==', 'order.datepayment', '2008-02-15 12:34:56' ) );
28
		$result = $orderManager->searchItems( $search );
29
30
		if( ( self::$orderItem = reset( $result ) ) === false ) {
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
		$products = self::$orderBaseItem->getProducts();
44
		$view = \TestHelperHtml::getView( 'unittest', $this->context->getConfig() );
45
46
		$view->extAddressItem = self::$orderBaseItem->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY, 0 );
47
		$view->extOrderProductItem = reset( $products );
48
		$view->extVoucherCode = 'test';
49
50
		$view->addHelper( 'mail', new \Aimeos\MW\View\Helper\Mail\Standard( $view, $this->emailMock ) );
51
52
		$this->object = new \Aimeos\Client\Html\Email\Voucher\Standard( $this->context );
53
		$this->object->setView( $view );
54
	}
55
56
57
	protected function tearDown() : void
58
	{
59
		unset( $this->object );
60
	}
61
62
63
	public function testGetHeader()
64
	{
65
		$config = $this->context->getConfig();
66
		$config->set( 'client/html/email/from-email', 'me@localhost' );
67
		$config->set( 'client/html/email/from-name', 'My company' );
68
69
		$this->emailMock->expects( $this->once() )->method( 'addHeader' )
70
			->with( $this->equalTo( 'X-MailGenerator' ), $this->equalTo( 'Aimeos' ) );
71
72
		$this->emailMock->expects( $this->once() )->method( 'addTo' )
73
			->with( $this->equalTo( '[email protected]' ), $this->equalTo( 'Our Unittest' ) );
74
75
		$this->emailMock->expects( $this->once() )->method( 'addFrom' )
76
			->with( $this->equalTo( 'me@localhost' ), $this->equalTo( 'My company' ) );
77
78
		$this->emailMock->expects( $this->once() )->method( 'addReplyTo' )
79
			->with( $this->equalTo( 'me@localhost' ), $this->equalTo( 'My company' ) );
80
81
		$this->emailMock->expects( $this->once() )->method( 'setSubject' )
82
			->with( $this->stringContains( 'Your voucher' ) );
83
84
		$output = $this->object->getHeader();
85
		$this->assertNotNull( $output );
86
	}
87
88
89
	public function testGetBody()
90
	{
91
		$output = $this->object->getBody();
92
		$this->assertNotNull( $output );
93
	}
94
95
96
	public function testGetSubClientInvalid()
97
	{
98
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
99
		$this->object->getSubClient( 'invalid', 'invalid' );
100
	}
101
102
103
	public function testGetSubClientInvalidName()
104
	{
105
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
106
		$this->object->getSubClient( '$$$', '$$$' );
107
	}
108
}
109