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\Html;
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\Html\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 testGetBody()
59
	{
60
		$ds = DIRECTORY_SEPARATOR;
61
62
		$logo = '..' . $ds . 'themes' . $ds . 'elegance' . $ds . 'media' . $ds . 'aimeos.png';
63
		$this->context->getConfig()->set( 'client/html/email/logo', $logo );
64
65
		$theme = '..' . $ds . 'themes' . $ds . 'elegance';
66
		$this->context->getConfig()->set( 'client/html/common/template/baseurl', $theme );
67
68
69
		$this->emailMock->expects( $this->once() )->method( 'embedAttachment' )
70
			->will( $this->returnValue( 'cid:123-unique-id' ) );
71
72
		$this->emailMock->expects( $this->once() )->method( 'setBodyHtml' )
73
			->with( $this->matchesRegularExpression( '#<title>.*Your new account.*</title>#smu' ) );
74
75
		$this->object->setView( $this->object->addData( $this->object->getView() ) );
76
		$output = $this->object->getBody();
77
78
		$this->assertStringContainsString( '<!doctype html>', $output );
79
		$this->assertStringContainsString( 'cid:123-unique-id', $output );
80
81
		$this->assertStringContainsString( 'email-common-salutation', $output );
82
83
		$this->assertStringContainsString( 'email-common-intro', $output );
84
		$this->assertStringContainsString( 'An account', $output );
85
86
		$this->assertStringContainsString( 'Account', $output );
87
		$this->assertStringContainsString( 'Password', $output );
88
89
		$this->assertStringContainsString( 'email-common-outro', $output );
90
		$this->assertStringContainsString( 'If you have any questions', $output );
91
	}
92
93
94
	public function testGetSubClientInvalid()
95
	{
96
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
97
		$this->object->getSubClient( 'invalid', 'invalid' );
98
	}
99
100
101
	public function testGetSubClientInvalidName()
102
	{
103
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
104
		$this->object->getSubClient( '$$$', '$$$' );
105
	}
106
}
107