Completed
Push — master ( d9c87d...d2fca1 )
by Aimeos
06:49
created

StandardTest   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 218
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 14
c 2
b 0
f 0
lcom 1
cbo 8
dl 0
loc 218
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A tearDown() 0 4 1
A testGetHeader() 0 5 1
A testGetHeaderException() 0 14 1
A testGetBody() 0 5 1
A testGetBodyHtmlException() 0 14 1
A testGetBodyFrontendException() 0 14 1
A testGetBodyMShopException() 0 14 1
A testGetBodyException() 0 14 1
A testGetSubClientInvalid() 0 5 1
A testGetSubClientInvalidName() 0 5 1
A testProcess() 0 4 1
B testProcessAddItem() 0 40 1
B testProcessDeleteItem() 0 39 1
1
<?php
2
3
namespace Aimeos\Client\Html\Account\Favorite;
4
5
6
/**
7
 * @copyright Metaways Infosystems GmbH, 2014
8
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
9
 * @copyright Aimeos (aimeos.org), 2015
10
 */
11
class StandardTest extends \PHPUnit_Framework_TestCase
12
{
13
	private $object;
14
	private $context;
15
16
17
	protected function setUp()
18
	{
19
		$this->context = \TestHelperHtml::getContext();
20
21
		$paths = \TestHelperHtml::getHtmlTemplatePaths();
22
		$this->object = new \Aimeos\Client\Html\Account\Favorite\Standard( $this->context, $paths );
23
		$this->object->setView( \TestHelperHtml::getView() );
24
	}
25
26
27
	protected function tearDown()
28
	{
29
		unset( $this->object );
30
	}
31
32
33
	public function testGetHeader()
34
	{
35
		$output = $this->object->getHeader();
36
		$this->assertNotNull( $output );
37
	}
38
39
40
	public function testGetHeaderException()
41
	{
42
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Account\Favorite\Standard' )
43
			->setConstructorArgs( array( $this->context, array() ) )
44
			->setMethods( array( 'setViewParams' ) )
45
			->getMock();
46
47
		$object->expects( $this->once() )->method( 'setViewParams' )
48
			->will( $this->throwException( new \Exception() ) );
49
50
		$object->setView( \TestHelperHtml::getView() );
51
52
		$this->assertEquals( null, $object->getHeader() );
53
	}
54
55
56
	public function testGetBody()
57
	{
58
		$output = $this->object->getBody();
59
		$this->assertStringStartsWith( '<section class="aimeos account-favorite">', $output );
60
	}
61
62
63
	public function testGetBodyHtmlException()
64
	{
65
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Account\Favorite\Standard' )
66
			->setConstructorArgs( array( $this->context, array() ) )
67
			->setMethods( array( 'setViewParams' ) )
68
			->getMock();
69
70
		$object->expects( $this->once() )->method( 'setViewParams' )
71
			->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'test exception' ) ) );
72
73
		$object->setView( \TestHelperHtml::getView() );
74
75
		$this->assertContains( 'test exception', $object->getBody() );
76
	}
77
78
79
	public function testGetBodyFrontendException()
80
	{
81
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Account\Favorite\Standard' )
82
			->setConstructorArgs( array( $this->context, array() ) )
83
			->setMethods( array( 'setViewParams' ) )
84
			->getMock();
85
86
		$object->expects( $this->once() )->method( 'setViewParams' )
87
			->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'test exception' ) ) );
88
89
		$object->setView( \TestHelperHtml::getView() );
90
91
		$this->assertContains( 'test exception', $object->getBody() );
92
	}
93
94
95
	public function testGetBodyMShopException()
96
	{
97
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Account\Favorite\Standard' )
98
			->setConstructorArgs( array( $this->context, array() ) )
99
			->setMethods( array( 'setViewParams' ) )
100
			->getMock();
101
102
		$object->expects( $this->once() )->method( 'setViewParams' )
103
			->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) );
