Passed
Push — master ( 9a1840...11be31 )
by Aimeos
02:10
created

StandardTest::testProcessDelete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 19
rs 10
c 0
b 0
f 0
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\Customer\Import\Xml\Processor\Group;
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\Customer\Import\Xml\Processor\Group\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
		$grpId = \Aimeos\MShop::create( $this->context, 'customer/group' )->findItem( 'unitgroup' )->getId();
36
37
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
38
<group>
39
	<groupitem ref="unitgroup" />
40
</group>' );
41
42
		$customer = $this->object->process( $customer, $dom->firstChild );
43
44
		$this->assertEquals( 1, count( $customer->getGroups() ) );
45
		$this->assertEquals( $grpId, current( $customer->getGroups() ) );
46
	}
47
48
49
	public function testProcessUpdate()
50
	{
51
		$dom = new \DOMDocument();
52
		$customer = \Aimeos\MShop::create( $this->context, 'customer' )->createItem();
53
		$grpId = \Aimeos\MShop::create( $this->context, 'customer/group' )->findItem( 'unitgroup2' )->getId();
54
55
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
56
<group>
57
	<groupitem ref="unitgroup" />
58
</group>' );
59
60
		$customer = $this->object->process( $customer, $dom->firstChild );
61
62
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
63
<group>
64
	<groupitem ref="unitgroup2" />
65
</group>' );
66
67
		$customer = $this->object->process( $customer, $dom->firstChild );
68
69
		$this->assertEquals( 1, count( $customer->getGroups() ) );
70
		$this->assertEquals( $grpId, current( $customer->getGroups() ) );
71
	}
72
73
74
	public function testProcessDelete()
75
	{
76
		$dom = new \DOMDocument();
77
		$customer = \Aimeos\MShop::create( $this->context, 'customer' )->createItem();
78
79
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
80
<group>
81
	<groupitem ref="unitgroup" />
82
</group>' );
83
84
		$customer = $this->object->process( $customer, $dom->firstChild );
85
86
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
87
<group>
88
</group>' );
89
90
		$customer = $this->object->process( $customer, $dom->firstChild );
91
92
		$this->assertEquals( 0, count( $customer->getGroups() ) );
93
	}
94
}
95