Passed
Push — master ( 65a101...2c0bda )
by Aimeos
18:02
created

EmailTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 39
c 1
b 0
f 0
dl 0
loc 90
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 12 1
A tearDown() 0 3 1
A testCheckConfigBE() 0 18 1
A testGetConfigBE() 0 8 2
A testProcessBatch() 0 5 1
A testProcess() 0 5 1
A getOrderItem() 0 14 2
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021
6
 */
7
8
9
namespace Aimeos\MShop\Service\Provider\Delivery;
10
11
12
class EmailTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
17
18
	protected function setUp() : void
19
	{
20
		$this->context = \TestHelperMShop::getContext();
21
		$serviceManager = \Aimeos\MShop\Service\Manager\Factory::create( $this->context );
22
23
		$serviceItem = $serviceManager->create()->setConfig( [
24
			'email.from' => 'test@localhost',
25
			'email.to' => 'erp@localhost',
26
			'email.subject' => 'New orders',
27
		] );
28
29
		$this->object = new \Aimeos\MShop\Service\Provider\Delivery\Email( $this->context, $serviceItem );
30
	}
31
32
33
	protected function tearDown() : void
34
	{
35
		unset( $this->object );
36
	}
37
38
39
	public function testCheckConfigBE()
40
	{
41
		$attributes = [
42
			'email.from' => 'test@localhost',
43
			'email.to' => 'erp@localhost',
44
			'email.subject' => 'New orders',
45
			'email.template' => '/test.php',
46
			'email.order-template' => '/test-order.php',
47
		];
48
49
		$result = $this->object->checkConfigBE( $attributes );
50
51
		$this->assertEquals( 5, count( $result ) );
52
		$this->assertEquals( null, $result['email.from'] );
53
		$this->assertEquals( null, $result['email.to'] );
54
		$this->assertEquals( null, $result['email.subject'] );
55
		$this->assertEquals( null, $result['email.template'] );
56
		$this->assertEquals( null, $result['email.order-template'] );
57
	}
58
59
60
	public function testGetConfigBE()
61
	{
62
		$result = $this->object->getConfigBE();
63
64
		$this->assertEquals( 5, count( $result ) );
65
66
		foreach( $result as $key => $item ) {
67
			$this->assertInstanceOf( 'Aimeos\MW\Criteria\Attribute\Iface', $item );
68
		}
69
	}
70
71
72
	public function testProcess()
73
	{
74
		$order = $this->object->process( $this->getOrderItem() );
75
76
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::STAT_PROGRESS, $order->getDeliveryStatus() );
77
	}
78
79
80
	public function testProcessBatch()
81
	{
82
		$orders = $this->object->processBatch( [$this->getOrderItem()] );
83
84
		$this->assertEquals( \Aimeos\MShop\Order\Item\Base::STAT_PROGRESS, $orders->getDeliveryStatus()->first() );
85
	}
86
87
88
	protected function getOrderItem()
89
	{
90
		$manager = \Aimeos\MShop::create( $this->context, 'order' );
91
92
		$search = $manager->filter();
93
		$search->setConditions( $search->compare( '==', 'order.datepayment', '2008-02-15 12:34:56' ) );
94
95
		$result = $manager->search( $search )->toArray();
96
97
		if( ( $item = reset( $result ) ) === false ) {
98
			throw new \RuntimeException( sprintf( 'No order item for payment date "%1$s" found', '2008-02-15 12:34:56' ) );
99
		}
100
101
		return $item;
102
	}
103
}
104