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 Aimeos (aimeos.org), 2015-2018
6
 */
7
8
9
namespace Aimeos\Client\Html\Email\Account;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private static $customerItem;
15
	private $object;
16
	private $context;
17
	private $emailMock;
18
19
20
	public static function setUpBeforeClass() : void
21
	{
22
		$context = \TestHelperHtml::getContext();
23
24
		$manager = \Aimeos\MShop\Customer\Manager\Factory::create( $context );
25
26
		$search = $manager->createSearch();
27
		$search->setConditions( $search->compare( '==', 'customer.code', 'UTC001' ) );
28
		$result = $manager->searchItems( $search );
29
30
		if( ( self::$customerItem = reset( $result ) ) === false ) {
31
			throw new \RuntimeException( 'No customer found' );
32
		}
33
	}
34
35
36
	protected function setUp() : void
37
	{
38
		$this->context = \TestHelperHtml::getContext();
39
		$this->emailMock = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\Message\\None' )->getMock();
40
41
		$view = \TestHelperHtml::getView( 'unittest', $this->context->getConfig() );
42
		$view->extAddressItem = self::$customerItem->getPaymentAddress();
43
		$view->extAccountCode = self::$customerItem->getCode();
44
		$view->extAccountPassword = 'testpwd';
45
		$view->addHelper( 'mail', new \Aimeos\MW\View\Helper\Mail\Standard( $view, $this->emailMock ) );
46
47
		$this->object = new \Aimeos\Client\Html\Email\Account\Standard( $this->context );
48
		$this->object->setView( $view );
49
	}
50
51
52
	protected function tearDown() : void
53
	{
54
		unset( $this->object );
55
	}
56
57
58
	public function testGetHeader()
59
	{
60
		$config = $this->context->getConfig();
61
		$config->set( 'client/html/email/from-email', 'me@localhost' );
62
		$config->set( 'client/html/email/from-name', 'My company' );
63
64
		$this->emailMock->expects( $this->once() )->method( 'addHeader' )
65
			->with( $this->equalTo( 'X-MailGenerator' ), $this->equalTo( 'Aimeos' ) );
66
67
		$this->emailMock->expects( $this->once() )->method( 'addTo' )
68
			->with( $this->equalTo( '[email protected]' ), $this->equalTo( 'Our Unittest' ) );
69
70
		$this->emailMock->expects( $this->once() )->method( 'addFrom' )
71
			->with( $this->equalTo( 'me@localhost' ), $this->equalTo( 'My company' ) );
72
73
		$this->emailMock->expects( $this->once() )->method( 'addReplyTo' )
74
			->with( $this->equalTo( 'me@localhost' ), $this->equalTo( 'My company' ) );
75
76
		$this->emailMock->expects( $this->once() )->method( 'setSubject' )
77
			->with( $this->stringContains( 'Your new account' ) );
78
79
		$output = $this->object->getHeader();
80
		$this->assertNotNull( $output );
81
	}
82
83
84
	public function testGetBody()
85
	{
86
		$output = $this->object->getBody();
87
88
		$this->assertStringContainsString( 'Dear Mr Our Unittest', $output );
89
	}
90
91
92
	public function testGetSubClientInvalid()
93
	{
94
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
95
		$this->object->getSubClient( 'invalid', 'invalid' );
96
	}
97
98
99
	public function testGetSubClientInvalidName()
100
	{
101
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
102
		$this->object->getSubClient( '$$$', '$$$' );
103
	}
104
}
105