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\Subscription;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private static $subscriptionItem;
15
	private static $productItem;
16
	private static $addressItem;
17
	private $object;
18
	private $context;
19
	private $emailMock;
20
21
22
	public static function setUpBeforeClass() : void
23
	{
24
		$context = \TestHelperHtml::getContext();
25
26
		$manager = \Aimeos\MShop::create( $context, 'subscription' );
27
28
		$search = $manager->createSearch();
29
		$search->setConditions( $search->compare( '==', 'subscription.dateend', '2010-01-01' ) );
30
		$result = $manager->searchItems( $search );
31
32
		if( ( self::$subscriptionItem = reset( $result ) ) === false ) {
33
			throw new \RuntimeException( 'No subscription item found' );
34
		}
35
36
37
		$manager = \Aimeos\MShop::create( $context, 'order/base' );
38
39
		$search = $manager->createSearch();
40
		$search->setConditions( $search->compare( '==', 'order.base.price', '53.50' ) );
41
		$result = $manager->searchItems( $search, ['order/base/address', 'order/base/product'] );
42
43
		if( ( $baseItem = reset( $result ) ) === false ) {
44
			throw new \RuntimeException( 'No order base item found' );
45
		}
46
47
		foreach( $baseItem->getProducts() as $product )
48
		{
49
			if( $product->getProductCode() === 'CNC' ) {
50
				self::$productItem = $product;
51
			}
52
		}
53
54
		self::$addressItem = $baseItem->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT, 0 );
55
	}
56
57
58
	protected function setUp() : void
59
	{
60
		$this->context = \TestHelperHtml::getContext();
61
		$this->emailMock = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\Message\\None' )->getMock();
62
63
		$view = \TestHelperHtml::getView( 'unittest', $this->context->getConfig() );
64
		$view->extSubscriptionItem = self::$subscriptionItem;
65
		$view->extOrderProductItem = self::$productItem;
66
		$view->extAddressItem = self::$addressItem;
67
		$view->addHelper( 'mail', new \Aimeos\MW\View\Helper\Mail\Standard( $view, $this->emailMock ) );
68
69
		$this->object = new \Aimeos\Client\Html\Email\Subscription\Standard( $this->context );
70
		$this->object->setView( $view );
71
	}
72
73
74
	protected function tearDown() : void
75
	{
76
		unset( $this->object );
77
	}
78
79
80
	public function testGetHeader()
81
	{
82
		$config = $this->context->getConfig();
83
		$config->set( 'client/html/email/from-email', 'me@localhost' );
84
		$config->set( 'client/html/email/from-name', 'My company' );
85
86
		$this->emailMock->expects( $this->once() )->method( 'addHeader' )
87
			->with( $this->equalTo( 'X-MailGenerator' ), $this->equalTo( 'Aimeos' ) );
88
89
		$this->emailMock->expects( $this->once() )->method( 'addTo' )
90
			->with( $this->equalTo( '[email protected]' ), $this->equalTo( 'Our Unittest' ) );
91
92
		$this->emailMock->expects( $this->once() )->method( 'addFrom' )
93
			->with( $this->equalTo( 'me@localhost' ), $this->equalTo( 'My company' ) );
94
95
		$this->emailMock->expects( $this->once() )->method( 'addReplyTo' )
96
			->with( $this->equalTo( 'me@localhost' ), $this->equalTo( 'My company' ) );
97
98
		$this->emailMock->expects( $this->once() )->method( 'setSubject' )
99
			->with( $this->stringContains( 'Your subscription' ) );
100
101
		$output = $this->object->getHeader();
102
		$this->assertNotNull( $output );
103
	}
104
105
106
	public function testGetBody()
107
	{
108
		$output = $this->object->getBody();
109
110
		$this->assertStringContainsString( 'Dear Mr Our Unittest', $output );
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