Completed
Push — master ( f7db67...021307 )
by Aimeos
02:33
created

StandardTest::testGetListsItem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 15
c 1
b 0
f 0
rs 9.4285
cc 2
eloc 10
nc 2
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Customer;
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 = \TestHelperFrontend::getContext();
21
		$this->object = new \Aimeos\Controller\Frontend\Customer\Standard( $this->context );
22
	}
23
24
25
	protected function tearDown()
26
	{
27
		unset( $this->context, $this->object );
28
	}
29
30
31
	public function testAddEditSaveDeleteItem()
32
	{
33
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' );
34
		$id = $manager->findItem( 'UTC001' )->getId();
35
36
		$this->context->setUserId( $id );
37
		$item = $this->object->addItem( ['customer.code' => 'unittest-ctnl', 'customer.status' => 1] );
38
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $item );
39
40
		$this->context->setUserId( $item->getId() );
41
		$item = $this->object->editItem( $item->getId(), ['customer.code' => 'unittest-ctnl2'] );
42
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $item );
43
44
		$item->setStatus( 0 );
45
		$this->object->saveItem( $item );
46
		$this->assertEquals( 0, $item->getStatus() );
47
48
		$this->object->deleteItem( $item->getId() );
49
50
		$this->setExpectedException( '\Aimeos\MShop\Exception' );
51
		$manager->findItem( 'unittest-ctnl' );
52
	}
53
54
55
	public function testCreateItem()
56
	{
57
		$result = $this->object->createItem();
58
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $result );
59
	}
60
61
62
	public function testGetItem()
63
	{
64
		$id = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->findItem( 'UTC001' )->getId();
65
		$this->context->setUserId( $id );
66
67
		$result = $this->object->getItem( $id, ['customer/address', 'text'] );
68
69
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $result );
70
		$this->assertEquals( 1, count( $result->getRefItems( 'text' ) ) );
71
		$this->assertEquals( 1, count( $result->getAddressItems() ) );
72
	}
73
74
75
	public function testFindItem()
76
	{
77
		$result = $this->object->findItem( 'UTC001' );
78
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $result );
79
	}
80
81
82
	public function testAddEditSaveDeleteAddressItem()
83
	{
84
		$customer = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->findItem( 'UTC001' );
85
		$this->context->setUserId( $customer->getId() );
86
87
		$item = $this->object->addAddressItem( ['customer.address.lastname' => 'unittest-ctnl'] );
88
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $item );
89
90
		$item = $this->object->editAddressItem( $item->getId(), ['customer.address.lastname' => 'unittest-ctnl2'] );
91
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $item );
92
93
		$item->setLastName( 'test' );
94
		$this->object->saveAddressItem( $item );
95
		$this->assertEquals( 'test', $item->getLastName() );
96
97
		$this->object->deleteAddressItem( $item->getId() );
98
	}
99
100
101
	public function testCreateAddressItem()
102
	{
103
		$result = $this->object->createAddressItem();
104
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $result );
105
	}
106
107
108
	public function testGetAddressItem()
109
	{
110
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer/address' );
111
		$search = $manager->createSearch();
112
		$search->setSlice( 0, 1 );
113
		$result = $manager->searchItems( $search );
114
115
		if( ( $item = reset( $result ) ) === false ) {
116
			throw new \RuntimeException( 'No customer address available' );
117
		}
118
119
		$this->context->setUserId( $item->getParentId() );
120
		$result = $this->object->getAddressItem( $item->getId() );
121
		$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $result );
122
	}
123
124
125
	public function testAddEditDeleteListsItem()
126
	{
127
		$customer = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->findItem( 'UTC001' );
128
		$this->context->setUserId( $customer->getId() );
129
130
		$values = [
131
			'customer.lists.type' => 'favorite',
132
			'customer.lists.domain' => 'product',
133
			'customer.lists.refid' => '-1'
134
		];
135
136
		$item = $this->object->addListsItem( $values );
137
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Lists\Iface', $item );
138
139
		$item = $this->object->editListsItem( $item->getId(), ['customer.lists.refid' => '-2'] );
140
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Lists\Iface', $item );
141
142
		$this->object->deleteListsItem( $item->getId() );
143
144
		$this->setExpectedException( '\Aimeos\MShop\Exception' );
145
		$this->object->getListsItem( $item->getId() );
146
	}
147
148
149
	public function testGetListsItem()
150
	{
151
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer/lists' );
152
		$search = $manager->createSearch();
153
		$search->setSlice( 0, 1 );
154
		$result = $manager->searchItems( $search );
155
156
		if( ( $item = reset( $result ) ) === false ) {
157
			throw new \RuntimeException( 'No customer lists item available' );
158
		}
159
160
		$this->context->setUserId( $item->getParentId() );
161
		$result = $this->object->getListsItem( $item->getId() );
162
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Lists\Iface', $result );
163
	}
164
165
166
	public function testSearchListsItem()
167
	{
168
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' );
169
		$customer = $manager->findItem( 'UTC001' );
170
		$this->context->setUserId( $customer->getId() );
171
172
		$filter = $this->object->createListsFilter();
173
		$result = $this->object->searchListsItems( $filter );
174
175
		foreach( $result as $item )
176
		{
177
			$this->assertEquals( $customer->getId(), $item->getParentId() );
178
			$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Lists\Iface', $item );
179
		}
180
	}
181
}
182