StandardTest::testProcess()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 19
rs 9.9666
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-2025
6
 */
7
8
9
namespace Aimeos\Controller\Jobs\Common\Import\Xml\Processor\Lists\Attribute;
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
		$this->object = new \Aimeos\Controller\Jobs\Common\Import\Xml\Processor\Lists\Attribute\Standard( $this->context );
22
	}
23
24
25
	protected function tearDown() : void
26
	{
27
		unset( $this->object, $this->context );
28
	}
29
30
31
	public function testProcess()
32
	{
33
		$dom = new \DOMDocument();
34
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
35
36
		$refId1 = $manager->find( 'black', [], 'product', 'color' )->getId();
37
		$refId2 = $manager->find( 'white', [], 'product', 'color' )->getId();
38
39
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
40
<attribute>
41
	<attributeitem ref="product|color|black" lists.type="default" />
42
	<attributeitem ref="product|color|white" lists.type="test" />
43
</attribute>' );
44
45
		$attribute = $this->object->process( $manager->create(), $dom->firstChild );
46
47
		$this->assertEquals( 2, count( $attribute->getListItems() ) );
48
		$this->assertNotNull( $attribute->getListItem( 'attribute', 'test', $refId2 ) );
49
		$this->assertNotNull( $attribute->getListItem( 'attribute', 'default', $refId1 ) );
50
	}
51
52
53
	public function testProcessUpdate()
54
	{
55
		$dom = new \DOMDocument();
56
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
57
		$listManager = \Aimeos\MShop::create( $this->context, 'attribute/lists' );
58
59
		$attribute = $manager->create();
60
		$refId1 = $manager->find( 'black', [], 'product', 'color' )->getId();
61
		$refId2 = $manager->find( 'white', [], 'product', 'color' )->getId();
62
63
		$attribute->addListItem( 'attribute',
64
			$listManager->create()->setType( 'default' )->setId( 1 )->setRefId( $refId1 )
65
		);
66
		$attribute->addListItem( 'attribute',
67
			$listManager->create()->setType( 'test' )->setId( 2 )->setRefId( $refId2 )
68
		);
69
70
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
71
<attribute>
72
	<attributeitem ref="product|color|white" lists.type="test" />
73
	<attributeitem ref="product|color|black" lists.type="default" />
74
</attribute>' );
75
76
		$attribute = $this->object->process( $attribute, $dom->firstChild );
77
78
		$this->assertEquals( 2, count( $attribute->getListItems() ) );
79
		$this->assertNotNull( $attribute->getListItem( 'attribute', 'test', $refId2 ) );
80
		$this->assertNotNull( $attribute->getListItem( 'attribute', 'default', $refId1 ) );
81
	}
82
83
84
	public function testProcessDelete()
85
	{
86
		$dom = new \DOMDocument();
87
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
88
		$listManager = \Aimeos\MShop::create( $this->context, 'attribute/lists' );
89
90
		$attribute = $manager->create();
91
		$refId1 = $manager->find( 'black', [], 'product', 'color' )->getId();
92
		$refId2 = $manager->find( 'white', [], 'product', 'color' )->getId();
93
94
		$attribute->addListItem( 'attribute',
95
			$listManager->create()->setType( 'default' )->setId( 1 )->setRefId( $refId1 )
96
		);
97
		$attribute->addListItem( 'attribute',
98
			$listManager->create()->setType( 'test' )->setId( 2 )->setRefId( $refId2 )
99
		);
100
101
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
102
<attribute>
103
	<attributeitem ref="product|color|white" lists.type="default" />
104
</attribute>' );
105
106
		$attribute = $this->object->process( $attribute, $dom->firstChild );
107
108
		$this->assertEquals( 1, count( $attribute->getListItems() ) );
109
		$this->assertNotNull( $attribute->getListItem( 'attribute', 'default', $refId2 ) );
110
	}
111
}
112