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
|
|
|
|