|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2019 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Common\Common\Import\Xml\Processor\Address; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $context; |
|
15
|
|
|
private $object; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->context = \TestHelperCntl::getContext(); |
|
21
|
|
|
$this->object = new \Aimeos\Controller\Common\Common\Import\Xml\Processor\Address\Standard( $this->context ); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
protected function tearDown() |
|
26
|
|
|
{ |
|
27
|
|
|
unset( $this->object, $this->context ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
public function testProcess() |
|
32
|
|
|
{ |
|
33
|
|
|
$dom = new \DOMDocument(); |
|
34
|
|
|
$customer = \Aimeos\MShop::create( $this->context, 'customer' )->createItem(); |
|
35
|
|
|
|
|
36
|
|
|
$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?> |
|
37
|
|
|
<address> |
|
38
|
|
|
<addressitem> |
|
39
|
|
|
<customer.address.salutation><![CDATA[mr]]></customer.address.salutation> |
|
40
|
|
|
<customer.address.firstname><![CDATA[Test]]></customer.address.firstname> |
|
41
|
|
|
<customer.address.lastname><![CDATA[User]]></customer.address.lastname> |
|
42
|
|
|
</addressitem> |
|
43
|
|
|
<addressitem> |
|
44
|
|
|
<customer.address.salutation><![CDATA[mrs]]></customer.address.salutation> |
|
45
|
|
|
<customer.address.firstname><![CDATA[Mytest]]></customer.address.firstname> |
|
46
|
|
|
<customer.address.lastname><![CDATA[Lastuser]]></customer.address.lastname> |
|
47
|
|
|
</addressitem> |
|
48
|
|
|
</address>' ); |
|
49
|
|
|
|
|
50
|
|
|
$customer = $this->object->process( $customer, $dom->firstChild ); |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
$pos = 0; |
|
54
|
|
|
$expected = [['mr', 'Test', 'User'], ['mrs', 'Mytest', 'Lastuser']]; |
|
55
|
|
|
|
|
56
|
|
|
$items = $customer->getAddressItems(); |
|
57
|
|
|
$this->assertEquals( 2, count( $items ) ); |
|
58
|
|
|
|
|
59
|
|
|
foreach( $items as $item ) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->assertEquals( $expected[$pos][0], $item->getSalutation() ); |
|
62
|
|
|
$this->assertEquals( $expected[$pos][1], $item->getFirstname() ); |
|
63
|
|
|
$this->assertEquals( $expected[$pos][2], $item->getLastname() ); |
|
64
|
|
|
$pos++; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
public function testProcessUpdate() |
|
70
|
|
|
{ |
|
71
|
|
|
$dom = new \DOMDocument(); |
|
72
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'customer/address' ); |
|
73
|
|
|
$customer = \Aimeos\MShop::create( $this->context, 'customer' )->createItem(); |
|
74
|
|
|
|
|
75
|
|
|
$customer->addAddressItem( $manager->createItem()->setSalutation( 'mr' ) |
|
|
|
|
|
|
76
|
|
|
->setFirstname( 'Test' )->setLastname( 'User' )->setId( 1 ), 1 ); |
|
77
|
|
|
$customer->addAddressItem( $manager->createItem()->setSalutation( 'mrs' ) |
|
78
|
|
|
->setFirstname( 'Mytest' )->setLastname( 'Lastuser' )->setId( 2 ), 2 ); |
|
79
|
|
|
|
|
80
|
|
|
$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?> |
|
81
|
|
|
<address> |
|
82
|
|
|
<addressitem> |
|
83
|
|
|
<customer.address.salutation><![CDATA[mrs]]></customer.address.salutation> |
|
84
|
|
|
<customer.address.firstname><![CDATA[Mytest]]></customer.address.firstname> |
|
85
|
|
|
<customer.address.lastname><![CDATA[Lastuser]]></customer.address.lastname> |
|
86
|
|
|
</addressitem> |
|
87
|
|
|
<addressitem> |
|
88
|
|
|
<customer.address.salutation><![CDATA[mr]]></customer.address.salutation> |
|
89
|
|
|
<customer.address.firstname><![CDATA[Test]]></customer.address.firstname> |
|
90
|
|
|
<customer.address.lastname><![CDATA[User]]></customer.address.lastname> |
|
91
|
|
|
</addressitem> |
|
92
|
|
|
</address>' ); |
|
93
|
|
|
|
|
94
|
|
|
$customer = $this->object->process( $customer, $dom->firstChild ); |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
$pos = 0; |
|
98
|
|
|
$expected = [['mrs', 'Mytest', 'Lastuser'], ['mr', 'Test', 'User']]; |
|
99
|
|
|
|
|
100
|
|
|
$items = $customer->getAddressItems(); |
|
101
|
|
|
$this->assertEquals( 2, count( $items ) ); |
|
102
|
|
|
|
|
103
|
|
|
foreach( $items as $item ) |
|
104
|
|
|
{ |
|
105
|
|
|
$this->assertEquals( $expected[$pos][0], $item->getSalutation() ); |
|
106
|
|
|
$this->assertEquals( $expected[$pos][1], $item->getFirstname() ); |
|
107
|
|
|
$this->assertEquals( $expected[$pos][2], $item->getLastname() ); |
|
108
|
|
|
$pos++; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
public function testProcessDelete() |
|
114
|
|
|
{ |
|
115
|
|
|
$dom = new \DOMDocument(); |
|
116
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'customer/address' ); |
|
117
|
|
|
$customer = \Aimeos\MShop::create( $this->context, 'customer' )->createItem(); |
|
118
|
|
|
|
|
119
|
|
|
$customer->addAddressItem( $manager->createItem()->setSalutation( 'mr' ) |
|
120
|
|
|
->setFirstname( 'Test' )->setLastname( 'User' )->setId( 1 ), 1 ); |
|
121
|
|
|
$customer->addAddressItem( $manager->createItem()->setSalutation( 'mrs' ) |
|
122
|
|
|
->setFirstname( 'Mytest' )->setLastname( 'Lastuser' )->setId( 2 ), 2 ); |
|
123
|
|
|
|
|
124
|
|
|
$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?> |
|
125
|
|
|
<address> |
|
126
|
|
|
<addressitem> |
|
127
|
|
|
<customer.address.salutation><![CDATA[mr]]></customer.address.salutation> |
|
128
|
|
|
<customer.address.firstname><![CDATA[Test]]></customer.address.firstname> |
|
129
|
|
|
<customer.address.lastname><![CDATA[User]]></customer.address.lastname> |
|
130
|
|
|
</addressitem> |
|
131
|
|
|
</address>' ); |
|
132
|
|
|
|
|
133
|
|
|
$customer = $this->object->process( $customer, $dom->firstChild ); |
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
$pos = 0; |
|
137
|
|
|
$expected = [['mr', 'Test', 'User']]; |
|
138
|
|
|
|
|
139
|
|
|
$items = $customer->getAddressItems(); |
|
140
|
|
|
$this->assertEquals( 1, count( $items ) ); |
|
141
|
|
|
|
|
142
|
|
|
foreach( $items as $item ) |
|
143
|
|
|
{ |
|
144
|
|
|
$this->assertEquals( $expected[$pos][0], $item->getSalutation() ); |
|
145
|
|
|
$this->assertEquals( $expected[$pos][1], $item->getFirstname() ); |
|
146
|
|
|
$this->assertEquals( $expected[$pos][2], $item->getLastname() ); |
|
147
|
|
|
$pos++; |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.