Passed
Push — master ( e68c42...a842b1 )
by Aimeos
01:54
created

StandardTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
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\Common\Import\Xml\Processor\Lists\Product;
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\Lists\Product\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
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
35
36
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
37
<product>
38
	<productitem ref="CNC" lists.type="default" />
39
	<productitem ref="CNE" lists.type="test" />
40
</product>' );
41
42
		$product = $this->object->process( $manager->createItem(), $dom->firstChild );
43
44
		$this->assertEquals( 2, count( $product->getListItems() ) );
45
		$this->assertNotNull( $product->getListItem( 'product', 'test', $manager->findItem( 'CNE' )->getId() ) );
46
		$this->assertNotNull( $product->getListItem( 'product', 'default', $manager->findItem( 'CNC' )->getId() ) );
47
	}
48
49
50
	public function testProcessUpdate()
51
	{
52
		$dom = new \DOMDocument();
53
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
54
		$listManager = \Aimeos\MShop::create( $this->context, 'product/lists' );
55
56
		$product = $manager->createItem();
57
		$refId1 = $manager->findItem( 'CNC' )->getId();
58
		$refId2 = $manager->findItem( 'CNE' )->getId();
59
60
		$product->addListItem( 'product',
61
			$listManager->createItem()->setType( 'default' )->setId( 1 )->setRefId( $refId1 )
1 ignored issue
show
Bug introduced by
The method setRefId() does not exist on Aimeos\MShop\Common\Item\Iface. Did you maybe mean setId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
			$listManager->createItem()->setType( 'default' )->setId( 1 )->/** @scrutinizer ignore-call */ setRefId( $refId1 )

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.

Loading history...
62
		);
63
		$product->addListItem( 'product',
64
			$listManager->createItem()->setType( 'test' )->setId( 2 )->setRefId( $refId2 )
65
		);
66
67
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
68
<product>
69
	<productitem ref="CNE" lists.type="test" />
70
	<productitem ref="CNC" lists.type="default" />
71
</product>' );
72
73
		$product = $this->object->process( $product, $dom->firstChild );
74
75
		$this->assertEquals( 2, count( $product->getListItems() ) );
76
		$this->assertNotNull( $product->getListItem( 'product', 'test', $refId2 ) );
77
		$this->assertNotNull( $product->getListItem( 'product', 'default', $refId1 ) );
78
	}
79
80
81
	public function testProcessDelete()
82
	{
83
		$dom = new \DOMDocument();
84
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
85
		$listManager = \Aimeos\MShop::create( $this->context, 'product/lists' );
86
87
		$product = $manager->createItem();
88
		$refId1 = $manager->findItem( 'CNC' )->getId();
89
		$refId2 = $manager->findItem( 'CNE' )->getId();
90
91
		$product->addListItem( 'product',
92
			$listManager->createItem()->setType( 'default' )->setId( 1 )->setRefId( $refId1 )
93
		);
94
		$product->addListItem( 'product',
95
			$listManager->createItem()->setType( 'test' )->setId( 2 )->setRefId( $refId2 )
96
		);
97
98
		$dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
99
<product>
100
	<productitem ref="CNE" lists.type="default" />
101
</product>' );
102
103
		$product = $this->object->process( $product, $dom->firstChild );
104
105
		$this->assertEquals( 1, count( $product->getListItems() ) );
106
		$this->assertNotNull( $product->getListItem( 'product', 'default', $refId2 ) );
107
	}
108
}
109