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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2014
6
 * @copyright Aimeos (aimeos.org), 2015-2018
7
 */
8
9
10
namespace Aimeos\Client\Html\Email\Watch\Html;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
14
{
15
	private static $productItems;
16
	private static $customerItem;
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\Customer\Manager\Factory::create( $context );
27
28
		$search = $manager->createSearch();
29
		$search->setConditions( $search->compare( '==', 'customer.code', 'UTC001' ) );
30
		$result = $manager->searchItems( $search );
31
32
		if( ( self::$customerItem = reset( $result ) ) === false ) {
33
			throw new \RuntimeException( 'No customer found' );
34
		}
35
36
		$manager = \Aimeos\MShop\Product\Manager\Factory::create( $context );
37
38
		$search = $manager->createSearch();
39
		$search->setConditions( $search->compare( '==', 'product.code', array( 'CNC', 'CNE' ) ) );
40
41
		foreach( $manager->searchItems( $search, array( 'text', 'price', 'media' ) ) as $id => $product )
42
		{
43
			$prices = $product->getRefItems( 'price', 'default', 'default' );
44
45
			self::$productItems[$id]['price'] = reset( $prices );
46
			self::$productItems[$id]['currency'] = 'EUR';
47
			self::$productItems[$id]['item'] = $product;
48
		}
49
	}
50
51
52
	protected function setUp() : void
53
	{
54
		$this->context = \TestHelperHtml::getContext();
55
		$this->emailMock = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\Message\\None' )->getMock();
56
57
		$view = \TestHelperHtml::getView( 'unittest', $this->context->getConfig() );
58
		$view->extProducts = self::$productItems;
59
		$view->extAddressItem = self::$customerItem->getPaymentAddress();
60
		$view->addHelper( 'mail', new \Aimeos\MW\View\Helper\Mail\Standard( $view, $this->emailMock ) );
61
62
		$this->object = new \Aimeos\Client\Html\Email\Watch\Html\Standard( $this->context );
63
		$this->object->setView( $view );
64
	}
65
66
67
	protected function tearDown() : void
68
	{
69
		unset( $this->object );
70
	}
71
72
73
	public function testGetBody()
74
	{
75
		$ds = DIRECTORY_SEPARATOR;
76
		$file = '..' . $ds . 'themes' . $ds . 'elegance' . $ds . 'media' . $ds . 'aimeos.png';
77
		$this->context->getConfig()->set( 'client/html/email/logo', $file );
78
79
		$this->emailMock->expects( $this->once() )->method( 'embedAttachment' )
80
			->will( $this->returnValue( 'cid:123-unique-id' ) );
81
82
		$this->emailMock->expects( $this->once() )->method( 'setBodyHtml' )
83
			->with( $this->matchesRegularExpression( '#<title>.*Your watched products.*</title>#smu' ) );
84
85
		$this->object->setView( $this->object->addData( $this->object->getView() ) );
86
		$output = $this->object->getBody();
87
88
		$this->assertStringStartsWith( '<!doctype html>', $output );
89
		$this->assertStringContainsString( 'cid:123-unique-id', $output );
90
91
		$this->assertStringContainsString( 'email-common-salutation', $output );
92
93
		$this->assertStringContainsString( 'email-common-intro', $output );
94
		$this->assertStringContainsString( 'One or more products', $output );
95
96
		$this->assertStringContainsString( 'common-summary-detail common-summary', $output );
97
		$this->assertStringContainsString( 'Cafe Noire Cappuccino', $output );
98
		$this->assertStringContainsString( 'Cafe Noire Expresso', $output );
99
100
		$this->assertStringContainsString( 'email-common-outro', $output );
101
		$this->assertStringContainsString( 'If you have any questions', $output );
102
	}
103
104
105
	public function testGetSubClientInvalid()
106
	{
107
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
108
		$this->object->getSubClient( 'invalid', 'invalid' );
109
	}
110
111
112
	public function testGetSubClientInvalidName()
113
	{
114
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
115
		$this->object->getSubClient( '$$$', '$$$' );
116
	}
117
}
118