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\Html;
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\Html\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 testGetBody()
81
	{
82
		$ds = DIRECTORY_SEPARATOR;
83
		$file = '..' . $ds . 'themes' . $ds . 'elegance' . $ds . 'media' . $ds . 'aimeos.png';
84
		$this->context->getConfig()->set( 'client/html/email/logo', $file );
85
86
		$this->emailMock->expects( $this->once() )->method( 'embedAttachment' )
87
			->will( $this->returnValue( 'cid:123-unique-id' ) );
88
89
		$this->emailMock->expects( $this->once() )->method( 'setBodyHtml' )
90
			->with( $this->matchesRegularExpression( '#<title>.*Your subscription.*</title>#smu' ) );
91
92
		$this->object->setView( $this->object->addData( $this->object->getView() ) );
93
		$output = $this->object->getBody();
94
95
		$this->assertStringStartsWith( '<!doctype html>', $output );
96
		$this->assertStringContainsString( 'cid:123-unique-id', $output );
97
98
		$this->assertStringContainsString( 'email-common-salutation', $output );
99
100
		$this->assertStringContainsString( 'email-common-intro', $output );
101
		$this->assertStringContainsString( 'The subscription', $output );
102
103
		$this->assertStringContainsString( 'common-summary-detail common-summary', $output );
104
		$this->assertStringContainsString( 'Cafe Noire Cappuccino', $output );
105
106
		$this->assertStringContainsString( 'email-common-outro', $output );
107
		$this->assertStringContainsString( 'If you have any questions', $output );
108
	}
109
110
111
	public function testGetSubClientInvalid()
112
	{
113
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
114
		$this->object->getSubClient( 'invalid', 'invalid' );
115
	}
116
117
118
	public function testGetSubClientInvalidName()
119
	{
120
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
121
		$this->object->getSubClient( '$$$', '$$$' );
122
	}
123
}
124