|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2025 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Jobs\Order\Export\Csv; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $context; |
|
15
|
|
|
private $object; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() : void |
|
19
|
|
|
{ |
|
20
|
|
|
$this->context = \TestHelper::context(); |
|
21
|
|
|
$aimeos = \TestHelper::getAimeos(); |
|
22
|
|
|
|
|
23
|
|
|
$this->object = new \Aimeos\Controller\Jobs\Order\Export\Csv\Standard( $this->context, $aimeos ); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
protected function tearDown() : void |
|
28
|
|
|
{ |
|
29
|
|
|
unset( $this->object, $this->context ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
public function testGetName() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->assertEquals( 'Order export CSV', $this->object->getName() ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
public function testGetDescription() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->assertEquals( 'Exports orders to CSV file', $this->object->getDescription() ); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
public function testRun() |
|
46
|
|
|
{ |
|
47
|
|
|
$mqmStub = $this->getMockBuilder( '\\Aimeos\\Base\\MQueue\\Manager\\Standard' ) |
|
48
|
|
|
->setConstructorArgs( [[]] ) |
|
49
|
|
|
->onlyMethods( ['get'] ) |
|
50
|
|
|
->getMock(); |
|
51
|
|
|
|
|
52
|
|
|
$mqStub = $this->getMockBuilder( '\\Aimeos\\Base\\MQueue\\Standard' ) |
|
53
|
|
|
->disableOriginalConstructor() |
|
54
|
|
|
->onlyMethods( ['getQueue'] ) |
|
55
|
|
|
->getMock(); |
|
56
|
|
|
|
|
57
|
|
|
$queueStub = $this->getMockBuilder( '\\Aimeos\\Base\\MQueue\\Queue\\Standard' ) |
|
58
|
|
|
->disableOriginalConstructor() |
|
59
|
|
|
->onlyMethods( ['del', 'get'] ) |
|
60
|
|
|
->getMock(); |
|
61
|
|
|
|
|
62
|
|
|
$msgStub = $this->getMockBuilder( '\\Aimeos\\Base\\MQueue\\Message\\Standard' ) |
|
63
|
|
|
->disableOriginalConstructor() |
|
64
|
|
|
->onlyMethods( ['getBody'] ) |
|
65
|
|
|
->getMock(); |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
$this->context->setMessageQueueManager( $mqmStub ); |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$mqmStub->expects( $this->once() )->method( 'get' ) |
|
72
|
|
|
->willReturn( $mqStub ); |
|
73
|
|
|
|
|
74
|
|
|
$mqStub->expects( $this->once() )->method( 'getQueue' ) |
|
75
|
|
|
->willReturn( $queueStub ); |
|
76
|
|
|
|
|
77
|
|
|
$queueStub->expects( $this->exactly( 2 ) )->method( 'get' ) |
|
78
|
|
|
->willReturn( $msgStub, null ); |
|
79
|
|
|
|
|
80
|
|
|
$queueStub->expects( $this->once() )->method( 'del' ); |
|
81
|
|
|
|
|
82
|
|
|
$msgStub->expects( $this->once() )->method( 'getBody' ) |
|
83
|
|
|
->willReturn( '{"sitecode":"unittest"}' ); |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
$this->object->run(); |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
$jobManager = \Aimeos\MAdmin::create( $this->context, 'job' ); |
|
90
|
|
|
$jobSearch = $jobManager->filter(); |
|
91
|
|
|
$jobSearch->setConditions( $jobSearch->compare( '=~', 'job.label', 'order-export_' ) ); |
|
92
|
|
|
$jobItems = $jobManager->search( $jobSearch ); |
|
93
|
|
|
$jobManager->delete( $jobItems->toArray() ); |
|
94
|
|
|
|
|
95
|
|
|
$this->assertEquals( 1, count( $jobItems ) ); |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
$filename = dirname( dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) ) . '/tmp/' . $jobItems->first()->getLabel(); |
|
99
|
|
|
$fp = fopen( $filename, 'r' ); |
|
100
|
|
|
|
|
101
|
|
|
$invoice = fgetcsv( $fp, null, ',', '"', '' ); |
|
102
|
|
|
$address1 = fgetcsv( $fp, null, ',', '"', '' ); |
|
103
|
|
|
$address2 = fgetcsv( $fp, null, ',', '"', '' ); |
|
104
|
|
|
$service1 = fgetcsv( $fp, null, ',', '"', '' ); |
|
105
|
|
|
$service2 = fgetcsv( $fp, null, ',', '"', '' ); |
|
106
|
|
|
$coupon1 = fgetcsv( $fp, null, ',', '"', '' ); |
|
107
|
|
|
$coupon2 = fgetcsv( $fp, null, ',', '"', '' ); |
|
108
|
|
|
$product1 = fgetcsv( $fp, null, ',', '"', '' ); |
|
109
|
|
|
$product2 = fgetcsv( $fp, null, ',', '"', '' ); |
|
110
|
|
|
$product3 = fgetcsv( $fp, null, ',', '"', '' ); |
|
111
|
|
|
$product4 = fgetcsv( $fp, null, ',', '"', '' ); |
|
112
|
|
|
|
|
113
|
|
|
fclose( $fp ); |
|
114
|
|
|
unlink( $filename ); |
|
115
|
|
|
|
|
116
|
|
|
$this->assertEquals( 'invoice', $invoice[0] ); |
|
117
|
|
|
$this->assertEquals( 'address', $address1[0] ); |
|
118
|
|
|
$this->assertEquals( 'address', $address2[0] ); |
|
119
|
|
|
$this->assertEquals( 'service', $service1[0] ); |
|
120
|
|
|
$this->assertEquals( 'service', $service2[0] ); |
|
121
|
|
|
$this->assertEquals( 'coupon', $coupon1[0] ); |
|
122
|
|
|
$this->assertEquals( 'coupon', $coupon2[0] ); |
|
123
|
|
|
$this->assertEquals( 'product', $product1[0] ); |
|
124
|
|
|
$this->assertEquals( 'product', $product2[0] ); |
|
125
|
|
|
$this->assertEquals( 'product', $product3[0] ); |
|
126
|
|
|
$this->assertEquals( 'product', $product4[0] ); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|