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;
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
	/**
53
	 * Sets up the fixture, for example, opens a network connection.
54
	 * This method is called before a test is executed.
55
	 *
56
	 * @access protected
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->extProducts = self::$productItems;
65
		$view->extAddressItem = self::$customerItem->getPaymentAddress();
66
		$view->addHelper( 'mail', new \Aimeos\MW\View\Helper\Mail\Standard( $view, $this->emailMock ) );
67
68
		$this->object = new \Aimeos\Client\Html\Email\Watch\Standard( $this->context );
69
		$this->object->setView( $view );
70
	}
71
72
73
	/**
74
	 * Tears down the fixture, for example, closes a network connection.
75
	 * This method is called after a test is executed.
76
	 *
77
	 * @access protected
78
	 */
79
	protected function tearDown() : void
80
	{
81
		unset( $this->object );
82
	}
83
84
85
	public function testGetHeader()
86
	{
87
		$config = $this->context->getConfig();
88
		$config->set( 'client/html/email/from-email', 'me@localhost' );
89
		$config->set( 'client/html/email/from-name', 'My company' );
90
91
		$this->emailMock->expects( $this->once() )->method( 'addHeader' )
92
			->with( $this->equalTo( 'X-MailGenerator' ), $this->equalTo( 'Aimeos' ) );
93
94
		$this->emailMock->expects( $this->once() )->method( 'addTo' )
95
			->with( $this->equalTo( '[email protected]' ), $this->equalTo( 'Our Unittest' ) );
96
97
		$this->emailMock->expects( $this->once() )->method( 'addFrom' )
98
			->with( $this->equalTo( 'me@localhost' ), $this->equalTo( 'My company' ) );
99
100
		$this->emailMock->expects( $this->once() )->method( 'addReplyTo' )
101
			->with( $this->equalTo( 'me@localhost' ), $this->equalTo( 'My company' ) );
102
103
		$this->emailMock->expects( $this->once() )->method( 'setSubject' )
104
			->with( $this->stringContains( 'Your watched products' ) );
105
106
		$output = $this->object->getHeader();
107
		$this->assertNotNull( $output );
108
	}
109
110
111
	public function testGetBody()
112
	{
113
		$output = $this->object->getBody();
114
115
		$this->assertStringContainsString( 'Dear Mr Our Unittest', $output );
116
	}
117
118
119
	public function testGetSubClientInvalid()
120
	{
121
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
122
		$this->object->getSubClient( 'invalid', 'invalid' );
123
	}
124
125
126
	public function testGetSubClientInvalidName()
127
	{
128
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
129
		$this->object->getSubClient( '$$$', '$$$' );
130
	}
131
}
132