Passed
Push — master ( e3443a...9a4066 )
by Aimeos
01:47
created

StandardTest::testProcessDelete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 40
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 22
nc 2
nop 0
dl 0
loc 40
rs 9.568
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\Common\Import\Xml\Processor\Lists\Text;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
1 ignored issue
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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\Lists\Text\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
		$product = \Aimeos\MShop::create( $this->context, 'product' )->createItem();
35
36
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
37
<text>
38
	<textitem lists.type="default">
39
		<text.type><![CDATA[name]]></text.type>
40
		<text.languageid><![CDATA[de]]></text.languageid>
41
		<text.content><![CDATA[Test]]></text.content>
42
	</textitem>
43
	<textitem lists.type="test">
44
		<text.type><![CDATA[short]]></text.type>
45
		<text.languageid><![CDATA[de]]></text.languageid>
46
		<text.content><![CDATA[Kurztest]]></text.content>
47
	</textitem>
48
</text>' );
49
50
		$product = $this->object->process( $product, $dom->firstChild );
51
52
		$pos = 0;
53
		$expected = [['default', 'name', 'de', 'Test'], ['test', 'short', 'de', 'Kurztest']];
54
55
		$listItems = $product->getListItems( 'text' );
56
		$this->assertEquals( 2, count( $listItems ) );
57
58
		foreach( $listItems as $listItem )
59
		{
60
			$this->assertEquals( $expected[$pos][0], $listItem->getType() );
61
			$this->assertEquals( $expected[$pos][1], $listItem->getRefItem()->getType() );
62
			$this->assertEquals( $expected[$pos][2], $listItem->getRefItem()->getLanguageId() );
63
			$this->assertEquals( $expected[$pos][3], $listItem->getRefItem()->getContent() );
64
			$pos++;
65
		}
66
	}
67
68
69
	public function testProcessUpdate()
70
	{
71
		$dom = new \DOMDocument();
72
		$manager = \Aimeos\MShop::create( $this->context, 'text' );
73
		$listManager = \Aimeos\MShop::create( $this->context, 'product/lists' );
74
		$product = \Aimeos\MShop::create( $this->context, 'product' )->createItem();
75
76
		$product->addListItem( 'text',
77
			$listManager->createItem()->setType( 'default' )->setId( 1 ),
78
			$manager->createItem()->setType( 'name' )->setLanguageId( 'de' )->setContent( 'Test' )
79
		);
80
		$product->addListItem( 'text',
81
			$listManager->createItem()->setType( 'test' )->setId( 2 ),
82
			$manager->createItem()->setType( 'short' )->setLanguageId( 'de' )->setContent( 'Kurztest' )
83
		);
84
85
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
86
<text>
87
	<textitem lists.type="test">
88
		<text.type><![CDATA[short]]></text.type>
89
		<text.languageid><![CDATA[de]]></text.languageid>
90
		<text.content><![CDATA[Kurztest]]></text.content>
91
	</textitem>
92
	<textitem lists.type="default">
93
		<text.type><![CDATA[name]]></text.type>
94
		<text.languageid><![CDATA[de]]></text.languageid>
95
		<text.content><![CDATA[Test]]></text.content>
96
	</textitem>
97
</text>' );
98
99
		$product = $this->object->process( $product, $dom->firstChild );
100
101
		$pos = 0;
102
		$expected = [['test', 'short', 'de', 'Kurztest'], ['default', 'name', 'de', 'Test']];
103
104
		$listItems = $product->getListItems();
105
		$this->assertEquals( 2, count( $listItems ) );
106
107
		foreach( $listItems as $listItem )
108
		{
109
			$this->assertEquals( $expected[$pos][0], $listItem->getType() );
110
			$this->assertEquals( $expected[$pos][1], $listItem->getRefItem()->getType() );
111
			$this->assertEquals( $expected[$pos][2], $listItem->getRefItem()->getLanguageId() );
112
			$this->assertEquals( $expected[$pos][3], $listItem->getRefItem()->getContent() );
113
			$pos++;
114
		}
115
	}
116
117
118
	public function testProcessDelete()
119
	{
120
		$dom = new \DOMDocument();
121
		$manager = \Aimeos\MShop::create( $this->context, 'text' );
122
		$listManager = \Aimeos\MShop::create( $this->context, 'product/lists' );
123
		$product = \Aimeos\MShop::create( $this->context, 'product' )->createItem();
124
125
		$product->addListItem( 'text',
126
			$listManager->createItem()->setType( 'default' )->setId( 1 ),
127
			$manager->createItem()->setType( 'name' )->setLanguageId( 'de' )->setContent( 'Test' )
128
		);
129
		$product->addListItem( 'text',
130
			$listManager->createItem()->setType( 'test' )->setId( 2 ),
131
			$manager->createItem()->setType( 'short' )->setLanguageId( 'de' )->setContent( 'Kurztest' )
132
		);
133
134
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
135
<text>
136
	<textitem lists.type="default">
137
		<text.type><![CDATA[short]]></text.type>
138
		<text.languageid><![CDATA[de]]></text.languageid>
139
		<text.content><![CDATA[Kurztest]]></text.content>
140
	</textitem>
141
</text>' );
142
143
		$product = $this->object->process( $product, $dom->firstChild );
144
145
		$pos = 0;
146
		$expected = [['default', 'short', 'de', 'Kurztest']];
147
148
		$listItems = $product->getListItems();
149
		$this->assertEquals( 1, count( $listItems ) );
150
151
		foreach( $listItems as $listItem )
152
		{
153
			$this->assertEquals( $expected[$pos][0], $listItem->getType() );
154
			$this->assertEquals( $expected[$pos][1], $listItem->getRefItem()->getType() );
155
			$this->assertEquals( $expected[$pos][2], $listItem->getRefItem()->getLanguageId() );
156
			$this->assertEquals( $expected[$pos][3], $listItem->getRefItem()->getContent() );
157
			$pos++;
158
		}
159
	}
160
}
161