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, 2013
6
 * @copyright Aimeos (aimeos.org), 2015-2018
7
 */
8
9
10
namespace Aimeos\Client\Html\Email\Delivery\Html;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
14
{
15
	private static $orderItem;
16
	private static $orderBaseItem;
17
	private $object;
18
	private $context;
19
	private $emailMock;
20
21
22
	public static function setUpBeforeClass() : void
23
	{
24
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::create( \TestHelperHtml::getContext() );
25
		$orderBaseManager = $orderManager->getSubManager( 'base' );
26
27
		$search = $orderManager->createSearch();
28
		$search->setConditions( $search->compare( '==', 'order.datepayment', '2008-02-15 12:34:56' ) );
29
		$result = $orderManager->searchItems( $search );
30
31
		if( ( self::$orderItem = reset( $result ) ) === false ) {
32
			throw new \RuntimeException( 'No order found' );
33
		}
34
35
		self::$orderBaseItem = $orderBaseManager->load( self::$orderItem->getBaseId() );
36
	}
37
38
39
	protected function setUp() : void
40
	{
41
		$this->context = \TestHelperHtml::getContext();
42
		$this->emailMock = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\Message\\None' )->getMock();
43
44
		$view = \TestHelperHtml::getView( 'unittest', $this->context->getConfig() );
45
		$view->extOrderItem = self::$orderItem;
46
		$view->extOrderBaseItem = self::$orderBaseItem;
47
		$view->addHelper( 'mail', new \Aimeos\MW\View\Helper\Mail\Standard( $view, $this->emailMock ) );
48
49
		$this->object = new \Aimeos\Client\Html\Email\Delivery\Html\Standard( $this->context );
50
		$this->object->setView( $view );
51
	}
52
53
54
	protected function tearDown() : void
55
	{
56
		unset( $this->object );
57
	}
58
59
60
	public function testGetBody()
61
	{
62
		$ds = DIRECTORY_SEPARATOR;
63
		$file = '..' . $ds . 'themes' . $ds . 'elegance' . $ds . 'media' . $ds . 'aimeos.png';
64
		$this->context->getConfig()->set( 'client/html/email/logo', $file );
65
66
		$this->emailMock->expects( $this->once() )->method( 'embedAttachment' )
67
			->will( $this->returnValue( 'cid:123-unique-id' ) );
68
69
		$this->emailMock->expects( $this->once() )->method( 'setBodyHtml' );
70
71
		$this->object->setView( $this->object->addData( $this->object->getView() ) );
72
		$output = $this->object->getBody();
73
74
		$this->assertStringStartsWith( '<!doctype html>', $output );
75
		$this->assertStringContainsString( 'cid:123-unique-id', $output );
76
		$this->assertStringContainsString( 'The delivery status of your order', $output );
77
		$this->assertStringContainsString( 'Cafe Noire Expresso', $output );
78
		$this->assertStringContainsString( 'If you have any questions', $output );
79
		$this->assertStringContainsString( 'All orders are subject', $output );
80
	}
81
82
83
	public function testGetSubClientInvalid()
84
	{
85
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
86
		$this->object->getSubClient( 'invalid', 'invalid' );
87
	}
88
89
90
	public function testGetSubClientInvalidName()
91
	{
92
		$this->expectException( '\\Aimeos\\Client\\Html\\Exception' );
93
		$this->object->getSubClient( '$$$', '$$$' );
94
	}
95
}
96