104
105
		$object->setView( \TestHelperHtml::getView() );
106
107
		$this->assertContains( 'test exception', $object->getBody() );
108
	}
109
110
111
	public function testGetBodyException()
112
	{
113
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Account\Favorite\Standard' )
114
			->setConstructorArgs( array( $this->context, array() ) )
115
			->setMethods( array( 'setViewParams' ) )
116
			->getMock();
117
118
		$object->expects( $this->once() )->method( 'setViewParams' )
119
			->will( $this->throwException( new \Exception() ) );
120
121
		$object->setView( \TestHelperHtml::getView() );
122
123
		$this->assertContains( 'A non-recoverable error occured', $object->getBody() );
124
	}
125
126
127
	public function testGetSubClientInvalid()
128
	{
129
		$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' );
130
		$this->object->getSubClient( 'invalid', 'invalid' );
131
	}
132
133
134
	public function testGetSubClientInvalidName()
135
	{
136
		$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' );
137
		$this->object->getSubClient( '$$$', '$$$' );
138
	}
139
140
141
	public function testProcess()
142
	{
143
		$this->object->process();
144
	}
145
146
147
	public function testProcessAddItem()
148
	{
149
		$this->context->setUserId( '123' );
150
151
		$view = $this->object->getView();
152
		$param = array(
153
			'fav_action' => 'add',
154
			'fav_id' => 321,
155
		);
156
157
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param );
158
		$view->addHelper( 'param', $helper );
159
160
161
162
		$listManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Customer\\Manager\\Lists\\Standard' )
163
			->setMethods( array( 'saveItem', 'moveItem' ) )
164
			->setConstructorArgs( array( $this->context ) )
165
			->getMock();
166
167
		$managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Customer\\Manager\\Standard' )
168
			->setMethods( array( 'getSubManager' ) )
169
			->setConstructorArgs( array( $this->context ) )
170
			->getMock();
171
172
		$name = 'ClientHtmlAccountFavoriteDefaultProcess';
173
		$this->context->getConfig()->set( 'mshop/customer/manager/name', $name );
174
175
		\Aimeos\MShop\Customer\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Customer\\Manager\\' . $name, $managerStub );
176
177
178
		$managerStub->expects( $this->atLeastOnce() )->method( 'getSubManager' )
179
			->will( $this->returnValue( $listManagerStub ) );
180
181
		$listManagerStub->expects( $this->once() )->method( 'saveItem' );
182
		$listManagerStub->expects( $this->once() )->method( 'moveItem' );
183
184
185
		$this->object->process();
186
	}
187
188
189
	public function testProcessDeleteItem()
190
	{
191
		$this->context->setUserId( '123' );
192
193
		$view = $this->object->getView();
194
		$param = array(
195
			'fav_action' => 'delete',
196
			'fav_id' => 321,
197
		);
198
199
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param );
200
		$view->addHelper( 'param', $helper );
201
202
203
204
		$listManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Customer\\Manager\\Lists\\Standard' )
205
			->setMethods( array( 'deleteItems' ) )
206
			->setConstructorArgs( array( $this->context ) )
207
			->getMock();
208
209
		$managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Customer\\Manager\\Standard' )
210
			->setMethods( array( 'getSubManager' ) )
211
			->setConstructorArgs( array( $this->context ) )
212
			->getMock();
213
214
		$name = 'ClientHtmlAccountFavoriteDefaultProcess';
215
		$this->context->getConfig()->set( 'mshop/customer/manager/name', $name );
216
217
		\Aimeos\MShop\Customer\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Customer\\Manager\\' . $name, $managerStub );
218
219
220
		$managerStub->expects( $this->atLeastOnce() )->method( 'getSubManager' )
221
			->will( $this->returnValue( $listManagerStub ) );
222
223
		$listManagerStub->expects( $this->once() )->method( 'deleteItems' );
224
225
226
		$this->object->process();
227
	}
228
}