|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2019-2023 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Service\Provider\Delivery; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class XmlTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $context; |
|
15
|
|
|
private $object; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() : void |
|
19
|
|
|
{ |
|
20
|
|
|
file_exists( 'tmp' ) ?: mkdir( 'tmp' ); |
|
21
|
|
|
|
|
22
|
|
|
$this->context = \TestHelper::context(); |
|
23
|
|
|
$serviceManager = \Aimeos\MShop::create( $this->context, 'service' ); |
|
24
|
|
|
$serviceItem = $serviceManager->create()->setConfig( [ |
|
25
|
|
|
'xml.exportpath' => 'tmp/order-export_%d.xml', |
|
26
|
|
|
'xml.updatedir' => __DIR__ . '/_tests', |
|
27
|
|
|
] ); |
|
28
|
|
|
|
|
29
|
|
|
$this->object = new \Aimeos\MShop\Service\Provider\Delivery\Xml( $this->context, $serviceItem ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
protected function tearDown() : void |
|
34
|
|
|
{ |
|
35
|
|
|
\Aimeos\MShop::cache( false ); |
|
36
|
|
|
unset( $this->object ); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
public function testGetConfigBE() |
|
41
|
|
|
{ |
|
42
|
|
|
$result = $this->object->getConfigBE(); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertEquals( 4, count( $result ) ); |
|
45
|
|
|
|
|
46
|
|
|
foreach( $result as $key => $item ) { |
|
47
|
|
|
$this->assertInstanceOf( 'Aimeos\Base\Criteria\Attribute\Iface', $item ); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
public function testCheckConfigBE() |
|
53
|
|
|
{ |
|
54
|
|
|
$attributes = [ |
|
55
|
|
|
'xml.backupdir' => '/backup', |
|
56
|
|
|
'xml.exportpath' => 'order-%H:%i:%s.xml', |
|
57
|
|
|
'xml.template' => 'body.xml', |
|
58
|
|
|
'xml.updatedir' => '/', |
|
59
|
|
|
]; |
|
60
|
|
|
|
|
61
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertEquals( 4, count( $result ) ); |
|
64
|
|
|
$this->assertEquals( null, $result['xml.backupdir'] ); |
|
65
|
|
|
$this->assertEquals( null, $result['xml.exportpath'] ); |
|
66
|
|
|
$this->assertEquals( null, $result['xml.template'] ); |
|
67
|
|
|
$this->assertEquals( null, $result['xml.updatedir'] ); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
public function testPush() |
|
72
|
|
|
{ |
|
73
|
|
|
$orders = $this->object->push( [$this->getOrderItem()] ); |
|
74
|
|
|
$file = 'tmp/order-export_' . date( 'd' ) . '.xml'; |
|
75
|
|
|
$xml = simplexml_load_file( $file ); |
|
76
|
|
|
unlink( $file ); |
|
77
|
|
|
|
|
78
|
|
|
$this->assertEquals( 1, count( $orders ) ); |
|
79
|
|
|
$this->assertEquals( \Aimeos\MShop\Order\Item\Base::STAT_PROGRESS, $orders->getStatusDelivery()->first() ); |
|
80
|
|
|
$this->assertEquals( '2008-02-15 12:34:56', (string) $xml->orderitem[0]->{'order.datepayment'} ); |
|
81
|
|
|
$this->assertEquals( 'unittest', (string) $xml->orderitem[0]->{'order.sitecode'} ); |
|
82
|
|
|
$this->assertEquals( 'payment', (string) $xml->orderitem[0]->address->addressitem[0]['type'] ); |
|
83
|
|
|
$this->assertEquals( 0, (string) $xml->orderitem[0]->address->addressitem[0]['position'] ); |
|
84
|
|
|
$this->assertEquals( 1, (string) $xml->orderitem[0]->product->productitem[0]['position'] ); |
|
85
|
|
|
$this->assertEquals( 3, (string) $xml->orderitem[0]->product->productitem[0]->attribute->attributeitem->count() ); |
|
86
|
|
|
$this->assertEquals( 'payment', (string) $xml->orderitem[0]->service->serviceitem[0]['type'] ); |
|
87
|
|
|
$this->assertEquals( 0, (string) $xml->orderitem[0]->service->serviceitem[0]['position'] ); |
|
88
|
|
|
$this->assertEquals( 9, (string) $xml->orderitem[0]->service->serviceitem[0]->attribute->attributeitem->count() ); |
|
89
|
|
|
$this->assertEquals( 2, (string) $xml->orderitem[0]->coupon->couponitem->count() ); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
public function testUpdateAsync() |
|
94
|
|
|
{ |
|
95
|
|
|
\Aimeos\MShop::cache( true ); |
|
96
|
|
|
|
|
97
|
|
|
$price = \Aimeos\MShop::create( $this->context, 'price' )->create(); |
|
98
|
|
|
$locale = \Aimeos\MShop::create( $this->context, 'locale' )->create(); |
|
99
|
|
|
|
|
100
|
|
|
$itemMock = $this->getMockBuilder( \Aimeos\MShop\Order\Item\Standard::class ) |
|
101
|
|
|
->setMethods( ['setStatusDelivery', 'setStatusPayment', 'setDateDelivery', 'setDatePayment'] ) |
|
102
|
|
|
->setConstructorArgs( [$price, $locale, []] ) |
|
103
|
|
|
->getMock(); |
|
104
|
|
|
|
|
105
|
|
|
$itemMock->expects( $this->once() )->method( 'setStatusDelivery' )->will( $this->returnSelf() ); |
|
106
|
|
|
$itemMock->expects( $this->once() )->method( 'setStatusPayment' )->will( $this->returnSelf() ); |
|
107
|
|
|
$itemMock->expects( $this->once() )->method( 'setDateDelivery' )->will( $this->returnSelf() ); |
|
108
|
|
|
$itemMock->expects( $this->once() )->method( 'setDatePayment' )->will( $this->returnSelf() ); |
|
109
|
|
|
|
|
110
|
|
|
$mock = $this->getMockBuilder( \Aimeos\MShop\Order\Manager\Standard::class ) |
|
111
|
|
|
->setMethods( ['save', 'search'] ) |
|
112
|
|
|
->setConstructorArgs( [$this->context] ) |
|
113
|
|
|
->getMock(); |
|
114
|
|
|
|
|
115
|
|
|
$mock->expects( $this->once() )->method( 'search' ) |
|
116
|
|
|
->will( $this->returnValue( map( ['123' => $itemMock] ) ) ); |
|
117
|
|
|
|
|
118
|
|
|
$mock->expects( $this->once() )->method( 'save' ); |
|
119
|
|
|
|
|
120
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Order\Manager\Standard::class, $mock ); |
|
121
|
|
|
|
|
122
|
|
|
$this->object->updateAsync(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
protected function getOrderItem() |
|
127
|
|
|
{ |
|
128
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'order' ); |
|
129
|
|
|
|
|
130
|
|
|
$search = $manager->filter()->add( 'order.datepayment', '==', '2008-02-15 12:34:56' ); |
|
131
|
|
|
$ref = ['order/address', 'order/coupon', 'order/product', 'order/service']; |
|
132
|
|
|
|
|
133
|
|
|
return $manager->search( $search, $ref ) |
|
134
|
|
|
->first( new \RuntimeException( sprintf( 'No order item for payment date "%1$s" found', '2008-02-15 12:34:56' ) ) ); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|